/includes/bootstrap.php

  1. <?php 
  2.  
  3. abstract class Bootstrap 
  4. protected $plugin_version; 
  5. protected $plugins_url; 
  6.  
  7. public function __construct( $plugin_version, $plugins_url ) 
  8. $this->plugin_version = $plugin_version; 
  9. $this->plugins_url = untrailingslashit( $plugins_url ); 
  10.  
  11. public function register() 
  12. add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) ); 
  13. add_filter( 'admin_head', array( $this, 'admin_head') ); 
  14. add_filter( 'tiny_mce_before_init', array( $this, 'tiny_mce_before_init' ), 9999 ); 
  15. add_filter( 'mce_buttons_2', array( $this, 'mce_buttons_2' ) ); 
  16. add_filter( 'the_content', array( $this, 'the_content' ) ); 
  17.  
  18. add_shortcode( 'label', array( $this, 'shortcode_label' ) ); 
  19. add_shortcode( 'badge', array( $this, 'shortcode_badge' ) ); 
  20. add_shortcode( 'icon', array( $this, 'shortcode_icon' ) ); 
  21.  
  22. public function shortcode_icon( $p ) 
  23. $class = array(); 
  24.  
  25. if ( isset( $p[0] ) && ( $icon = preg_replace( '/^icon-/', '', $p[0] ) ) ) { 
  26. if ( 'bootstrap3' === Content_Bootstrap::get_bootstrap_version() ) { 
  27. $class[] = esc_attr( 'glyphicon-'.$icon ); 
  28. } else { 
  29. $class[] = esc_attr( 'icon-'.$icon ); 
  30.  
  31. if ( isset( $p[1] ) && ('white' === preg_replace( '/^icon-/', '', $p[1] ) ) ) { 
  32. $class[] = 'icon-white'; 
  33.  
  34. if ( 'bootstrap3' === Content_Bootstrap::get_bootstrap_version() ) { 
  35. return sprintf( 
  36. '<span class="glyphicon %s" aria-hidden="true"></span>',  
  37. join( ' ', $class ) 
  38. ); 
  39. } else { 
  40. return sprintf( 
  41. '<i class="%s"></i>',  
  42. join( ' ', $class ) 
  43. ); 
  44.  
  45. public function shortcode_label( $p, $content ) 
  46. if ( 'bootstrap3' === Content_Bootstrap::get_bootstrap_version() ) { 
  47. $labels = array( 
  48. 'default',  
  49. 'primary',  
  50. 'success',  
  51. 'info',  
  52. 'warning',  
  53. 'danger',  
  54. ); 
  55.  
  56. $class = array( 'label' ); 
  57. if ( isset( $p['name'] ) && in_array( $p['name'], $labels ) ) { 
  58. $class[] = 'label-' . $p['name']; 
  59. } else { 
  60. $class[] = 'label-default'; 
  61.  
  62. return sprintf( 
  63. '<span class="%s">%s</span>',  
  64. join( ' ', $class ),  
  65. do_shortcode( $content ) 
  66. ); 
  67. } else { 
  68. $class = array( 'label' ); 
  69. if ( isset( $p['name'] ) && preg_match( '/^[a-z]+$/', $p['name'] ) ) { 
  70. $class[] = 'label-'.esc_attr( $p['name'] ); 
  71.  
  72. return sprintf( 
  73. '<span class="%s">%s</span>',  
  74. join( ' ', $class ),  
  75. do_shortcode( $content ) 
  76. ); 
  77.  
  78. public function shortcode_badge( $p, $content ) 
  79. if ( 'bootstrap3' === Content_Bootstrap::get_bootstrap_version() ) { 
  80. return sprintf( 
  81. '<span class="badge">%s</span>',  
  82. do_shortcode( $content ) 
  83. ); 
  84. } else { 
  85. $class = array( 'badge' ); 
  86. if ( isset( $p['name'] ) && preg_match( '/^[a-z]+$/', $p['name'] ) ) { 
  87. $class[] = 'badge-'.esc_attr( $p['name'] ); 
  88.  
  89. return sprintf( 
  90. '<span class="%s">%s</span>',  
  91. join( ' ', $class ),  
  92. do_shortcode( $content ) 
  93. ); 
  94.  
  95. public function the_content( $content ) 
  96. $wrap = apply_filters( 'content_bootstrap_wrap', true ); 
  97. if ( 'bootstrap3' === Content_Bootstrap::get_bootstrap_version() ) { 
  98. if ( $wrap ) { 
  99. return '<div class="content-bootstrap-3-area">'.$content.'</div>'; 
  100. } else { 
  101. return $content; 
  102. } else { 
  103. if ( $wrap ) { 
  104. return '<div class="content-bootstrap-area">'.$content.'</div>'; 
  105. } else { 
  106. return $content; 
  107.  
  108. public function mce_buttons_2( $buttons ) 
  109. array_unshift( $buttons, 'styleselect' ); 
  110. return $buttons; 
  111.  
  112. abstract public function tiny_mce_before_init( $init ); 
  113.  
  114. abstract public function admin_head(); 
  115.  
  116. public function wp_enqueue_scripts() 
  117. wp_enqueue_style( 
  118. 'content-bootstrap',  
  119. $this->get_bootstrap_dir() . '/css/content-bootstrap.css',  
  120. array(),  
  121. $this->plugin_version 
  122. ); 
  123.  
  124. protected function get_bootstrap_dir() 
  125. $dir = apply_filters( 
  126. 'content_bootstrap_dir',  
  127. $this->plugins_url . '/bootstrap/' . Content_Bootstrap::get_bootstrap_version() 
  128. ); 
  129.  
  130. return untrailingslashit( $dir ); 
.