function usercode_admin_tab($section) { $textareas = array('wp_head' => __('<head> Tag', 'seo-ultimate'), 'the_content_before' => __('Before Item Content', 'seo-ultimate'), 'the_content_after' => __('After Item Content', 'seo-ultimate'), 'wp_footer' => __('Footer', 'seo-ultimate')); $textareas = suarr::aprintf("{$section}_%s", false, $textareas); $this->admin_form_table_start(); $this->textareas($textareas, 5, 30, array('disabled' => !$this->user_authorized())); $this->admin_form_table_end(); }
function optimize_slug($slug) { //If no slug exists, start off with the post title if (empty($slug) && isset($_POST['post_title'])) { $slug = $_POST['post_title']; } //Prepare the title and the words for comparison $slug = sustr::tolower(stripslashes($slug)); $words = sustr::tolower(stripslashes($this->get_setting('words_to_remove'))); //Remove the stopwords from the slug $newslug = implode("-", array_diff(explode(" ", $slug), suarr::explode_lines($words))); //Make sure we haven't removed too much! if (empty($newslug)) { return $slug; } else { return $newslug; } }
function admin_page_contents() { if ($this->should_show_sdf_theme_promo()) { echo "\n\n<div class='row'>\n"; echo "\n\n<div class='col-sm-8 col-md-9'>\n"; } $this->admin_form_start(false, false); $textareas = array('wp_head' => __('<head> Tag', 'seo-ultimate'), 'the_content_before' => __('Before Item Content', 'seo-ultimate'), 'the_content_after' => __('After Item Content', 'seo-ultimate'), 'wp_footer' => __('Footer', 'seo-ultimate')); $textareas = suarr::aprintf("global_%s", false, $textareas); $this->textareas($textareas, 5, 30, array('disabled' => !$this->user_authorized())); $this->admin_form_end(null, false); if ($this->should_show_sdf_theme_promo()) { echo "\n\n</div>\n"; echo "\n\n<div class='col-sm-4 col-md-3'>\n"; $this->promo_sdf_banners(); echo "\n\n</div>\n"; echo "\n\n</div>\n"; } }
function admin_page_contents() { $this->admin_form_table_start(); $this->checkboxes(suarr::aprintf('autolink_posttype_%s', false, suarr::simplify(get_post_types(array('public' => true), 'objects'), 'name', array('labels', 'name'))), __('Add Autolinks to...', 'seo-wizard')); $this->checkboxes(array('enable_self_links' => __('Allow posts to link to themselves', 'seo-wizard'), 'enable_current_url_links' => __('Allow posts to link to the URL by which the visitor is accessing the post', 'seo-wizard')), __('Self-Linking', 'seo-wizard')); $this->checkboxes(array('limit_lpp' => __('Don’t add any more than %d autolinks per post/page/etc.', 'seo-wizard'), 'limit_lpa' => __('Don’t link the same anchor text any more than %d times per post/page/etc.', 'seo-wizard'), 'limit_lpu' => __('Don’t link to the same destination any more than %d times per post/page/etc.', 'seo-wizard')), __('Quantity Restrictions', 'seo-wizard')); $legacy_sitewide_lpa_in_use = $this->plugin->get_module_var('content-autolinks', 'legacy_sitewide_lpa_in_use', false); $this->checkboxes(array('dampen_sitewide_lpa' => __('Globally decrease autolinking frequency by %d%', 'seo-wizard'), 'enable_perlink_dampen_sitewide_lpa' => array('description' => __('Add a “Dampener” column to the Content Links editor to let me customize frequency dampening on a per-link basis', 'seo-wizard'), 'disabled' => $legacy_sitewide_lpa_in_use, 'checked' => $legacy_sitewide_lpa_in_use ? true : null)), __('Additional Dampening Effect', 'seo-wizard')); $this->textbox('linkfree_tags', __('Tag Restrictions', 'seo-wizard'), $this->get_default_setting('linkfree_tags'), false, array('help_text' => __('Don’t add autolinks to text within these HTML tags <em>(separate with commas)</em>:', 'seo-wizard'))); $siloing_checkboxes = array(); $post_types = get_post_types(array('public' => true), 'objects'); foreach ($post_types as $post_type) { $taxonomies = suwp::get_object_taxonomies($post_type->name); if (count($taxonomies)) { $siloing_checkboxes['dest_limit_' . $post_type->name] = sprintf(__('%s can only link to internal destinations that share at least one...', 'seo-wizard'), $post_type->labels->name); foreach ($taxonomies as $taxonomy) { $siloing_checkboxes['dest_limit_' . $post_type->name . '_within_' . $taxonomy->name] = array('description' => $taxonomy->labels->singular_name, 'indent' => true); } } } $this->checkboxes($siloing_checkboxes, __('Siloing', 'seo-wizard')); $this->textbox('autolink_class', __('CSS Class for Autolinks', 'seo-wizard')); $this->admin_form_table_end(); }
/** * Outputs a JSON-encoded list of posts and terms on the blog. * * @since 6.0 */ function jlsuggest_autocomplete() { if (!function_exists('json_encode')) { die; } if (!current_user_can('manage_options')) { die; } $items = array(); $include = empty($_GET['types']) ? array() : explode(',', $_GET['types']); if ((!$include || in_array('home', $include)) && sustr::ihas($_GET['q'], 'home')) { $items[] = array('text' => __('Home', 'seo-ultimate'), 'isheader' => true); $items[] = array('text' => __('Blog Homepage', 'seo-ultimate'), 'value' => 'obj_home', 'selectedtext' => __('Blog Homepage', 'seo-ultimate')); } $posttypeobjs = get_post_types(array('public' => true), 'objects'); foreach ($posttypeobjs as $posttypeobj) { if ($include && !in_array('posttype', $include) && !in_array('posttype_' . $posttypeobj->name, $include)) { continue; } $stati = get_available_post_statuses($posttypeobj->name); suarr::remove_value($stati, 'auto-draft'); $stati = implode(',', $stati); $posts = get_posts(array('orderby' => 'title', 'order' => 'ASC', 'post_status' => $stati, 'numberposts' => -1, 'post_type' => $posttypeobj->name, 'post_mime_type' => isset($_GET['post_mime_type']) ? $_GET['post_mime_type'] : '', 'sentence' => 1, 's' => $_GET['q'])); if (count($posts)) { $items[] = array('text' => $posttypeobj->labels->name, 'isheader' => true); foreach ($posts as $post) { $items[] = array('text' => $post->post_title, 'value' => 'obj_posttype_' . $posttypeobj->name . '/' . $post->ID, 'selectedtext' => $post->post_title . '<span class="type"> — ' . $posttypeobj->labels->singular_name . '</span>'); } } } $taxonomyobjs = suwp::get_taxonomies(); foreach ($taxonomyobjs as $taxonomyobj) { if ($include && !in_array('taxonomy', $include) && !in_array('taxonomy_' . $posttypeobj->name, $include)) { continue; } $terms = get_terms($taxonomyobj->name, array('search' => $_GET['q'])); if (count($terms)) { $items[] = array('text' => $taxonomyobj->labels->name, 'isheader' => true); foreach ($terms as $term) { $items[] = array('text' => $term->name, 'value' => 'obj_taxonomy_' . $taxonomyobj->name . '/' . $term->term_id, 'selectedtext' => $term->name . '<span class="type"> — ' . $taxonomyobj->labels->singular_name . '</span>'); } } } if (!$include || in_array('author', $include)) { $authors = get_users(array('search' => $_GET['q'], 'fields' => array('ID', 'user_login'))); if (count($authors)) { $items[] = array('text' => __('Author Archives', 'seo-ultimate'), 'isheader' => true); foreach ($authors as $author) { $items[] = array('text' => $author->user_login, 'value' => 'obj_author/' . $author->ID, 'selectedtext' => $author->user_login . '<span class="type"> — ' . __('Author', 'seo-ultimate') . '</span>'); } } } if ($this->module_exists('internal-link-aliases') && (!$include || in_array('internal-link-alias', $include))) { $aliases = $this->get_setting('aliases', array(), 'internal-link-aliases'); $alias_dir = $this->get_setting('alias_dir', 'go', 'internal-link-aliases'); if (is_array($aliases) && count($aliases)) { $header_outputted = false; foreach ($aliases as $alias_id => $alias) { if ($alias['to']) { $h_alias_to = su_esc_html($alias['to']); $to_rel_url = "/{$alias_dir}/{$h_alias_to}/"; if (strpos($alias['from'], $_GET['q']) !== false || strpos($to_rel_url, $_GET['q']) !== false) { if (!$header_outputted) { $items[] = array('text' => __('Link Masks', 'seo-ultimate'), 'isheader' => true); $header_outputted = true; } $items[] = array('text' => $to_rel_url, 'value' => 'obj_internal-link-alias/' . $alias_id, 'selectedtext' => $to_rel_url . '<span class="type"> — ' . __('Link Mask', 'seo-ultimate') . '</span>'); } } } } } echo json_encode($items); die; }
function init() { if ($this->is_action('su-export')) { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="SEO Ultimate Settings (' . date('Y-m-d') . ').dat"'); $export = array(); $psdata = (array) get_option('seo_ultimate', array()); //Module statuses $export['modules'] = apply_filters('su_modules_export_array', $psdata['modules']); //Module settings $modules = array_keys($psdata['modules']); $module_settings = array(); foreach ($modules as $module) { if (!$this->plugin->call_module_func($module, 'get_settings_key', $key) || !$key) { $key = $module; } $msdata = (array) get_option("seo_ultimate_module_{$key}", array()); if ($msdata) { $module_settings[$key] = $msdata; } } $export['settings'] = apply_filters('su_settings_export_array', $module_settings); //Encode $export = base64_encode(serialize($export)); //Output echo $export; die; } elseif ($this->is_action('su-import')) { if (strlen($_FILES['settingsfile']['name'])) { $file = $_FILES['settingsfile']['tmp_name']; if (is_uploaded_file($file)) { $import = base64_decode(file_get_contents($file)); if (is_serialized($import)) { $import = unserialize($import); //Module statuses $psdata = (array) get_option('seo_ultimate', array()); $psdata['modules'] = array_merge($psdata['modules'], $import['modules']); update_option('seo_ultimate', $psdata); //Module settings $module_settings = apply_filters('su_settings_import_array', $import['settings']); foreach ($module_settings as $key => $module_settings) { $msdata = (array) get_option("seo_ultimate_module_{$key}", array()); $msdata = array_merge($msdata, $module_settings); update_option("seo_ultimate_module_{$key}", $msdata); } $this->queue_message('success', __('Settings successfully imported.', 'seo-ultimate')); } else { $this->queue_message('error', __('The uploaded file is not in the proper format. Settings could not be imported.', 'seo-ultimate')); } } else { $this->queue_message('error', __('The settings file could not be uploaded successfully.', 'seo-ultimate')); } } else { $this->queue_message('warning', __('Settings could not be imported because no settings file was selected. Please click the “Browse” button and select a file to import.', 'seo-ultimate')); } } elseif ($this->is_action('su-reset')) { $psdata = (array) get_option('seo_ultimate', array()); $modules = array_keys($psdata['modules']); foreach ($modules as $module) { if (!$this->plugin->call_module_func($module, 'get_settings_key', $key) || !$key) { $key = $module; } delete_option("seo_ultimate_module_{$key}"); } unset($psdata['modules']); update_option('seo_ultimate', $psdata); $this->load_default_settings(); } elseif ($this->is_action('dj-export')) { header('Content-Disposition: attachment; filename="Deeplink Juggernaut Content Links (' . date('Y-m-d') . ').csv"'); $djlinks = $this->get_setting('links', array(), 'autolinks'); $csv_headers = array('anchor' => 'Anchor', 'to_type' => 'Destination Type', 'to_id' => 'Destination', 'title' => 'Title', 'sitewide_lpa' => 'Site Cap', 'nofollow' => 'Nofollow', 'target' => 'Target'); if (is_array($djlinks) && count($djlinks)) { $djlinks = suarr::key_replace($djlinks, $csv_headers, true, true); } else { $djlinks = array(array_fill_keys($csv_headers, '')); } suio::export_csv($djlinks); die; } elseif ($this->is_action('dj-import')) { if (strlen($_FILES['settingsfile']['name'])) { $file = $_FILES['settingsfile']['tmp_name']; if (is_uploaded_file($file)) { $import = suio::import_csv($file); if ($import === false) { $this->queue_message('error', __('The uploaded file is not in the proper format. Links could not be imported.', 'seo-ultimate')); } else { $import = suarr::key_replace($import, array('Anchor' => 'anchor', 'Destination Type' => 'to_type', 'Destination' => 'to_id', 'URL' => 'to_id', 'Title' => 'title', 'Site Cap' => 'sidewide_lpa', 'Nofollow' => 'nofollow', 'Target' => 'target'), true, true); $import = suarr::value_replace($import, array('No' => false, 'Yes' => true, 'URL' => 'url'), true, false); $djlinks = array(); foreach ($import as $link) { //Validate destination type if ($link['to_type'] != 'url' && !sustr::startswith($link['to_type'], 'posttype_') && !sustr::startswith($link['to_type'], 'taxonomy_')) { $link['to_type'] = 'url'; } //Validate nofollow if (!is_bool($link['nofollow'])) { $link['nofollow'] = false; } //Validate target $link['target'] = ltrim($link['target'], '_'); if (!in_array($link['target'], array('self', 'blank'))) { //Only _self or _blank are supported right now $link['target'] = 'self'; } //Add link! $djlinks[] = $link; } $this->update_setting('links', $djlinks, 'autolinks'); $this->queue_message('success', __('Links successfully imported.', 'seo-ultimate')); } } else { $this->queue_message('error', __('The CSV file could not be uploaded successfully.', 'seo-ultimate')); } } else { $this->queue_message('warning', __('Links could not be imported because no CSV file was selected. Please click the “Browse” button and select a file to import.', 'seo-ultimate')); } } }
function save_post_autolinks($false, $value, $metakey, $post) { if ($post->post_type == 'revision') { return true; } $links = $this->get_setting('links', array()); $new_links = array(); $keep_anchors = array(); $others_anchors = array(); $new_anchors = suarr::explode_lines($value); $new_anchors = array_map('trim', $new_anchors); array_filter($new_anchors); if (count($new_anchors)) { foreach ($links as $link_data) { if ($link_data['to_type'] == 'posttype_' . $post->post_type && $link_data['to_id'] == $post->ID) { if (in_array($link_data['anchor'], $new_anchors)) { $keep_anchors[] = $link_data['anchor']; $new_links[] = $link_data; } } else { $others_anchors[] = $link_data['anchor']; $new_links[] = $link_data; } } $anchors_to_add = array_diff($new_anchors, $keep_anchors, $others_anchors); if (count($anchors_to_add)) { foreach ($anchors_to_add as $anchor_to_add) { if (trim($anchor_to_add)) { $new_links[] = array('anchor' => $anchor_to_add, 'to_type' => 'posttype_' . $post->post_type, 'to_id' => $post->ID, 'title' => '', 'nofollow' => false, 'target' => 'self'); } } } $this->update_setting('links', $new_links); } return true; }
function log_hit($hit) { if ($hit['status_code'] == 404) { if ($this->get_setting('restrict_logging', true)) { if (!($this->get_setting('log_spiders', true) && suweb::is_search_engine_ua($hit['user_agent'])) && !($this->get_setting('log_errors_with_referers', true) && strlen($hit['referer']))) { return $hit; } } $exceptions = suarr::explode_lines($this->get_setting('exceptions', '')); foreach ($exceptions as $exception) { if (preg_match(sustr::wildcards_to_regex($exception), $hit['url'])) { return $hit; } } $l = $this->get_setting('log', array()); $max_log_size = absint(sustr::preg_filter('0-9', strval($this->get_setting('max_log_size', 100)))); while (count($l) > $max_log_size) { array_pop($l); } $u = $hit['url']; if (!isset($l[$u])) { $l[$u] = array(); $l[$u]['hit_count'] = 0; $l[$u]['is_new'] = isset($hit['is_new']) ? $hit['is_new'] : true; $l[$u]['referers'] = array(); $l[$u]['user_agents'] = array(); $l[$u]['last_hit_time'] = 0; } $l[$u]['hit_count']++; if (!$l[$u]['is_new'] && $hit['is_new']) { $l[$u]['is_new'] = true; } if ($hit['time'] > $l[$u]['last_hit_time']) { $l[$u]['last_hit_time'] = $hit['time']; } if (strlen($hit['referer']) && !in_array($hit['referer'], $l[$u]['referers'])) { $l[$u]['referers'][] = $hit['referer']; } if (strlen($hit['user_agent']) && !in_array($hit['user_agent'], $l[$u]['user_agents'])) { $l[$u]['user_agents'][] = $hit['user_agent']; } $this->update_setting('log', $l); } return $hit; }
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_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); }
static function array_unique_i($a) { $n = array(); foreach ($a as $k => $v) { if (!suarr::in_array_i($v, $n)) { $n[$k] = $v; } } return $n; }
function do_import() { $this->do_import_deactivate(SU_AIOSP_PATH); $this->do_import_postmeta(suarr::aprintf('_aioseop_%s', '_su_%s', array('title', 'description', 'keywords')), '_aioseop_disable'); }