BWS_Filter

The Bootstrap Widget Styling BWS Filter class.

Defined (1)

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

/includes/class-bws-filter.php  
  1. class BWS_Filter { 
  2. protected static $instance; 
  3. protected static $types_of_widgets_called = array(); 
  4. protected $markup; 
  5. protected $type_of_filter; 
  6.  
  7. private function __construct( $html_to_filter , $type_of_filter ) { 
  8. $this->markup = $html_to_filter; 
  9. $this->type_of_filter = $type_of_filter; 
  10.  
  11. protected static function reformat( $html_to_filter , $type_of_filter ) { 
  12. self::$instance = new self( $html_to_filter , $type_of_filter ); 
  13. self::$instance->get_filtered_markup(); 
  14. return self::$instance->markup; 
  15.  
  16. function get_filtered_markup() { 
  17. $this->remove_ul_tags_if_filter_type_is_pages(); 
  18. $this->close_ul_if_first_call_of_filter(); 
  19. $this->replace_parenthesized_number_with_badge_number(); 
  20. $this->remove_li_tags(); 
  21. $this->add_list_group_class_to_anchor_tags(); 
  22. $this->move_span_inside_anchor_closing_tag(); 
  23. $this->add_closing_div_depending_on_filter_type(); 
  24.  
  25. function remove_ul_tags_if_filter_type_is_pages() { 
  26. if ( 'pages' === $this->type_of_filter ) { 
  27. $this->markup = preg_replace( '/<[\/]?ul.*?>/' , '' , $this->markup ); 
  28.  
  29. function close_ul_if_first_call_of_filter() { 
  30. if ( self::is_first_instance_of_type() ) { 
  31. self::close_ul_and_add_opening_div(); 
  32.  
  33. function is_first_instance_of_type() { 
  34. if ( ! isset( self::$types_of_widgets_called[ $this->type_of_filter ] ) ) { 
  35. self::$types_of_widgets_called[ $this->type_of_filter ] = true; 
  36. return true; 
  37. return false; 
  38.  
  39. function close_ul_and_add_opening_div() { 
  40. $this->markup = '</ul><div class="list-group">' . $this->markup; 
  41.  
  42. function replace_parenthesized_number_with_badge_number() { 
  43. $regex = '/\((\d{1, 3})\)/'; 
  44. $new_count_markup = "<span class='badge pull-right'>$1</span>"; 
  45. $this->markup = preg_replace( $regex , $new_count_markup , $this->markup ); 
  46.  
  47. function remove_li_tags() { 
  48. $regex = '/<li.*?>/'; 
  49. $this->markup = preg_replace( $regex , '' , $this->markup ); 
  50.  
  51. function add_list_group_class_to_anchor_tags() { 
  52. $this->markup = str_replace( '<a' , '<a class="list-group-item"' , $this->markup ); 
  53.  
  54. function move_span_inside_anchor_closing_tag() { 
  55. $new_markup = "$2$1"; 
  56. $regex = "/(<\/a>).*?(<span.+?<\/span>)/"; 
  57. $this->markup = preg_replace( $regex , $new_markup , $this->markup ); 
  58.  
  59. function add_closing_div_depending_on_filter_type() { 
  60. if ( 'archives' !== $this->type_of_filter ) { 
  61. $this->markup .= '</div>';