/**
  * Filter POST variables.
  *
  * @param string $var_name
  *
  * @return mixed
  */
 private function filter_input_post($var_name)
 {
     $val = filter_input(INPUT_POST, $var_name);
     if ($val) {
         return YMBESEO_Utils::sanitize_text_field($val);
     }
     return '';
 }
Пример #2
0
 /**
  * Make sure the needed scripts are loaded for admin pages
  */
 function init()
 {
     if (filter_input(INPUT_GET, 'YMBESEO_reset_defaults') && wp_verify_nonce(filter_input(INPUT_GET, 'nonce'), 'YMBESEO_reset_defaults') && current_user_can('manage_options')) {
         YMBESEO_Options::reset();
         wp_redirect(admin_url('admin.php?page=YMBESEO_dashboard'));
     }
     if (YMBESEO_Utils::grant_access()) {
         add_action('admin_enqueue_scripts', array($this, 'config_page_scripts'));
         add_action('admin_enqueue_scripts', array($this, 'config_page_styles'));
     }
 }
Пример #3
0
 /**
  * Get the datetime object, in site's time zone, if the datetime string was valid
  *
  * @param string $datetime_string The datetime string in UTC time zone, that needs to be converted to a DateTime object.
  * @param string $format
  *
  * @return DateTime|null in site's time zone
  */
 public function get_datetime_with_timezone($datetime_string, $format = 'c')
 {
     static $utc_timezone, $local_timezone;
     if (!isset($utc_timezone)) {
         $utc_timezone = new DateTimeZone('UTC');
         $local_timezone = new DateTimeZone($this->get_timezone_string());
     }
     if (!empty($datetime_string) && YMBESEO_Utils::is_valid_datetime($datetime_string)) {
         $datetime = new DateTime($datetime_string, $utc_timezone);
         $datetime->setTimezone($local_timezone);
         return $datetime->format($format);
     }
     return null;
 }
 /**
  * Clear rewrite rules
  *
  * @deprecated 1.5.6.1
  * @deprecated use YMBESEO_Utils::clear_rewrites()
  * @see        YMBESEO_Utils::clear_rewrites()
  */
 public static function clear_rewrites()
 {
     _deprecated_function(__METHOD__, 'WPSEO 1.5.6.1', 'YMBESEO_Utils::clear_rewrites()');
     YMBESEO_Utils::clear_rewrites();
 }
Пример #5
0
<?php

/**
 * @package YMBESEO\Admin
 */
