Exemplo n.º 1
0
 public static function determine_appropriate_tags()
 {
     // Check for memoized return value...
     if (!empty(self::$page_tags)) {
         return self::$page_tags;
     }
     global $post;
     $tags = array();
     // get page template
     $page_template = self::determine_page_template();
     // determine $meta_tag_designations
     switch ($page_template) {
         case 'neighborhood':
             // Neighborhood / City Page
             $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
             $tags['title'] = $term->name;
             $tags['address'] = "";
             $descrip = strip_tags($term->description);
             $descrip_more = '';
             if (strlen($descrip) > 155) {
                 $descrip = substr($descrip, 0, 155);
                 $descrip_more = ' ...';
             }
             $descrip = str_replace('"', '', $descrip);
             $descrip = str_replace("'", '', $descrip);
             $descripwords = preg_split('/[\\n\\r\\t ]+/', $descrip, -1, PREG_SPLIT_NO_EMPTY);
             array_pop($descripwords);
             $tags['description'] = implode(' ', $descripwords) . $descrip_more;
             $image_array = get_tax_meta($term->term_id, 'image_1');
             $tags['image'] = isset($image_array['src']) ? $image_array['src'] : '';
             break;
         case 'search':
             $tags['itemtype'] = 'http://schema.org/LocalBusiness';
             $tags['title'] = 'Search results for: ' . get_search_query();
             break;
         case 'category':
             $category = get_the_category();
             $tags['title'] = $category[0]->cat_name;
             $tags['description'] = $category[0]->description;
             break;
         case 'date':
             if (is_day()) {
                 $tags['title'] = get_the_date() . ' Archives';
             } elseif (is_month()) {
                 $tags['title'] = get_the_date('F Y') . ' Archives';
             } elseif (is_year()) {
                 $tags['title'] = get_the_date('Y') . ' Archives';
             } else {
                 $tags['title'] = 'Blog Archives';
             }
             break;
         case 'tag':
             $tag = single_tag_title('', false);
             $tags['title'] = $tag . ' tagged posts';
             $tags['itemtype'] = 'http://schema.org/Blog';
             $tags['description'] = tag_description();
             break;
         case 'author':
             $tags['author'] = get_the_author();
             $tags['itemtype'] = 'http://schema.org/Blog';
             $tags['title'] = 'Author Archives: ' . get_the_author_meta('display_name', get_query_var('author'));
             // $image - should be author's face is one is set... could also check for same name in agent's list too.
             $tags['description'] = tag_description();
             break;
         case 'property':
             $content = get_option('placester_listing_layout');
             if (isset($content) && $content != '') {
                 return $content;
             }
             $html = '';
             $listing = PLS_Plugin_API::get_listing_in_loop();
             if (is_null($listing)) {
                 break;
             }
             // Single Property
             $tags['itemtype'] = 'http://schema.org/Offer';
             if (isset($listing['location']['unit']) && $listing['location']['unit'] != null) {
                 $tags['title'] = @$listing['location']['address'] . ', ' . $listing['location']['unit'] . ' ' . @$listing['location']['locality'] . ', ' . @$listing['location']['region'];
                 $tags['address'] = @$listing['location']['address'] . ', ' . $listing['location']['unit'] . ' ' . @$listing['location']['locality'] . ', ' . @$listing['location']['region'];
             } else {
                 $tags['title'] = @$listing['location']['address'] . ' ' . @$listing['location']['locality'] . ', ' . @$listing['location']['region'];
                 $tags['address'] = @$listing['location']['address'] . ' ' . @$listing['location']['locality'] . ', ' . @$listing['location']['region'];
             }
             $tags['image'] = @$listing['images']['0']['url'];
             $tags['description'] = esc_html(strip_tags($listing['cur_data']['desc']));
             break;
         case 'agent':
             $tags['itemtype'] = 'http://schema.org/RealEstateAgent';
             $tags['title'] = $post->post_title;
             break;
         case 'service':
             $tags['itemtype'] = 'http://schema.org/ProfessionalService';
             $tags['title'] = $post->post_title;
             break;
         case 'testimonial':
             $tags['itemtype'] = 'http://schema.org/Review';
             $tags['title'] = $post->post_title;
             break;
         case 'community':
             $tags['title'] = $post->post_title;
             $tags['description'] = PLS_Format::shorten_excerpt($post, 155);
             break;
         case 'single':
             $tags['itemtype'] = 'http://schema.org/BlogPosting';
             $tags['title'] = $post->post_title;
             if (has_post_thumbnail($post->ID)) {
                 $post_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
                 $tags['image'] = $post_image[0];
             }
             $tags['description'] = PLS_Format::shorten_excerpt($post, 155);
             $tags['address'] = @pls_get_option('pls-company-street') . " " . @pls_get_option('pls-company-locality') . ", " . @pls_get_option('pls-company-region');
             $tags['author'] = $post->post_author;
             break;
         case 'other':
         default:
             // Home and other pages
             $tags['itemtype'] = 'http://schema.org/LocalBusiness';
             if (is_home()) {
                 $tags['title'] = pls_get_option('pls-company-name');
             } elseif (isset($post)) {
                 $values = get_post_custom($post->ID);
                 // give Yoast SEO a hand setting the title
                 $tags['title'] = !empty($values['_yoast_wpseo_title'][0]) ? $values['_yoast_wpseo_title'][0] : $post->post_title;
             } else {
                 $tags['title'] = '';
             }
             break;
     }
     $meta_data = self::process_defaults($tags);
     // Memoize this output...
     self::$page_tags = $meta_data;
     return $meta_data;
 }