function init() { if ($this->is_action('update')) { $psdata = (array) get_option('seo_ultimate', array()); foreach ($_POST as $key => $newvalue) { if (substr($key, 0, 3) == 'su-') { $key = str_replace(array('su-', '-module-status'), '', $key); $newvalue = intval($newvalue); $oldvalue = $psdata['modules'][$key]; if ($oldvalue != $newvalue) { if ($oldvalue == SU_MODULE_DISABLED) { $this->plugin->call_module_func($key, 'activate'); } if ($newvalue == SU_MODULE_DISABLED) { $this->plugin->call_module_func($key, 'deactivate'); } } $psdata['modules'][$key] = $newvalue; } } update_option('seo_ultimate', $psdata); wp_redirect(add_query_arg('su-modules-updated', '1', suurl::current()), 301); exit; } }
/** * Saves information about the current hit into an array, which is later saved to the database. * * @since 0.1 * @uses get_current_url() * @uses $hit_id * * @param string $status_header The full HTTP status header. Unused and returned as-is. * @param int $status_code The numeric HTTP status code. * @param string $redirect_url The URL to which the visitor is being redirected. Optional. * @return string Returns the $status_header variable unchanged. */ function log_hit($status_header, $status_code, $redirect_url = '') { //Only log hits from non-logged-in users if (!is_user_logged_in()) { //Get the current URL $url = suurl::current(); //Put it all into an array $data = array('time' => time(), 'ip_address' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', 'url' => $url, 'redirect_url' => $redirect_url, 'redirect_trigger' => $this->hit_redirect_trigger, 'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'status_code' => $status_code); //We don't want to overwrite a redirect URL if it's already been logged if (!empty($this->hit['redirect_url'])) { $data['redirect_url'] = $this->hit['redirect_url']; } //Put the hit data into our variable. //We'll save it to the database later, since the hit data may change as we gather further information //(e.g. when the redirect URL is discovered). $this->hit = $data; } //This function can be used as a WordPress filter, so we return the needed variable. return $status_header; }
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 autolink_footer($args = array()) { if ($this->already_outputted) { return; } extract(wp_parse_args($args, array('footer_link_section_format' => $this->get_setting('footer_link_section_format', '{links}'), 'footer_link_format' => $this->get_setting('footer_link_format', '{link}'), 'footer_link_sep' => $this->get_setting('footer_link_sep', ' | '))), EXTR_SKIP); $links = $this->get_setting('footer_links', array()); suarr::vksort($links, 'anchor'); $link_html = array(); foreach ($links as $link_data) { if (isset($link_data['from']) && count($link_data['from'])) { $from = $link_data['from'][0]; } else { $from = array(''); } $from_match_children = isset($link_data['from_match_children']) && $link_data['from_match_children']; $from_match_negative = isset($link_data['from_match_negative']) && $link_data['from_match_negative']; if (!isset($link_data['to'])) { $link_data['to'] = ''; } list($from_genus, $from_type, $from_id) = $this->jlsuggest_value_explode($from); $is_from = $from_match_negative; switch ($from_genus) { case 'posttype': $post_ids = array($from_id); if ($from_match_children) { $post_ids[] = wp_get_post_parent_id($from_id); } //Requires WordPress 3.1 foreach ($post_ids as $post_id) { if (is_single($post_id) || is_page($post_id)) { $is_from = !$from_match_negative; break; } } break; case 'taxonomy': if (suwp::is_tax($from_type, $from_id) || $from_match_children && is_singular() && has_term($from_id, $from_type)) { $is_from = !$from_match_negative; } break; case 'home': if (is_home()) { $is_from = !$from_match_negative; } break; case 'author': if (is_author($from_id) || $from_match_children && is_singular() && get_the_author_meta('id') == $from_id) { $is_from = !$from_match_negative; } break; case 'url': if ($from_id) { if (suurl::equal(suurl::current(), $from_id) || $from_match_children && sustr::startswith(suurl::current(), $from_id)) { $is_from = !$from_match_negative; } } else { $is_from = true; } //No "from" restriction break; } if (!$is_from) { continue; } $h_anchor = esc_html($link_data['anchor']); $rel = $link_data['nofollow'] ? ' rel="nofollow"' : ''; $target = $link_data['target'] == 'blank' ? ' target="_blank"' : ''; $title = strlen($a_titletext = su_esc_attr($link_data['title'])) ? " title=\"{$a_titletext}\"" : ''; $a_url = su_esc_attr($this->jlsuggest_value_to_url($link_data['to'])); if (strlen(trim($h_anchor)) && strlen(trim((string) $a_url)) && $a_url != 'http://') { $link_html[] = str_replace('{link}', "<a href=\"{$a_url}\"{$title}{$rel}{$target}>{$h_anchor}</a>", $footer_link_format); } } echo str_replace('{links}', implode($footer_link_sep, $link_html), $footer_link_section_format); }
function redirect_aliases() { $aliases = $this->get_setting('aliases', array()); $alias_dir = $this->get_setting('alias_dir', 'go'); foreach ($aliases as $alias) { if ($to = $alias['to']) { if (suurl::equal(suurl::current(), get_bloginfo('url') . "/{$alias_dir}/{$to}/")) { wp_redirect($alias['from']); } } } }
function remove_nonexistent_pagination() { if (!is_admin()) { global $wp_rewrite, $wp_query; $url = suurl::current(); if (is_singular()) { $num = absint(get_query_var('page')); $post = $wp_query->get_queried_object(); $max = count(explode('<!--nextpage-->', $post->post_content)); if ($max > 0 && ($num == 1 || $num > 1 && $num > $max)) { if ($wp_rewrite->using_permalinks()) { wp_redirect(preg_replace('|/[0-9]{1,9}/?$|', '/', $url), 301); } else { wp_redirect(remove_query_arg('page', $url), 301); } } } elseif (is_404() && ($num = absint(get_query_var('paged')))) { if ($wp_rewrite->using_permalinks()) { wp_redirect(preg_replace('|/page/[0-9]{1,9}/?$|', '/', $url), 301); } else { wp_redirect(remove_query_arg('paged', $url), 301); } } } }