if (!defined('YMBESEO_VERSION')) {
    header('Status: 403 Forbidden');
    header('HTTP/1.1 403 Forbidden');
    exit;
}
$tool_page = (string) filter_input(INPUT_GET, 'tool');
$yform = Yoast_Form::get_instance();
$yform->admin_header(false);
if ('' === $tool_page) {
    $tools = array('bulk-editor' => array('title' => __('Bulk editor', 'ymbeseo'), 'desc' => __('This tool allows you to quickly change titles and descriptions of your posts and pages without having to go into the editor for each page.', 'ymbeseo')), 'import-export' => array('title' => __('Import and Export', 'ymbeseo'), 'desc' => __('Import settings from other SEO plugins and export your settings for re-use on (another) blog.', 'ymbeseo')));
    if (YMBESEO_Utils::allow_system_file_edit() === true && !is_multisite()) {
        $tools['file-editor'] = array('title' => __('File editor', 'ymbeseo'), 'desc' => __('This tool allows you to quickly change important files for your SEO, like your robots.txt and, if you have one, your .htaccess file.', 'ymbeseo'));
    }
    /* translators: %1$s expands to Yoast SEO */
    echo '<p>', sprintf(__('%1$s comes with some very powerful built-in tools:', 'ymbeseo'), 'Yoast SEO'), '</p>';
    asort($tools);
    echo '<ul class="ul-disc">';
    foreach ($tools as $slug => $tool) {
        echo '<li>';
        echo '<strong><a href="', admin_url('admin.php?page=YMBESEO_tools&tool=' . $slug), '">', $tool['title'], '</a></strong><br/>';
        echo $tool['desc'];
        echo '</li>';
    }
    echo '</ul>';
} else {
    echo '<a href="', admin_url('admin.php?page=YMBESEO_tools'), '">', __('&laquo; Back to Tools page', 'ymbeseo'), '</a>';
 /**
  * Clean a given option value
  *
  * @param  array  $option_value          Old (not merged with defaults or filtered) option value to
  *                                       clean according to the rules for this option.
  * @param  string $current_version       (optional) Version from which to upgrade, if not set,
  *                                       version specific upgrades will be disregarded.
  * @param  array  $all_old_option_values (optional) Only used when importing old options to have
  *                                       access to the real old values, in contrast to the saved ones.
  *
  * @return  array            Cleaned option
  */
 protected function clean_option($option_value, $current_version = null, $all_old_option_values = null)
 {
     static $original = null;
     // Double-run this function to ensure renaming of the taxonomy options will work.
     if (!isset($original) && has_action('YMBESEO_double_clean_titles', array($this, 'clean')) === false) {
         add_action('YMBESEO_double_clean_titles', array($this, 'clean'));
         $original = $option_value;
     }
     /*
     Move options from very old option to this one
     	   @internal Don't rename to the 'current' names straight away as that would prevent
     	   the rename/unset combi below from working
     	   @todo [JRF] maybe figure out a smarter way to deal with this
     */
     $old_option = null;
     if (isset($all_old_option_values)) {
         // Ok, we have an import.
         if (isset($all_old_option_values['YMBESEO_indexation']) && is_array($all_old_option_values['YMBESEO_indexation']) && $all_old_option_values['YMBESEO_indexation'] !== array()) {
             $old_option = $all_old_option_values['YMBESEO_indexation'];
         }
     } else {
         $old_option = get_option('YMBESEO_indexation');
     }
     if (is_array($old_option) && $old_option !== array()) {
         $move = array('noindexauthor' => 'noindex-author', 'disableauthor' => 'disable-author', 'noindexdate' => 'noindex-archive', 'noindexcat' => 'noindex-category', 'noindextag' => 'noindex-post_tag', 'noindexpostformat' => 'noindex-post_format', 'noindexsubpages' => 'noindex-subpages', 'hidersdlink' => 'hide-rsdlink', 'hidefeedlinks' => 'hide-feedlinks', 'hidewlwmanifest' => 'hide-wlwmanifest', 'hideshortlink' => 'hide-shortlink');
         foreach ($move as $old => $new) {
             if (isset($old_option[$old]) && !isset($option_value[$new])) {
                 $option_value[$new] = $old_option[$old];
             }
         }
         unset($move, $old, $new);
     }
     unset($old_option);
     // Fix wrongness created by buggy version 1.2.2.
     if (isset($option_value['title-home']) && $option_value['title-home'] === '%%sitename%% - %%sitedesc%% - 12345') {
         $option_value['title-home-wpseo'] = '%%sitename%% - %%sitedesc%%';
     }
     /*
     Renaming these options to avoid ever overwritting these if a (bloody stupid) user /
     	   programmer would use any of the following as a custom post type or custom taxonomy:
     	   'home', 'author', 'archive', 'search', '404', 'subpages'
     
     	   Similarly, renaming the tax options to avoid a custom post type and a taxonomy
     	   with the same name occupying the same option
     */
     $rename = array('title-home' => 'title-home-wpseo', 'title-author' => 'title-author-wpseo', 'title-archive' => 'title-archive-wpseo', 'title-search' => 'title-search-wpseo', 'title-404' => 'title-404-wpseo', 'metadesc-home' => 'metadesc-home-wpseo', 'metadesc-author' => 'metadesc-author-wpseo', 'metadesc-archive' => 'metadesc-archive-wpseo', 'metakey-home' => 'metakey-home-wpseo', 'metakey-author' => 'metakey-author-wpseo', 'noindex-subpages' => 'noindex-subpages-wpseo', 'noindex-author' => 'noindex-author-wpseo', 'noindex-archive' => 'noindex-archive-wpseo');
     foreach ($rename as $old => $new) {
         if (isset($option_value[$old]) && !isset($option_value[$new])) {
             $option_value[$new] = $option_value[$old];
             unset($option_value[$old]);
         }
     }
     unset($rename, $old, $new);
     /**
      * @internal This clean-up action can only be done effectively once the taxonomies and post_types
      * have been registered, i.e. at the end of the init action.
      */
     if (isset($original) && current_filter() === 'YMBESEO_double_clean_titles' || did_action('YMBESEO_double_clean_titles') > 0) {
         $rename = array('title-' => 'title-tax-', 'metadesc-' => 'metadesc-tax-', 'metakey-' => 'metakey-tax-', 'noindex-' => 'noindex-tax-', 'tax-hideeditbox-' => 'hideeditbox-tax-');
         $taxonomy_names = get_taxonomies(array('public' => true), 'names');
         $post_type_names = get_post_types(array('public' => true), 'names');
         $defaults = $this->get_defaults();
         if ($taxonomy_names !== array()) {
             foreach ($taxonomy_names as $tax) {
                 foreach ($rename as $old_prefix => $new_prefix) {
                     if (isset($original[$old_prefix . $tax]) && !isset($original[$new_prefix . $tax]) && (!isset($option_value[$new_prefix . $tax]) || isset($option_value[$new_prefix . $tax]) && $option_value[$new_prefix . $tax] === $defaults[$new_prefix . $tax])) {
                         $option_value[$new_prefix . $tax] = $original[$old_prefix . $tax];
                         /*
                         Check if there is a cpt with the same name as the tax,
                         	   if so, we should make sure that the old setting hasn't been removed
                         */
                         if (!isset($post_type_names[$tax]) && isset($option_value[$old_prefix . $tax])) {
                             unset($option_value[$old_prefix . $tax]);
                         } else {
                             if (isset($post_type_names[$tax]) && !isset($option_value[$old_prefix . $tax])) {
                                 $option_value[$old_prefix . $tax] = $original[$old_prefix . $tax];
                             }
                         }
                         if ($old_prefix === 'tax-hideeditbox-') {
                             unset($option_value[$old_prefix . $tax]);
                         }
                     }
                 }
             }
         }
         unset($rename, $taxonomy_names, $post_type_names, $defaults, $tax, $old_prefix, $new_prefix);
     }
     /*
     Make sure the values of the variable option key options are cleaned as they
     	   may be retained and would not be cleaned/validated then
     */
     if (is_array($option_value) && $option_value !== array()) {
         foreach ($option_value as $key => $value) {
             $switch_key = $this->get_switch_key($key);
             // Similar to validation routine - any changes made there should be made here too.
             switch ($switch_key) {
                 /* text fields */
                 case 'title-':
                 case 'metadesc-':
                 case 'metakey-':
                 case 'bctitle-ptarchive-':
                     $option_value[$key] = YMBESEO_Utils::sanitize_text_field($value);
                     break;
                 case 'separator':
                     if (!array_key_exists($value, $this->get_separator_options())) {
                         $option_value[$key] = false;
                     }
                     break;
                     /*
                     Boolean fields
                     */
                     /*
                     					Covers:
                     * 		'noindex-'
                     * 		'showdate-'
                     * 		'hideeditbox-'
                     */
                 /*
                 Boolean fields
                 */
                 /*
                 					Covers:
                 * 		'noindex-'
                 * 		'showdate-'
                 * 		'hideeditbox-'
                 */
                 default:
                     $option_value[$key] = YMBESEO_Utils::validate_bool($value);
                     break;
             }
         }
         unset($key, $value, $switch_key);
     }
     return $option_value;
 }
/**
 * Check whether file editing is allowed for the .htaccess and robots.txt files
 *
 * @deprecated 1.5.6.1
 * @deprecated use YMBESEO_Utils::allow_system_file_edit()
 * @see        YMBESEO_Utils::allow_system_file_edit()
 *
 * @internal   current_user_can() checks internally whether a user is on wp-ms and adjusts accordingly.
 *
 * @return bool
 */
function YMBESEO_allow_system_file_edit()
{
    _deprecated_function(__FUNCTION__, 'WPSEO 1.5.6.1', 'YMBESEO_Utils::allow_system_file_edit()');
    return YMBESEO_Utils::allow_system_file_edit();
}
 /**
  * Replace `%%variable_placeholders%%` with their real value based on the current requested page/post/cpt/etc
  *
  * @param string $string the string to replace the variables in.
  * @param array  $args   the object some of the replacement values might come from,
  *                       could be a post, taxonomy or term.
  * @param array  $omit   variables that should not be replaced by this function.
  *
  * @return string
  */
 public function replace($string, $args, $omit = array())
 {
     $string = strip_tags($string);
     // Let's see if we can bail super early.
     if (strpos($string, '%%') === false) {
         return YMBESEO_Utils::standardize_whitespace($string);
     }
     $args = (array) $args;
     if (isset($args['post_content']) && !empty($args['post_content'])) {
         $args['post_content'] = YMBESEO_Utils::strip_shortcode($args['post_content']);
     }
     if (isset($args['post_excerpt']) && !empty($args['post_excerpt'])) {
         $args['post_excerpt'] = YMBESEO_Utils::strip_shortcode($args['post_excerpt']);
     }
     $this->args = (object) wp_parse_args($args, $this->defaults);
     // Clean $omit array.
     if (is_array($omit) && $omit !== array()) {
         $omit = array_map(array(__CLASS__, 'remove_var_delimiter'), $omit);
     }
     $replacements = array();
     if (preg_match_all('`%%([^%]+(%%single)?)%%?`iu', $string, $matches)) {
         $replacements = $this->set_up_replacements($matches, $omit);
     }
     /**
      * Filter: 'YMBESEO_replacements' - Allow customization of the replacements before they are applied
      *
      * @api array $replacements The replacements
      */
     $replacements = apply_filters('YMBESEO_replacements', $replacements);
     // Do the actual replacements.
     if (is_array($replacements) && $replacements !== array()) {
         $string = str_replace(array_keys($replacements), array_values($replacements), $string);
     }
     /**
      * Filter: 'YMBESEO_replacements_final' - Allow overruling of whether or not to remove placeholders
      * which didn't yield a replacement
      *
      * @example <code>add_filter( 'YMBESEO_replacements_final', '__return_false' );</code>
      *
      * @api     bool $final
      */
     if (apply_filters('YMBESEO_replacements_final', true) === true && (isset($matches[1]) && is_array($matches[1]))) {
         // Remove non-replaced variables.
         $remove = array_diff($matches[1], $omit);
         // Make sure the $omit variables do not get removed.
         $remove = array_map(array(__CLASS__, 'add_var_delimiter'), $remove);
         $string = str_replace($remove, '', $string);
     }
     // Undouble separators which have nothing between them, i.e. where a non-replaced variable was removed.
     if (isset($replacements['%%sep%%']) && (is_string($replacements['%%sep%%']) && $replacements['%%sep%%'] !== '')) {
         $q_sep = preg_quote($replacements['%%sep%%'], '`');
         $string = preg_replace('`' . $q_sep . '(?:\\s*' . $q_sep . ')*`u', $replacements['%%sep%%'], $string);
     }
     // Remove superfluous whitespace.
     $string = YMBESEO_Utils::standardize_whitespace($string);
     return trim($string);
 }
Пример #9
0
 /**
  * Retrieve the body from the post.
  *
  * @param object $post The post object.
  *
  * @return string The post content.
  */
 function get_body($post)
 {
     // This filter allows plugins to add their content to the content to be analyzed.
     $post_content = apply_filters('YMBESEO_pre_analysis_post_content', $post->post_content, $post);
     // Strip shortcodes, for obvious reasons, if plugins think their content should be in the analysis, they should
     // hook into the above filter.
     $post_content = YMBESEO_Utils::trim_nbsp_from_string(YMBESEO_Utils::strip_shortcode($post_content));
     if (trim($post_content) == '') {
         return '';
     }
     $htmdata3 = preg_replace('`<(?:\\x20*script|script).*?(?:/>|/script>)`', '', $post_content);
     if ($htmdata3 == null) {
         $htmdata3 = $post_content;
     } else {
         unset($post_content);
     }
     $htmdata4 = preg_replace('`<!--.*?-->`', '', $htmdata3);
     if ($htmdata4 == null) {
         $htmdata4 = $htmdata3;
     } else {
         unset($htmdata3);
     }
     $htmdata5 = preg_replace('`<(?:\\x20*style|style).*?(?:/>|/style>)`', '', $htmdata4);
     if ($htmdata5 == null) {
         $htmdata5 = $htmdata4;
     } else {
         unset($htmdata4);
     }
     return $htmdata5;
 }
Пример #10
0
 /**
  * Validate the post meta values
  *
  * @static
  *
  * @param  mixed  $meta_value The new value.
  * @param  string $meta_key   The full meta key (including prefix).
  *
  * @return string             Validated meta value
  */
 public static function sanitize_post_meta($meta_value, $meta_key)
 {
     $field_def = self::$meta_fields[self::$fields_index[$meta_key]['subset']][self::$fields_index[$meta_key]['key']];
     $clean = self::$defaults[$meta_key];
     switch (true) {
         case $meta_key === self::$meta_prefix . 'linkdex':
             $int = YMBESEO_Utils::validate_int($meta_value);
             if ($int !== false && $int >= 0) {
                 $clean = strval($int);
                 // Convert to string to make sure default check works.
             }
             break;
         case $field_def['type'] === 'checkbox':
             // Only allow value if it's one of the predefined options.
             if (in_array($meta_value, array('on', 'off'), true)) {
                 $clean = $meta_value;
             }
             break;
         case $field_def['type'] === 'select' || $field_def['type'] === 'radio':
             // Only allow value if it's one of the predefined options.
             if (isset($field_def['options'][$meta_value])) {
                 $clean = $meta_value;
             }
             break;
         case $field_def['type'] === 'multiselect' && $meta_key === self::$meta_prefix . 'meta-robots-adv':
             $clean = self::validate_meta_robots_adv($meta_value);
             break;
         case $field_def['type'] === 'text' && $meta_key === self::$meta_prefix . 'canonical':
         case $field_def['type'] === 'text' && $meta_key === self::$meta_prefix . 'redirect':
             // Validate as url(-part).
             $url = YMBESEO_Utils::sanitize_url($meta_value);
             if ($url !== '') {
                 $clean = $url;
             }
             break;
         case $field_def['type'] === 'upload' && $meta_key === self::$meta_prefix . 'opengraph-image':
             // Validate as url.
             $url = YMBESEO_Utils::sanitize_url($meta_value, array('http', 'https', 'ftp', 'ftps'));
             if ($url !== '') {
                 $clean = $url;
             }
             break;
         case $field_def['type'] === 'textarea':
             if (is_string($meta_value)) {
                 // Remove line breaks and tabs.
                 // @todo [JRF => Yoast] verify that line breaks and the likes aren't allowed/recommended in meta header fields.
                 $meta_value = str_replace(array("\n", "\r", "\t", '  '), ' ', $meta_value);
                 $clean = YMBESEO_Utils::sanitize_text_field(trim($meta_value));
             }
             break;
         case 'multiselect' === $field_def['type']:
             $clean = $meta_value;
             break;
         case $field_def['type'] === 'text':
         default:
             if (is_string($meta_value)) {
                 $clean = YMBESEO_Utils::sanitize_text_field(trim($meta_value));
             }
             break;
     }
     $clean = apply_filters('YMBESEO_sanitize_post_meta_' . $meta_key, $clean, $meta_value, $field_def, $meta_key);
     return $clean;
 }
Пример #11
0
 /**
  * Display an OpenGraph image tag
  *
  * @param string $img - Source URL to the image.
  *
  * @return bool
  */
 private function add_image($img)
 {
     // Filter: 'YMBESEO_opengraph_image' - Allow changing the OpenGraph image.
     $img = trim(apply_filters('YMBESEO_opengraph_image', $img));
     if (empty($img)) {
         return false;
     }
     if (YMBESEO_Utils::is_url_relative($img) === true) {
         $img = $this->get_relative_path($img);
     }
     if (in_array($img, $this->images)) {
         return false;
     }
     array_push($this->images, $img);
     return true;
 }
Пример #12
0
 /**
  * Validate the option
  *
  * @param  array $dirty New value for the option.
  * @param  array $clean Clean value for the option, normally the defaults.
  * @param  array $old   Old value of the option.
  *
  * @return  array      Validated clean value for the option to be saved to the database
  */
 protected function validate_option($dirty, $clean, $old)
 {
     foreach ($clean as $key => $value) {
         switch ($key) {
             /* Automagic Facebook connect key */
             case 'fbconnectkey':
                 if (isset($old[$key]) && $old[$key] !== '' && preg_match('`^[a-f0-9]{32}$`', $old[$key]) > 0) {
                     $clean[$key] = $old[$key];
                 } else {
                     $clean[$key] = self::get_fbconnectkey();
                 }
                 break;
                 /* Will not always exist in form */
             /* Will not always exist in form */
             case 'fb_admins':
                 if (isset($dirty[$key]) && is_array($dirty[$key])) {
                     if ($dirty[$key] === array()) {
                         $clean[$key] = array();
                     } else {
                         foreach ($dirty[$key] as $user_id => $fb_array) {
                             /*
                              * @todo [JRF/JRF => Yoast/whomever] add user_id validation -
                              * are these WP user-ids or FB user-ids ? Probably FB user-ids,
                              * if so, find out the rules for FB user-ids
                              */
                             if (is_array($fb_array) && $fb_array !== array()) {
                                 foreach ($fb_array as $fb_key => $fb_value) {
                                     switch ($fb_key) {
                                         case 'name':
                                             /**
                                              * @todo [JRF => whomever] add validation for name based
                                              * on rules if there are any
                                              * Input comes from: $_GET['userrealname']
                                              */
                                             $clean[$key][$user_id][$fb_key] = sanitize_text_field($fb_value);
                                             break;
                                         case 'link':
                                             $clean[$key][$user_id][$fb_key] = YMBESEO_Utils::sanitize_url($fb_value);
                                             break;
                                     }
                                 }
                             }
                         }
                         unset($user_id, $fb_array, $fb_key, $fb_value);
                     }
                 } elseif (isset($old[$key]) && is_array($old[$key])) {
                     $clean[$key] = $old[$key];
                 }
                 break;
                 /* text fields */
             /* text fields */
             case 'og_frontpage_desc':
             case 'og_frontpage_title':
                 if (isset($dirty[$key]) && $dirty[$key] !== '') {
                     $clean[$key] = YMBESEO_Utils::sanitize_text_field($dirty[$key]);
                 }
                 break;
                 /* url text fields - no ftp allowed */
             /* url text fields - no ftp allowed */
             case 'facebook_site':
             case 'instagram_url':
             case 'linkedin_url':
             case 'myspace_url':
             case 'pinterest_url':
             case 'plus-publisher':
             case 'og_default_image':
             case 'og_frontpage_image':
             case 'youtube_url':
             case 'google_plus_url':
                 $this->validate_url($key, $dirty, $old, $clean);
                 break;
             case 'pinterestverify':
                 $this->validate_verification_string($key, $dirty, $old, $clean);
                 break;
                 /* twitter user name */
             /* twitter user name */
             case 'twitter_site':
                 if (isset($dirty[$key]) && $dirty[$key] !== '') {
                     $twitter_id = sanitize_text_field(ltrim($dirty[$key], '@'));
                     /**
                      * From the Twitter documentation about twitter screen names:
                      * Typically a maximum of 15 characters long, but some historical accounts
                      * may exist with longer names.
                      * A username can only contain alphanumeric characters (letters A-Z, numbers 0-9)
                      * with the exception of underscores
                      * @link https://support.twitter.com/articles/101299-why-can-t-i-register-certain-usernames
                      * @link https://dev.twitter.com/docs/platform-objects/users
                      */
                     if (preg_match('`^[A-Za-z0-9_]{1,25}$`', $twitter_id)) {
                         $clean[$key] = $twitter_id;
                     } elseif (preg_match('`^http(?:s)?://(?:www\\.)?twitter\\.com/(?P<handle>[A-Za-z0-9_]{1,25})/?$`', $twitter_id, $matches)) {
                         $clean[$key] = $matches['handle'];
                     } else {
                         if (isset($old[$key]) && $old[$key] !== '') {
                             $twitter_id = sanitize_text_field(ltrim($old[$key], '@'));
                             if (preg_match('`^[A-Za-z0-9_]{1,25}$`', $twitter_id)) {
                                 $clean[$key] = $twitter_id;
                             }
                         }
                         if (function_exists('add_settings_error')) {
                             add_settings_error($this->group_name, '_' . $key, sprintf(__('%s does not seem to be a valid Twitter user-id. Please correct.', 'ymbeseo'), '<strong>' . esc_html(sanitize_text_field($dirty[$key])) . '</strong>'), 'error');
                         }
                     }
                     unset($twitter_id);
                 }
                 break;
             case 'twitter_card_type':
                 if (isset($dirty[$key], self::$twitter_card_types[$dirty[$key]]) && $dirty[$key] !== '') {
                     $clean[$key] = $dirty[$key];
                 }
                 break;
                 /* boolean fields */
             /* boolean fields */
             case 'googleplus':
             case 'opengraph':
             case 'twitter':
                 $clean[$key] = isset($dirty[$key]) ? YMBESEO_Utils::validate_bool($dirty[$key]) : false;
                 break;
         }
     }
     /**
      * Only validate 'fbadminapp', so leave the clean default.
      */
     if (isset($dirty['fbadminapp']) && !empty($dirty['fbadminapp'])) {
         $clean['fbadminapp'] = $dirty['fbadminapp'];
     }
     return $clean;
 }
 /**
  * Setting an error on the screen
  *
  * @param string $plugin_section
  * @param string $readable_plugin_section This is the value for the translation.
  */
 protected function set_error($plugin_section, $readable_plugin_section)
 {
     $plugins_as_string = $this->get_conflicting_plugins_as_string($plugin_section);
     $error_message = '<h3>' . __('Warning!', 'ymbeseo') . '</h3>';
     /* translators: %1$s: 'Facebook & Open Graph' plugin name(s) of possibly conflicting plugin(s), %2$s to Yoast SEO */
     $error_message .= '<p>' . sprintf(__('The %1$s plugin(s) might cause issues when used in conjunction with %2$s.', 'ymbeseo'), $plugins_as_string, 'Yoast SEO') . '</p>';
     $error_message .= sprintf($readable_plugin_section, 'Yoast SEO', $plugins_as_string) . '<br/><br/>';
     $error_message .= '<p><strong>' . __('Recommended solution', 'ymbeseo') . '</strong><br/>';
     /* translators: %1$s: 'Facebook & Open Graph' plugin name(s) of possibly conflicting plugin(s). %2$s to Yoast SEO */
     $error_message .= sprintf(__('We recommend you deactivate %1$s and have another look at your %2$s configuration using the button above.', 'ymbeseo'), $plugins_as_string, 'Yoast SEO') . '</p>';
     foreach ($this->active_plugins[$plugin_section] as $plugin_file) {
         /* translators: %s: 'Facebook' plugin name of possibly conflicting plugin */
         $error_message .= '<a target="_blank" class="button-primary" href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=all', 'deactivate-plugin_' . $plugin_file) . '">' . sprintf(__('Deactivate %s', 'ymbeseo'), YMBESEO_Utils::get_plugin_name($plugin_file)) . '</a> ';
     }
     /* translators: %1$s expands to Yoast SEO */
     $error_message .= '<p class="alignright"><small>' . sprintf(__('This warning is generated by %1$s.', 'ymbeseo'), 'Yoast SEO') . '</small></p><div class="clear"></div>';
     // Add the message to the notifications center.
     Yoast_Notification_Center::get()->add_notification(new Yoast_Notification($error_message, array('type' => 'error yoast-dismissible', 'id' => 'wpseo-dismiss-plugin-conflict', 'nonce' => wp_create_nonce('dismiss-plugin-conflict'), 'data_json' => array('section' => $plugin_section, 'plugins' => $this->active_plugins[$plugin_section]))));
 }
