/**
  * Front-end display content for related listing 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)
 {
     // prints the widget
     extract($args, EXTR_SKIP);
     /** This filter is documented in geodirectory_widgets.php */
     $title = empty($instance['title']) ? __('Related Listing', 'geodirectory') : apply_filters('widget_title', __($instance['title'], 'geodirectory'));
     /** This filter is documented in geodirectory-functions/general_functions.php */
     $post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
     /**
      * Filter the relation type to get related listing.
      *
      * @since 1.0.0
      * @param string $instance['relate_to'] Can be tags or category.
      */
     $relate_to = empty($instance['relate_to']) ? 'category' : apply_filters('widget_relate_to', $instance['relate_to']);
     /** This filter is documented in geodirectory-functions/general_functions.php */
     $layout = empty($instance['layout']) ? 'gridview_onehalf' : apply_filters('widget_layout', $instance['layout']);
     /** This filter is documented in geodirectory-functions/general_functions.php */
     $add_location_filter = empty($instance['add_location_filter']) ? '0' : apply_filters('widget_add_location_filter', $instance['add_location_filter']);
     /** This filter is documented in geodirectory-functions/general_functions.php */
     $listing_width = empty($instance['listing_width']) ? '' : apply_filters('widget_listing_width', $instance['listing_width']);
     /** This filter is documented in geodirectory-functions/general_functions.php */
     $list_sort = empty($instance['list_sort']) ? 'latest' : apply_filters('widget_list_sort', $instance['list_sort']);
     /** This filter is documented in geodirectory-functions/general_functions.php */
     $character_count = empty($instance['character_count']) ? 20 : apply_filters('widget_list_character_count', $instance['character_count']);
     $arr = array('before_title' => $before_title, 'after_title' => $after_title, 'title' => $title, 'post_number' => $post_number, 'relate_to' => $relate_to, 'layout' => $layout, 'add_location_filter' => $add_location_filter, 'listing_width' => $listing_width, 'list_sort' => $list_sort, 'character_count' => $character_count, 'is_widget' => '1');
     if ($widget_display = geodir_related_posts_display($arr)) {
         echo $before_widget;
         echo $widget_display;
         echo $after_widget;
     }
 }
/**
 * The main function responsible for displaying tabs in frontend detail page.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $post The current post object.
 * @global array $post_images List of images attached to the post.
 * @global string $video The video embed content.
 * @global string $special_offers Special offers content.
 * @global string $related_listing Related listing html.
 * @global string $geodir_post_detail_fields Detail field html.
 */
