/** * Home map Taxonomy walker. * * @since 1.0.0 * @package GeoDirectory * @param string $cat_taxonomy Name of the taxonomy e.g place_category. * @param int $cat_parent Optional. Parent term ID to retrieve its child terms. Default 0. * @param bool $hide_empty Optional. Do you want to hide the terms that has no posts. Default true. * @param int $pading Optional. CSS padding value in pixels. e.g: 12 will be considers as 12px. * @param string $map_canvas_name Unique canvas name for your map. * @param bool $child_collapse Do you want to collapse child terms by default?. * @param bool $is_home_map Optional. Is this a home page map? Default: false. * @return string|void */ function home_map_taxonomy_walker($cat_taxonomy, $cat_parent = 0, $hide_empty = true, $pading = 0, $map_canvas_name = '', $child_collapse, $is_home_map = false) { global $cat_count, $geodir_cat_icons; $exclude_categories = get_option('geodir_exclude_cat_on_map'); $exclude_categories_new = get_option('geodir_exclude_cat_on_map_upgrade'); // check if exclude categories saved before fix of categories identical names if ($exclude_categories_new) { $gd_cat_taxonomy = isset($cat_taxonomy[0]) ? $cat_taxonomy[0] : ''; $exclude_categories = !empty($exclude_categories[$gd_cat_taxonomy]) && is_array($exclude_categories[$gd_cat_taxonomy]) ? array_unique($exclude_categories[$gd_cat_taxonomy]) : array(); } $exclude_cat_str = implode(',', $exclude_categories); if ($exclude_cat_str == '') { $exclude_cat_str = '0'; } $cat_terms = get_terms($cat_taxonomy, array('parent' => $cat_parent, 'exclude' => $exclude_cat_str, 'hide_empty ' => $hide_empty)); $main_list_class = ''; //If there are terms, start displaying if (count($cat_terms) > 0) { //Displaying as a list $p = $pading * 15; $pading++; if ($cat_parent == 0) { $list_class = 'main_list'; $display = ''; } else { $list_class = 'sub_list'; $display = !$child_collapse ? '' : 'display:none'; } $out = '<ul class="treeview ' . $list_class . '" style="margin-left:' . $p . 'px;' . $display . ';">'; $geodir_cat_icons = geodir_get_term_icon(); foreach ($cat_terms as $cat_term) { $post_type = isset($_REQUEST['post_type']) ? $_REQUEST['post_type'] : 'gd_place'; $icon = !empty($geodir_cat_icons) && isset($geodir_cat_icons[$cat_term->term_id]) ? $geodir_cat_icons[$cat_term->term_id] : ''; if (!in_array($cat_term->term_id, $exclude_categories)) { //Secret sauce. Function calls itself to display child elements, if any $checked = 'checked="checked"'; // Untick the category by default on home map if ($is_home_map && ($geodir_home_map_untick = get_option('geodir_home_map_untick'))) { if (!empty($geodir_home_map_untick) && in_array($post_type . '_' . $cat_term->term_id, $geodir_home_map_untick)) { $checked = ''; } } $term_check = '<input type="checkbox" ' . $checked . ' class="group_selector ' . $main_list_class . '"'; $term_check .= ' name="' . $map_canvas_name . '_cat[]" group="catgroup' . $cat_term->term_id . '"'; $term_check .= ' alt="' . $cat_term->taxonomy . '" title="' . esc_attr(ucfirst($cat_term->name)) . '" value="' . $cat_term->term_id . '" onclick="javascript:build_map_ajax_search_param(\'' . $map_canvas_name . '\',false, this)">'; $term_check .= '<img height="15" width="15" alt="" src="' . $icon . '" title="' . ucfirst($cat_term->name) . '"/>'; $out .= '<li>' . $term_check . '<label>' . ucfirst($cat_term->name) . '</label><i class="fa fa-long-arrow-down"></i>'; } // get sub category by recurson $out .= home_map_taxonomy_walker($cat_taxonomy, $cat_term->term_id, $hide_empty, $pading, $map_canvas_name, $child_collapse, $is_home_map); $out .= '</li>'; } $out .= '</ul>'; return $out; } else { if ($cat_parent == 0) { return _e('No category', 'geodirectory'); } } return; }
/** * Generates category list HTML. * * @since 1.0.0 * @package GeoDirectory * @global string $geodir_post_category_str The geodirectory post category. * @param array $terms An array of term objects. * @param int $category_limit Number of categories to display by default. */ function geodir_helper_cat_list_output($terms, $category_limit) { global $geodir_post_category_str, $cat_count; $term_icons = geodir_get_term_icon(); $geodir_post_category_str = array(); foreach ($terms as $cat) { $post_type = str_replace("category", "", $cat->taxonomy); $term_icon_url = !empty($term_icons) && isset($term_icons[$cat->term_id]) ? $term_icons[$cat->term_id] : ''; $cat_count++; $geodir_post_category_str[] = array('posttype' => $post_type, 'termid' => $cat->term_id); $class_row = $cat_count > $category_limit ? 'geodir-pcat-hide geodir-hide' : 'geodir-pcat-show'; $total_post = $cat->count; $term_link = get_term_link($cat, $cat->taxonomy); /** * Filer the category term link. * * @since 1.4.5 * @param string $term_link The term permalink. * @param int $cat->term_id The term id. * @param string $post_type Wordpress post type. */ $term_link = apply_filters('geodir_category_term_link', $term_link, $cat->term_id, $post_type); echo '<li class="' . $class_row . '"><a href="' . $term_link . '">'; echo '<img alt="' . $cat->name . ' icon" class="" style="height:20px;vertical-align:middle;" src="' . $term_icon_url . '"/> '; echo ucwords($cat->name) . ' (<span class="geodir_term_class geodir_link_span geodir_category_class_' . $post_type . '_' . $cat->term_id . '" >' . $total_post . '</span>) '; echo '</a></li>'; } }
/** * Retrive markers data to use in map * * @since 1.0.0 * * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @global array $geodir_cat_icons Array of the category icon urls. * * @return string */ function get_markers() { global $wpdb, $plugin_prefix, $geodir_cat_icons; $search = ''; $main_query_array; $srcharr = array("'", "/", "-", '"', '\\'); $replarr = array("′", "⁄", "–", "“", ''); $post_type = isset($_REQUEST['gd_posttype']) ? $_REQUEST['gd_posttype'] : 'gd_place'; $map_cat_ids_array = array('0'); $cat_find_array = array(" FIND_IN_SET(%d, pd." . $post_type . "category)"); $field_default_cat = ''; if (isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] != '') { $map_cat_arr = trim($_REQUEST['cat_id'], ','); if (!empty($map_cat_arr)) { $field_default_cat .= "when (default_category IN (" . $map_cat_arr . ")) then default_category "; $map_cat_ids_array = explode(',', $map_cat_arr); $cat_find_array = array(); foreach ($map_cat_ids_array as $cat_id) { $field_default_cat .= "when ( find_in_set({$cat_id}, `" . $post_type . "category`) > 0) then {$cat_id} "; $cat_find_array[] = " FIND_IN_SET(%d, pd." . $post_type . "category)"; $main_query_array[] = $cat_id; } } } if (!empty($field_default_cat)) { $field_default_cat = ''; } if (!empty($cat_find_array)) { $search .= "AND (" . implode(' OR ', $cat_find_array) . ")"; } $main_query_array = $map_cat_ids_array; if (isset($_REQUEST['search']) && !empty($_REQUEST['search']) && $_REQUEST['search'] != __('Title', GEODIRECTORY_TEXTDOMAIN)) { $search .= " AND p.post_title like %s"; $main_query_array[] = "%" . $_REQUEST['search'] . "%"; } /** * @todo below code is for testing and should be removed in the future by stiofan */ /* if(isset($_REQUEST['zl']) && $_REQUEST['zl']) { $search .= " AND pd.post_latitude > %s AND pd.post_latitude < %s AND pd.post_longitude > %s AND pd.post_longitude < %s "; $main_query_array[] = min($_REQUEST['lat_sw'],$_REQUEST['lat_ne']); $main_query_array[] = max($_REQUEST['lat_sw'],$_REQUEST['lat_ne']); $main_query_array[] = max($_REQUEST['lon_sw'],$_REQUEST['lon_ne']); $main_query_array[] = min($_REQUEST['lon_sw'],$_REQUEST['lon_ne']); } */ $gd_posttype = ''; if (isset($_REQUEST['gd_posttype']) && $_REQUEST['gd_posttype'] != '') { $table = $plugin_prefix . $_REQUEST['gd_posttype'] . '_detail'; $gd_posttype = " AND p.post_type = %s"; $main_query_array[] = $_REQUEST['gd_posttype']; } else { $table = $plugin_prefix . 'gd_place_detail'; } $join = $table . " as pd "; /** * Filter the SQL JOIN clause for the markers data * * @since 1.0.0 * * @param string $join Row of SQL JOIN clause to join table. */ $join = apply_filters('geodir_home_map_listing_join', $join); /** * Filter the searched fields for the markers data * * @since 1.0.0 * * @param string $search Row of searched fields to use in WHERE clause. */ $search = apply_filters('geodir_home_map_listing_where', $search); $search = str_replace(array("'%", "%'"), array("'%%", "%%'"), $search); $cat_type = $post_type . 'category'; if ($post_type == 'gd_event') { $event_select = ",pd.recurring_dates"; } else { $event_select = ""; } $sql_select = 'SELECT pd.default_category,pd.' . $cat_type . ',pd.post_title,pd.post_id,pd.post_latitude,pd.post_longitude ' . $event_select; /** * Filter the SQL SELECT clause to retrive fields data * * @since 1.0.0 * * @param string $sql_select Row of SQL SELECT clause. */ $select = apply_filters('geodir_home_map_listing_select', $sql_select); $catsql = $wpdb->prepare("{$select} {$field_default_cat} FROM " . $wpdb->posts . " as p," . $join . " WHERE p.ID = pd.post_id\r\n\t\t\t\tAND p.post_status = 'publish' " . $search . $gd_posttype, $main_query_array); /** * Filter the SQL query to retrive markers data * * @since 1.0.0 * * @param string $catsql Row of SQL query. * @param string $search Row of searched fields to use in WHERE clause. */ $catsql = apply_filters('geodir_home_map_listing_query', $catsql, $search); //echo $catsql; // print_r($_REQUEST); $catinfo = $wpdb->get_results($catsql); $cat_content_info = array(); $content_data = array(); $post_ids = array(); /** * Called before marker data is processed into JSON. * * Called before marker data is processed into JSON, this action can be used to change the format or add/remove markers. * * @since 1.4.9 * @param object $catinfo The posts object containing all marker data. * @see 'geodir_after_marker_post_process' */ do_action('geodir_before_marker_post_process', $catinfo); // Sort any posts into a ajax array if (!empty($catinfo)) { $geodir_cat_icons = geodir_get_term_icon(); global $geodir_date_format; foreach ($catinfo as $catinfo_obj) { $icon = !empty($geodir_cat_icons) && isset($geodir_cat_icons[$catinfo_obj->default_category]) ? $geodir_cat_icons[$catinfo_obj->default_category] : ''; $e_dates = ''; if ($post_type == 'gd_event') { $event_arr = maybe_unserialize($catinfo_obj->recurring_dates); $e_arr = explode(",", $event_arr['event_recurring_dates']); $e = 0; foreach ($e_arr as $e_date) { if (strtotime($e_date) >= strtotime(date("Y-m-d"))) { $e++; $e_dates .= ' :: ' . date($geodir_date_format, strtotime($e_date)); // only show 3 event dates if ($e == 3) { break; } } } // if the event is old don't show it on the map if ($e_dates == '') { continue; } } $post_title = $catinfo_obj->post_title . $e_dates; $title = str_replace($srcharr, $replarr, $post_title); $content_data[] = '{"id":"' . $catinfo_obj->post_id . '","t": "' . $title . '","lt": "' . $catinfo_obj->post_latitude . '","ln": "' . $catinfo_obj->post_longitude . '","mk_id":"' . $catinfo_obj->post_id . '_' . $catinfo_obj->default_category . '","i":"' . $icon . '"}'; $post_ids[] = $catinfo_obj->post_id; } } /** * Called after marker data is processed into JSON. * * Called after marker data is processed into JSON, this action can be used to change the format or add/remove markers. * * @since 1.4.9 * @param array $content_data The array containing all markers in JSON format. * @param object $catinfo The posts object containing all marker data. * @see 'geodir_before_marker_post_process' */ do_action('geodir_after_marker_post_process', $content_data, $catinfo); if (!empty($content_data)) { $cat_content_info[] = implode(',', $content_data); } $totalcount = count(array_unique($post_ids)); if (!empty($cat_content_info)) { return '[{"totalcount":"' . $totalcount . '",' . substr(implode(',', $cat_content_info), 1) . ']'; } else { return '[{"totalcount":"0"}]'; } }
/** * 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>"; }
/** * Get the cpt categories content. * * @since 1.5.4 * * @param array $params An array of cpt categories parameters. * @return string CPT categories content. */ function geodir_cpt_categories_output($params) { $args = wp_parse_args((array) $params, array('title' => '', 'post_type' => array(), 'hide_empty' => '', 'show_count' => '', 'hide_icon' => '', 'cpt_left' => '', 'sort_by' => 'count', 'max_count' => 'all', 'max_level' => '1')); $sort_by = isset($args['sort_by']) && in_array($args['sort_by'], array('az', 'count')) ? $args['sort_by'] : 'count'; $gd_post_types = geodir_get_posttypes('array'); $post_type_arr = !is_array($args['post_type']) ? explode(',', $args['post_type']) : $args['post_type']; $current_posttype = geodir_get_current_posttype(); $is_listing = false; $is_category = false; if (geodir_is_page('listing')) { $current_posttype = geodir_get_current_posttype(); if ($current_posttype != '' && isset($gd_post_types[$current_posttype])) { $is_listing = true; if (is_tax()) { // category page $current_term_id = get_queried_object_id(); $current_taxonomy = get_query_var('taxonomy'); $current_posttype = geodir_get_current_posttype(); if ($current_term_id && $current_posttype && get_query_var('taxonomy') == $current_posttype . 'category') { $is_category = true; } } } } $parent_category = 0; if ($is_listing) { $post_type_arr = array($current_posttype); if ($is_category) { $parent_category = $current_term_id; } } $post_types = array(); if (!empty($post_type_arr)) { if (in_array('0', $post_type_arr)) { $post_types = $gd_post_types; } else { foreach ($post_type_arr as $cpt) { if (isset($gd_post_types[$cpt])) { $post_types[$cpt] = $gd_post_types[$cpt]; } } } } if (empty($post_type_arr)) { $post_types = $gd_post_types; } $hide_empty = !empty($args['hide_empty']) ? true : false; $max_count = strip_tags($args['max_count']); $all_childs = $max_count == 'all' ? true : false; $max_count = $max_count > 0 ? (int) $max_count : 0; $max_level = strip_tags($args['max_level']); $show_count = !empty($args['show_count']) ? true : false; $hide_icon = !empty($args['hide_icon']) ? true : false; $cpt_left = !empty($args['cpt_left']) ? true : false; if (!$cpt_left) { $cpt_left = "gd-cpt-flat"; } else { $cpt_left = ''; } $orderby = 'count'; $order = 'DESC'; if ($sort_by == 'az') { $orderby = 'name'; $order = 'ASC'; } $output = ''; if (!empty($post_types)) { foreach ($post_types as $cpt => $cpt_info) { $cat_taxonomy = $cpt . 'category'; $categories = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'parent' => $parent_category)); if ($hide_empty) { $categories = geodir_filter_empty_terms($categories); } if ($sort_by == 'count') { $categories = geodir_sort_terms($categories, 'count'); } if (!empty($categories)) { $term_icons = !$hide_icon ? geodir_get_term_icon() : array(); $row_class = ''; if ($is_listing) { $row_class = $is_category ? ' gd-cptcat-categ' : ' gd-cptcat-listing'; } $cpt_row = '<div class="gd-cptcat-row gd-cptcat-' . $cpt . $row_class . ' ' . $cpt_left . '">'; if ($is_category) { $term_info = get_term($current_term_id, $cat_taxonomy); $term_icon_url = !empty($term_icons) && isset($term_icons[$term_info->term_id]) ? $term_icons[$term_info->term_id] : ''; $term_icon_url = $term_icon_url != '' ? '<img alt="' . esc_attr($term_info->name) . ' icon" src="' . $term_icon_url . '" /> ' : ''; $count = $show_count ? ' <span class="gd-cptcat-count">(' . $term_info->count . ')</span>' : ''; $cpt_row .= '<h2 class="gd-cptcat-title">' . $term_icon_url . $term_info->name . $count . '</h2>'; } else { $cpt_row .= '<h2 class="gd-cptcat-title">' . __($cpt_info['labels']['name'], 'geodirectory') . '</h2>'; } foreach ($categories 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); $cpt_row .= '<ul class="gd-cptcat-ul gd-cptcat-parent ' . $cpt_left . '">'; $cpt_row .= '<li class="gd-cptcat-li gd-cptcat-li-main">'; $count = $show_count ? ' <span class="gd-cptcat-count">(' . $category->count . ')</span>' : ''; $cpt_row .= '<h3 class="gd-cptcat-cat"><a href="' . esc_url($term_link) . '" title="' . esc_attr($category->name) . '">' . $term_icon_url . $category->name . $count . '</a></h3>'; if (($all_childs || $max_count > 0) && ($max_level == 'all' || (int) $max_level > 0)) { $cpt_row .= geodir_cpt_categories_child_cats($category->term_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons); } $cpt_row .= '</li>'; $cpt_row .= '</ul>'; } $cpt_row .= '</ul></div>'; $output .= $cpt_row; } } } return $output; }
/** * Retrive markers data to use in map * * @since 1.0.0 * @since 1.5.7 Fixed non recurring events markers. * * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @global array $geodir_cat_icons Array of the category icon urls. * * @return string */ function get_markers() { global $wpdb, $plugin_prefix, $geodir_cat_icons; $search = ''; $main_query_array; $srcharr = array("'", "/", "-", '"', '\\'); $replarr = array("′", "⁄", "–", "“", ''); $post_type = isset($_REQUEST['gd_posttype']) ? $_REQUEST['gd_posttype'] : 'gd_place'; $map_cat_ids_array = array('0'); $cat_find_array = array(" FIND_IN_SET(%d, pd." . $post_type . "category)"); $field_default_cat = ''; if (isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] != '') { $map_cat_arr = trim($_REQUEST['cat_id'], ','); if (!empty($map_cat_arr)) { $field_default_cat .= "WHEN (default_category IN (" . $map_cat_arr . ")) THEN default_category "; $map_cat_ids_array = explode(',', $map_cat_arr); $cat_find_array = array(); foreach ($map_cat_ids_array as $cat_id) { $field_default_cat .= "WHEN (FIND_IN_SET({$cat_id}, `" . $post_type . "category`) > 0) THEN {$cat_id} "; $cat_find_array[] = " FIND_IN_SET(%d, pd." . $post_type . "category)"; $main_query_array[] = $cat_id; } } } if (!empty($field_default_cat)) { $field_default_cat = ''; } if (!empty($cat_find_array)) { $search .= "AND (" . implode(' OR ', $cat_find_array) . ")"; } $main_query_array = $map_cat_ids_array; if (isset($_REQUEST['search']) && !empty($_REQUEST['search']) && $_REQUEST['search'] != __('Title', 'geodirectory')) { $search .= " AND p.post_title LIKE %s"; $main_query_array[] = "%" . $_REQUEST['search'] . "%"; } /** * Filter the marker query search SQL, values are replaces with %s or %d. * * @since 1.5.3 * * @param string $search The SQL query for search/where. */ $search = apply_filters('geodir_marker_search', $search); /** * Filter the marker query search SQL values %s and %d, this is an array of values. * * @since 1.5.3 * * @param array $main_query_array The SQL query values for search/where. */ $main_query_array = apply_filters('geodir_marker_main_query_array', $main_query_array); $gd_posttype = ''; if (isset($_REQUEST['gd_posttype']) && $_REQUEST['gd_posttype'] != '') { $table = $plugin_prefix . $_REQUEST['gd_posttype'] . '_detail'; $gd_posttype = " AND p.post_type = %s"; $main_query_array[] = $_REQUEST['gd_posttype']; } else { $table = $plugin_prefix . 'gd_place_detail'; } $join = ", " . $table . " AS pd "; /** * Filter the SQL JOIN clause for the markers data * * @since 1.0.0 * * @param string $join Row of SQL JOIN clause to join table. */ $join = apply_filters('geodir_home_map_listing_join', $join); /** * Filter the searched fields for the markers data * * @since 1.0.0 * * @param string $search Row of searched fields to use in WHERE clause. */ $search = apply_filters('geodir_home_map_listing_where', $search); $search = str_replace(array("'%", "%'"), array("'%%", "%%'"), $search); $cat_type = $post_type . 'category'; if ($post_type == 'gd_event') { $event_select = ", pd.recurring_dates, pd.is_recurring"; } else { $event_select = ""; } $sql_select = 'SELECT pd.default_category, pd.' . $cat_type . ', pd.post_title, pd.post_id, pd.post_latitude, pd.post_longitude' . $event_select; /** * Filter the SQL SELECT clause to retrive fields data * * @since 1.0.0 * * @param string $sql_select Row of SQL SELECT clause. */ $select = apply_filters('geodir_home_map_listing_select', $sql_select); $groupby = " GROUP BY pd.post_id"; /** * Filter the SQL GROUP BY clause to retrive map markers data. * * @since 1.5.7 * * @param string $groupby Row of SQL GROUP BY clause. */ $groupby = apply_filters('geodir_home_map_listing_groupby', $groupby); $catsql = $wpdb->prepare("{$select} {$field_default_cat} FROM " . $wpdb->posts . " as p" . $join . " WHERE p.ID = pd.post_id AND p.post_status = 'publish' " . $search . $gd_posttype . $groupby, $main_query_array); /** * Filter the SQL query to retrive markers data * * @since 1.0.0 * * @param string $catsql Row of SQL query. * @param string $search Row of searched fields to use in WHERE clause. */ $catsql = apply_filters('geodir_home_map_listing_query', $catsql, $search); $catinfo = $wpdb->get_results($catsql); $cat_content_info = array(); $content_data = array(); $post_ids = array(); /** * Called before marker data is processed into JSON. * * Called before marker data is processed into JSON, this action can be used to change the format or add/remove markers. * * @since 1.5.3 * @param object $catinfo The posts object containing all marker data. * @see 'geodir_after_marker_post_process' */ $catinfo = apply_filters('geodir_before_marker_post_process', $catinfo); /** * Called before marker data is processed into JSON. * * Called before marker data is processed into JSON, this action can be used to change the format or add/remove markers. * * @since 1.4.9 * @param object $catinfo The posts object containing all marker data. * @see 'geodir_after_marker_post_process' */ do_action('geodir_before_marker_post_process_action', $catinfo); // Sort any posts into a ajax array if (!empty($catinfo)) { $geodir_cat_icons = geodir_get_term_icon(); global $geodir_date_format; $today = strtotime(date_i18n('Y-m-d')); foreach ($catinfo as $catinfo_obj) { $post_title = $catinfo_obj->post_title; if ($post_type == 'gd_event' && !empty($catinfo_obj->recurring_dates)) { $event_dates = ''; $recurring_data = isset($catinfo_obj->recurring_dates) ? maybe_unserialize($catinfo_obj->recurring_dates) : array(); $post_info = geodir_get_post_info($catinfo_obj->post_id); if (!empty($catinfo_obj->is_recurring) && !empty($recurring_data) && !empty($recurring_data['is_recurring']) && geodir_event_recurring_pkg($post_info)) { $recurring_dates = explode(',', $recurring_data['event_recurring_dates']); if (!empty($recurring_dates)) { $e = 0; foreach ($recurring_dates as $date) { if (strtotime($date) >= $today) { $event_dates .= ' :: ' . date_i18n($geodir_date_format, strtotime($date)); $e++; if ($e == 3) { // only show 3 event dates break; } } } } } else { $start_date = !empty($recurring_data['event_start']) && $recurring_data['event_start'] != '0000-00-00 00:00:00' ? $recurring_data['event_start'] : ''; $end_date = !empty($recurring_data['event_end']) && $recurring_data['event_end'] != '0000-00-00 00:00:00' ? $recurring_data['event_end'] : $start_date; if ($end_date != '' && strtotime($end_date) >= $today) { $event_dates .= ' :: ' . date_i18n($geodir_date_format, strtotime($start_date)) . ' -> ' . date_i18n($geodir_date_format, strtotime($end_date)); } } if (empty($event_dates)) { continue; } $post_title .= $event_dates; } $icon = !empty($geodir_cat_icons) && isset($geodir_cat_icons[$catinfo_obj->default_category]) ? $geodir_cat_icons[$catinfo_obj->default_category] : ''; $mark_extra = isset($catinfo_obj->marker_extra) ? $catinfo_obj->marker_extra : ''; $title = str_replace($srcharr, $replarr, $post_title); $content_data[] = '{"id":"' . $catinfo_obj->post_id . '","t": "' . $title . '","lt": "' . $catinfo_obj->post_latitude . '","ln": "' . $catinfo_obj->post_longitude . '","mk_id":"' . $catinfo_obj->post_id . '_' . $catinfo_obj->default_category . '","i":"' . $icon . '"' . $mark_extra . '}'; $post_ids[] = $catinfo_obj->post_id; } } /** * Called after marker data is processed into JSON. * * Called after marker data is processed into JSON, this action can be used to change the format or add/remove markers. * * @since 1.4.9 * @param array $content_data The array containing all markers in JSON format. * @param object $catinfo The posts object containing all marker data. * @see 'geodir_before_marker_post_process' */ do_action('geodir_after_marker_post_process', $content_data, $catinfo); if (!empty($content_data)) { $cat_content_info[] = implode(',', $content_data); } $totalcount = count(array_unique($post_ids)); if (!empty($cat_content_info)) { return '[{"totalcount":"' . $totalcount . '",' . substr(implode(',', $cat_content_info), 1) . ']'; } else { return '[{"totalcount":"0"}]'; } }