function head_tag_output() { global $post; $kw = false; //If we're viewing the homepage, look for homepage meta data. if (is_home()) { $kw = $this->get_setting('home_keywords'); //If we're viewing a post or page... } elseif (is_singular()) { //...look for its meta data $kw = $this->get_postmeta('keywords'); //...and add default values if ($posttypename = get_post_type()) { $taxnames = get_object_taxonomies($posttypename); foreach ($taxnames as $taxname) { if ($this->get_setting("auto_keywords_posttype_{$posttypename}_tax_{$taxname}", false)) { $terms = get_the_terms(0, $taxname); $terms = suarr::flatten_values($terms, 'name'); $terms = implode(',', $terms); $kw .= ',' . $terms; } } if ($this->get_setting("auto_keywords_posttype_{$posttypename}_words", false)) { $words = preg_split("/[\\s+]/", strip_tags($post->post_content), null, PREG_SPLIT_NO_EMPTY); $words = array_count_values($words); arsort($words); $words = array_filter($words, array(&$this, 'filter_word_counts')); $words = array_keys($words); $stopwords = suarr::explode_lines($this->get_setting('words_to_remove', array(), 'slugs')); $stopwords = array_map(array('sustr', 'tolower'), $stopwords); $words = array_map(array('sustr', 'tolower'), $words); $words = array_diff($words, $stopwords); $words = array_slice($words, 0, $this->get_setting("auto_keywords_posttype_{$posttypename}_words_value")); $words = implode(',', $words); $kw .= ',' . $words; } } //If we're viewing a term, look for its meta data. } elseif (suwp::is_tax()) { global $wp_query; $tax_keywords = $this->get_setting('taxonomy_keywords'); $term_id = $wp_query->get_queried_object_id(); if (isset($tax_keywords[$term_id])) { $kw = $tax_keywords[$term_id]; } else { $kw = ''; } } if ($globals = $this->get_setting('global_keywords')) { if (strlen($kw)) { $kw .= ','; } $kw .= $globals; } $kw = str_replace(array("\r\n", "\n"), ',', $kw); $kw = explode(',', $kw); $kw = array_map('trim', $kw); //Remove extra spaces from beginning/end of keywords $kw = array_filter($kw); //Remove blank keywords $kw = suarr::array_unique_i($kw); //Remove duplicate keywords $kw = implode(',', $kw); //Do we have keywords? If so, output them. if ($kw) { $kw = su_esc_attr($kw); echo "\t<meta name=\"keywords\" content=\"{$kw}\" />\n"; } }
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; }
/** * Goes through an array of arrays/objects, plucks two elements/properties from each array/object, and constructs a new array, with one element/property as the key, and the other as the value. * * @param array $arr The array to run this process on. * @param array|string|int $keyloc The location (either a string/integer key, or an array of nested keys) of the elements' values to be used as keys in the new array * @param array|string|int $valloc The location (either a string/integer key, or an array of nested keys) of the elements' values to be used as values in the new array * @param bool $use_default_if_empty Whether or not to use a default value in the event that nothing is located at $keyloc or $valloc for a given array/object in $arr * @param mixed $default * * @return array */ static function simplify($arr, $keyloc, $valloc, $use_default_if_empty = false, $default = '') { $keys = suarr::flatten_values($arr, $keyloc, $use_default_if_empty, $default); $values = suarr::flatten_values($arr, $valloc, $use_default_if_empty, $default); return array_combine($keys, $values); }