Пример #14
0
}
$yform = Yoast_Form::get_instance();
$options = get_site_option('YMBESEO_ms');
if (isset($_POST['YMBESEO_submit'])) {
    check_admin_referer('wpseo-network-settings');
    foreach (array('access', 'defaultblog') as $opt) {
        $options[$opt] = $_POST['YMBESEO_ms'][$opt];
    }
    unset($opt);
    YMBESEO_Options::update_site_option('YMBESEO_ms', $options);
    add_settings_error('YMBESEO_ms', 'settings_updated', __('Settings Updated.', 'ymbeseo'), 'updated');
}
if (isset($_POST['YMBESEO_restore_blog'])) {
    check_admin_referer('wpseo-network-restore');
    if (isset($_POST['YMBESEO_ms']['restoreblog']) && is_numeric($_POST['YMBESEO_ms']['restoreblog'])) {
        $restoreblog = (int) YMBESEO_Utils::validate_int($_POST['YMBESEO_ms']['restoreblog']);
        $blog = get_blog_details($restoreblog);
        if ($blog) {
            YMBESEO_Options::reset_ms_blog($restoreblog);
            add_settings_error('YMBESEO_ms', 'settings_updated', sprintf(__('%s restored to default SEO settings.', 'ymbeseo'), esc_html($blog->blogname)), 'updated');
        } else {
            add_settings_error('YMBESEO_ms', 'settings_updated', sprintf(__('Blog %s not found.', 'ymbeseo'), esc_html($restoreblog)), 'error');
        }
        unset($restoreblog, $blog);
    }
}
/* Set up selectbox dropdowns for smaller networks (usability) */
$use_dropdown = true;
if (get_blog_count() > 100) {
    $use_dropdown = false;
} else {
Пример #15
0
 /**
  * Recursively trim whitespace round a string value or of string values within an array
  * Only trims strings to avoid typecasting a variable (to string)
  *
  * @deprecated 1.5.6.1
  * @deprecated use YMBESEO_Utils::trim_recursive()
  * @see        YMBESEO_Utils::trim_recursive()
  *
  * @static
  *
  * @param   mixed $value Value to trim or array of values to trim.
  *
  * @return  mixed      Trimmed value or array of trimmed values
  */
 public static function trim_recursive($value)
 {
     _deprecated_function(__FUNCTION__, 'WPSEO 1.5.6.1', 'YMBESEO_Utils::trim_recursive()');
     return YMBESEO_Utils::trim_recursive($value);
 }
Пример #16
0
 /**
  * Parsing the matched images
  *
  * @param array  $matches
  * @param object $p
  * @param string $scheme
  * @param string $host
  *
  * @return array
  */
 private function parse_matched_images($matches, $p, $scheme, $host)
 {
     $return = array();
     foreach ($matches[0] as $img) {
         if (preg_match('`src=["\']([^"\']+)["\']`', $img, $match)) {
             $src = $match[1];
             if (YMBESEO_Utils::is_url_relative($src) === true) {
                 if ($src[0] !== '/') {
                     continue;
                 } else {
                     // The URL is relative, we'll have to make it absolute.
                     $src = $this->home_url . $src;
                 }
             } elseif (strpos($src, 'http') !== 0) {
                 // Protocol relative url, we add the scheme as the standard requires a protocol.
                 $src = $scheme . ':' . $src;
             }
             if (strpos($src, $host) === false) {
                 continue;
             }
             if ($src != esc_url($src)) {
                 continue;
             }
             if (isset($return[$src])) {
                 continue;
             }
             $image = array('src' => apply_filters('YMBESEO_xml_sitemap_img_src', $src, $p));
             if (preg_match('`title=["\']([^"\']+)["\']`', $img, $title_match)) {
                 $image['title'] = str_replace(array('-', '_'), ' ', $title_match[1]);
             }
             unset($title_match);
             if (preg_match('`alt=["\']([^"\']+)["\']`', $img, $alt_match)) {
                 $image['alt'] = str_replace(array('-', '_'), ' ', $alt_match[1]);
             }
             unset($alt_match);
             $image = apply_filters('YMBESEO_xml_sitemap_img', $image, $p);
             $return[] = $image;
         }
         unset($match, $src);
     }
     return $return;
 }
Пример #17
0
 /**
  * This function normally outputs the canonical but is also used in other places to retrieve
  * the canonical URL for the current page.
  *
  * @return void
  */
 private function generate_canonical()
 {
     $canonical = false;
     $canonical_override = false;
     // Set decent canonicals for homepage, singulars and taxonomy pages.
     if (is_singular()) {
         $obj = get_queried_object();
         $canonical = get_permalink($obj->ID);
         $this->canonical_unpaged = $canonical;
         $canonical_override = YMBESEO_Meta::get_value('canonical');
         // Fix paginated pages canonical, but only if the page is truly paginated.
         if (get_query_var('page') > 1) {
             $num_pages = substr_count($obj->post_content, '<!--nextpage-->') + 1;
             if ($num_pages && get_query_var('page') <= $num_pages) {
                 if (!$GLOBALS['wp_rewrite']->using_permalinks()) {
                     $canonical = add_query_arg('page', get_query_var('page'), $canonical);
                 } else {
                     $canonical = user_trailingslashit(trailingslashit($canonical) . get_query_var('page'));
                 }
             }
         }
     } else {
         if (is_search()) {
             $canonical = get_search_link();
         } elseif (is_front_page()) {
             $canonical = home_url();
         } elseif ($this->is_posts_page()) {
             $canonical = get_permalink(get_option('page_for_posts'));
         } elseif (is_tax() || is_tag() || is_category()) {
             $term = get_queried_object();
             $canonical_override = YMBESEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'canonical');
             $canonical = get_term_link($term, $term->taxonomy);
         } elseif (is_post_type_archive()) {
             $post_type = get_query_var('post_type');
             if (is_array($post_type)) {
                 $post_type = reset($post_type);
             }
             $canonical = get_post_type_archive_link($post_type);
         } elseif (is_author()) {
             $canonical = get_author_posts_url(get_query_var('author'), get_query_var('author_name'));
         } elseif (is_archive()) {
             if (is_date()) {
                 if (is_day()) {
                     $canonical = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'));
                 } elseif (is_month()) {
                     $canonical = get_month_link(get_query_var('year'), get_query_var('monthnum'));
                 } elseif (is_year()) {
                     $canonical = get_year_link(get_query_var('year'));
                 }
             }
         }
         $this->canonical_unpaged = $canonical;
         if ($canonical && get_query_var('paged') > 1) {
             global $wp_rewrite;
             if (!$wp_rewrite->using_permalinks()) {
                 if (is_front_page()) {
                     $canonical = trailingslashit($canonical);
                 }
                 $canonical = add_query_arg('paged', get_query_var('paged'), $canonical);
             } else {
                 if (is_front_page()) {
                     $canonical = YMBESEO_xml_sitemaps_base_url('');
                 }
                 $canonical = user_trailingslashit(trailingslashit($canonical) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged'));
             }
         }
     }
     $this->canonical_no_override = $canonical;
     if (is_string($canonical) && $canonical !== '') {
         // Force canonical links to be absolute, relative is NOT an option.
         if (YMBESEO_Utils::is_url_relative($canonical) === true) {
             $canonical = $this->base_url($canonical);
         }
     }
     /**
      * Filter: 'YMBESEO_canonical' - Allow filtering of the canonical URL put out by Yoast SEO
      *
      * @api string $canonical The canonical URL
      */
     $canonical = apply_filters('YMBESEO_canonical', $canonical);
     if (is_string($canonical_override) && $canonical_override !== '') {
         $this->canonical = $canonical_override;
     } else {
         $this->canonical = $canonical;
     }
 }
Пример #18
0
 /**
  * Register (whitelist) the option for the configuration pages.
  * The validation callback is already registered separately on the sanitize_option hook,
  * so no need to double register.
  *
  * @return void
  */
 public function register_setting()
 {
     if (YMBESEO_Utils::grant_access()) {
         register_setting($this->group_name, $this->option_name);
     }
 }
Пример #19
0
 /**
  * Validate the meta data for one individual term and removes default values (no need to save those)
  *
  * @static
  *
  * @param  array $meta_data New values.
  * @param  array $old_meta  The original values.
  *
  * @return  array        Validated and filtered value
  */
 public static function validate_term_meta_data($meta_data, $old_meta)
 {
     $clean = self::$defaults_per_term;
     $meta_data = array_map(array('YMBESEO_Utils', 'trim_recursive'), $meta_data);
     if (!is_array($meta_data) || $meta_data === array()) {
         return $clean;
     }
     foreach ($clean as $key => $value) {
         switch ($key) {
             case 'YMBESEO_noindex':
                 if (isset($meta_data[$key])) {
                     if (isset(self::$no_index_options[$meta_data[$key]])) {
                         $clean[$key] = $meta_data[$key];
                     }
                 } elseif (isset($old_meta[$key])) {
                     // Retain old value if field currently not in use.
                     $clean[$key] = $old_meta[$key];
                 }
                 break;
             case 'YMBESEO_sitemap_include':
                 if (isset($meta_data[$key], self::$sitemap_include_options[$meta_data[$key]])) {
                     $clean[$key] = $meta_data[$key];
                 }
                 break;
             case 'YMBESEO_canonical':
                 if (isset($meta_data[$key]) && $meta_data[$key] !== '') {
                     $url = YMBESEO_Utils::sanitize_url($meta_data[$key]);
                     if ($url !== '') {
                         $clean[$key] = $url;
                     }
                     unset($url);
                 }
                 break;
             case 'YMBESEO_metakey':
             case 'YMBESEO_bctitle':
                 if (isset($meta_data[$key])) {
                     $clean[$key] = YMBESEO_Utils::sanitize_text_field(stripslashes($meta_data[$key]));
                 } elseif (isset($old_meta[$key])) {
                     // Retain old value if field currently not in use.
                     $clean[$key] = $old_meta[$key];
                 }
                 break;
             case 'YMBESEO_title':
             case 'YMBESEO_desc':
             default:
                 if (isset($meta_data[$key]) && is_string($meta_data[$key])) {
                     $clean[$key] = YMBESEO_Utils::sanitize_text_field(stripslashes($meta_data[$key]));
                 }
                 break;
         }
         $clean[$key] = apply_filters('YMBESEO_sanitize_tax_meta_' . $key, $clean[$key], isset($meta_data[$key]) ? $meta_data[$key] : null, isset($old_meta[$key]) ? $old_meta[$key] : null);
     }
     // Only save the non-default values.
     return array_diff_assoc($clean, self::$defaults_per_term);
 }
Пример #20
0
/**
 * On deactivation, flush the rewrite rules so XML sitemaps stop working.
 */
function _YMBESEO_deactivate()
{
    require_once YMBESEO_PATH . 'inc/ymbeseo-functions.php';
    add_action('shutdown', 'flush_rewrite_rules');
    YMBESEO_remove_capabilities();
    // Clear cache so the changes are obvious.
    YMBESEO_Utils::clear_cache();
    do_action('YMBESEO_deactivate');
}
Пример #21
0
 /**
  * Comparing the issue with the list of current existing issues
  *
  * @param array    $crawl_issues
  * @param stdClass $issue
  */
 private function issue_compare(&$crawl_issues, $issue)
 {
     $issue->pageUrl = YMBESEO_Utils::format_url((string) $issue->pageUrl);
     if (!in_array($issue->pageUrl, $this->current_issues)) {
         array_push($crawl_issues, $this->get_issue($this->create_issue($issue)));
     }
 }
Пример #22
0
 /**
  * Enqueues the (tiny) global JS needed for the plugin.
  */
 function config_page_scripts()
 {
     if (YMBESEO_Utils::grant_access()) {
         wp_enqueue_script('wpseo-admin-global-script', plugins_url('js/wp-seo-admin-global' . YMBESEO_CSSJS_SUFFIX . '.js', YMBESEO_FILE), array('jquery'), YMBESEO_VERSION, true);
     }
 }
Пример #23
0
 /**
  * Runs the needed cleanup after an update, setting the DB version to latest version, flushing caches etc.
  */
 private function finish_up()
 {
     $this->options = get_option('wpseo');
     // Re-get to make sure we have the latest version.
     update_option('wpseo', $this->options);
     // This also ensures the DB version is equal to YMBESEO_VERSION.
     add_action('shutdown', 'flush_rewrite_rules');
     // Just flush rewrites, always, to at least make them work after an upgrade.
     YMBESEO_Utils::clear_sitemap_cache();
     // Flush the sitemap cache.
     YMBESEO_Options::ensure_options_exist();
     // Make sure all our options always exist - issue #1245.
 }
 /**
  * Validate the option
  *
  * @param  array $dirty New value for the option.
  * @param  array $clean Clean value for the option, normally the defaults.
  * @param  array $old   Old value of the option.
  *
  * @return  array      Validated clean value for the option to be saved to the database
  */
 protected function validate_option($dirty, $clean, $old)
 {
     foreach ($clean as $key => $value) {
         switch ($key) {
             case 'version':
                 $clean[$key] = YMBESEO_VERSION;
                 break;
             case 'blocking_files':
                 /**
                  * @internal [JRF] to really validate this we should also do a file_exists()
                  * on each array entry and remove files which no longer exist, but that might be overkill
                  */
                 if (isset($dirty[$key]) && is_array($dirty[$key])) {
                     $clean[$key] = array_unique($dirty[$key]);
                 } elseif (isset($old[$key]) && is_array($old[$key])) {
                     $clean[$key] = array_unique($old[$key]);
                 }
                 break;
             case 'theme_description_found':
                 if (isset($dirty[$key]) && is_string($dirty[$key])) {
                     $clean[$key] = $dirty[$key];
                     // @todo [JRF/whomever] maybe do wp_kses ?
                 } elseif (isset($old[$key]) && is_string($old[$key])) {
                     $clean[$key] = $old[$key];
                 }
                 break;
             case 'company_or_person':
                 if (isset($dirty[$key]) && $dirty[$key] !== '') {
                     if (in_array($dirty[$key], array('company', 'person'))) {
                         $clean[$key] = $dirty[$key];
                     }
                 }
                 break;
                 /* text fields */
             /* text fields */
             case 'company_name':
             case 'person_name':
             case 'website_name':
             case 'alternate_website_name':
                 if (isset($dirty[$key]) && $dirty[$key] !== '') {
                     $clean[$key] = sanitize_text_field($dirty[$key]);
                 }
                 break;
             case 'company_logo':
                 $this->validate_url($key, $dirty, $old, $clean);
                 break;
                 /* verification strings */
             /* verification strings */
             case 'alexaverify':
             case 'googleverify':
             case 'msverify':
             case 'yandexverify':
                 $this->validate_verification_string($key, $dirty, $old, $clean);
                 break;
                 /* boolean|null fields - if set a check was done, if null, it hasn't */
             /* boolean|null fields - if set a check was done, if null, it hasn't */
             case 'theme_has_description':
                 if (isset($dirty[$key])) {
                     $clean[$key] = YMBESEO_Utils::validate_bool($dirty[$key]);
                 } elseif (isset($old[$key])) {
                     $clean[$key] = YMBESEO_Utils::validate_bool($old[$key]);
                 }
                 break;
                 /*
                 				Boolean dismiss warnings - not fields - may not be in form
                 					   (and don't need to be either as long as the default is false)
                 */
             /*
             				Boolean dismiss warnings - not fields - may not be in form
             					   (and don't need to be either as long as the default is false)
             */
             case 'ignore_blog_public_warning':
             case 'ignore_meta_description_warning':
             case 'ignore_page_comments':
             case 'ignore_permalink':
             case 'ms_defaults_set':
                 if (isset($dirty[$key])) {
                     $clean[$key] = YMBESEO_Utils::validate_bool($dirty[$key]);
                 } elseif (isset($old[$key])) {
                     $clean[$key] = YMBESEO_Utils::validate_bool($old[$key]);
                 }
                 break;
                 /*
                 Boolean (checkbox) fields
                 */
                 /*
                 				Covers
                 * 		'disableadvanced_meta'
                 * 		'yoast_tracking'
                 */
             /*
             Boolean (checkbox) fields
             */
             /*
             				Covers
             * 		'disableadvanced_meta'
             * 		'yoast_tracking'
             */
             default:
                 $clean[$key] = isset($dirty[$key]) ? YMBESEO_Utils::validate_bool($dirty[$key]) : false;
                 break;
         }
     }
     return $clean;
 }
Пример #25
0
/**
 * Adds an SEO admin bar menu with several options. If the current user is an admin he can also go straight to several settings menu's from here.
 */
function YMBESEO_admin_bar_menu()
{
    // If the current user can't write posts, this is all of no use, so let's not output an admin menu.
    if (!current_user_can('edit_posts')) {
        return;
    }
    global $wp_admin_bar, $post;
    $focuskw = '';
    $score = '';
    $seo_url = get_admin_url(null, 'admin.php?page=YMBESEO_dashboard');
    if ((is_singular() || is_admin() && in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'), true)) && isset($post) && is_object($post) && apply_filters('YMBESEO_use_page_analysis', true) === true) {
        $focuskw = YMBESEO_Meta::get_value('focuskw', $post->ID);
        $perc_score = YMBESEO_Meta::get_value('linkdex', $post->ID);
        $calc_score = YMBESEO_Utils::calc($perc_score, '/', 10, true);
        $txtscore = YMBESEO_Utils::translate_score($calc_score);
        $title = YMBESEO_Utils::translate_score($calc_score, false);
        $score = '<div title="' . esc_attr($title) . '" class="' . esc_attr('wpseo-score-icon ' . $txtscore . ' ' . $perc_score) . '"></div>';
        $seo_url = get_edit_post_link($post->ID);
        if ($txtscore !== 'na') {
            $seo_url .= '#YMBESEO_linkdex';
        }
    }
    $wp_admin_bar->add_menu(array('id' => 'wpseo-menu', 'title' => __('SEO', 'ymbeseo') . $score, 'href' => $seo_url));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __('Keyword Research', 'ymbeseo'), '#'));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-adwordsexternal', 'title' => __('AdWords External', 'ymbeseo'), 'href' => 'http://adwords.google.com/keywordplanner', 'meta' => array('target' => '_blank')));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-googleinsights', 'title' => __('Google Insights', 'ymbeseo'), 'href' => 'http://www.google.com/insights/search/#q=' . urlencode($focuskw) . '&cmpt=q', 'meta' => array('target' => '_blank')));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-wordtracker', 'title' => __('SEO Book', 'ymbeseo'), 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank')));
    if (!is_admin()) {
        $url = YMBESEO_Frontend::get_instance()->canonical(false);
        if (is_string($url)) {
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-analysis', 'title' => __('Analyze this page', 'ymbeseo'), '#'));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-inlinks-ose', 'title' => __('Check Inlinks (OSE)', 'ymbeseo'), 'href' => '//moz.com/researchtools/ose/links?site=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-kwdensity', 'title' => __('Check Keyword Density', 'ymbeseo'), 'href' => '//www.zippy.co.uk/keyworddensity/index.php?url=' . urlencode($url) . '&keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cache', 'title' => __('Check Google Cache', 'ymbeseo'), 'href' => '//webcache.googleusercontent.com/search?strip=1&q=cache:' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-header', 'title' => __('Check Headers', 'ymbeseo'), 'href' => '//quixapp.com/headers/?r=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-richsnippets', 'title' => __('Check Rich Snippets', 'ymbeseo'), 'href' => '//www.google.com/webmasters/tools/richsnippets?q=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-facebookdebug', 'title' => __('Facebook Debugger', 'ymbeseo'), 'href' => '//developers.facebook.com/tools/debug/og/object?q=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pinterestvalidator', 'title' => __('Pinterest Rich Pins Validator', 'ymbeseo'), 'href' => '//developers.pinterest.com/rich_pins/validator/?link=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-htmlvalidation', 'title' => __('HTML Validator', 'ymbeseo'), 'href' => '//validator.w3.org/check?uri=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cssvalidation', 'title' => __('CSS Validator', 'ymbeseo'), 'href' => '//jigsaw.w3.org/css-validator/validator?uri=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pagespeed', 'title' => __('Google Page Speed Test', 'ymbeseo'), 'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-modernie', 'title' => __('Modern IE Site Scan', 'ymbeseo'), 'href' => '//www.modern.ie/en-us/report#' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-google-mobile-friendly', 'title' => __('Mobile-Friendly Test', 'ymbeseo'), 'href' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url=' . urlencode($url), 'meta' => array('target' => '_blank')));
        }
    }
    $admin_menu = current_user_can('manage_options');
    if (!$admin_menu && is_multisite()) {
        $options = get_site_option('YMBESEO_ms');
        $admin_menu = $options['access'] === 'superadmin' && is_super_admin();
    }
    // @todo: add links to bulk title and bulk description edit pages.
    if ($admin_menu) {
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-settings', 'title' => __('SEO Settings', 'ymbeseo')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-general', 'title' => __('General', 'ymbeseo'), 'href' => admin_url('admin.php?page=YMBESEO_dashboard')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-titles', 'title' => __('Titles &amp; Metas', 'ymbeseo'), 'href' => admin_url('admin.php?page=YMBESEO_titles')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-social', 'title' => __('Social', 'ymbeseo'), 'href' => admin_url('admin.php?page=YMBESEO_social')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-xml', 'title' => __('XML Sitemaps', 'ymbeseo'), 'href' => admin_url('admin.php?page=YMBESEO_xml')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-YMBESEO_advanced', 'title' => __('Advanced', 'ymbeseo'), 'href' => admin_url('admin.php?page=YMBESEO_advanced')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-licenses', 'title' => __('Extensions', 'ymbeseo'), 'href' => admin_url('admin.php?page=YMBESEO_licenses')));
    }
}
 /**
  * Validate the option
  *
  * @param  array $dirty New value for the option.
  * @param  array $clean Clean value for the option, normally the defaults.
  * @param  array $old   Old value of the option.
  *
  * @return  array      Validated clean value for the option to be saved to the database
  */
 protected function validate_option($dirty, $clean, $old)
 {
     foreach ($clean as $key => $value) {
         switch ($key) {
             case 'access':
                 if (isset($dirty[$key]) && in_array($dirty[$key], self::$allowed_access_options, true)) {
                     $clean[$key] = $dirty[$key];
                 } elseif (function_exists('add_settings_error')) {
                     add_settings_error($this->group_name, '_' . $key, sprintf(__('%1$s is not a valid choice for who should be allowed access to the %2$s settings. Value reset to the default.', 'ymbeseo'), esc_html(sanitize_text_field($dirty[$key])), 'Yoast SEO'), 'error');
                 }
                 break;
             case 'defaultblog':
                 if (isset($dirty[$key]) && ($dirty[$key] !== '' && $dirty[$key] !== '-')) {
                     $int = YMBESEO_Utils::validate_int($dirty[$key]);
                     if ($int !== false && $int > 0) {
                         // Check if a valid blog number has been received.
                         $exists = get_blog_details($int, false);
                         if ($exists && $exists->deleted == 0) {
                             $clean[$key] = $int;
                         } elseif (function_exists('add_settings_error')) {
                             add_settings_error($this->group_name, '_' . $key, esc_html__('The default blog setting must be the numeric blog id of the blog you want to use as default.', 'ymbeseo') . '<br>' . sprintf(esc_html__('This must be an existing blog. Blog %s does not exist or has been marked as deleted.', 'ymbeseo'), '<strong>' . esc_html(sanitize_text_field($dirty[$key])) . '</strong>'), 'error');
                         }
                         unset($exists);
                     } elseif (function_exists('add_settings_error')) {
                         add_settings_error($this->group_name, '_' . $key, esc_html__('The default blog setting must be the numeric blog id of the blog you want to use as default.', 'ymbeseo') . '<br>' . esc_html__('No numeric value was received.', 'ymbeseo'), 'error');
                     }
                     unset($int);
                 }
                 break;
             default:
                 $clean[$key] = isset($dirty[$key]) ? YMBESEO_Utils::validate_bool($dirty[$key]) : false;
                 break;
         }
     }
     return $clean;
 }
