/** * Generates popular post category HTML. * * @since 1.0.0 * @since 1.5.1 Added option to set default post type. * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @global string $geodir_post_category_str The geodirectory post category. * @param array|string $args Display arguments including before_title, after_title, before_widget, and after_widget. * @param array|string $instance The settings for the particular instance of the widget. */ function geodir_popular_post_category_output($args = '', $instance = '') { // prints the widget global $wpdb, $plugin_prefix, $geodir_post_category_str; extract($args, EXTR_SKIP); echo $before_widget; /** This filter is documented in geodirectory_widgets.php */ $title = empty($instance['title']) ? __('Popular Categories', 'geodirectory') : apply_filters('widget_title', __($instance['title'], 'geodirectory')); $gd_post_type = geodir_get_current_posttype(); $category_limit = isset($instance['category_limit']) && $instance['category_limit'] > 0 ? (int) $instance['category_limit'] : 15; $default_post_type = !empty($gd_post_type) ? $gd_post_type : (isset($instance['default_post_type']) && gdsc_is_post_type_valid($instance['default_post_type']) ? $instance['default_post_type'] : ''); $taxonomy = array(); if (!empty($gd_post_type)) { $taxonomy[] = $gd_post_type . "category"; } else { $taxonomy = geodir_get_taxonomies($gd_post_type); } $terms = get_terms($taxonomy); $a_terms = array(); $b_terms = array(); foreach ($terms as $term) { if ($term->count > 0) { $a_terms[$term->taxonomy][] = $term; } } if (!empty($a_terms)) { foreach ($a_terms as $b_key => $b_val) { $b_terms[$b_key] = geodir_sort_terms($b_val, 'count'); } $default_taxonomy = $default_post_type != '' && isset($b_terms[$default_post_type . 'category']) ? $default_post_type . 'category' : ''; $tax_change_output = ''; if (count($b_terms) > 1) { $tax_change_output .= "<select data-limit='{$category_limit}' class='geodir-cat-list-tax' onchange='geodir_get_post_term(this);'>"; foreach ($b_terms as $key => $val) { $ptype = get_post_type_object(str_replace("category", "", $key)); $tax_change_output .= "<option value='{$key}' " . selected($key, $default_taxonomy, false) . ">" . __($ptype->labels->singular_name, 'geodirectory') . " " . __('Categories', 'geodirectory') . "</option>"; } $tax_change_output .= "</select>"; } if (!empty($b_terms)) { $terms = $default_taxonomy != '' && isset($b_terms[$default_taxonomy]) ? $b_terms[$default_taxonomy] : reset($b_terms); // get the first array global $cat_count; //make global so we can change via function $cat_count = 0; ?> <div class="geodir-category-list-in clearfix"> <div class="geodir-cat-list clearfix"> <?php echo $before_title . __($title) . $after_title; echo $tax_change_output; echo '<ul class="geodir-popular-cat-list">'; geodir_helper_cat_list_output($terms, $category_limit); echo '</ul>'; ?> </div> <?php $hide = ''; if ($cat_count < $category_limit) { $hide = 'style="display:none;"'; } echo "<div class='geodir-cat-list-more' {$hide} >"; echo '<a href="javascript:void(0)" class="geodir-morecat geodir-showcat">' . __('More Categories', 'geodirectory') . '</a>'; echo '<a href="javascript:void(0)" class="geodir-morecat geodir-hidecat geodir-hide">' . __('Less Categories', 'geodirectory') . '</a>'; echo "</div>"; /* add scripts */ add_action('wp_footer', 'geodir_popular_category_add_scripts', 100); ?> </div> <?php } } echo $after_widget; }
/** * Front-end display content for best of widget. * * @since 1.3.9 * @since 1.5.1 Added filter to view all link. * @since 1.5.1 Declare function public. * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); /** * Filter the best of widget tab layout. * * @since 1.3.9 * * @param string $instance['tab_layout'] Best of widget tab layout name. */ $tab_layout = empty($instance['tab_layout']) ? 'bestof-tabs-on-top' : apply_filters('bestof_widget_tab_layout', $instance['tab_layout']); echo '<div class="bestof-widget-tab-layout ' . $tab_layout . '">'; echo $before_widget; $loc_terms = geodir_get_current_location_terms(); if ($loc_terms) { $cur_location = ' : ' . ucwords(str_replace('-', ' ', end($loc_terms))); } else { $cur_location = ''; } /** * Filter the current location name. * * @since 1.3.9 * * @param string $cur_location Current location name. */ $cur_location = apply_filters('bestof_widget_cur_location', $cur_location); /** * Filter the widget title. * * @since 1.3.9 * * @param string $instance['title'] The widget title. */ $title = empty($instance['title']) ? wp_sprintf(__('Best of %s', 'geodirectory'), get_bloginfo('name') . $cur_location) : apply_filters('bestof_widget_title', __($instance['title'], 'geodirectory')); /** * Filter the post type. * * @since 1.3.9 * * @param string $instance['post_type'] The post type. */ $post_type = empty($instance['post_type']) ? 'gd_place' : apply_filters('bestof_widget_post_type', $instance['post_type']); /** * Filter the listing limit. * * @since 1.3.9 * * @param int $instance['post_limit'] No. of posts to display. */ $post_limit = empty($instance['post_limit']) ? '5' : apply_filters('bestof_widget_post_limit', $instance['post_limit']); /** * Filter the category limit. * * @since 1.3.9 * * @param int $instance['categ_limit'] No. of categories to display. */ $categ_limit = empty($instance['categ_limit']) ? '3' : apply_filters('bestof_widget_categ_limit', $instance['categ_limit']); $use_viewing_post_type = !empty($instance['use_viewing_post_type']) ? true : false; /** * Filter the use of location filter. * * @since 1.3.9 * * @param int|bool $instance['add_location_filter'] Filter listings using current location. */ $add_location_filter = empty($instance['add_location_filter']) ? '1' : apply_filters('bestof_widget_location_filter', $instance['add_location_filter']); // set post type to current viewing post type if ($use_viewing_post_type) { $current_post_type = geodir_get_current_posttype(); if ($current_post_type != '' && $current_post_type != $post_type) { $post_type = $current_post_type; } } if (isset($instance['character_count'])) { /** * Filter the widget's excerpt character count. * * @since 1.3.9 * * @param int $instance['character_count'] Excerpt character count. */ $character_count = apply_filters('bestof_widget_list_character_count', $instance['character_count']); } else { $character_count = ''; } $category_taxonomy = geodir_get_taxonomies($post_type); $term_args = array('hide_empty' => true, 'parent' => 0); if (is_tax()) { $taxonomy = get_query_var('taxonomy'); $cur_term = get_query_var('term'); $term_data = get_term_by('name', $cur_term, $taxonomy); $term_args['parent'] = $term_data->term_id; } $terms = get_terms($category_taxonomy[0], $term_args); $term_reviews = geodir_count_reviews_by_terms(); $a_terms = array(); foreach ($terms as $term) { if ($term->count > 0) { if (isset($term_reviews[$term->term_id])) { $term->review_count = $term_reviews[$term->term_id]; } else { $term->review_count = '0'; } $a_terms[] = $term; } } $terms = geodir_sort_terms($a_terms, 'review_count'); $query_args = array('posts_per_page' => $post_limit, 'is_geodir_loop' => true, 'post_type' => $post_type, 'gd_location' => $add_location_filter ? true : false, 'order_by' => 'high_review'); if ($character_count >= 0) { $query_args['excerpt_length'] = $character_count; } $layout = array(); if ($tab_layout == 'bestof-tabs-as-dropdown') { $layout[] = $tab_layout; } else { $layout[] = 'bestof-tabs-as-dropdown'; $layout[] = $tab_layout; } echo $before_title . __($title) . $after_title; //term navigation - start echo '<div class="geodir-tabs gd-bestof-tabs" id="gd-bestof-tabs" style="position:relative;">'; $final_html = ''; foreach ($layout as $tab_layout) { $nav_html = ''; $is_dropdown = $tab_layout == 'bestof-tabs-as-dropdown' ? true : false; if ($is_dropdown) { $nav_html .= '<select id="geodir_bestof_tab_dd" class="chosen_select" name="geodir_bestof_tab_dd" data-placeholder="' . esc_attr(__('Select Category', 'geodirectory')) . '">'; } else { $nav_html .= '<dl class="geodir-tab-head geodir-bestof-cat-list">'; $nav_html .= '<dt></dt>'; } $term_icon = geodir_get_term_icon(); $cat_count = 0; foreach ($terms as $cat) { $cat_count++; if ($cat_count > $categ_limit) { break; } if ($is_dropdown) { $selected = $cat_count == 1 ? 'selected="selected"' : ''; $nav_html .= '<option ' . $selected . ' value="' . $cat->term_id . '">' . ucwords($cat->name) . '</option>'; } else { if ($cat_count == 1) { $nav_html .= '<dd class="geodir-tab-active">'; } else { $nav_html .= '<dd class="">'; } $term_icon_url = !empty($term_icon) && isset($term_icon[$cat->term_id]) ? $term_icon[$cat->term_id] : ''; $nav_html .= '<a data-termid="' . $cat->term_id . '" href="' . get_term_link($cat, $cat->taxonomy) . '">'; $nav_html .= '<img alt="' . $cat->name . ' icon" class="bestof-cat-icon" src="' . $term_icon_url . '"/>'; $nav_html .= '<span>'; $nav_html .= ucwords($cat->name); $nav_html .= '<small>'; if (isset($cat->review_count)) { $num_reviews = $cat->review_count; if ($num_reviews == 0) { $reviews = __('No Reviews', 'geodirectory'); } elseif ($num_reviews > 1) { $reviews = $num_reviews . __(' Reviews', 'geodirectory'); } else { $reviews = __('1 Review', 'geodirectory'); } $nav_html .= $reviews; } $nav_html .= '</small>'; $nav_html .= '</span>'; $nav_html .= '</a>'; $nav_html .= '</dd>'; } } if ($is_dropdown) { $nav_html .= '</select>'; } else { $nav_html .= '</dl>'; } $final_html .= $nav_html; } if ($terms) { echo $final_html; } echo '</div>'; //term navigation - end //first term listings by default - start $first_term = ''; if ($terms) { $first_term = $terms[0]; $tax_query = array('taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $first_term->term_id); $query_args['tax_query'] = array($tax_query); } ?> <input type="hidden" id="bestof_widget_post_type" name="bestof_widget_post_type" value="<?php echo $post_type; ?> "> <input type="hidden" id="bestof_widget_post_limit" name="bestof_widget_post_limit" value="<?php echo $post_limit; ?> "> <input type="hidden" id="bestof_widget_taxonomy" name="bestof_widget_taxonomy" value="<?php echo $category_taxonomy[0]; ?> "> <input type="hidden" id="bestof_widget_location_filter" name="bestof_widget_location_filter" value="<?php if ($add_location_filter) { echo 1; } else { echo 0; } ?> "> <input type="hidden" id="bestof_widget_char_count" name="bestof_widget_char_count" value="<?php echo $character_count; ?> "> <div class="geo-bestof-contentwrap geodir-tabs-content" style="position: relative; z-index: 0;"> <p id="geodir-bestof-loading" class="geodir-bestof-loading"><i class="fa fa-cog fa-spin"></i></p> <?php echo '<div id="geodir-bestof-places">'; if ($terms) { $view_all_link = add_query_arg(array('sort_by' => 'rating_count_desc'), get_term_link($first_term, $first_term->taxonomy)); /** * Filter the page link to view all lisitngs. * * @since 1.5.1 * * @param array $view_all_link View all listings page link. * @param array $post_type The Post type. * @param array $first_term The category term object. */ $view_all_link = apply_filters('geodir_bestof_widget_view_all_link', $view_all_link, $post_type, $first_term); echo '<h3 class="bestof-cat-title">' . wp_sprintf(__('Best of %s', 'geodirectory'), $first_term->name) . '<a href="' . esc_url($view_all_link) . '">' . __("View all", 'geodirectory') . '</a></h3>'; } geodir_bestof_places_by_term($query_args); echo "</div>"; ?> </div> <?php //first term listings by default - end ?> <?php echo $after_widget; echo "</div>"; }
/** * Processes GeoDirectory ajax url calls. * * @see geodir_get_ajax_url() * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global object $current_user Current user object. * @todo check if nonce is required here and if so add one. */ function geodir_ajax_handler() { global $wpdb; if (isset($_REQUEST['gd_listing_view']) && $_REQUEST['gd_listing_view'] != '') { $_SESSION['gd_listing_view'] = $_REQUEST['gd_listing_view']; echo '1'; } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'category_ajax') { if (isset($_REQUEST['main_catid']) && isset($_REQUEST['cat_tax']) && isset($_REQUEST['exclude'])) { geodir_addpost_categories_html($_REQUEST['cat_tax'], $_REQUEST['main_catid'], '', '', '', $_REQUEST['exclude']); } elseif (isset($_REQUEST['catpid']) && isset($_REQUEST['cat_tax'])) { geodir_editpost_categories_html($_REQUEST['cat_tax'], $_REQUEST['catpid']); } } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'admin_ajax' || isset($_REQUEST['create_field']) || isset($_REQUEST['sort_create_field'])) { if (current_user_can('manage_options')) { /** * Contains admin ajax handling functions. * * @since 1.0.0 * @package GeoDirectory */ include_once geodir_plugin_path() . '/geodirectory-admin/geodir_admin_ajax.php'; } else { wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['geodir_autofill']) && $_REQUEST['geodir_autofill'] != '' && isset($_REQUEST['_wpnonce'])) { if (current_user_can('manage_options')) { switch ($_REQUEST['geodir_autofill']) { case "geodir_dummy_delete": if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'geodir_dummy_posts_delete_noncename')) { return; } if (isset($_REQUEST['posttype'])) { /** * Used to delete the dummy post data per post type. * * Uses dynamic hook, geodir_delete_dummy_posts_$_REQUEST['posttype']. * * @since 1.0.0 */ do_action('geodir_delete_dummy_posts_' . $_REQUEST['posttype']); } break; case "geodir_dummy_insert": if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'geodir_dummy_posts_insert_noncename')) { return; } global $dummy_post_index, $city_bound_lat1, $city_bound_lng1, $city_bound_lat2, $city_bound_lng2; $dummy_post_index = $_REQUEST['insert_dummy_post_index']; $city_bound_lat1 = $_REQUEST['city_bound_lat1']; $city_bound_lng1 = $_REQUEST['city_bound_lng1']; $city_bound_lat2 = $_REQUEST['city_bound_lat2']; $city_bound_lng2 = $_REQUEST['city_bound_lng2']; if (isset($_REQUEST['posttype'])) { /** * Used to insert the dummy post data per post type. * * Uses dynamic hook, geodir_insert_dummy_posts_$_REQUEST['posttype']. * * @since 1.0.0 */ do_action('geodir_insert_dummy_posts_' . $_REQUEST['posttype']); } break; } } else { wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['geodir_import_data']) && $_REQUEST['geodir_import_data'] != '') { if (current_user_can('manage_options')) { geodir_import_data(); } else { wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['popuptype']) && $_REQUEST['popuptype'] != '' && isset($_REQUEST['post_id']) && $_REQUEST['post_id'] != '') { if ($_REQUEST['popuptype'] == 'b_send_inquiry' || $_REQUEST['popuptype'] == 'b_sendtofriend') { require_once geodir_plugin_path() . '/geodirectory-templates/popup-forms.php'; } exit; } /*if(isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'filter_ajax'){ include_once ( geodir_plugin_path() . '/geodirectory-templates/advance-search-form.php'); }*/ if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'map_ajax') { /** * Contains map marker functions. * * @since 1.0.0 * @package GeoDirectory */ include_once geodir_plugin_path() . '/geodirectory-functions/map-functions/get_markers.php'; } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'favorite') { if (is_user_logged_in()) { switch ($_REQUEST['ajax_action']) { case "add": geodir_add_to_favorite($_REQUEST['pid']); break; case "remove": geodir_remove_from_favorite($_REQUEST['pid']); break; } } else { wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'add_listing') { $is_current_user_owner = true; if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $is_current_user_owner = geodir_listing_belong_to_current_user($_REQUEST['pid']); } $request = isset($_SESSION['listing']) ? unserialize($_SESSION['listing']) : ''; if (is_user_logged_in() && $is_current_user_owner) { switch ($_REQUEST['ajax_action']) { case "add": case "update": if (isset($request['geodir_spamblocker']) && $request['geodir_spamblocker'] == '64' && isset($request['geodir_filled_by_spam_bot']) && $request['geodir_filled_by_spam_bot'] == '') { $last_id = geodir_save_listing(); if ($last_id) { //$redirect_to = get_permalink( $last_id ); $redirect_to = geodir_getlink(get_permalink(geodir_success_page_id()), array('pid' => $last_id)); } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $redirect_to = get_permalink(geodir_add_listing_page_id()); $redirect_to = geodir_getlink($redirect_to, array('pid' => $post->pid), false); } else { $redirect_to = get_permalink(geodir_add_listing_page_id()); } wp_redirect($redirect_to); } else { if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect(home_url()); } break; case "cancel": unset($_SESSION['listing']); if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '' && get_permalink($_REQUEST['pid'])) { wp_redirect(get_permalink($_REQUEST['pid'])); } else { geodir_remove_temp_images(); wp_redirect(geodir_getlink(get_permalink(geodir_add_listing_page_id()), array('listing_type' => $_REQUEST['listing_type']))); } break; case "publish": if (isset($request['geodir_spamblocker']) && $request['geodir_spamblocker'] == '64' && isset($request['geodir_filled_by_spam_bot']) && $request['geodir_filled_by_spam_bot'] == '') { if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $new_post = array(); $new_post['ID'] = $_REQUEST['pid']; //$new_post['post_status'] = 'publish'; $lastid = wp_update_post($new_post); if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect(get_permalink($lastid)); } else { $last_id = geodir_save_listing(); if ($last_id) { //$redirect_to = get_permalink( $last_id ); $redirect_to = geodir_getlink(get_permalink(geodir_success_page_id()), array('pid' => $last_id)); } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $redirect_to = get_permalink(geodir_add_listing_page_id()); $redirect_to = geodir_getlink($redirect_to, array('pid' => $post->pid), false); } else { $redirect_to = get_permalink(geodir_add_listing_page_id()); } if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect($redirect_to); } } else { if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect(home_url()); } break; case "delete": if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { global $current_user; get_currentuserinfo(); $post_type = get_post_type($_REQUEST['pid']); $lastid = wp_delete_post($_REQUEST['pid']); if ($lastid && !is_wp_error($lastid)) { wp_redirect($_SERVER['HTTP_REFERER']); } //wp_redirect( geodir_getlink(get_author_posts_url($current_user->ID),array('geodir_dashbord'=>'true','stype'=>$post_type ),false) ); } break; } if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } } else { if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'user_login') { /** * Contains registration and login functions. * @todo Fix the file path. * * @since 1.0.0 * @package GeoDirectory */ include_once geodir_plugin_path() . '/geodirectory-functions/geodirectory_reg.php'; } if (isset($_REQUEST['ajax_action']) && $_REQUEST['ajax_action'] == 'geodir_get_term_list') { $terms_o = get_terms(sanitize_text_field($_REQUEST['term'])); // Skip terms which has no listing if (!empty($terms_o)) { $filter_terms = array(); foreach ($terms_o as $term) { if ($term->count > 0) { $filter_terms[] = $term; } } $terms_o = $filter_terms; } $terms = geodir_sort_terms($terms_o, 'count'); geodir_helper_cat_list_output($terms, intval($_REQUEST['limit'])); exit; } die; }
/** * Get the child categories content. * * @since 1.5.4 * * @param int $parent_id Parent category id. * @param string $cpt The post type. * @param bool $hide_empty If true then filter the empty categories. * @param bool $show_count If true then category count will be displayed. * @param string $sort_by Sorting order for categories. * @param bool|string $max_count Max no of sub-categories count to display. * @param bool|string $max_level Max depth level sub-categories to display. * @param array $term_icons Array of terms icons url. * @param int $depth Category depth level. Default 1. * @return string Html content. */ function geodir_cpt_categories_child_cats($parent_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons, $depth = 1) { $cat_taxonomy = $cpt . 'category'; $orderby = 'count'; $order = 'DESC'; if ($sort_by == 'az') { $orderby = 'name'; $order = 'ASC'; } if ($max_level != 'all' && $depth > (int) $max_level) { return ''; } $child_cats = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'parent' => $parent_id, 'number' => $max_count)); if ($hide_empty) { $child_cats = geodir_filter_empty_terms($child_cats); } if (empty($child_cats)) { return ''; } if ($sort_by == 'count') { $child_cats = geodir_sort_terms($child_cats, 'count'); } $content = '<li class="gd-cptcat-li gd-cptcat-li-sub"><ul class="gd-cptcat-ul gd-cptcat-sub gd-cptcat-sub-' . $depth . '">'; $depth++; foreach ($child_cats as $category) { $term_icon_url = !empty($term_icons) && isset($term_icons[$category->term_id]) ? $term_icons[$category->term_id] : ''; $term_icon_url = $term_icon_url != '' ? '<img alt="' . esc_attr($category->name) . ' icon" src="' . $term_icon_url . '" /> ' : ''; $term_link = get_term_link($category, $category->taxonomy); /** Filter documented in geodirectory-functions/general_functions.php **/ $term_link = apply_filters('geodir_category_term_link', $term_link, $category->term_id, $cpt); $count = $show_count ? ' <span class="gd-cptcat-count">(' . $category->count . ')</span>' : ''; $content .= '<li class="gd-cptcat-li gd-cptcat-li-sub">'; $content .= '<a href="' . esc_url($term_link) . '" title="' . esc_attr($category->name) . '">' . $term_icon_url . $category->name . $count . '</a></li>'; $content .= geodir_cpt_categories_child_cats($category->term_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons, $depth); } $content .= '</li></ul>'; return $content; }