BB_Query_Form

The BuddyPress BB Query Form class.

Defined (1)

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

/bp-forums/bbpress/bb-includes/class.bb-query.php  
  1. class BB_Query_Form extends BB_Query { 
  2. var $defaults; 
  3. var $allowed; 
  4.  
  5. // Can optionally pass unique id string to help out filters 
  6. function __construct( $type = 'topic', $defaults = '', $allowed = '', $id = '' ) { 
  7. $this->defaults = wp_parse_args( $defaults ); 
  8. $this->allowed = wp_parse_args( $allowed ); 
  9. if ( !empty($defaults) || !empty($allowed) ) 
  10. $this->query_from_env($type, $defaults, $allowed, $id); 
  11.  
  12. function BB_Query_Form( $type = 'topic', $defaults = '', $allowed = '', $id = '' ) { 
  13. $this->__construct( $type, $defaults, $allowed, $id ); 
  14.  
  15. function form( $args = null ) { 
  16. $_post = 'post' == $this->type; 
  17.  
  18. $defaults = array( 
  19. 'search' => true,  
  20. 'forum' => true,  
  21. 'tag' => false,  
  22. 'open' => false,  
  23. 'topic_author' => false,  
  24. 'post_author' => false,  
  25. 'topic_status' => false,  
  26. 'post_status' => false,  
  27. 'topic_title' => false,  
  28. 'poster_ip' => false,  
  29.  
  30. 'method' => 'get',  
  31. 'submit' => __('Search »'),  
  32. 'action' => '' 
  33. ); 
  34. $defaults['id'] = $_post ? 'post-search-form' : 'topic-search-form'; 
  35.  
  36. $args = wp_parse_args( $args, $defaults ); 
  37. extract( $args, EXTR_SKIP ); 
  38.  
  39. $id = esc_attr( $id ); 
  40. $method = 'get' == strtolower($method) ? 'get' : 'post'; 
  41. $submit = esc_attr( $submit ); 
  42. if ( !$action = esc_url( $action ) ) 
  43. $action = ''; 
  44.  
  45. if ( $this->query_vars ) 
  46. $query_vars =& $this->query_vars; 
  47. else 
  48. $query_vars = $this->fill_query_vars( $this->defaults ); 
  49.  
  50. extract($query_vars, EXTR_PREFIX_ALL, 'q'); 
  51.  
  52. $r = "<form action='$action' method='$method' id='$id' class='search-form'>\n"; 
  53.  
  54. $r .= "\t<fieldset>\n"; 
  55.  
  56. if ( $search ) { 
  57. if ( $_post ) { 
  58. $s_value = esc_attr( $q_post_text ); 
  59. $s_name = 'post_text'; 
  60. $s_id = 'post-text'; 
  61. } else { 
  62. $s_value = esc_attr( $q_search ); 
  63. $s_name = $s_id = 'search'; 
  64. $r .= "\t<div><label for=\"$s_id\">" . __('Search term') . "</label>\n"; 
  65. $r .= "\t\t<div><input name='$s_name' id='$s_id' type='text' class='text-input' value='$s_value' /></div>\n"; 
  66. $r .= "\t</div>\n\n"; 
  67.  
  68. if ( $forum ) { 
  69. $r .= "\t<div><label for=\"forum-id\">" . __('Forum') . "</label>\n"; 
  70. $r .= "\t\t<div>" . bb_get_forum_dropdown( array( 'selected' => $q_forum_id, 'none' => __('Any') ) ) . "</div>\n"; 
  71. $r .= "\t</div>\n\n"; 
  72.  
  73. if ( $tag ) { 
  74. $q_tag = esc_attr( $q_tag ); 
  75. $r .= "\t<div><label for=\"topic-tag\">" . __('Tag') . "</label>\n"; 
  76. $r .= "\t\t<div><input name='tag' id='topic-tag' type='text' class='text-input' value='$q_tag' /></div>\n"; 
  77. $r .= "\t</div>\n\n"; 
  78.  
  79. if ( $topic_author ) { 
  80. $q_topic_author = esc_attr( $q_topic_author ); 
  81. $r .= "\t<div><label for=\"topic-author\">" . __('Topic author') . "</label>\n"; 
  82. $r .= "\t\t<div><input name='topic_author' id='topic-author' type='text' class='text-input' value='$q_topic_author' /></div>\n"; 
  83. $r .= "\t</div>\n\n"; 
  84.  
  85. if ( $post_author ) { 
  86. $q_post_author = esc_attr( $q_post_author ); 
  87. $r .= "\t<div><label for=\"post-author\">" . __('Post author') . "</label>\n"; 
  88. $r .= "\t\t<div><input name='post_author' id='post-author' type='text' class='text-input' value='$q_post_author' /></div>\n"; 
  89. $r .= "\t</div>\n\n"; 
  90.  
  91. $stati = apply_filters( 'bb_query_form_post_status', array( 'all' => _x( 'All', 'post status' ), '0' => __('Normal'), '1' => __('Deleted') ), $this->type ); 
  92.  
  93. if ( $topic_status ) { 
  94. $r .= "\t<div><label for=\"topic-status\">" . __('Topic status') . "</label>\n"; 
  95. $r .= "\t\t<div><select name='topic_status' id='topic-status'>\n"; 
  96. foreach ( $stati as $status => $label ) { 
  97. $selected = (string) $status == (string) $q_topic_status ? " selected='selected'" : ''; 
  98. $r .= "\t\t\t<option value='$status'$selected>$label</option>\n"; 
  99. $r .= "\t\t</select></div>\n"; 
  100. $r .= "\t</div>\n\n"; 
  101.  
  102. if ( $post_status ) { 
  103. $r .= "\t<div><label for=\"post-status\">" . __('Post status') . "</label>\n"; 
  104. $r .= "\t\t<div><select name='post_status' id='post-status'>\n"; 
  105. foreach ( $stati as $status => $label ) { 
  106. $selected = (string) $status == (string) $q_post_status ? " selected='selected'" : ''; 
  107. $r .= "\t\t\t<option value='$status'$selected>$label</option>\n"; 
  108. $r .= "\t\t</select></div>\n"; 
  109. $r .= "\t</div>\n\n"; 
  110.  
  111. if ( $poster_ip ) { 
  112. $r .= "\t<div><label for=\"poster-ip\">" . __('Poster IP address') . "</label>\n"; 
  113. $r .= "\t\t<div><input name='poster_ip' id='poster-ip' type='text' class='text-input' value='$q_poster_ip' /></div>\n"; 
  114. $r .= "\t</div>\n\n"; 
  115.  
  116. if ( $open ) { 
  117. $r .= "\t<div><label for=\"topic-open\">" . __('Open?') . "</label>\n"; 
  118. $r .= "\t\t<div><select name='open' id='topic-open'>\n"; 
  119. foreach ( array( 'all' => _x( 'All', 'posting status' ), '1' => _x( 'Open', 'posting status' ), '0' => __('Closed') ) as $status => $label ) { 
  120. $label = esc_html( $label ); 
  121. $selected = (string) $status == (string) $q_open ? " selected='selected'" : ''; 
  122. $r .= "\t\t\t<option value='$status'$selected>$label</option>\n"; 
  123. $r .= "\t\t</select></div>\n"; 
  124. $r .= "\t</div>\n\n"; 
  125.  
  126. if ( $topic_title ) { 
  127. $q_topic_title = esc_attr( $q_topic_title ); 
  128. $r .= "\t<div><label for=\"topic-title\">" . __('Title') . "</label>\n"; 
  129. $r .= "\t\t<div><input name='topic_title' id='topic-title' type='text' class='text-input' value='$q_topic_title' /></div>\n"; 
  130. $r .= "\t</div>\n\n"; 
  131.  
  132. $r .= apply_filters( 'bb_query_form_inputs', '', $args, $query_vars ); 
  133.  
  134. $r .= "\t<div class=\"submit\"><label for=\"$id-submit\">" . __('Search') . "</label>\n"; 
  135. $r .= "\t\t<div><input type='submit' class='button submit-input' value='$submit' id='$id-submit' /></div>\n"; 
  136. $r .= "\t</div>\n"; 
  137.  
  138. $r .= "\t</fieldset>\n\n"; 
  139.  
  140. do_action( 'bb_query_form', $args, $query_vars ); 
  141.  
  142. $r .= "</form>\n\n"; 
  143.  
  144. echo $r;