コード例 #1
0
ファイル: general_functions.php プロジェクト: bangjojo/wp
/**
 * 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;
}
コード例 #2
0
ファイル: shortcode_functions.php プロジェクト: bangjojo/wp
/**
 * Get the geodirectory listings.
 *
 * @since 1.4.2
 *
 * @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.
 * @global bool   $geodir_event_widget_listview Check that current listview is event.
 * @global object $post The current post object.
 * @global array $map_jason Map data in json format.
 * @global array $map_canvas_arr Map canvas array.
 *
 * @param array $args Array of arguements to filter listings.
 * @return string Listings HTML content.
 */
function geodir_sc_gd_listings_output($args = array())
{
    $title = !empty($args['title']) ? __($args['title'], 'geodirectory') : '';
    $post_type = !empty($args['post_type']) ? $args['post_type'] : 'gd_place';
    $category = !empty($args['category']) ? $args['category'] : '0';
    $post_number = !empty($args['post_number']) ? $args['post_number'] : 10;
    $add_location_filter = !empty($args['add_location_filter']) ? true : false;
    $list_sort = !empty($args['list_sort']) ? $args['list_sort'] : 'latest';
    $character_count = isset($args['character_count']) ? $args['character_count'] : '';
    $layout = !empty($args['layout']) ? $args['layout'] : 'gridview_onehalf';
    $with_pagination = !empty($args['with_pagination']) ? true : false;
    $event_type = !empty($args['event_type']) ? $args['event_type'] : '';
    $top_pagination = $with_pagination && !empty($args['top_pagination']) ? true : false;
    $bottom_pagination = $with_pagination && !empty($args['bottom_pagination']) ? true : false;
    $shortcode_atts = !empty($args['shortcode_atts']) ? $args['shortcode_atts'] : array();
    // ajax mode
    $geodir_ajax = !empty($args['geodir_ajax']) ? true : false;
    $pageno = $geodir_ajax && !empty($args['pageno']) ? $args['pageno'] : 1;
    $query_args = array('posts_per_page' => $post_number, 'is_geodir_loop' => true, 'gd_location' => $add_location_filter, 'post_type' => $post_type, 'order_by' => $list_sort, 'pageno' => $pageno);
    if ($character_count >= 0) {
        $query_args['excerpt_length'] = $character_count;
    }
    if (!empty($args['show_featured_only'])) {
        $query_args['show_featured_only'] = 1;
    }
    if (!empty($args['show_special_only'])) {
        $query_args['show_special_only'] = 1;
    }
    if (!empty($args['with_pics_only'])) {
        $query_args['with_pics_only'] = 0;
        $query_args['featured_image_only'] = 1;
    }
    if (!empty($args['with_videos_only'])) {
        $query_args['with_videos_only'] = 1;
    }
    $with_no_results = !empty($args['without_no_results']) ? false : true;
    if (!empty($category) && isset($category[0]) && $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;
    if ($post_type == 'gd_event' && function_exists('geodir_event_get_widget_events')) {
        global $geodir_event_widget_listview;
        $geodir_event_widget_listview = true;
        if ($event_type && in_array($event_type, array('past', 'today', 'upcoming'))) {
            $query_args['geodir_event_type'] = $event_type;
        }
        $total_posts = geodir_event_get_widget_events($query_args, true);
        $widget_listings = $total_posts > 0 ? geodir_event_get_widget_events($query_args) : array();
    } else {
        $total_posts = geodir_get_widget_listings($query_args, true);
        $widget_listings = $total_posts > 0 ? geodir_get_widget_listings($query_args) : array();
    }
    $current_gridview_columns_widget = $gridview_columns_widget;
    ob_start();
    if (!empty($widget_listings) || $with_no_results) {
        if (!$geodir_ajax) {
            /**
             * Called before the shortcode [gd_listings] content is output.
             *
             * @since 1.0.0
             */
            do_action('geodir_before_sc_gd_listings');
            ?>
        <div class="geodir_locations geodir_location_listing geodir-sc-gd-listings">
		<?php 
        }
        ?>
            <?php 
        if ($title != '') {
            ?>
            <div class="geodir_list_heading clearfix">
                <?php 
            echo $title;
            ?>
            </div>
			<?php 
        }
        ?>
            <?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.
         *
         * @since 1.0.0
         *
         * @param string The template file to display listing.
         */
        $template = apply_filters("geodir_template_part-widget-listing-listview", geodir_locate_template('widget-listing-listview'));
        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;
        if (isset($_SESSION['gd_listing_view'])) {
            unset($_SESSION['gd_listing_view']);
        }
        if ($with_pagination && $top_pagination) {
            echo geodir_sc_listings_pagination($total_posts, $post_number, $pageno);
        }
        /**
         * Includes listing listview template.
         *
         * @since 1.0.0
         */
        include $template;
        if ($with_pagination && $bottom_pagination) {
            echo geodir_sc_listings_pagination($total_posts, $post_number, $pageno);
        }
        $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;
        global $gridview_columns_widget;
        $gridview_columns_widget = $current_gridview_columns_widget;
        ?>
			<p class="geodir-sclisting-loading" style="display:none;"><i class="fa fa-cog fa-spin"></i></p>
			<?php 
        if (!$geodir_ajax) {
            ?>
        </div>
		<script type="text/javascript">
		  function gd_sc_gopage(obj, pid) {
			var pid = parseInt(pid);
			var container = jQuery(obj).closest('.geodir-sc-gd-listings');
			if(!pid > 0 || !(container && typeof container != 'undefined')) {
			  return false;
			}
			var scatts = "<?php 
            echo addslashes(json_encode($shortcode_atts));
            ?>
";
			
			var data = {
			  'action': 'geodir_sclistings',
			  'geodir_sclistings_nonce': '<?php 
            echo wp_create_nonce("geodir-sclistings-nonce");
            ?>
',
			  'scatts': scatts,
			  'geodir_ajax': true,
			  'pageno': pid
			};
			
			jQuery(document).ajaxStop(function() {
			  jQuery(container).find('.geodir_category_list_view').css({'opacity': '1'});
			  jQuery(container).find('.geodir-sclisting-loading').hide();
			});
			
			jQuery(container).find('.geodir_category_list_view').css({'opacity': '0.4'});
			jQuery(container).find('.geodir-sclisting-loading').show();
			
			jQuery.post(geodir_var.geodir_ajax_url, data, function(response) {
			  if(response && response != '0') {
				jQuery(container).html(response);
			  }
			});
		  }
		</script>
		<?php 
        }
        ?>
    <?php 
    }
    $output = ob_get_contents();
    ob_end_clean();
    return trim($output);
}