Beispiel #1
0
/**
 * Generates popular postview HTML.
 *
 * @since 1.0.0
 * @since 1.5.1 View all link fixed for location filter disabled.
 * @package GeoDirectory
 * @global object $post The current post object.
 * @global string $gridview_columns_widget The girdview style of the listings for widget.
 * @global bool $geodir_is_widget_listing Is this a widget listing?. Default: false.
 * @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_postview_output($args = '', $instance = '')
{
    //print_r($args);
    //print_r($instance);
    // prints the widget
    extract($args, EXTR_SKIP);
    echo $before_widget;
    /** This filter is documented in geodirectory_widgets.php */
    $title = empty($instance['title']) ? ucwords($instance['category_title']) : apply_filters('widget_title', __($instance['title'], 'geodirectory'));
    /**
     * Filter the widget post type.
     *
     * @since 1.0.0
     * @param string $instance['post_type'] Post type of listing.
     */
    $post_type = empty($instance['post_type']) ? 'gd_place' : apply_filters('widget_post_type', $instance['post_type']);
    /**
     * Filter the widget's term.
     *
     * @since 1.0.0
     * @param string $instance['category'] Filter by term. Can be any valid term.
     */
    $category = empty($instance['category']) ? '0' : apply_filters('widget_category', $instance['category']);
    /**
     * Filter the widget listings limit.
     *
     * @since 1.0.0
     * @param string $instance['post_number'] Number of listings to display.
     */
    $post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
    /**
     * Filter widget's "layout" type.
     *
     * @since 1.0.0
     * @param string $instance['layout'] Widget layout type.
     */
    $layout = empty($instance['layout']) ? 'gridview_onehalf' : apply_filters('widget_layout', $instance['layout']);
    /**
     * Filter widget's "add_location_filter" value.
     *
     * @since 1.0.0
     * @param string|bool $instance['add_location_filter'] Do you want to add location filter? Can be 1 or 0.
     */
    $add_location_filter = empty($instance['add_location_filter']) ? '0' : apply_filters('widget_add_location_filter', $instance['add_location_filter']);
    /**
     * Filter widget's listing width.
     *
     * @since 1.0.0
     * @param string $instance['listing_width'] Listing width.
     */
    $listing_width = empty($instance['listing_width']) ? '' : apply_filters('widget_listing_width', $instance['listing_width']);
    /**
     * Filter widget's "list_sort" type.
     *
     * @since 1.0.0
     * @param string $instance['list_sort'] Listing sort by type.
     */
    $list_sort = empty($instance['list_sort']) ? 'latest' : apply_filters('widget_list_sort', $instance['list_sort']);
    $use_viewing_post_type = !empty($instance['use_viewing_post_type']) ? true : false;
    // 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;
            $category = array();
            // old post type category will not work for current changed post type
        }
    }
    // replace widget title dynamically
    $posttype_plural_label = __(get_post_type_plural_label($post_type), 'geodirectory');
    $posttype_singular_label = __(get_post_type_singular_label($post_type), 'geodirectory');
    $title = str_replace("%posttype_plural_label%", $posttype_plural_label, $title);
    $title = str_replace("%posttype_singular_label%", $posttype_singular_label, $title);
    if (isset($instance['character_count'])) {
        /**
         * Filter the widget's excerpt character count.
         *
         * @since 1.0.0
         * @param int $instance['character_count'] Excerpt character count.
         */
        $character_count = apply_filters('widget_list_character_count', $instance['character_count']);
    } else {
        $character_count = '';
    }
    if (empty($title) || $title == 'All') {
        $title .= ' ' . __(get_post_type_plural_label($post_type), 'geodirectory');
    }
    $location_url = array();
    $city = get_query_var('gd_city');
    if (!empty($city)) {
        if (get_option('geodir_show_location_url') == 'all') {
            $country = get_query_var('gd_country');
            $region = get_query_var('gd_region');
            if (!empty($country)) {
                $location_url[] = $country;
            }
            if (!empty($region)) {
                $location_url[] = $region;
            }
        }
        $location_url[] = $city;
    }
    $location_url = implode("/", $location_url);
    $skip_location = false;
    if (!$add_location_filter && !empty($_SESSION['gd_multi_location'])) {
        $skip_location = true;
        unset($_SESSION['gd_multi_location']);
    }
    if (get_option('permalink_structure')) {
        $viewall_url = get_post_type_archive_link($post_type);
    } else {
        $viewall_url = get_post_type_archive_link($post_type);
    }
    if (!empty($category) && $category[0] != '0') {
        global $geodir_add_location_url;
        $geodir_add_location_url = '0';
        if ($add_location_filter != '0') {
            $geodir_add_location_url = '1';
        }
        $viewall_url = get_term_link((int) $category[0], $post_type . 'category');
        $geodir_add_location_url = NULL;
    }
    if ($skip_location) {
        $_SESSION['gd_multi_location'] = 1;
    }
    $query_args = array('posts_per_page' => $post_number, 'is_geodir_loop' => true, 'gd_location' => $add_location_filter ? true : false, 'post_type' => $post_type, 'order_by' => $list_sort);
    if ($character_count) {
        $query_args['excerpt_length'] = $character_count;
    }
    if (!empty($instance['show_featured_only'])) {
        $query_args['show_featured_only'] = 1;
    }
    if (!empty($instance['show_special_only'])) {
        $query_args['show_special_only'] = 1;
    }
    if (!empty($instance['with_pics_only'])) {
        $query_args['with_pics_only'] = 0;
        $query_args['featured_image_only'] = 1;
    }
    if (!empty($instance['with_videos_only'])) {
        $query_args['with_videos_only'] = 1;
    }
    $with_no_results = !empty($instance['without_no_results']) ? false : true;
    if (!empty($category) && $category[0] != '0') {
        $category_taxonomy = geodir_get_taxonomies($post_type);
        ######### WPML #########
        if (function_exists('icl_object_id')) {
            $category = gd_lang_object_ids($category, $category_taxonomy[0]);
        }
        ######### WPML #########
        $tax_query = array('taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $category);
        $query_args['tax_query'] = array($tax_query);
    }
    global $gridview_columns_widget, $geodir_is_widget_listing;
    $widget_listings = geodir_get_widget_listings($query_args);
    if (!empty($widget_listings) || $with_no_results) {
        ?>
        <div class="geodir_locations geodir_location_listing">

            <?php 
        /**
         * Called before the div containing the title and view all link in popular post view widget.
         *
         * @since 1.0.0
         */
        do_action('geodir_before_view_all_link_in_widget');
        ?>
            <div class="geodir_list_heading clearfix">
            <?php 
        if ($title == 'ร้านอาหาร') {
            echo '<img src = "/wordpress/wp-content/food.png" width="100%">';
        } else {
            echo '<img src = "/wordpress/wp-content/u.png" width="100%">';
        }
        ?>
      
          
            
                <?php 
        //echo $before_title . $title . $after_title;
        ?>
                <a href="<?php 
        echo $viewall_url;
        ?>
"
                   class="geodir-viewall"><?php 
        _e('View all', 'geodirectory');
        ?>
</a>
            </div>
            <?php 
        /**
         * Called after the div containing the title and view all link in popular post view widget.
         *
         * @since 1.0.0
         */
        do_action('geodir_after_view_all_link_in_widget');
        ?>
            <?php 
        if (strstr($layout, 'gridview')) {
            $listing_view_exp = explode('_', $layout);
            $gridview_columns_widget = $layout;
            $layout = $listing_view_exp[0];
        } else {
            $gridview_columns_widget = '';
        }
        /**
         * Filter the widget listing listview template path.
         *
         * @since 1.0.0
         */
        $template = apply_filters("geodir_template_part-widget-listing-listview", geodir_locate_template('widget-listing-listview'));
        if (!isset($character_count)) {
            /**
             * Filter the widget's excerpt character count.
             *
             * @since 1.0.0
             * @param int $instance['character_count'] Excerpt character count.
             */
            $character_count = $character_count == '' ? 50 : apply_filters('widget_character_count', $character_count);
        }
        global $post, $map_jason, $map_canvas_arr;
        $current_post = $post;
        $current_map_jason = $map_jason;
        $current_map_canvas_arr = $map_canvas_arr;
        $geodir_is_widget_listing = true;
        /**
         * Includes related listing listview template.
         *
         * @since 1.0.0
         */
        include $template;
        $geodir_is_widget_listing = false;
        $GLOBALS['post'] = $current_post;
        if (!empty($current_post)) {
            setup_postdata($current_post);
        }
        $map_jason = $current_map_jason;
        $map_canvas_arr = $current_map_canvas_arr;
        ?>
        </div>
    <?php 
    }
    echo $after_widget;
}
        /**
         *
         * @global object $wpdb WordPress Database object.
         *
         * @param array $args
         * @param array $instance
         */
        public function widget($args, $instance)
        {
            extract($args, EXTR_SKIP);
            echo $before_widget;
            $title = empty($instance['title']) ? $instance['category_title'] : apply_filters('widget_title', $instance['title']);
            $hood_post_type = empty($instance['hood_post_type']) ? 'gd_place' : apply_filters('widget_hood_post_type', $instance['hood_post_type']);
            $hood_category = empty($instance['hood_category']) ? '0' : apply_filters('widget_hood_category', $instance['hood_category']);
            $post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
            $layout = empty($instance['layout']) ? 'gridview_onehalf' : apply_filters('widget_layout', $instance['layout']);
            $add_location_filter = empty($instance['add_location_filter']) ? '0' : apply_filters('widget_layout', $instance['add_location_filter']);
            $list_sort = empty($instance['list_sort']) ? 'latest' : apply_filters('widget_list_sort', $instance['list_sort']);
            $character_count = empty($instance['character_count']) ? 20 : apply_filters('widget_list_sort', $instance['character_count']);
            if (empty($title) || $title == 'All') {
                $title .= ' Neighbourhood ' . get_post_type_plural_label($hood_post_type);
            }
            global $wpdb, $post, $geodir_post_type;
            if ($geodir_post_type == '') {
                $geodir_post_type = 'gd_place';
            }
            $all_postypes = geodir_get_posttypes();
            $location_id = '';
            $not_in_array = array();
            if (geodir_is_page('detail') || geodir_is_page('preview') || geodir_is_page('add-listing')) {
                if (isset($post->post_type) && $post->post_type == $hood_post_type && isset($post->post_location_id)) {
                    $not_in_array[] = $post->ID;
                    $location_id = $post->post_location_id;
                }
            } elseif (in_array($geodir_post_type, $all_postypes) && $geodir_post_type == $hood_post_type) {
                if (isset($_SESSION['gd_city']) && $_SESSION['gd_city'] != '') {
                    $location_id = $wpdb->get_var($wpdb->prepare("SELECT location_id FROM " . POST_LOCATION_TABLE . " WHERE city_slug = %s", array($_SESSION['gd_city'])));
                } else {
                    $default_location = geodir_get_default_location();
                    $location_id = $default_location->location_id;
                }
            }
            $gd_neighbourhoods = geodir_get_neighbourhoods($location_id);
            if ($gd_neighbourhoods) {
                ?>
			
			<div class="geodir_locations geodir_location_listing">
						<div class="locatin_list_heading clearfix">
							<h3><?php 
                _e(ucfirst($title), GEODIRLOCATION_TEXTDOMAIN);
                ?>
</h3>
						</div>
						
						<?php 
                $hood_slug_arr = array();
                if (!empty($gd_neighbourhoods)) {
                    foreach ($gd_neighbourhoods as $hoodslug) {
                        $hood_slug_arr[] = $hoodslug->hood_slug;
                    }
                }
                $query_args = array('posts_per_page' => $post_number, 'is_geodir_loop' => true, 'post__not_in' => $not_in_array, 'gd_neighbourhood' => $hood_slug_arr, 'gd_location' => $add_location_filter ? true : false, 'post_type' => $hood_post_type, 'order_by' => $list_sort, 'excerpt_length' => $character_count);
                if ($hood_category != 0 || $hood_category != '') {
                    $category_taxonomy = geodir_get_taxonomies($hood_post_type);
                    $tax_query = array('taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $hood_category);
                    $query_args['tax_query'] = array($tax_query);
                }
                global $gridview_columns;
                query_posts($query_args);
                if (strstr($layout, 'gridview')) {
                    $listing_view_exp = explode('_', $layout);
                    $gridview_columns = $layout;
                    $layout = $listing_view_exp[0];
                }
                $template = apply_filters("geodir_template_part-listing-listview", geodir_plugin_path() . '/geodirectory-templates/listing-listview.php');
                include $template;
                wp_reset_query();
                ?>
				
						 
					</div>
			
			<?php 
            }
            echo $after_widget;
        }