BWS_Filter

The Bootstrap Widget Styling BWS Filter class.

Defined (1)

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

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