当前位置: 首页>>代码示例>>PHP>>正文


PHP WPSEO_Utils::calc方法代码示例

本文整理汇总了PHP中WPSEO_Utils::calc方法的典型用法代码示例。如果您正苦于以下问题:PHP WPSEO_Utils::calc方法的具体用法?PHP WPSEO_Utils::calc怎么用?PHP WPSEO_Utils::calc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WPSEO_Utils的用法示例。


在下文中一共展示了WPSEO_Utils::calc方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wpseo_calc

/**
 * Do simple reliable math calculations without the risk of wrong results
 * @see http://floating-point-gui.de/
 * @see the big red warning on http://php.net/language.types.float.php
 *
 * @deprecated 1.6.1
 * @deprecated use WPSEO_Utils::calc()
 * @see WPSEO_Utils::calc()
 *
 * In the rare case that the bcmath extension would not be loaded, it will return the normal calculation results
 *
 * @since 1.5.0
 *
 * @param	mixed  $number1   Scalar (string/int/float/bool)
 * @param	string $action    Calculation action to execute.
 * @param	mixed  $number2   Scalar (string/int/float/bool)
 * @param	bool   $round     Whether or not to round the result. Defaults to false.
 * @param	int    $decimals  Decimals for rounding operation. Defaults to 0.
 * @param	int    $precision Calculation precision. Defaults to 10.
 * @return	mixed				Calculation Result or false if either or the numbers isn't scalar or
 *								an invalid operation was passed
 */
function wpseo_calc($number1, $action, $number2, $round = false, $decimals = 0, $precision = 10)
{
    _deprecated_function(__FUNCTION__, 'WPSEO 1.6.1', 'WPSEO_Utils::calc()');
    return WPSEO_Utils::calc($number1, $action, $number2, $round, $decimals, $precision);
}
开发者ID:presteege,项目名称:presteege.fr,代码行数:27,代码来源:wpseo-functions.php

示例2: wpseo_admin_bar_menu

