/** * The geodirectory popular post view shortcode. * * This implements the functionality of the shortcode for displaying popular post view. * * @since 1.0.0 * @package GeoDirectory * @param array $atts { * Attributes of the shortcode. * * @type string $add_location_filter Filter listings using current location. Default 0. * @type string $before_widget HTML content to prepend to each widget's HTML output. Default. Empty. * @type string $after_widget HTML content to append to each widget's HTML output. Default. Empty. * @type string $before_title HTML content to prepend to the title when displayed. Default. <h3 class="widget-title">. * @type string $after_title HTML content to append to the title when displayed. Default. </h3>. * @type string $category Category ids to filter listings. Ex: 1,3. Default. 0. * @type string $category_title Category title. Default. Empty. * @type string $character_count The excerpt length. Default. 20. * @type string $layout Layout to display listing. Should be gridview_onehalf, gridview_onethird, * gridview_onefourth, gridview_onefifth, list. Default 'gridview_onehalf'. Default. gridview_onehalf. * @type string $list_sort Sort by. Default. latest. * @type string $listing_width Width of the listing in %. Default. Empty. * @type string $post_number No. of post to display. Default. 5. * @type string $post_type Post type of listing. Default. gd_place. * @type string $show_featured_only Display only featured listings. Default. 0. * @type string $show_special_only Display only special offers listings. Default. 0. * @type string $title Widget title. Default. Empty. * @type string $use_viewing_post_type Filter using viewing post type. Default. 1. * @type string $with_pics_only Only display listings which has image available. Default empty. Default. 0. * @type string $with_videos_only Only display listings which has video available. Default. 0. * * } * @return string Popular post view HTML. */ function geodir_sc_popular_post_view($atts) { ob_start(); $defaults = array('post_type' => 'gd_place', 'category' => '0', 'post_number' => '5', 'layout' => 'gridview_onehalf', 'add_location_filter' => '0', 'list_sort' => 'latest', 'use_viewing_post_type' => '1', 'character_count' => '20', 'listing_width' => '', 'show_featured_only' => '0', 'show_special_only' => '0', 'with_pics_only' => '0', 'with_videos_only' => '0', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', 'title' => '', 'category_title' => ''); $params = shortcode_atts($defaults, $atts); /** * Validate our incoming params */ // Validate the selected post type, default to gd_place on fail if (!gdsc_is_post_type_valid($params['post_type'])) { $params['post_type'] = 'gd_place'; } // Validate the selected category/ies - Grab the current list based on post_type $category_taxonomy = geodir_get_taxonomies($params['post_type']); $categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'ids')); // Make sure we have an array if (!is_array($params['category'])) { $params['category'] = explode(',', $params['category']); } // Array_intersect returns only the items in $params['category'] that are also in our category list // Otherwise it becomes empty and later on that will mean "All" $params['category'] = array_intersect($params['category'], $categories); // Post_number needs to be a positive integer $params['post_number'] = absint($params['post_number']); if (0 == $params['post_number']) { $params['post_number'] = 1; } // Validate our layout choice // Outside of the norm, I added some more simple terms to match the existing // So now I just run the switch to set it properly. $params['layout'] = gdsc_validate_layout_choice($params['layout']); // Validate our sorting choice $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort']); // Validate character_count $params['character_count'] = absint($params['character_count']); if (20 > $params['character_count']) { $params['character_count'] = 20; } // Validate Listing width, used in the template widget-listing-listview.php // The context is in width=$listing_width% - So we need a positive number between 0 & 100 $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); // Validate the checkboxes used on the widget $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); $params['show_featured_only'] = gdsc_to_bool_val($params['show_featured_only']); $params['show_special_only'] = gdsc_to_bool_val($params['show_special_only']); $params['with_pics_only'] = gdsc_to_bool_val($params['with_pics_only']); $params['with_videos_only'] = gdsc_to_bool_val($params['with_videos_only']); $params['use_viewing_post_type'] = gdsc_to_bool_val($params['use_viewing_post_type']); /** * End of validation */ geodir_popular_postview_output($params, $params); $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * Front-end display content for popular posts widget. * * @since 1.0.0 * @since 1.5.1 Declare function public. * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { geodir_popular_postview_output($args, $instance); }