Пример #27
0
$yform->textinput('entries-per-page', __('Max entries per sitemap', 'ymbeseo'));
?>
		</div>

		<div id="user-sitemap" class="wpseotab">
			<?php 
$yform->checkbox('disable_author_sitemap', __('Disable author/user sitemap', 'ymbeseo'), false);
?>
			<div id="xml_user_block">
				<p><strong><?php 
_e('Exclude users without posts', 'ymbeseo');
?>
</strong><br/>
					<?php 
$yform->checkbox('disable_author_noposts', __('Disable all users with zero posts', 'ymbeseo'), false);
$roles = YMBESEO_Utils::get_roles();
if (is_array($roles) && $roles !== array()) {
    echo '<p><strong>' . __('Exclude user roles', 'ymbeseo') . '</strong><br/>';
    echo __('Please check the appropriate box below if there\'s a user role that you do <strong>NOT</strong> want to include in your sitemap:', 'ymbeseo') . '</p>';
    foreach ($roles as $role_key => $role_name) {
        $yform->checkbox('user_role-' . $role_key . '-not_in_sitemap', $role_name);
    }
}
?>
			</div>
		</div>

		<div id="post-types" class="wpseotab">

			<?php 
$post_types = apply_filters('YMBESEO_sitemaps_supported_post_types', get_post_types(array('public' => true), 'objects'));
Пример #28
0
/**
 * This invalidates our XML Sitemaps cache.
 *
 * @param string $type
 */