function geodir_show_detail_page_tabs()
{
    global $post, $post_images, $video, $special_offers, $related_listing, $geodir_post_detail_fields;
    $post_id = !empty($post) && isset($post->ID) ? (int) $post->ID : 0;
    $request_post_id = !empty($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0;
    $is_backend_preview = is_single() && !empty($_REQUEST['post_type']) && !empty($_REQUEST['preview']) && !empty($_REQUEST['p']) && is_super_admin() ? true : false;
    // skip if preview from backend
    if ($is_backend_preview && !$post_id > 0 && $request_post_id > 0) {
        $post = geodir_get_post_info($request_post_id);
        setup_postdata($post);
    }
    $geodir_post_detail_fields = geodir_show_listing_info('detail');
    if (geodir_is_page('detail')) {
        $video = geodir_get_video($post->ID);
        $special_offers = geodir_get_special_offers($post->ID);
        $related_listing_array = array();
        if (get_option('geodir_add_related_listing_posttypes')) {
            $related_listing_array = get_option('geodir_add_related_listing_posttypes');
        }
        $related_listing = '';
        if (in_array($post->post_type, $related_listing_array)) {
            $request = array('post_number' => get_option('geodir_related_post_count'), 'relate_to' => get_option('geodir_related_post_relate_to'), 'layout' => get_option('geodir_related_post_listing_view'), 'add_location_filter' => get_option('geodir_related_post_location_filter'), 'list_sort' => get_option('geodir_related_post_sortby'), 'character_count' => get_option('geodir_related_post_excerpt'));
            $related_listing = geodir_related_posts_display($request);
        }
        $post_images = geodir_get_images($post->ID, 'thumbnail');
        $thumb_image = '';
        if (!empty($post_images)) {
            foreach ($post_images as $image) {
                $caption = !empty($image->caption) ? $image->caption : '';
                $thumb_image .= '<a href="' . $image->src . '" title="' . $caption . '">';
                $thumb_image .= geodir_show_image($image, 'thumbnail', true, false);
                $thumb_image .= '</a>';
            }
        }
        $map_args = array();
        $map_args['map_canvas_name'] = 'detail_page_map_canvas';
        $map_args['width'] = '600';
        $map_args['height'] = '300';
        if ($post->post_mapzoom) {
            $map_args['zoom'] = '' . $post->post_mapzoom . '';
        }
        $map_args['autozoom'] = false;
        $map_args['child_collapse'] = '0';
        $map_args['enable_cat_filters'] = false;
        $map_args['enable_text_search'] = false;
        $map_args['enable_post_type_filters'] = false;
        $map_args['enable_location_filters'] = false;
        $map_args['enable_jason_on_load'] = true;
        $map_args['enable_map_direction'] = true;
        $map_args['map_class_name'] = 'geodir-map-detail-page';
        $map_args['maptype'] = !empty($post->post_mapview) ? $post->post_mapview : 'ROADMAP';
    } elseif (geodir_is_page('preview')) {
        $video = isset($post->geodir_video) ? $post->geodir_video : '';
        $special_offers = isset($post->geodir_special_offers) ? $post->geodir_special_offers : '';
        if (isset($post->post_images)) {
            $post->post_images = trim($post->post_images, ",");
        }
        if (isset($post->post_images) && !empty($post->post_images)) {
            $post_images = explode(",", $post->post_images);
        }
        $thumb_image = '';
        if (!empty($post_images)) {
            foreach ($post_images as $image) {
                if ($image != '') {
                    $thumb_image .= '<a href="' . $image . '">';
                    $thumb_image .= geodir_show_image(array('src' => $image), 'thumbnail', true, false);
                    $thumb_image .= '</a>';
                }
            }
        }
        global $map_jason;
        $map_jason[] = $post->marker_json;
        $address_latitude = isset($post->post_latitude) ? $post->post_latitude : '';
        $address_longitude = isset($post->post_longitude) ? $post->post_longitude : '';
        $mapview = isset($post->post_mapview) ? $post->post_mapview : '';
        $mapzoom = isset($post->post_mapzoom) ? $post->post_mapzoom : '';
        if (!$mapzoom) {
            $mapzoom = 12;
        }
        $map_args = array();
        $map_args['map_canvas_name'] = 'preview_map_canvas';
        $map_args['width'] = '950';
        $map_args['height'] = '300';
        $map_args['child_collapse'] = '0';
        $map_args['maptype'] = $mapview;
        $map_args['autozoom'] = false;
        $map_args['zoom'] = "{$mapzoom}";
        $map_args['latitude'] = $address_latitude;
        $map_args['longitude'] = $address_longitude;
        $map_args['enable_cat_filters'] = false;
        $map_args['enable_text_search'] = false;
        $map_args['enable_post_type_filters'] = false;
        $map_args['enable_location_filters'] = false;
        $map_args['enable_jason_on_load'] = true;
        $map_args['enable_map_direction'] = true;
        $map_args['map_class_name'] = 'geodir-map-preview-page';
    }
    $arr_detail_page_tabs = geodir_detail_page_tabs_list();
    // get this sooner so we can get the active tab for the user
    $active_tab_name = '';
    foreach ($arr_detail_page_tabs as $tabs) {
        if (isset($tabs['is_active_tab']) && $tabs['is_active_tab'] && isset($tabs['heading_text']) && $tabs['heading_text']) {
            $active_tab_name = __($tabs['heading_text'], 'geodirectory');
        }
    }
    ?>

    <div class="geodir-tabs" id="gd-tabs" style="position:relative;">

        <div id="geodir-tab-mobile-menu" >
            <i class="fa fa-bars"></i>
            <span class="geodir-mobile-active-tab"><?php 
    echo $active_tab_name;
    ?>
</span>
            <i class="fa fa-sort-desc"></i>
        </div>

        <dl class="geodir-tab-head">
            <?php 
    /**
     * Called before the details page tab list headings, inside the `dl` tag.
     *
     * @since 1.0.0
     * @see 'geodir_after_tab_list'
     */
    do_action('geodir_before_tab_list');
    ?>
            <?php 
    foreach ($arr_detail_page_tabs as $tab_index => $detail_page_tab) {
        if ($detail_page_tab['is_display']) {
            ?>
                    <dt></dt> <!-- added to comply with validation -->
                    <dd <?php 
            if ($detail_page_tab['is_active_tab']) {
                ?>
class="geodir-tab-active"<?php 
            }
            ?>
 >
                        <a data-tab="#<?php 
            echo $tab_index;
            ?>
"
                           data-status="enable"><?php 
            _e($detail_page_tab['heading_text'], 'geodirectory');
            ?>
</a>
                    </dd>

                    <?php 
            ob_start();
            ?>
                    <li id="<?php 
            echo $tab_index;
            ?>
Tab" <?php 
            if ($tab_index == 'post_profile') {
                //echo 'itemprop="description"';
            }
            ?>
>
                        <div id="<?php 
            echo $tab_index;
            ?>
" class="hash-offset"></div>
                        <?php 
            /**
             * Called before the details tab content is output per tab.
             *
             * @since 1.0.0
             * @param string $tab_index The tab name ID.
             */
            do_action('geodir_before_tab_content', $tab_index);
            /**
             * Called before the details tab content is output per tab.
             *
             * Uses dynamic hook name: geodir_before_$tab_index_tab_content
             *
             * @since 1.0.0
             * @todo do we need this if we have the hook above? 'geodir_before_tab_content'
             */
            do_action('geodir_before_' . $tab_index . '_tab_content');
            /// write a code to generate content of each tab
            switch ($tab_index) {
                case 'post_profile':
                    /**
                     * Called before the listing description content on the details page tab.
                     *
                     * @since 1.0.0
                     */
                    do_action('geodir_before_description_on_listing_detail');
                    if (geodir_is_page('detail')) {
                        the_content();
                    } else {
                        /** This action is documented in geodirectory_template_actions.php */
                        echo apply_filters('the_content', stripslashes($post->post_desc));
                    }
                    /**
                     * Called after the listing description content on the details page tab.
                     *
                     * @since 1.0.0
                     */
                    do_action('geodir_after_description_on_listing_detail');
                    break;
                case 'post_info':
                    echo $geodir_post_detail_fields;
                    break;
                case 'post_images':
                    echo $thumb_image;
                    break;
                case 'post_video':
                    /** This action is documented in geodirectory_template_actions.php */
                    echo apply_filters('the_content', stripslashes($video));
                    // we apply the_content filter so oembed works also;
                    break;
                case 'special_offers':
                    echo wpautop(stripslashes($special_offers));
                    break;
                case 'post_map':
                    geodir_draw_map($map_args);
                    break;
                case 'reviews':
                    comments_template();
                    break;
                case 'related_listing':
                    echo $related_listing;
                    break;
                default:
                    if ((isset($post->{$tab_index}) || !isset($post->{$tab_index}) && (strpos($tab_index, 'gd_tab_') !== false || $tab_index == 'link_business')) && !empty($detail_page_tab['tab_content'])) {
                        echo $detail_page_tab['tab_content'];
                    }
                    break;
            }
            /**
             * Called after the details tab content is output per tab.
             *
             * @since 1.0.0
             */
            do_action('geodir_after_tab_content', $tab_index);
            /**
             * Called after the details tab content is output per tab.
             *
             * Uses dynamic hook name: geodir_after_$tab_index_tab_content
             *
             * @since 1.0.0
             * @todo do we need this if we have the hook above? 'geodir_after_tab_content'
             */
            do_action('geodir_after_' . $tab_index . '_tab_content');
            ?>
 </li>
                    <?php 
            /**
             * Filter the current tab content.
             *
             * @since 1.0.0
             */
            $arr_detail_page_tabs[$tab_index]['tab_content'] = apply_filters("geodir_modify_" . $detail_page_tab['tab_content'] . "_tab_content", ob_get_clean());
        }
        // end of if for is_display
    }
    // end of foreach
    /**
     * Called after the details page tab list headings, inside the `dl` tag.
     *
     * @since 1.0.0
     * @see 'geodir_before_tab_list'
     */
    do_action('geodir_after_tab_list');
    ?>
        </dl>
        <ul class="geodir-tabs-content entry-content" style="position:relative;">
            <?php 
    foreach ($arr_detail_page_tabs as $detail_page_tab) {
        if ($detail_page_tab['is_display'] && !empty($detail_page_tab['tab_content'])) {
            echo $detail_page_tab['tab_content'];
        }
        // end of if
    }
    // end of foreach
    /**
     * Called after all the tab content is output in `li` tags, called before the closing `ul` tag.
     *
     * @since 1.0.0
     */
    do_action('geodir_add_tab_content');
    ?>
        </ul>
        <!--gd-tabs-content ul end-->
    </div>
    <script>
        if (window.location.hash && window.location.hash.indexOf('&') === -1 && jQuery(window.location.hash + 'Tab').length) {
            hashVal = window.location.hash;
        } else {
            hashVal = jQuery('dl.geodir-tab-head dd.geodir-tab-active').find('a').attr('data-tab');
        }
        jQuery('dl.geodir-tab-head dd').each(function () {
            //Get all tabs
            var tabs = jQuery(this).children('dd');
            var tab = '';
            tab = jQuery(this).find('a').attr('data-tab');
            if (hashVal != tab) {
                jQuery(tab + 'Tab').hide();
            }

        });
    </script>

<?php 
}
示例#3
0
/**
 * The geodirectory related listing widget shortcode.
 *
 * This implements the functionality of the shortcode for displaying related listing widget.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @param array $atts {
 *     Attributes of the shortcode.
 *
 *     @type int $add_location_filter   Filter listings using current location. Default 0.
 *     @type string $before_title       HTML content to prepend to the title when displayed. Default. <style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>.
 *     @type int $character_count       The excerpt length Default. 20.
 *     @type int $is_widget             Is this a widget? Default. 1.
 *     @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 int $post_number           No. of post to display. Default. 5.
 *     @type string $relate_to          Type to use for making relation. Can be tags or category. Default. category.
 *
 * }
 * @return string Related widget HTML.
 */
function geodir_sc_related_listings($atts)
{
    ob_start();
    $defaults = array('post_number' => 5, 'relate_to' => 'category', 'layout' => 'gridview_onehalf', 'add_location_filter' => 0, 'listing_width' => '', 'list_sort' => 'latest', 'character_count' => 20, 'is_widget' => 1, 'before_title' => '<style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>');
    // The "before_title" code is an ugly & terrible hack. But it works for now. I should enqueue a new stylesheet.
    $params = shortcode_atts($defaults, $atts);
    /**
     * Begin validating parameters
     */
    // Validate that post_number is a number and is 1 or higher
    $params['post_number'] = absint($params['post_number']);
    if (0 === $params['post_number']) {
        $params['post_number'] = 1;
    }
    // Validate relate_to - only category or tags
    $params['relate_to'] = strtolower($params['relate_to']);
    if ('category' != $params['relate_to'] && 'tags' != $params['relate_to']) {
        $params['relate_to'] = 'category';
    }
    // Validate layout selection
    $params['layout'] = gdsc_validate_layout_choice($params['layout']);
    // Validate sorting option
    $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort']);
    // Validate add_location_filter
    $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']);
    // Validate listing_width
    $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']);
    // Validate character_count
    $params['character_count'] = absint($params['character_count']);
    if (20 > $params['character_count']) {
        $params['character_count'] = 20;
    }
    if ($related_display = geodir_related_posts_display($params)) {
        echo $related_display;
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}