BREBoostrapShortcodes

=============================================================.

Defined (1)

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

/admin/bootstrap-shortcode.php  
  1. class BREBoostrapShortcodes { 
  2.  
  3. function __construct() { 
  4. add_action( 'init', array( $this, 'add_shortcodes' ) );  
  5.  
  6. /** 
  7. * add_shortcodes 
  8. * @author Filip Stefansson 
  9. * @since 1.0 
  10. **/ 
  11. function add_shortcodes() { 
  12. add_shortcode('button', array( $this, 'bs_button' ));  
  13. add_shortcode('alert', array( $this, 'bs_alert' )); 
  14. add_shortcode('code', array( $this, 'bs_code' )); 
  15. add_shortcode('span', array( $this, 'bs_span' )); 
  16. add_shortcode('row', array( $this, 'bs_row' )); 
  17. add_shortcode('label', array( $this, 'bs_label' )); 
  18. add_shortcode('badge', array( $this, 'bs_badge' )); 
  19. add_shortcode('icon', array( $this, 'bs_icon' )); 
  20. add_shortcode('icon_white', array( $this, 'bs_icon_white' )); 
  21. add_shortcode('table', array( $this, 'bs_table' )); 
  22. add_shortcode('collapsibles', array( $this, 'bs_collapsibles' )); 
  23. add_shortcode('collapse', array( $this, 'bs_collapse' )); 
  24. add_shortcode('well', array( $this, 'bs_well' )); 
  25. add_shortcode('tabs', array( $this, 'bs_tabs' )); 
  26. add_shortcode('tab', array( $this, 'bs_tab' )); 
  27.  
  28. /** 
  29. * bs_button 
  30. * @author Filip Stefansson 
  31. * @since 1.0 
  32. * //DW mod added xclass var 
  33. **/ 
  34. function bs_button($atts, $content = null) { 
  35. extract(shortcode_atts(array( 
  36. "type" => '',  
  37. "size" => '',  
  38. "link" => '',  
  39. "xclass" => '' 
  40. ), $atts)); 
  41. return '<a href="' . $link . '" class="btn btn-' . $type . ' btn-' . $size . ' ' . $xclass . '">' . do_shortcode( $content ) . '</a>'; 
  42.  
  43. /** 
  44. * bs_alert 
  45. * @author Filip Stefansson 
  46. * @since 1.0 
  47. *  
  48. **/ 
  49. function bs_alert($atts, $content = null) { 
  50. extract(shortcode_atts(array( 
  51. "type" => '',  
  52. "close" => true 
  53. ), $atts)); 
  54. return '<div class="alert alert-' . $type . '">' . do_shortcode( $content ) . '<button type="button" class="close" data-dismiss="alert">×</button></div>'; 
  55.  
  56.  
  57.  
  58.  
  59. /**-------------------------------------------------------------------------------------- 
  60. * bs_code 
  61. * @author Filip Stefansson 
  62. * @since 1.0 
  63. *  
  64. *-------------------------------------------------------------------------------------*/ 
  65. function bs_code($atts, $content = null) { 
  66. extract(shortcode_atts(array( 
  67. "type" => '',  
  68. "size" => '',  
  69. "link" => '' 
  70. ), $atts)); 
  71. return '<pre><code>' . do_shortcode( $content ) . '</code></pre>'; 
  72.  
  73. /**-------------------------------------------------------------------------------------- 
  74. * bs_span 
  75. * @author Filip Stefansson 
  76. * @since 1.0 
  77. *  
  78. *-------------------------------------------------------------------------------------*/ 
  79. function bs_span( $atts, $content = null ) { 
  80. extract(shortcode_atts(array( 
  81. "size" => 'size' 
  82. ), $atts)); 
  83. return '<div class="span' . $size . '">' . do_shortcode( $content ) . '</div>'; 
  84.  
  85. /**-------------------------------------------------------------------------------------- 
  86. * bs_row 
  87. * @author Filip Stefansson 
  88. * @since 1.0 
  89. *  
  90. *-------------------------------------------------------------------------------------*/ 
  91. function bs_row( $atts, $content = null ) { 
  92. return '<div class="row-fluid">' . do_shortcode( $content ) . '</div>'; 
  93.  
  94. /**-------------------------------------------------------------------------------------- 
  95. * bs_label 
  96. * @author Filip Stefansson 
  97. * @since 1.0 
  98. *  
  99. *-------------------------------------------------------------------------------------*/ 
  100. function bs_label( $atts, $content = null ) { 
  101. extract(shortcode_atts(array( 
  102. "type" => 'type' 
  103. ), $atts)); 
  104.  
  105. return '<span class="label label-' . $type . '">' . do_shortcode( $content ) . '</span>'; 
  106.  
  107.  
  108. /**-------------------------------------------------------------------------------------- 
  109. * bs_badge 
  110. * @author Filip Stefansson 
  111. * @since 1.0 
  112. *  
  113. *-------------------------------------------------------------------------------------*/ 
  114. function bs_badge( $atts, $content = null ) { 
  115. extract(shortcode_atts(array( 
  116. "type" => 'type' 
  117. ), $atts)); 
  118.  
  119. return '<span class="badge badge-' . $type . '">' . do_shortcode( $content ) . '</span>'; 
  120.  
  121.  
  122.  
  123.  
  124.  
  125. /**-------------------------------------------------------------------------------------- 
  126. * bs_icon 
  127. * @author Filip Stefansson 
  128. * @since 1.0 
  129. * //DW Mod to add icon sizing 
  130. *-------------------------------------------------------------------------------------*/ 
  131. function bs_icon( $atts, $content = null ) { 
  132. extract(shortcode_atts(array( 
  133. "type" => 'type',  
  134. "size" => 'normal',  
  135. ), $atts)); 
  136.  
  137. return '<i class="icon icon-' . $type . ' icon-' . $size .'"></i>';  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. /**-------------------------------------------------------------------------------------- 
  144. * bs_icon_white 
  145. * @author Filip Stefansson 
  146. * @since 1.0 
  147. *  
  148. *-------------------------------------------------------------------------------------*/ 
  149. function bs_icon_white( $atts, $content = null ) { 
  150. extract(shortcode_atts(array( 
  151. "type" => 'type' 
  152. ), $atts)); 
  153.  
  154. return '<i class="icon icon-' . $type . ' icon-white"></i>'; 
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161. /**-------------------------------------------------------------------------------------- 
  162. * simple_table 
  163. * @author Filip Stefansson 
  164. * @since 1.0 
  165. *  
  166. *-------------------------------------------------------------------------------------*/ 
  167. function bs_table( $atts ) { 
  168. extract( shortcode_atts( array( 
  169. 'cols' => 'none',  
  170. 'data' => 'none',  
  171. 'type' => 'type' 
  172. ), $atts ) ); 
  173. $cols = explode(', ', $cols); 
  174. $data = explode(', ', $data); 
  175. $total = count($cols); 
  176. $output = ''; 
  177. $output .= '<table class="table table-'. $type .' table-bordered"><tr>'; 
  178. foreach($cols as $col): 
  179. $output .= '<th>'.$col.'</th>'; 
  180. endforeach; 
  181. $output .= '</tr><tr>'; 
  182. $counter = 1; 
  183. foreach($data as $datum): 
  184. $output .= '<td>'.$datum.'</td>'; 
  185. if($counter%$total==0): 
  186. $output .= '</tr>'; 
  187. endif; 
  188. $counter++; 
  189. endforeach; 
  190. $output .= '</table>'; 
  191. return $output; 
  192.  
  193.  
  194.  
  195.  
  196. /**-------------------------------------------------------------------------------------- 
  197. * bs_well 
  198. * @author Filip Stefansson 
  199. * @since 1.0 
  200. *  
  201. *-------------------------------------------------------------------------------------*/ 
  202. function bs_well( $atts, $content = null ) { 
  203. extract(shortcode_atts(array( 
  204. "size" => 'size' 
  205. ), $atts)); 
  206.  
  207. return '<div class="well well-' . $size . '">' . do_shortcode( $content ) . '</div>'; 
  208.  
  209.  
  210.  
  211. /**-------------------------------------------------------------------------------------- 
  212. * bs_tabs 
  213. * @author Filip Stefansson 
  214. * @since 1.0 
  215. * Modified by TwItCh twitch@designweapon.com 
  216. *Now acts a whole nav/tab/pill shortcode solution! 
  217. *-------------------------------------------------------------------------------------*/ 
  218. function bs_tabs( $atts, $content = null ) { 
  219.  
  220. if( isset($GLOBALS['tabs_count']) ) 
  221. $GLOBALS['tabs_count']++; 
  222. else 
  223. $GLOBALS['tabs_count'] = 0; 
  224. extract( shortcode_atts( array( 
  225. 'tabtype' => 'nav-tabs',  
  226. 'tabdirection' => '',  
  227. ), $atts ) ); 
  228. //DW $defaults = array('tabtype' => 'bla', 'tabdirection' => 'one'); 
  229. //DW extract( shortcode_atts( $defaults, array(), $atts ) ); 
  230.  
  231. // Extract the tab titles for use in the tab widget. 
  232. preg_match_all( '/tab title="([^\"]+)"/i', $content, $matches, PREG_OFFSET_CAPTURE ); 
  233.  
  234. $tab_titles = array(); 
  235. if( isset($matches[1]) ) { $tab_titles = $matches[1]; } 
  236.  
  237. $output = ''; 
  238.  
  239. if( count($tab_titles) ) { 
  240. $output .= '<div class="tabbable tabs-'.$tabdirection.'"><ul class="nav '. $tabtype .'" id="custom-tabs-'. rand(1, 100) .'">'; 
  241.  
  242. $i = 0; 
  243. foreach( $tab_titles as $tab ) { 
  244. if($i == 0) 
  245. $output .= '<li class="active">'; 
  246. else 
  247. $output .= '<li>'; 
  248.  
  249. $output .= '<a href="#custom-tab-' . $GLOBALS['tabs_count'] . '-' . sanitize_title( $tab[0] ) . '" data-toggle="tab">' . $tab[0] . '</a></li>'; 
  250. $i++; 
  251.  
  252. $output .= '</ul>'; 
  253. $output .= '<div class="tab-content">'; 
  254. $output .= do_shortcode( $content ); 
  255. $output .= '</div></div>'; 
  256. } else { 
  257. $output .= do_shortcode( $content ); 
  258.  
  259. return $output; 
  260.  
  261.  
  262.  
  263.  
  264. /**-------------------------------------------------------------------------------------- 
  265. * bs_tab 
  266. * @author Filip Stefansson 
  267. * @since 1.0 
  268. *  
  269. *-------------------------------------------------------------------------------------*/ 
  270. function bs_tab( $atts, $content = null ) { 
  271.  
  272. if( !isset($GLOBALS['current_tabs']) ) { 
  273. $GLOBALS['current_tabs'] = $GLOBALS['tabs_count']; 
  274. $state = 'active'; 
  275. } else { 
  276.  
  277. if( $GLOBALS['current_tabs'] == $GLOBALS['tabs_count'] ) { 
  278. $state = '';  
  279. } else { 
  280. $GLOBALS['current_tabs'] = $GLOBALS['tabs_count']; 
  281. $state = 'active'; 
  282.  
  283. $defaults = array( 'title' => 'Tab'); 
  284. extract( shortcode_atts( $defaults, $atts ) ); 
  285.  
  286. return '<div id="custom-tab-' . $GLOBALS['tabs_count'] . '-'. sanitize_title( $title ) .'" class="tab-pane ' . $state . '">'. do_shortcode( $content ) .'</div>'; 
  287.  
  288.  
  289.  
  290.  
  291. /**-------------------------------------------------------------------------------------- 
  292. * bs_collapsibles 
  293. * @author Filip Stefansson 
  294. * @since 1.0 
  295. *  
  296. *-------------------------------------------------------------------------------------*/ 
  297. function bs_collapsibles( $atts, $content = null ) { 
  298.  
  299. if( isset($GLOBALS['collapsibles_count']) ) 
  300. $GLOBALS['collapsibles_count']++; 
  301. else 
  302. $GLOBALS['collapsibles_count'] = 0; 
  303.  
  304. $defaults = array(); 
  305. extract( shortcode_atts( $defaults, $atts ) ); 
  306.  
  307. // Extract the tab titles for use in the tab widget. 
  308. preg_match_all( '/collapse title="([^\"]+)"/i', $content, $matches, PREG_OFFSET_CAPTURE ); 
  309.  
  310. $tab_titles = array(); 
  311. if( isset($matches[1]) ) { $tab_titles = $matches[1]; } 
  312.  
  313. $output = ''; 
  314.  
  315. if( count($tab_titles) ) { 
  316. $output .= '<div class="accordion" id="accordion-' . $GLOBALS['collapsibles_count'] . '">'; 
  317. $output .= do_shortcode( $content ); 
  318. $output .= '</div>'; 
  319. } else { 
  320. $output .= do_shortcode( $content ); 
  321.  
  322. return $output; 
  323.  
  324.  
  325.  
  326.  
  327. /**-------------------------------------------------------------------------------------- 
  328. * bs_collapse 
  329. * @author Filip Stefansson 
  330. * @since 1.0 
  331. *  
  332. *-------------------------------------------------------------------------------------*/ 
  333. function bs_collapse( $atts, $content = null ) { 
  334.  
  335. if( !isset($GLOBALS['current_collapse']) ) 
  336. $GLOBALS['current_collapse'] = 0; 
  337. else  
  338. $GLOBALS['current_collapse']++; 
  339.  
  340.  
  341. $defaults = array( 'title' => 'Tab', 'state' => ''); 
  342. extract( shortcode_atts( $defaults, $atts ) ); 
  343.  
  344. if (!empty($state))  
  345. $state = 'in'; 
  346.  
  347. return ' 
  348. <div class="accordion-group"> 
  349. <div class="accordion-heading"> 
  350. <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion-' . $GLOBALS['collapsibles_count'] . '" href="#collapse_' . $GLOBALS['current_collapse'] . '_'. sanitize_title( $title ) .'"> 
  351. ' . $title . '  
  352. </a> 
  353. </div> 
  354. <div id="collapse_' . $GLOBALS['current_collapse'] . '_'. sanitize_title( $title ) .'" class="accordion-body collapse ' . $state . '"> 
  355. <div class="accordion-inner"> 
  356. ' . $content . '  
  357. </div> 
  358. </div> 
  359. </div> 
  360. '; 
  361.