function YMBESEO_invalidate_sitemap_cache($type)
{
    // Always delete the main index sitemaps cache, as that's always invalidated by any other change.
    delete_transient('YMBESEO_sitemap_cache_1');
    delete_transient('YMBESEO_sitemap_cache_' . $type);
    YMBESEO_Utils::clear_sitemap_cache(array($type));
}
Пример #29
0
 /**
  * Validate a value as integer
  *
  * @static
  *
  * @param mixed $value
  *
  * @return int|bool int or false in case of failure to convert to int
  */
 public static function validate_int($value)
 {
     if (!isset(self::$has_filters)) {
         self::$has_filters = extension_loaded('filter');
     }
     if (self::$has_filters) {
         return filter_var($value, FILTER_VALIDATE_INT);
     } else {
         return self::emulate_filter_int($value);
     }
 }
 /**
  * Clean a given option value
  *
  * @param  array  $option_value          Old (not merged with defaults or filtered) option value to
  *                                       clean according to the rules for this option.
  * @param  string $current_version       (optional) Version from which to upgrade, if not set,
  *                                       version specific upgrades will be disregarded.
  * @param  array  $all_old_option_values (optional) Only used when importing old options to have
  *                                       access to the real old values, in contrast to the saved ones.
  *
  * @return  array            Cleaned option
  */
 protected function clean_option($option_value, $current_version = null, $all_old_option_values = null)
 {
     /*
     Make sure the values of the variable option key options are cleaned as they
     	   may be retained and would not be cleaned/validated then
     */
     if (is_array($option_value) && $option_value !== array()) {
         foreach ($option_value as $key => $value) {
             $switch_key = $this->get_switch_key($key);
             // Similar to validation routine - any changes made there should be made here too.
             switch ($switch_key) {
                 case 'user_role-':
                     /* 'user_role-' . $role_name. '-not_in_sitemap' fields */
                 /* 'user_role-' . $role_name. '-not_in_sitemap' fields */
                 case 'post_types-':
                     /* 'post_types-' . $pt->name . '-not_in_sitemap' fields */
                 /* 'post_types-' . $pt->name . '-not_in_sitemap' fields */
                 case 'taxonomies-':
                     /* 'taxonomies-' . $tax->name . '-not_in_sitemap' fields */
                     $option_value[$key] = YMBESEO_Utils::validate_bool($value);
                     break;
             }
         }
     }
     return $option_value;
 }