ShortcodeController

The Eewee responsive design ShortcodeController class.

Defined (1)

The class is defined in the following location(s).

/inc/controllers/ShortcodeController.php  
  1. class ShortcodeController{ 
  2.  
  3. public function __construct() { 
  4. $this->initAction(); 
  5.  
  6. /** 
  7. * init des shortcodes 
  8. */ 
  9. public function initAction() { 
  10. add_shortcode('eewee-alert', array($this, 'eewee_shortcode_alert')); 
  11. add_shortcode('eewee-btn', array($this, 'eewee_shortcode_btn')); 
  12. add_shortcode('eewee-img', array($this, 'eewee_shortcode_img')); 
  13. add_shortcode('eewee-color', array($this, 'eewee_shortcode_color')); 
  14. add_shortcode('eewee-bq', array($this, 'eewee_shortcode_blockquote')); 
  15. add_shortcode('eewee-dl', array($this, 'eewee_shortcode_description_dl')); 
  16. add_shortcode('eewee-dt', array($this, 'eewee_shortcode_description_dt')); 
  17. add_shortcode('eewee-dd', array($this, 'eewee_shortcode_description_dd')); 
  18. add_shortcode('eewee-col', array($this, 'eewee_shortcode_col')); 
  19. add_shortcode('eewee-post', array($this, 'eewee_shortcode_post'));  
  20. add_shortcode('eewee-carousel', array($this, 'eewee_shortcode_carousel')); 
  21.  
  22. /** 
  23. * Button 
  24. * @param x $atts 
  25. */ 
  26. public function eewee_shortcode_alert( $atts='', $content=null ) { 
  27. extract(shortcode_atts(array( 
  28. 'type' => 'block', // block, error, success, info 
  29. 'title'=> '', // title H4 
  30. 'mess' => '' // message 
  31. ), $atts)); 
  32.  
  33.  
  34. $a = ' 
  35. <div class="alert alert-'.esc_attr($type).'"> 
  36. <button type="button" class="close" data-dismiss="alert">x</button>'; 
  37.  
  38. if( !empty($title) ) { $a .= '<h4>'.esc_attr($title).'</h4>'; } 
  39. if( !empty($mess) ) { $a .= esc_attr($mess); } 
  40. if( !empty($content) ) { $a .= esc_attr($content); } 
  41.  
  42. $a .= ' 
  43. </div>'; 
  44.  
  45. return $a; 
  46.  
  47. /** 
  48. * Button 
  49. * @param x $atts 
  50. */ 
  51. public function eewee_shortcode_btn( $atts='', $content=null ) { 
  52. extract(shortcode_atts(array( 
  53. 'type' => '', // nothing, primary, info, success, warning, danger, inverse, link 
  54. 'size'=> 'small', // large, small, mini 
  55. 'block' => 'n', // y : yes, n : no 
  56. 'mess' => 'button' // message 
  57. ), $atts)); 
  58.  
  59. if( !empty($type) ) { $typeCustom = "btn-".esc_attr($type); } 
  60. if( !empty($size) ) { $sizeCustom = "btn-".esc_attr($size); } 
  61. if( !empty($block) ) { $blockCustom = "btn-".esc_attr($block); } 
  62.  
  63. $a = ' 
  64. <button class="btn '.$typeCustom.' '.$sizeCustom.' '.$blockCustom.'" type="button">'; 
  65.  
  66. if( !empty($mess) ) { $a .= esc_attr($mess); } 
  67. if( !empty($content) ) { $a .= esc_attr($content); } 
  68.  
  69. $a .= ' 
  70. </button>'; 
  71.  
  72. return $a; 
  73.  
  74. /** 
  75. * Image 
  76. * @param x $atts 
  77. */ 
  78. public function eewee_shortcode_img( $atts='', $content=null ) { 
  79. extract(shortcode_atts(array( 
  80. 'type' => 'rounded', // rounded, circle, polaroid 
  81. 'url' => '' // url of your image 
  82. ), $atts)); 
  83.  
  84.  
  85. $a = '<img src="'.esc_attr($url).'" class="img-'.esc_attr($type).'">'; 
  86.  
  87. return $a; 
  88.  
  89. /** 
  90. * Text color 
  91. * @param x $atts 
  92. */ 
  93. public function eewee_shortcode_color( $atts='', $content=null ) { 
  94. extract(shortcode_atts(array( 
  95. 'type' => 'muted', // muted, warning, error, info, success 
  96. 'mess' => '' // message 
  97. ), $atts)); 
  98.  
  99. if( $type != "muted" && !empty($type) ) { $typeCustom = "text-".esc_attr($type); } 
  100. else{ $typeCustom = $type; } 
  101.  
  102. $a = '<p class="'.esc_attr($typeCustom).'">'.esc_attr($mess).'</p>'; 
  103.  
  104. return $a; 
  105.  
  106. /** 
  107. * Blockquote 
  108. * @param x $atts 
  109. */ 
  110. public function eewee_shortcode_blockquote( $atts='', $content=null ) { 
  111. extract(shortcode_atts(array( 
  112. 'mess' => '', // message big 
  113. 'mess2' => '', // message small 
  114. 'cite' => '', // citation 
  115. 'position' => '' // left, right 
  116. ), $atts)); 
  117.  
  118.  
  119. if( !empty($mess2) ) {  
  120. if( !empty($cite) ) { $cite = '<cite title="'.esc_attr($cite).'">'.esc_attr($cite).'</cite>'; } 
  121. $mess2 = "<small>".esc_attr($mess2)." ".$cite."</small>"; 
  122. if( !empty($position) ) {  
  123. $position = "pull-".esc_attr($position); 
  124.  
  125.  
  126. $a = ' 
  127. <blockquote class="'.$position.'"> 
  128. <p>'.esc_attr($mess).'</p> 
  129. '.$mess2.' 
  130. </blockquote>'; 
  131.  
  132. return $a; 
  133.  
  134. /** 
  135. * Description list 
  136. * @param x $atts 
  137. */ 
  138. public function eewee_shortcode_description_dl( $atts='', $content=null ) { 
  139. extract(shortcode_atts(array( 
  140. 'position' => '' // horizontal 
  141. ), $atts)); 
  142.  
  143. if( empty($position) ) { 
  144. $position = ""; 
  145. }else{ 
  146. $position = "dl-horizontal"; 
  147.  
  148. $a = '<dl class="'.$position.'">'.do_shortcode($content).'</dl>'; 
  149. return $a; 
  150. public function eewee_shortcode_description_dt( $atts='', $content=null ) { 
  151. if( !empty($atts['mess']) ) { $c = $atts['mess']; } 
  152. else{ $c = $content; } 
  153. $a = '<dt>'.$c."</dt>"; 
  154. return $a; 
  155. public function eewee_shortcode_description_dd( $atts='', $content=null ) { 
  156. if( !empty($atts['mess']) ) { $c = $atts['mess']; } 
  157. else{ $c = $content; } 
  158. $a = '<dd>'.$c."</dd>"; 
  159. return $a; 
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. /** 
  171. * Colonne 
  172. * @param x $atts 
  173. */ 
  174. public function eewee_shortcode_col( $atts='', $content=null ) { 
  175. extract(shortcode_atts(array( 
  176. 'f' => 'fluid',  
  177. 't1' => '',  
  178. 't2' => '',  
  179. 't3' => '',  
  180. 't4' => '',  
  181. 'm1' => '',  
  182. 'm2' => '',  
  183. 'm3' => '',  
  184. 'm4' => '' 
  185. ), $atts)); 
  186.  
  187. if( $f == "fluid" ) { $f = '-fluid'; } 
  188. if( empty($t1) ) { $a1 = '<div class="span'.$t1.'">'.$m1.'</div>'; } 
  189. if( empty($t2) ) { $a2 = '<div class="span'.$t2.'">'.$m2.'</div>'; } 
  190. if( empty($t3) ) { $a3 = '<div class="span'.$t3.'">'.$m3.'</div>'; } 
  191. if( empty($t4) ) { $a4 = '<div class="span'.$t4.'">'.$m4.'</div>'; } 
  192.  
  193. $a = ' 
  194. <div class="row'.$f.'"> 
  195. '.$a1.' 
  196. '.$a2.' 
  197. '.$a3.' 
  198. '.$a4.' 
  199. </div>'; 
  200. return $a; 
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209. /** 
  210. * Choose : tab or accordion 
  211. * @param x $atts 
  212. */ 
  213. public function eewee_shortcode_post( $atts='' ) { 
  214. extract(shortcode_atts(array( 
  215. 'type' => '',  
  216. 'categ' => '',  
  217. 'qty' => '3',  
  218. 'w' => '',  
  219. 'open' => 'y' 
  220. ), $atts)); 
  221.  
  222. switch( $type ) { 
  223. case "tab" : 
  224. $args = array( 
  225. "type" => $type,  
  226. "categ" => $categ,  
  227. "qty" => $qty,  
  228. "w" => $w 
  229. ); 
  230.  
  231. echo $this->eewee_shortcode_post_tab($args); 
  232. break; 
  233.  
  234. case "accordion" : 
  235. $args = array( 
  236. "type" => $type,  
  237. "categ" => $categ,  
  238. "qty" => $qty,  
  239. "w" => $w,  
  240. "open" => $open 
  241. ); 
  242.  
  243. echo $this->eewee_shortcode_post_accordion($args); 
  244. break; 
  245.  
  246. /** 
  247. * Tab system 
  248. * @param x $atts 
  249. */ 
  250. public function eewee_shortcode_post_tab( $tbl ) { 
  251. extract($tbl); 
  252.  
  253. $tools = new ToolsController(); 
  254.  
  255. // init categ 
  256. $args = array(); 
  257. if( !empty($categ) ) { 
  258. $args['include'] = $categ; 
  259.  
  260. // recup les categ d'article pour la home 
  261. $t_post = new TPost(); 
  262. $liste_categs = $t_post->getCategList( $args ); 
  263.  
  264. // tab 
  265. $d = ' 
  266. <ul class="nav nav-tabs" id="myTab">'; 
  267.  
  268. foreach( $liste_categs as $liste_categ ) { 
  269. $d .= '<li><a href="#'.$liste_categ->slug.'">'.$liste_categ->name.'</a></li>'; 
  270.  
  271. $d .= ' 
  272. </ul>'; 
  273.  
  274. // content 
  275. $d .= '  
  276. <div class="tab-content">'; 
  277.  
  278. // init post 
  279. $args = array(); 
  280. if( !empty($qty) ) { 
  281. $args['numberposts'] = $qty; 
  282.  
  283. foreach( $liste_categs as $liste_categ ) { 
  284. $d .= '<div class="tab-pane" id="'.$liste_categ->slug.'">'; 
  285.  
  286. $args['category'] = $liste_categ->cat_ID; 
  287. $actus = $t_post->getPosts( $args ); 
  288.  
  289. foreach( $actus as $actu ) { 
  290. $d .= "  
  291. <div class='row-fluid'> 
  292. <div class='span2'>"; 
  293.  
  294. $thumbnail = get_the_post_thumbnail(  
  295. $actu->ID,  
  296. array(200, 150),  
  297. array( 
  298. 'class'=>'img-rounded pull-left post-tab-marge-img',  
  299. 'alt' => trim(strip_tags( $actu->post_excerpt )),  
  300. 'title' => trim(strip_tags( $actu->post_title )) 
  301. ); 
  302. if( empty( $thumbnail ) ) { 
  303. $d .= ""; 
  304. }else{ 
  305. $d .= "<a href='".get_permalink($actu->ID)."'>".$thumbnail."</a>"; 
  306.  
  307. $d .= "  
  308. </div> 
  309. <div class='span10'>"; 
  310.  
  311. $d .= " 
  312. <div class='addthis_toolbox addthis_default_style pull-left' style='width:200px;> 
  313. <a class='addthis_button_preferred_1'></a> 
  314. <a class='addthis_button_preferred_2'></a> 
  315. <a class='addthis_button_preferred_3'></a> 
  316. <a class='addthis_button_preferred_4'></a> 
  317. <a class='addthis_button_compact'></a> 
  318. <a class='addthis_counter addthis_bubble_style'></a> 
  319. </div> 
  320. <script type='text/javascript' src='http://s7.addthis.com/js/300/addthis_widget.js#pubid=".$idAddthis."'></script> 
  321. <br />"; 
  322.  
  323. $d .= " 
  324. <h3>".$actu->post_title."</h3> 
  325. ".$tools->getContentLimit($actu->post_content, 300)." 
  326. <br /> 
  327. <a href='".get_permalink($actu->ID)."' class='btn btn-mini btn-info'>".__("Read more", "eewee")."...</a><br /> 
  328. <br />"; 
  329.  
  330. $d .= "  
  331. </div> 
  332. </div>"; 
  333.  
  334. $d .= '</div>'; 
  335.  
  336. $d .= ' 
  337. </div>'; 
  338.  
  339. $d .= ' 
  340. <script type="text/javascript"> 
  341. jQuery(document).ready(function($) { 
  342. $(document).ready(function() { 
  343. $("#myTab a").click(function (e) { 
  344. e.preventDefault(); 
  345. $(this).tab("show"); 
  346. }); 
  347.  
  348. $("#myTab a:first").tab("show"); 
  349. }); 
  350. }); 
  351. </script>'; 
  352.  
  353. // BASE STRUCTURE 
  354. /**$d = ' 
  355. <ul class="nav nav-tabs" id="myTab"> 
  356. <li class="active"><a href="#home">Home</a></li> 
  357. <li><a href="#profile">Profile</a></li> 
  358. <li><a href="#messages">Messages</a></li> 
  359. <li><a href="#settings">Settings</a></li> 
  360. </ul> 
  361.  
  362. <div class="tab-content"> 
  363. <div class="tab-pane active" id="home">xxx</div> 
  364. <div class="tab-pane" id="profile">aaa</div> 
  365. <div class="tab-pane" id="messages">bbb</div> 
  366. <div class="tab-pane" id="settings">ccc</div> 
  367. </div> 
  368.  
  369. <script type="text/javascript"> 
  370. jQuery(document).ready(function($) { 
  371. $(document).ready(function() { 
  372. $("#myTab a").click(function (e) { 
  373. e.preventDefault(); 
  374. $(this).tab("show"); 
  375. }); 
  376.  
  377. $("#myTab a:first").tab("show"); 
  378. }); 
  379. }); 
  380. </script>';*/ 
  381.  
  382. return $d; 
  383.  
  384.  
  385. /** 
  386. * Accordion system 
  387. * @param x $atts 
  388. */ 
  389. public function eewee_shortcode_post_accordion( $tbl ) { 
  390. extract($tbl); 
  391.  
  392. $tools = new ToolsController(); 
  393.  
  394. // init categ 
  395. $args = array(); 
  396. if( !empty($categ) ) { 
  397. $args['include'] = $categ; 
  398.  
  399. // recup les categ d'article pour la home 
  400. $t_post = new TPost(); 
  401. $liste_categs = $t_post->getCategList( $args ); 
  402.  
  403. $d .= ' 
  404. <div class="accordion" id="accordion2">'; 
  405.  
  406. // init post 
  407. $args = array(); 
  408. if( !empty($qty) ) { 
  409. $args['numberposts'] = $qty; 
  410. $i=0; 
  411. foreach( $liste_categs as $liste_categ ) { 
  412. $openYN = ""; 
  413. if( $i == 0 && $open == "y" ) { 
  414. $openYN = "in"; 
  415. $i++; 
  416.  
  417. if( $w <= 0 || $w > 100 ) { 
  418. $width = "style='width:100%'"; 
  419. }elseif( !empty( $w ) ) { 
  420. $width = "style='width:".$w."%'"; 
  421.  
  422. $d .= ' 
  423. <div class="accordion-group" '.$width.'>'; 
  424.  
  425. $d .= ' 
  426. <div class="accordion-heading"> 
  427. <a class="accordion-toggle" data-toggle="collapse" data-parent= "#accordion2" href= "#'.$liste_categ->cat_ID.'" > 
  428. '.$liste_categ->name.' 
  429. </a> 
  430. </div>'; 
  431.  
  432. $args['category'] = $liste_categ->cat_ID; 
  433. $actus = $t_post->getPosts( $args ); 
  434.  
  435. $d .= ' 
  436. <div id="'.$liste_categ->cat_ID.'" class="accordion-body collapse '.$openYN.'"> 
  437. <div class="accordion-inner">'; 
  438.  
  439. foreach( $actus as $actu ) { 
  440.  
  441. $d .= "  
  442. <div class='row-fluid'> 
  443. <div class='span2'>"; 
  444.  
  445. $thumbnail = get_the_post_thumbnail( 
  446. $actu->ID,  
  447. array(200, 150),  
  448. array( 
  449. 'class'=>'img-rounded pull-left post-tab-marge-img',  
  450. 'alt' => trim(strip_tags( $actu->post_excerpt )),  
  451. 'title' => trim(strip_tags( $actu->post_title )) 
  452. ); 
  453. if( empty( $thumbnail ) ) { 
  454. $d .= ""; 
  455. }else{ 
  456. $d .= "<a href='".get_permalink($actu->ID)."'>".$thumbnail."</a>"; 
  457. $d .= "  
  458. </div> 
  459. <div class='span10'>"; 
  460.  
  461. $d .= " 
  462. <div class='addthis_toolbox addthis_default_style pull-left' style='width:200px;> 
  463. <a class='addthis_button_preferred_1'></a> 
  464. <a class='addthis_button_preferred_2'></a> 
  465. <a class='addthis_button_preferred_3'></a> 
  466. <a class='addthis_button_preferred_4'></a> 
  467. <a class='addthis_button_compact'></a> 
  468. <a class='addthis_counter addthis_bubble_style'></a> 
  469. </div> 
  470. <script type='text/javascript' src='http://s7.addthis.com/js/300/addthis_widget.js#pubid=".$idAddthis."'></script> 
  471. <br />"; 
  472.  
  473. $d .= " 
  474. <h3>".$actu->post_title."</h3> 
  475. ".$tools->getContentLimit($actu->post_content, 300)." 
  476. <br /> 
  477. <a href='".get_permalink($actu->ID)."' class='btn btn-mini btn-info'>".__("Read more", "eewee")."...</a><br /> 
  478. <br /> 
  479. <div class='clearfix'></div>"; 
  480.  
  481. $d .= "  
  482. </div> 
  483. </div>";  
  484.  
  485. }//foreach 
  486.  
  487. $d .= ' 
  488. </div> 
  489. </div>'; 
  490.  
  491.  
  492. $d .= ' 
  493. </div>'; 
  494.  
  495. }//foreach  
  496.  
  497. // Base structure 
  498. /** 
  499. $d = ' 
  500. <div class="accordion" id="accordion2"> 
  501. <div class="accordion-group"> 
  502. <div class="accordion-heading"> 
  503. <a class="accordion-toggle" data-toggle="collapse" data-parent= "#accordion2" href= "#collapseOne" > 
  504. Collapsible Group Item #1  
  505. </a> 
  506. </div> 
  507. <div id="collapseOne" class="accordion-body collapse in"> 
  508. <div class="accordion-inner"> 
  509. Anim pariatur cliche... 
  510. </div> 
  511. </div> 
  512. </div> 
  513. <div class="accordion-group"> 
  514. <div class="accordion-heading"> 
  515. <a class="accordion-toggle" data-toggle="collapse" data-parent= "#accordion2" href= "#collapseTwo" > 
  516. Collapsible Group Item #1  
  517. </a> 
  518. </div> 
  519. <div id="collapseTwo" class="accordion-body collapse"> 
  520. <div class="accordion-inner"> 
  521. Anim pariatur cliche... 
  522. </div> 
  523. </div> 
  524. </div> 
  525. </div> 
  526. '; 
  527. */ 
  528.  
  529. return $d; 
  530.  
  531.  
  532.  
  533. /** 
  534. * Colonne 
  535. * @param x $atts 
  536. */ 
  537. public function eewee_shortcode_carousel( $atts='' ) { 
  538. extract(shortcode_atts(array( 
  539. 'a' => '',  
  540. ), $atts)); 
  541.  
  542. $options = get_option('eewee_options'); 
  543. //echo "enabled : ".$options['eewee_carousel_enabled']."<hr />"; 
  544. if( $options['eewee_carousel_enabled'] ) { 
  545. if( $options['eewee_carousel_qty'] > 0 ) { 
  546. $qty = $options['eewee_carousel_qty']; 
  547. }else{ 
  548. $qty = 10; 
  549.  
  550. $a = ' 
  551. <div id="myCarousel" class="carousel slide"> 
  552. <!-- Carousel items --> 
  553. <div class="carousel-inner">'; 
  554.  
  555. for( $i=1 ; $i<=$qty ; $i++ ) { 
  556.  
  557. if( $i==1 ) { 
  558. $active = 'active'; 
  559. }else{ 
  560. $active = ''; 
  561.  
  562. $a .= ' 
  563. <div class="'.$active.' item"> 
  564. <img src="'.$options['eewee_carousel_img_'.$i].'" />'; 
  565.  
  566. if(  
  567. !empty($options['eewee_carousel_title_'.$i]) || 
  568. !empty($options['eewee_carousel_desc_'.$i]) 
  569. ) { 
  570. $a .= ' 
  571. <div class="carousel-caption"> 
  572. <h4>'.$options['eewee_carousel_title_'.$i].'</h4> 
  573. <p>'.$options['eewee_carousel_desc_'.$i].'</p> 
  574. </div>'; 
  575.  
  576. $a .= ' 
  577. </div>'; 
  578. }// for  
  579.  
  580. // $a .= ' 
  581. // <div class="item"><img src="http://lorempixel.com/1000/300/sports/1" /></div> 
  582. // <div class="item"><img src="http://lorempixel.com/1000/300/sports/2" /></div> 
  583. // <div class="item"><img src="http://lorempixel.com/1000/300/sports/3" /></div>'; 
  584.  
  585. $a .= ' 
  586. </div> 
  587.  
  588. <!-- Carousel nav --> 
  589. <a class="carousel-control left" href= "#myCarousel" data-slide="prev">‹</a> 
  590. <a class="carousel-control right" href= "#myCarousel" data-slide="next">›</a> 
  591. </div>'; 
  592. return $a; 
  593. }else{ 
  594. return ""; 
  595.  
  596. }//fin class