'', 'subtitle' => '', 'show_keyword' => 1, 'show_by' => 1, 'show_city' => 1, 'show_county' => false, 'show_state' => 1, 'show_country' => 1, 'show_category' => 1, ); } /** * @since 3.0.2 */ private function render_find_by_contact_name_field() { global $wpdb; $query = 'SELECT DISTINCT ad_contact_name FROM ' . AWPCP_TABLE_ADS . ' '; $query.= 'WHERE disabled = 0 AND (flagged IS NULL OR flagged = 0)'; $query.= 'ORDER BY ad_contact_name ASC'; $names = $wpdb->get_col( $query ); if ( empty( $names ) ) { $options = array(); } else { $options = array_combine( $names, $names ); } $selected = stripslashes_deep( awpcp_request_param( 'searchname', null ) ); return $this->select( $options, __('Find ads by Contact Name', 'another-wordpress-classifieds-plugin'), 'searchname', $selected, __( 'All Contact Names', 'another-wordpress-classifieds-plugin' ) ); } /** * @since 3.0.2 */ private function render_region_fields( $instance ) { if ( isset( $_REQUEST['regions'][0] ) ) { $regions = array( stripslashes_deep( $_REQUEST['regions'][0] ) ); } else { $regions = array(); } $options = array( 'showTextField' => false, 'showExistingRegionsOnly' => true, 'maxRegions' => 1, 'enabled_fields' => array( 'country' => $instance['show_country'], 'state' => $instance['show_state'], 'county' => $instance['show_county'], 'city' => $instance['show_city'], ), ); $selector = awpcp_multiple_region_selector( $regions, $options ); echo $selector->render( 'search', array(), array() ); } /** * @since 3.0 */ public function select($options, $label, $name, $selected=null, $default=null) { $id = 'awpcp-search-' . sanitize_title($label); $default = is_null( $default ) ? __('Select Option', 'another-wordpress-classifieds-plugin') : $default; $html = sprintf('', $id, $label); $html .= sprintf(''; return $html; } function widget($args, $instance) { extract($args); $instance = wp_parse_args($instance, $this->defaults()); if ( !empty( $instance['subtitle'] ) ) { $title = $instance['title'] . '
' . $instance['subtitle'] . ''; } else { $title = $instance['title'] . ''; } echo '
'; echo $before_widget . $before_title . $title . $after_title; echo '
'; $url_params = wp_parse_args( parse_url( url_searchads(), PHP_URL_QUERY ) ); foreach ( $url_params as $param => $value ) { echo ''; } echo ''; $keywordphrase = stripslashes_deep( awpcp_request_param( 'keywordphrase' ) ); if ($instance['show_keyword'] == 1) { echo ''; echo ''; } if ($instance['show_by'] == 1) { echo $this->render_find_by_contact_name_field(); } echo $this->render_region_fields( $instance ); if ($instance['show_category'] == 1) { $label = __('Search by Category', 'another-wordpress-classifieds-plugin'); $name = 'searchcategory'; $selected = stripslashes_deep( awpcp_request_param( $name, null ) ); $dropdown = new AWPCP_CategoriesDropdown(); echo $dropdown->render( array( 'context' => 'search', 'selected' => $selected, 'required' => false, 'name' => $name, 'label' => $label, ) ); } do_action( 'awpcp-search-listings-widget-form-field' ); echo '
'; echo '
'; echo '
'; echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['subtitle'] = strip_tags( $new_instance['subtitle'] ); $instance['show_keyword'] = absint( $new_instance['show_keyword'] ); $instance['show_by'] = absint( $new_instance['show_by'] ); $instance['show_city'] = absint( $new_instance['show_city'] ); $instance['show_county'] = absint( $new_instance['show_county'] ); $instance['show_state'] = absint( $new_instance['show_state'] ); $instance['show_country'] = absint( $new_instance['show_country'] ); $instance['show_category'] = absint( $new_instance['show_category'] ); return $instance; } function form($instance) { $instance = wp_parse_args((array) $instance, $this->defaults()); $title = strip_tags( $instance['title'] ); $subtitle = strip_tags( $instance['subtitle'] ); $show_keyword = absint( $instance['show_keyword'] ); $show_by = absint( $instance['show_by'] ); $show_city = absint( $instance['show_city'] ); $show_county = absint( $instance['show_county'] ); $show_state = absint( $instance['show_state'] ); $show_country = absint( $instance['show_country'] ); $show_category = absint( $instance['show_category'] ); include(AWPCP_DIR . '/frontend/templates/widget-search-form.tpl.php'); } }