function before_listing($trail)
 {
     // XXX: Taken from core/views.php:show_listing(). Probably a good idea to move this to an utility function.
     $id_or_slug = '';
     if (get_query_var('listing') || isset($_GET['listing'])) {
         $id_or_slug = get_query_var('listing') ? get_query_var('listing') : wpbdp_getv($_GET, 'listing', 0);
     } else {
         $id_or_slug = get_query_var('id') ? get_query_var('id') : wpbdp_getv($_GET, 'id', 0);
     }
     $listing_id = wpbdp_get_post_by_id_or_slug($id_or_slug, 'id', 'id');
     if (!$listing_id) {
         return;
     }
     $this->state['post'] = $GLOBALS['post'];
     $GLOBALS['post'] = get_post($listing_id);
 }
 public function _template_redirect()
 {
     global $wp_query;
     if ($wp_query->get('wpbdpx')) {
         // Handle some special wpbdpx actions.
         $wpbdpx = $wp_query->get('wpbdpx');
         if (isset($this->{$wpbdpx}) && method_exists($this->{$wpbdpx}, 'process_request')) {
             $this->{$wpbdpx}->process_request();
             exit;
         }
     }
     if (is_feed()) {
         return;
     }
     // handle some deprecated stuff
     if (is_search() && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] == WPBDP_POST_TYPE) {
         $url = esc_url_raw(add_query_arg(array('action' => 'search', 'dosrch' => 1, 'q' => wpbdp_getv($_REQUEST, 's', '')), wpbdp_get_page_link('main')));
         wp_redirect($url);
         exit;
     }
     if (get_query_var('taxonomy') == WPBDP_CATEGORY_TAX && _wpbdp_template_mode('category') == 'page') {
         wp_redirect(esc_url_raw(add_query_arg('category', get_query_var('term'), wpbdp_get_page_link('main'))));
         // XXX
         exit;
     }
     if (get_query_var('taxonomy') == WPBDP_TAGS_TAX && _wpbdp_template_mode('category') == 'page') {
         wp_redirect(esc_url_raw(add_query_arg('tag', get_query_var('term'), wpbdp_get_page_link('main'))));
         // XXX
         exit;
     }
     if (is_single() && get_query_var('post_type') == WPBDP_POST_TYPE && _wpbdp_template_mode('single') == 'page') {
         $url = wpbdp_get_page_link('main');
         if (get_query_var('name')) {
             wp_redirect(esc_url_raw(add_query_arg('listing', get_query_var('name'), $url)));
             // XXX
         } else {
             wp_redirect(esc_url_raw(add_query_arg('id', get_query_var('p'), $url)));
             // XXX
         }
         exit;
     }
     global $post;
     if ($post && $post->ID == wpbdp_get_page_id('main') && (get_query_var('id') || get_query_var('listing'))) {
         $id_or_slug = false;
         foreach (array('id', 'preview_id', 'listing') as $x) {
             if (get_query_var($x)) {
                 $id_or_slug = get_query_var($x);
                 break;
             }
         }
         $listing = wpbdp_get_post_by_id_or_slug($id_or_slug, wpbdp_get_option('permalinks-no-id') ? 'slug' : 'id');
         if (!$listing || 'publish' != $listing->post_status && !current_user_can('edit_posts')) {
             $this->controller->action = null;
             status_header(404);
             nocache_headers();
             include get_404_template();
             exit;
         }
     }
 }
Exemple #3
0
 public function show_listing()
 {
     if (!$this->check_main_page($msg)) {
         return $msg;
     }
     $id_or_slug = '';
     if (get_query_var('listing') || isset($_GET['listing'])) {
         $id_or_slug = get_query_var('listing') ? get_query_var('listing') : wpbdp_getv($_GET, 'listing', 0);
     } else {
         $id_or_slug = get_query_var('id') ? get_query_var('id') : wpbdp_getv($_GET, 'id', 0);
     }
     $listing_id = wpbdp_get_post_by_id_or_slug($id_or_slug, 'id', 'id');
     /*
             if (get_query_var('listing') || isset($_GET['listing'])) {
                 if ($posts = get_posts(array('post_status' => 'any', 'numberposts' => 1, 'post_type' => WPBDP_POST_TYPE, 'name' => get_query_var('listing') ? get_query_var('listing') : wpbdp_getv($_GET, 'listing', null) ) )) {
                     $listing_id = $posts[0]->ID;
                 } else {
                     $listing_id = null;
                 }
             } else {
                 $listing_id = get_query_var('id') ? get_query_var('id') : wpbdp_getv($_GET, 'id', null);
             }*/
     if (!$listing_id) {
         return;
     }
     $html = '';
     if ('publish' != get_post_status($listing_id)) {
         if (current_user_can('edit_posts')) {
             $html .= wpbdp_render_msg(_x('This is just a preview. The listing has not been published yet.', 'preview', 'WPBDM'));
         } else {
             return;
         }
     }
     // Handle ?v=viewname argument for alternative views (other than 'single').
     $view = '';
     if (isset($_GET['v'])) {
         $view = wpbdp_capture_action_array('wpbdp_listing_view_' . trim($_GET['v']), array($listing_id));
     }
     if (!$view) {
         $html .= wpbdp_render_listing($listing_id, 'single', false, true);
     } else {
         $html .= $view;
     }
     wp_reset_query();
     // Just in case some shortcode messed this up.
     return $html;
 }
 function language_switcher($languages)
 {
     global $wpbdp;
     $action = $wpbdp->controller->get_current_action();
     switch ($action) {
         case 'browsecategory':
             if (get_query_var('category')) {
                 if ($term = get_term_by('slug', get_query_var('category'), WPBDP_CATEGORY_TAX)) {
                     $category_id = $term->term_id;
                 } else {
                     $category_id = intval(get_query_var('category'));
                 }
             }
             $category_id = $category_id ? $category_id : intval(get_query_var('category_id'));
             $category_id = is_array($category_id) && 1 == count($category_id) ? $category_id[0] : $category_id;
             if (!$category_id) {
                 return $languages;
             }
             foreach ($languages as $l_code => $l) {
                 $trans_id = (int) icl_object_id($category_id, WPBDP_CATEGORY_TAX, false, $languages[$l_code]['language_code']);
                 $link = get_term_link($trans_id, WPBDP_CATEGORY_TAX);
                 if (!$trans_id || is_wp_error($link)) {
                     unset($languages[$l_code]);
                     continue;
                 }
                 $languages[$l_code]['url'] = $this->translate_link($link, $languages[$l_code]['language_code']);
             }
             break;
         case 'showlisting':
             $id_or_slug = '';
             if (get_query_var('listing') || isset($_GET['listing'])) {
                 $id_or_slug = get_query_var('listing') ? get_query_var('listing') : wpbdp_getv($_GET, 'listing', 0);
             } else {
                 $id_or_slug = get_query_var('id') ? get_query_var('id') : wpbdp_getv($_GET, 'id', 0);
             }
             $listing_id = wpbdp_get_post_by_id_or_slug($id_or_slug, 'id', 'id');
             if (!$listing_id) {
                 break;
             }
             foreach ($languages as $l_code => $l) {
                 $trans_id = icl_object_id($listing_id, WPBDP_POST_TYPE, true, $languages[$l_code]['language_code']);
                 if (!$trans_id) {
                     unset($languages[$l_code]);
                     continue;
                 }
                 $languages[$l_code]['url'] = $this->translate_link(get_permalink($trans_id), $languages[$l_code]['language_code']);
             }
             break;
         default:
             break;
     }
     return $languages;
 }