'',
'subtitle' => '',
'show_keyword' => 1,
'show_by' => 1,
'show_city' => 1,
'show_state' => 1,
'show_country' => 1,
'show_category' => 1,
);
}
// /**
// * @since 3.0
// */
// protected function get_ad_categories() {
// global $wpdb;
// $conditions[] = 'disabled = 0';
// $conditions[] = '(flagged IS NULL OR flagged = 0)';
// $query = 'SELECT DISTINCT ad_category_id AS id, category_name AS name FROM ' . AWPCP_TABLE_ADS . ' ';
// $query.= 'LEFT JOIN ' . AWPCP_TABLE_CATEGORIES . ' ON (category_id = ad_category_id)';
// $query.= 'WHERE ' . join(' AND ', $conditions);
// $query.= 'ORDER BY category_name';
// $results = $wpdb->get_results($query);
// $categories = array();
// foreach ($results as $result) {
// $categories[$result->id] = $result->name;
// }
// return $categories;
// }
/**
* @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 );
$options = array_combine( $names, $names );
$selected = stripslashes_deep( awpcp_post_param( 'searchname', null ) );
return $this->select( $options, __('Find ads by Contact Name', "AWPCP"), 'searchname', $selected, __( 'All Contact Names', 'AWPCP' ) );
}
/**
* @since 3.0.2
*/
private function render_region_fields( $instance ) {
global $wpdb;
$query = 'SELECT DISTINCT country, state, city FROM ' . AWPCP_TABLE_AD_REGIONS . ' ';
$query.= 'WHERE ad_id IN (';
$query.= 'SELECT ad_id FROM ' . AWPCP_TABLE_ADS . ' WHERE disabled = 0 AND (flagged IS NULL OR flagged = 0)';
$query.= ')';
$query.= 'ORDER BY ad_id ASC';
$results = $wpdb->get_results( $query );
$fields = array(
'city' => __('Search by City', "AWPCP"),
'state' => __('Search by State', "AWPCP"),
'country' => __('Search by Country', "AWPCP"),
);
foreach ( $fields as $name => $label ) {
if ( $instance[ "show_$name" ] ) {
$options = array_filter( array_unique( awpcp_get_properties( $results, $name, '' ) ) );
asort( $options );
$options = array_combine( $options, $options );
echo $this->render_region_field( $label, $options, $name ) . '
';
}
}
}
/**
* @since 3.0.2
*/
private function render_region_field( $label, $options, $name ) {
if ( isset( $_POST['regions'][0][ $name ] ) ) {
$selected = stripslashes_deep( $_POST['regions'][0][ $name ] );
} else {
$selected = null;
}
return $this->select( $options, $label, "regions[0][$name]", $selected );
}
/**
* @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', 'AWPCP') : $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'] . '
';
} else {
$title = $instance['title'] . '';
}
echo $before_widget . $before_title . $title . $after_title;
echo '