/**
 * 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 wpseo_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=wpseo_dashboard');
    if ((is_singular() || is_admin() && in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'), true)) && isset($post) && is_object($post) && apply_filters('wpseo_use_page_analysis', true) === true) {
        $focuskw = WPSEO_Meta::get_value('focuskw', $post->ID);
        $perc_score = WPSEO_Meta::get_value('linkdex', $post->ID);
        $calc_score = WPSEO_Utils::calc($perc_score, '/', 10, true);
        $txtscore = WPSEO_Utils::translate_score($calc_score);
        $title = WPSEO_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 .= '#wpseo_linkdex';
        }
    }
    $wp_admin_bar->add_menu(array('id' => 'wpseo-menu', 'title' => __('SEO', 'wordpress-seo') . $score, 'href' => $seo_url));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __('Keyword Research', 'wordpress-seo'), '#'));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-adwordsexternal', 'title' => __('AdWords External', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank')));
    if (!is_admin()) {
        $url = WPSEO_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', 'wordpress-seo'), '#'));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-inlinks-ose', 'title' => __('Check Inlinks (OSE)', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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', 'wordpress-seo'), '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('wpseo_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', 'wordpress-seo')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-general', 'title' => __('General', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_dashboard')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-titles', 'title' => __('Titles &amp; Metas', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_titles')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-social', 'title' => __('Social', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_social')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-xml', 'title' => __('XML Sitemaps', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_xml')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-wpseo_advanced', 'title' => __('Advanced', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_advanced')));
    }
}
开发者ID:naa986,项目名称:wp-seo,代码行数:63,代码来源:wpseo-non-ajax-functions.php

示例3: score_body

 /**
  * Score the body for length and keyword appearance.
  *
  * @param array  $job     The array holding the keywords.
  * @param array  $results The results array.
  * @param string $body    The body.
  * @param string $firstp  The first paragraph.
  */
 function score_body($job, &$results, $body, $firstp)
 {
     $lengthScore = array('good' => 300, 'ok' => 250, 'poor' => 200, 'bad' => 100);
     $lengthScore = apply_filters('wpseo_body_length_score', $lengthScore, $job);
     $scoreBodyGoodLength = __('There are %d words contained in the body copy, this is more than the %d word recommended minimum.', 'wordpress-seo');
     $scoreBodyPoorLength = __('There are %d words contained in the body copy, this is below the %d word recommended minimum. Add more useful content on this topic for readers.', 'wordpress-seo');
     $scoreBodyOKLength = __('There are %d words contained in the body copy, this is slightly below the %d word recommended minimum, add a bit more copy.', 'wordpress-seo');
     $scoreBodyBadLength = __('There are %d words contained in the body copy. This is far too low and should be increased.', 'wordpress-seo');
     $scoreKeywordDensityLow = __('The keyword density is %s%%, which is a bit low, the keyword was found %s times.', 'wordpress-seo');
     $scoreKeywordDensityHigh = __('The keyword density is %s%%, which is over the advised 4.5%% maximum, the keyword was found %s times.', 'wordpress-seo');
     $scoreKeywordDensityGood = __('The keyword density is %s%%, which is great, the keyword was found %s times.', 'wordpress-seo');
     $scoreFirstParagraphLow = __('The keyword doesn\'t appear in the first paragraph of the copy, make sure the topic is clear immediately.', 'wordpress-seo');
     $scoreFirstParagraphHigh = __('The keyword appears in the first paragraph of the copy.', 'wordpress-seo');
     $fleschurl = '<a href="http://en.wikipedia.org/wiki/Flesch-Kincaid_readability_test#Flesch_Reading_Ease">' . __('Flesch Reading Ease', 'wordpress-seo') . '</a>';
     $scoreFlesch = __('The copy scores %s in the %s test, which is considered %s to read. %s', 'wordpress-seo');
     // Replace images with their alt tags, then strip all tags.
     $body = preg_replace('`<img(?:[^>]+)?alt="([^"]+)"(?:[^>]+)>`', '$1', $body);
     $body = strip_tags($body);
     // Copy length check.
     $wordCount = $this->statistics()->word_count($body);
     if ($wordCount < $lengthScore['bad']) {
         $this->save_score_result($results, -20, sprintf($scoreBodyBadLength, $wordCount, $lengthScore['good']), 'body_length', $wordCount);
     } elseif ($wordCount < $lengthScore['poor']) {
         $this->save_score_result($results, -10, sprintf($scoreBodyPoorLength, $wordCount, $lengthScore['good']), 'body_length', $wordCount);
     } elseif ($wordCount < $lengthScore['ok']) {
         $this->save_score_result($results, 5, sprintf($scoreBodyPoorLength, $wordCount, $lengthScore['good']), 'body_length', $wordCount);
     } elseif ($wordCount < $lengthScore['good']) {
         $this->save_score_result($results, 7, sprintf($scoreBodyOKLength, $wordCount, $lengthScore['good']), 'body_length', $wordCount);
     } else {
         $this->save_score_result($results, 9, sprintf($scoreBodyGoodLength, $wordCount, $lengthScore['good']), 'body_length', $wordCount);
     }
     $body = $this->strtolower_utf8($body);
     $job['keyword'] = $this->strtolower_utf8($job['keyword']);
     $keywordWordCount = $this->statistics()->word_count($job['keyword']);
     if ($keywordWordCount > 10) {
         $this->save_score_result($results, 0, __('Your keyphrase is over 10 words, a keyphrase should be shorter and there can be only one keyphrase.', 'wordpress-seo'), 'focus_keyword_length');
     } else {
         // Keyword Density check.
         $keywordDensity = 0;
         if ($wordCount > 100) {
             $keywordCount = preg_match_all('`\\b' . preg_quote($job['keyword'], '`') . '\\b`miu', $body, $matches);
             if ($keywordCount > 0 && $keywordWordCount > 0 && $wordCount > $keywordCount) {
                 $keywordDensity = WPSEO_Utils::calc(WPSEO_Utils::calc($keywordCount, '/', WPSEO_Utils::calc($wordCount, '-', WPSEO_Utils::calc(WPSEO_Utils::calc($keywordWordCount, '-', 1), '*', $keywordCount))), '*', 100, true, 2);
             }
             if ($keywordDensity < 1) {
                 $this->save_score_result($results, 4, sprintf($scoreKeywordDensityLow, $keywordDensity, $keywordCount), 'keyword_density');
             } elseif ($keywordDensity > 4.5) {
                 $this->save_score_result($results, -50, sprintf($scoreKeywordDensityHigh, $keywordDensity, $keywordCount), 'keyword_density');
             } else {
                 $this->save_score_result($results, 9, sprintf($scoreKeywordDensityGood, $keywordDensity, $keywordCount), 'keyword_density');
             }
         }
     }
     $firstp = $this->strtolower_utf8($firstp);
     // First Paragraph Test.
     // Check without /u modifier as well as /u might break with non UTF-8 chars.
     if (preg_match('`\\b' . preg_quote($job['keyword'], '`') . '\\b`miu', $firstp) || preg_match('`\\b' . preg_quote($job['keyword'], '`') . '\\b`mi', $firstp) || preg_match('`\\b' . preg_quote($job['keyword_folded'], '`') . '\\b`miu', $firstp)) {
         $this->save_score_result($results, 9, $scoreFirstParagraphHigh, 'keyword_first_paragraph');
     } else {
         $this->save_score_result($results, 3, $scoreFirstParagraphLow, 'keyword_first_paragraph');
     }
     $lang = get_bloginfo('language');
     if (substr($lang, 0, 2) == 'en' && $wordCount > 100) {
         // Flesch Reading Ease check.
         $flesch = $this->statistics()->flesch_kincaid_reading_ease($body);
         $note = '';
         $level = '';
         $score = 1;
         if ($flesch >= 90) {
             $level = __('very easy', 'wordpress-seo');
             $score = 9;
         } elseif ($flesch >= 80) {
             $level = __('easy', 'wordpress-seo');
             $score = 9;
         } elseif ($flesch >= 70) {
             $level = __('fairly easy', 'wordpress-seo');
             $score = 8;
         } elseif ($flesch >= 60) {
             $level = __('OK', 'wordpress-seo');
             $score = 7;
         } elseif ($flesch >= 50) {
             $level = __('fairly difficult', 'wordpress-seo');
             $note = __('Try to make shorter sentences to improve readability.', 'wordpress-seo');
             $score = 6;
         } elseif ($flesch >= 30) {
             $level = __('difficult', 'wordpress-seo');
             $note = __('Try to make shorter sentences, using less difficult words to improve readability.', 'wordpress-seo');
             $score = 5;
         } elseif ($flesch >= 0) {
             $level = __('very difficult', 'wordpress-seo');
             $note = __('Try to make shorter sentences, using less difficult words to improve readability.', 'wordpress-seo');
             $score = 4;
//.........这里部分代码省略.........
开发者ID:Nisha318,项目名称:p3edtech,代码行数:101,代码来源:class-metabox.php

示例4: sort_notifications

 /**
  * Sort on type then priority
  *
  * @param Yoast_Notification $a Compare with B.
  * @param Yoast_Notification $b Compare with A.
  *
  * @return int 1, 0 or -1 for sorting offset.
  */
 private function sort_notifications(Yoast_Notification $a, Yoast_Notification $b)
 {
     $a_type = $a->get_type();
     $b_type = $b->get_type();
     if ($a_type === $b_type) {
         return WPSEO_Utils::calc($b->get_priority(), 'compare', $a->get_priority());
     }
     if ('error' === $a_type) {
         return -1;
     }
     if ('error' === $b_type) {
         return 1;
     }
     return 0;
 }
开发者ID:Garth619,项目名称:Femi9,代码行数:23,代码来源:class-yoast-notification-center.php

示例5: wpseo_calc

 /**
  * wpseo_calc has been deprecated in newer versions of wordpress-seo
  *
  * @param int    $number1
  * @param string $action
  * @param int    $number2
  * @param bool   $round
  *
  * @return mixed
  */
 protected function wpseo_calc($number1, $action, $number2, $round = false)
 {
     if (method_exists('WPSEO_Utils', 'calc')) {
         return WPSEO_Utils::calc($number1, $action, $number2, $round);
     }
     return wpseo_calc($number1, $action, $number2, $round);
 }
开发者ID:Infernosaint,项目名称:WPSetupTest2,代码行数:17,代码来源:class-ga-frontend-custom-dimensions.php

示例6: normalize_score

 /**
  * Normalizes score according to min & max allowed. If score larger
  * than max, max is returned. If score less than min, min is returned.
  * Also rounds result to specified precision.
  * Thanks to github.com/lvil.
  *
  * @param    int|float $score Initial score.
  * @param    int       $min   Minimum score allowed.
  * @param    int       $max   Maximum score allowed.
  * @param    int       $dps   Round to # decimals.
  *
  * @return    int|float
  */
 public function normalize_score($score, $min, $max, $dps = 1)
 {
     $score = WPSEO_Utils::calc($score, '+', 0, true, $dps);
     // Round.
     if (!$this->normalize) {
         return $score;
     }
     if ($score > $max) {
         $score = $max;
     } elseif ($score < $min) {
         $score = $min;
     }
     return $score;
 }
开发者ID:flasomm,项目名称:Montkailash,代码行数:27,代码来源:class-yoast-textstatistics.php


注:本文中的WPSEO_Utils::calc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。