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); 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; }
function apply_subproperty_markup($matches) { if (empty($matches[1])) { return ''; } $content = $matches[1]; extract($this->apply_subproperty_markup_args, EXTR_SKIP); foreach ($subproperties as $subproperty => $subproperty_data) { //Get the subproperty tags $subproperty_tag = is_array($subproperty_data['tags']) ? $subproperty_data['tags'][$format] : $subproperty_data['tags']; $subproperty_value = strval($this->get_postmeta("rich_snippet_{$type}_{$property}_{$subproperty}")); if ($subproperty_value) { $subproperty_markedup_value = $this->add_tags($subproperty_value, $subproperty_tag, $property_tag_template); $content = sustr::htmlsafe_str_replace($subproperty_value, $subproperty_markedup_value, $content, 1, $count); } } $content = $this->add_tags($content, $property_tag, $property_tag_format, false); return $content; }