/** * Returns the post count for a certain SEO rank * * @todo Merge/DRY this with the logic virtually the same in WPSEO_Metabox::column_sort_orderby() * * @param WPSEO_Rank $rank The SEO rank to get the post count for. * * @return int */ public function get_post_count($rank) { if (WPSEO_Rank::NO_FOCUS === $rank->get_rank()) { $posts = array('meta_query' => array('relation' => 'OR', array('key' => WPSEO_Meta::$meta_prefix . 'focuskw', 'value' => 'needs-a-value-anyway', 'compare' => 'NOT EXISTS'))); } elseif (WPSEO_Rank::NO_INDEX === $rank->get_rank()) { $posts = array('meta_key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', 'meta_value' => '1', 'compare' => '='); } else { $posts = array('meta_key' => WPSEO_Meta::$meta_prefix . 'linkdex', 'meta_value' => array($rank->get_starting_score(), $rank->get_end_score()), 'meta_compare' => 'BETWEEN', 'meta_type' => 'NUMERIC'); } $posts['fields'] = 'ids'; $posts['post_status'] = 'publish'; if (current_user_can('edit_others_posts') === false) { $posts['author'] = get_current_user_id(); } $posts = new WP_Query($posts); return $posts->found_posts; }
/** * Returns a dashboard widget label to use for a certain rank * * @param WPSEO_Rank $rank The rank to return a label for. * * @return string */ private function get_title_for_rank(WPSEO_Rank $rank) { $labels = array(WPSEO_Rank::NO_FOCUS => __('Posts without focus keyword', 'wordpress-seo'), WPSEO_Rank::BAD => __('Posts with bad SEO score', 'wordpress-seo'), WPSEO_Rank::OK => __('Posts with OK SEO score', 'wordpress-seo'), WPSEO_Rank::GOOD => __('Posts with good SEO score', 'wordpress-seo'), WPSEO_Rank::NO_INDEX => sprintf(__('Posts that are set to %s', 'wordpress-seo'), '<code>noindex</code>')); return $labels[$rank->get_rank()]; }
/** * Creates an icon by the given values. * * @param WPSEO_Rank $rank The ranking object. * @param string $title The title to show. * * @return string */ private function create_score_icon(WPSEO_Rank $rank, $title) { return '<div title="' . esc_attr($title) . '" class="wpseo-score-icon ' . esc_attr($rank->get_css_class()) . '"></div>'; }
/** * Parsing the score column * * @param integer $post_id The ID of the post for which to show the score. * * @return string */ private function parse_column_score($post_id) { if ('1' === WPSEO_Meta::get_value('meta-robots-noindex', $post_id)) { $rank = new WPSEO_Rank(WPSEO_Rank::NO_INDEX); $title = __('Post is set to noindex.', 'wordpress-seo'); WPSEO_Meta::set_value('linkdex', 0, $post_id); } elseif ('' === WPSEO_Meta::get_value('focuskw', $post_id)) { $rank = new WPSEO_Rank(WPSEO_Rank::NO_FOCUS); $title = __('Focus keyword not set.', 'wordpress-seo'); } else { $score = (int) WPSEO_Meta::get_value('linkdex', $post_id); $rank = WPSEO_Rank::from_numeric_score($score); $title = $rank->get_label(); } return '<div aria-hidden="true" title="' . esc_attr($title) . '" class="wpseo-score-icon ' . esc_attr($rank->get_css_class()) . '"></div><span class="screen-reader-text">' . $title . '</span>'; }
/** * Creates an icon by the given values. * * @param WPSEO_Rank $rank The ranking object. * @param string $title Optional. The title to show. Defaults to the rank label. * * @return string The HTML for a score icon. */ private function create_score_icon(WPSEO_Rank $rank, $title = '') { if (empty($title)) { $title = $rank->get_label(); } return '<div aria-hidden="true" title="' . esc_attr($title) . '" class="wpseo-score-icon ' . esc_attr($rank->get_css_class()) . '"></div><span class="screen-reader-text">' . $title . '</span>'; }
/** * Translates a decimal analysis score into a textual one. * * @static * * @param int $val The decimal score to translate. * @param bool $css_value Whether to return the i18n translated score or the CSS class value. * * @return string */ public static function translate_score($val, $css_value = true) { $seo_rank = WPSEO_Rank::from_numeric_score($val); if ($css_value) { return $seo_rank->get_css_class(); } return $seo_rank->get_label(); }