コード例 #1
0
 function _autolink_content($id, $content, $links, $limit, &$count, &$link_count, $round = 1, $linked_urls = array(), $context = 'the_content')
 {
     $links = array_values($links);
     $count = 0;
     if (!is_array($link_count)) {
         $link_count = array();
     }
     $i = 0;
     foreach ($links as $data) {
         if (!isset($link_count[$i])) {
             $link_count[$i] = 0;
         }
         $i++;
     }
     if (!$this->get_setting('autolink_posttype_' . get_post_type($id))) {
         return $content;
     }
     if ($this->get_postmeta('disable_autolinks', $id)) {
         return $content;
     }
     $limit_enabled = $this->get_setting('limit_lpp', false);
     if ($limit_enabled && $limit < 1) {
         return $content;
     }
     $oldlimit = $limit;
     $lpa_limit_enabled = $this->get_setting('limit_lpa', false);
     $lpa_limit = $lpa_limit_enabled ? $this->get_setting('limit_lpa_value', 5) : -1;
     $lpu_limit_enabled = $this->get_setting('limit_lpu', false);
     $lpu_limit = $lpu_limit_enabled ? $this->get_setting('limit_lpu_value', 1) : -1;
     $from_post_type = get_post_type();
     $dest_limit = $from_post_type ? (bool) $this->get_setting('dest_limit_' . $from_post_type, false) : false;
     $dest_limit_taxonomies = array();
     if ($dest_limit) {
         //$from_post_type_taxonomies = suwp::get_object_taxonomy_names($from_post_type);
         $from_post_type_taxonomies = suwp::get_taxonomy_names($from_post_type);
         foreach ($from_post_type_taxonomies as $from_post_type_taxonomy) {
             if ($this->get_setting('dest_limit_' . $from_post_type . '_within_' . $from_post_type_taxonomy, false)) {
                 $dest_limit_taxonomies[] = $from_post_type_taxonomy;
             }
         }
     }
     $autolink_class = $this->get_setting('autolink_class', '');
     $post = get_post($id);
     $i = 0;
     foreach ($links as $data) {
         $anchor = $data['anchor'];
         $to_id = su_esc_attr($data['to_id']);
         if (strlen(trim($anchor)) && $to_id !== 0 && $to_id != 'http://') {
             //*** Begin sitewide links-per-anchor dampening effect ***
             //Get the dampening percentage for this link, but only if per-link values are enabled
             if ($this->get_setting('enable_perlink_dampen_sitewide_lpa', false)) {
                 $link_dswlpa = $data['dampen_sitewide_lpa'];
             } else {
                 $link_dswlpa = false;
             }
             if (false === $link_dswlpa) {
                 //We need the === operator here so we don't match a zero
                 //There's no per-link value, so get the default, if a default value is specified and enabled
                 if ($this->get_setting('dampen_sitewide_lpa', false)) {
                     $link_dswlpa = $this->get_setting('dampen_sitewide_lpa_value', 0);
                 } else {
                     $link_dswlpa = false;
                 }
                 //Indicates there's neither a per-link value or a default value available
             }
             if (false !== $link_dswlpa) {
                 $link_dswlpa = absint($link_dswlpa);
                 if ($link_dswlpa == 0) {
                     break;
                 }
                 if ($link_dswlpa > 100) {
                     $link_dswlpa = 100;
                 }
                 //Rather than generating a random number, we use the MD5s of the anchor and the post's ID.
                 //This gives us a quasi-random dampening effect that will turn out the same way for any given post each time the dampener is applied.
                 //We don't want a post's autolinks changing every time the post is viewed.
                 $md5starts = array_slice(array_unique(str_split(md5($anchor))), 0, intval(round(16 * (1 - $link_dswlpa / 100))));
                 //Only apply this autolink if the MD5 of the post's ID starts with one of the allowed characters
                 if (!in_array(substr(md5($id), 0, 1), $md5starts)) {
                     continue;
                 }
                 //Don't apply autolink; continue to next item in the $links foreach loop
             }
             //*** End sitewide LPA dampener ***
             $type = $data['to_type'];
             if (sustr::startswith($type, 'posttype_')) {
                 $to_id = intval($to_id);
                 $to_post = get_post($to_id);
                 if (get_post_status($to_id) != 'publish') {
                     continue;
                 }
                 if (count($dest_limit_taxonomies)) {
                     $shares_term = false;
                     foreach ($dest_limit_taxonomies as $dest_limit_taxonomy) {
                         $from_terms = suarr::flatten_values(get_the_terms(null, $dest_limit_taxonomy), 'term_id');
                         if (is_object_in_taxonomy($to_post, $dest_limit_taxonomy)) {
                             $to_terms = suarr::flatten_values(get_the_terms($to_id, $dest_limit_taxonomy), 'term_id');
                         } else {
                             $to_terms = array();
                         }
                         if (count(array_intersect($from_terms, $to_terms))) {
                             $shares_term = true;
                             break;
                         }
                     }
                     if (!$shares_term) {
                         continue;
                     }
                 }
                 $url = get_permalink($to_id);
             } elseif ($type == 'url') {
                 $url = $to_id;
             } else {
                 $url = $this->jlsuggest_value_to_url($to_id ? "obj_{$type}/{$to_id}" : "obj_{$type}");
             }
             if (!is_string($url)) {
                 continue;
             }
             if (!$this->get_setting('enable_current_url_links', false) && suurl::equal($url, suurl::current())) {
                 continue;
             }
             if (!$this->get_setting('enable_self_links', false) && is_singular() && suurl::equal($url, get_permalink())) {
                 continue;
             }
             if ($lpu_limit_enabled && isset($linked_urls[$url]) && $linked_urls[$url] >= $lpu_limit) {
                 continue;
             }
             $rel = $data['nofollow'] ? ' rel="nofollow"' : '';
             $target = $data['target'] == 'blank' ? ' target="_blank"' : '';
             $title = strlen($titletext = su_esc_attr($data['title'])) ? " title=\"{$titletext}\"" : '';
             $class = $autolink_class ? ' class="' . su_esc_attr($autolink_class) . '"' : '';
             $a_url = su_esc_attr($url);
             $h_anchor = esc_html($anchor);
             $link = "<a href=\"{$a_url}\"{$title}{$rel}{$target}{$class}>\$1</a>";
             $lpa_lpu_limits = array();
             if ($lpa_limit_enabled) {
                 $lpa_lpu_limits[] = $lpa_limit;
             }
             if ($lpu_limit_enabled) {
                 $lpa_lpu_limits[] = $lpu_limit;
             }
             $lpa_lpu_limits = count($lpa_lpu_limits) ? sunum::lowest($lpa_lpu_limits) : -1;
             $content = sustr::htmlsafe_str_replace($h_anchor, $link, $content, $limit_enabled ? 1 : $lpa_lpu_limits, $new_count, $this->get_linkfree_tags());
             $link_count[$i] += $new_count;
             $count += $new_count;
             if ($lpu_limit_enabled) {
                 if (isset($linked_urls[$url])) {
                     $linked_urls[$url] += $new_count;
                 } else {
                     $linked_urls[$url] = $new_count;
                 }
             }
             if ($limit_enabled) {
                 $limit -= $new_count;
                 if ($limit < 1) {
                     return $content;
                 }
             }
         }
         $i++;
     }
     if ($limit_enabled && $limit < $oldlimit && $round < $lpa_limit) {
         $content = $this->_autolink_content($id, $content, $links, $limit, $count, $link_count, $round + 1, $linked_urls, $context);
     }
     return $content;
 }
コード例 #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";
                 }
             }
         }
     }
 }
コード例 #3
0
 function update_rewrite_filters()
 {
     if (suwp::permalink_mode()) {
         $taxonomies = suwp::get_taxonomy_names();
         foreach ($taxonomies as $taxonomy) {
             if ($this->get_setting("nobase_{$taxonomy}", false)) {
                 add_filter("{$taxonomy}_rewrite_rules", array(&$this, 'nobase_rewrite_rules'));
             } else {
                 remove_filter("{$taxonomy}_rewrite_rules", array(&$this, 'nobase_rewrite_rules'));
             }
         }
     }
 }