Ejemplo n.º 1
0
 function truncate_at_ellipsis($content)
 {
     $end = '[...]';
     if (sustr::has($content, $end)) {
         $content = sustr::upto($content, $end);
         $content = sustr::rtrim_substr($content, $end);
     }
     return sustr::endwith($content, '[…]');
 }
Ejemplo n.º 2
0
 function head_tag_output()
 {
     global $wp_query;
     $tags = $twitter_tags = array();
     if (is_home()) {
         //Type
         $tags['og:type'] = 'blog';
         //Twitter Type
         $twitter_tags['twitter:card'] = 'summary';
         //Title
         if (!($tags['og:title'] = $this->get_setting('home_og_title'))) {
             $tags['og:title'] = get_bloginfo('name');
         }
         //Description
         if (!($tags['og:description'] = $this->get_setting('home_og_description'))) {
             $tags['og:description'] = get_bloginfo('description');
         }
         //URL
         $tags['og:url'] = suwp::get_blog_home_url();
         //Image
         $tags['og:image'] = $this->get_setting('home_og_image');
     } elseif (is_singular()) {
         $post = $wp_query->get_queried_object();
         if (is_object($post)) {
             //Type
             if (!($tags['og:type'] = $this->get_postmeta('og_type'))) {
                 $tags['og:type'] = $this->get_setting("default_{$post->post_type}_og_type");
             }
             //Twitter Type
             if (!($twitter_tags['twitter:card'] = $this->get_postmeta('twitter_card'))) {
                 $twitter_tags['twitter:card'] = $this->get_setting("default_{$post->post_type}_twitter_card");
             }
             //Title
             if (!($tags['og:title'] = $this->get_postmeta('og_title'))) {
                 $tags['og:title'] = strip_tags(apply_filters('single_post_title', $post->post_title));
             }
             //Description
             if (!($tags['og:description'] = $this->get_postmeta('og_description'))) {
                 if ($this->plugin->call_module_func('meta-descriptions', 'get_meta_desc', $meta_desc, false) && $meta_desc) {
                     $tags['og:description'] = $meta_desc;
                 }
             }
             //URL
             $tags['og:url'] = get_permalink($post->ID);
             //Image
             $tags['og:image'] = $this->jlsuggest_value_to_url($this->get_postmeta('og_image'), true);
             if (!$tags['og:image']) {
                 if ('attachment' == $post->post_type) {
                     $tags['og:image'] = wp_get_attachment_url();
                 } elseif (current_theme_supports('post-thumbnails') && ($thumbnail_id = get_post_thumbnail_id($post->ID))) {
                     $tags['og:image'] = wp_get_attachment_url($thumbnail_id);
                 }
             }
             //Additional fields
             switch ($tags['og:type']) {
                 case 'article':
                     $tags['article:published_time'] = get_the_date('Y-m-d');
                     $tags['article:modified_time'] = get_the_modified_date('Y-m-d');
                     //Authorship generally doesn't apply to pages
                     if (!is_page() && $this->get_setting('enable_og_article_author', true)) {
                         $tags['article:author'] = get_author_posts_url($post->post_author);
                     }
                     $single_category = count(get_the_category()) == 1;
                     $taxonomy_names = suwp::get_taxonomy_names();
                     foreach ($taxonomy_names as $taxonomy_name) {
                         if ($terms = get_the_terms(get_the_ID(), $taxonomy_name)) {
                             if ($single_category && 'category' == $taxonomy_name) {
                                 $meta_property = 'article:section';
                             } else {
                                 $meta_property = 'article:tag';
                             }
                             foreach ($terms as $term) {
                                 $tags[$meta_property][] = $term->name;
                             }
                         }
                     }
                     break;
             }
             //Author's Twitter Handle
             $handle = get_user_meta($post->post_author, 'twitter', true);
             $handle = $this->sanitize_twitter_handle($handle);
             $twitter_tags['twitter:creator'] = $handle;
         }
     } elseif (is_author()) {
         $author = $wp_query->get_queried_object();
         if (is_object($author)) {
             //Type
             $tags['og:type'] = 'profile';
             //Title
             $tags['og:title'] = $author->display_name;
             //Description
             $tags['og:title'] = get_the_author_meta('description', $author->ID);
             //Image
             $tags['og:image'] = false;
             //URL
             $tags['og:url'] = get_author_posts_url($author->ID, $author->user_nicename);
             //First Name
             $tags['profile:first_name'] = get_the_author_meta('first_name', $author->ID);
             //Last Name
             $tags['profile:last_name'] = get_the_author_meta('last_name', $author->ID);
             //Username
             $tags['profile:username'] = $author->user_login;
             //Twitter Handle
             $handle = get_user_meta($author->ID, 'twitter', true);
             $handle = $this->sanitize_twitter_handle($handle);
             $twitter_tags['twitter:creator'] = $handle;
         }
     } else {
         return;
     }
     if ($tags['og:type'] == 'none') {
         $tags['og:type'] = '';
     }
     if ((!isset($tags['og:image']) || !$tags['og:image']) && $tags['og:image'] !== false) {
         $tags['og:image'] = $this->jlsuggest_value_to_url($this->get_setting('default_og_image'), true);
     }
     //Site Name
     if (!($tags['og:site_name'] = $this->get_setting('og_site_name'))) {
         $tags['og:site_name'] = get_bloginfo('name');
     }
     //FB App ID
     $tags['fb:app_id'] = $this->get_setting('default_fb_app_id');
     //Twitter Site Handle
     $twitter_tags['twitter:site'] = $this->get_setting('twitter_site_handle');
     $twitter_tags['twitter:site:id'] = $this->get_setting('twitter_site_id_handle');
     $twitter_tags['twitter:creator'] = $this->get_setting('twitter_creator_handle');
     $twitter_tags['twitter:creator:id'] = $this->get_setting('twitter_creator_id_handle');
     $twitter_tags['twitter:description'] = $this->get_setting('twitter_description_handle');
     $twitter_tags['twitter:title'] = $this->get_setting('twitter_title_handle');
     $twitter_tags['twitter:image:src'] = $this->get_setting('twitter_image_src_handle');
     $twitter_tags['twitter:image:width'] = $this->get_setting('twitter_image_width_handle');
     $twitter_tags['twitter:image:height'] = $this->get_setting('twitter_image_height_handle');
     $twitter_tags['twitter:data1'] = $this->get_setting('twitter_data1_handle');
     $twitter_tags['twitter:label1'] = $this->get_setting('twitter_label1_handle');
     $twitter_tags['twitter:data2'] = $this->get_setting('twitter_data2_handle');
     $twitter_tags['twitter:label2'] = $this->get_setting('twitter_label2_handle');
     $twitter_tags['twitter:image0:src'] = $this->get_setting('twitter_image0_src_handle');
     $twitter_tags['twitter:image1:src'] = $this->get_setting('twitter_image1_src_handle');
     $twitter_tags['twitter:image2:src'] = $this->get_setting('twitter_image2_src_handle');
     $twitter_tags['twitter:image3:src'] = $this->get_setting('twitter_image3_src_handle');
     $twitter_tags['twitter:player'] = $this->get_setting('twitter_player_handle');
     $twitter_tags['twitter:player:width'] = $this->get_setting('twitter_player_width_handle');
     $twitter_tags['twitter:player:height'] = $this->get_setting('twitter_player_height_handle');
     $twitter_tags['twitter:player:stream'] = $this->get_setting('twitter_player_stream_handle');
     $twitter_tags['twitter:app:name:iphone'] = $this->get_setting('twitter_app_name_iphone_handle');
     $twitter_tags['twitter:app:id:iphone'] = $this->get_setting('twitter_app_id_iphone_handle');
     $twitter_tags['twitter:app:url:iphone'] = $this->get_setting('twitter_app_url_iphone_handle');
     $twitter_tags['twitter:app:name:iphone'] = $this->get_setting('twitter_app_name_ipad_handle');
     $twitter_tags['twitter:app:id:iphone'] = $this->get_setting('twitter_app_id_ipad_handle');
     $twitter_tags['twitter:app:url:iphone'] = $this->get_setting('twitter_app_url_ipad_handle');
     $twitter_tags['twitter:app:name:googleplay'] = $this->get_setting('twitter_app_name_googleplay_handle');
     $twitter_tags['twitter:app:id:googleplay'] = $this->get_setting('twitter_app_id_googleplay_handle');
     $twitter_tags['twitter:app:url:googleplay'] = $this->get_setting('twitter_app_url_googleplay_handle');
     //Output meta tags
     $namespace_urls = $this->namespaces_declared ? array() : $this->get_namespace_urls();
     $doctype = $this->get_setting('doctype', '');
     switch ($doctype) {
         case 'xhtml':
             $output_formats = array('<meta%3$s name="%1$s" content="%2$s" />' => array_merge($tags, $twitter_tags));
             break;
         case 'html5':
             $output_formats = array('<meta%3$s property="%1$s" content="%2$s">' => array_merge($tags, $twitter_tags));
             break;
         default:
             $output_formats = array('<meta%3$s property="%1$s" content="%2$s" />' => $tags, '<meta%3$s name="%1$s" content="%2$s" />' => $twitter_tags);
             break;
     }
     foreach ($output_formats as $html_format => $format_tags) {
         foreach ($format_tags as $property => $values) {
             foreach ((array) $values as $value) {
                 $property = su_esc_attr($property);
                 $value = su_esc_attr($value);
                 if (strlen(trim($property)) && strlen(trim($value))) {
                     $namespace_attr = '';
                     $namespace = sustr::upto($property, ':');
                     if (!empty($namespace_urls[$namespace])) {
                         $a_namespace = su_esc_attr($namespace);
                         $a_namespace_url = su_esc_attr($namespace_urls[$namespace]);
                         switch ($doctype) {
                             case 'xhtml':
                                 $namespace_attr = " xmlns:{$a_namespace}=\"{$a_namespace_url}\"";
                                 break;
                             case 'html5':
                             default:
                                 $namespace_attr = " prefix=\"{$a_namespace}: {$a_namespace_url}\"";
                                 break;
                         }
                     }
                     echo "\t";
                     printf($html_format, $property, $value, $namespace_attr);
                     echo "\n";
                 }
             }
         }
     }
 }