diff options
author | Theo Chatzimichos <tampakrap@gentoo.org> | 2013-10-03 21:53:38 +0200 |
---|---|---|
committer | Theo Chatzimichos <tampakrap@gentoo.org> | 2013-10-03 21:53:38 +0200 |
commit | 61f7269ffabd11b7de56507c69191be42d7cfa60 (patch) | |
tree | 2ad81bec8d0c124019b23c841d80882c303801bc /plugins/jetpack/class.jetpack-user-agent.php | |
parent | forgot to include new files of jetpack (diff) | |
download | blogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.tar.gz blogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.tar.bz2 blogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.zip |
update jetpack
Diffstat (limited to 'plugins/jetpack/class.jetpack-user-agent.php')
-rw-r--r-- | plugins/jetpack/class.jetpack-user-agent.php | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/plugins/jetpack/class.jetpack-user-agent.php b/plugins/jetpack/class.jetpack-user-agent.php index 4c63a65a..d3324051 100644 --- a/plugins/jetpack/class.jetpack-user-agent.php +++ b/plugins/jetpack/class.jetpack-user-agent.php @@ -1326,38 +1326,51 @@ class Jetpack_User_Agent_Info { return false; } + /** + * Was the current request made by a known bot? + * + * @return boolean + */ static function is_bot() { - static $is_bot = false; - static $first_run = true; + static $is_bot = null; - if ( $first_run ) { - $first_run = false; + if ( is_null( $is_bot ) ) { + $is_bot = Jetpack_User_Agent_Info::is_bot_user_agent( $_SERVER['HTTP_USER_AGENT'] ); + } - /* - $bot_ips = array( ); + return $is_bot; + } - foreach ( $bot_ips as $bot_ip ) { - if ( $_SERVER['REMOTE_ADDR'] == $bot_ip ) - $is_bot = true; - } - */ + /** + * Is the given user-agent a known bot? + * If you want an is_bot check for the current request's UA, use is_bot() instead of passing a user-agent to this method. + * + * @param $ua (string) A user-agent string + * @return boolean + */ + static function is_bot_user_agent( $ua = null ) { - $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); + if ( empty( $ua ) ) + return false; - $bot_agents = array( - 'alexa', 'altavista', 'ask jeeves', 'attentio', 'baiduspider', 'bingbot', 'chtml generic', 'crawler', 'fastmobilecrawl', - 'feedfetcher-google', 'firefly', 'froogle', 'gigabot', 'googlebot', 'googlebot-mobile', 'heritrix', 'ia_archiver', 'irlbot', - 'infoseek', 'jumpbot', 'lycos', 'mediapartners', 'mediobot', 'motionbot', 'msnbot', 'mshots', 'openbot', - 'pythumbnail', 'scooter', 'slurp', 'snapbot', 'spider', 'surphace scout', 'taptubot', 'technoratisnoop', - 'teoma', 'twiceler', 'yahooseeker', 'yahooysmcm', 'yammybot', - ); - - foreach ( $bot_agents as $bot_agent ) { - if ( false !== strpos( $agent, $bot_agent ) ) - $is_bot = true; + $bot_agents = array( + 'alexa', 'altavista', 'ask jeeves', 'attentio', 'baiduspider', 'bingbot', 'chtml generic', 'crawler', 'fastmobilecrawl', + 'feedfetcher-google', 'firefly', 'froogle', 'gigabot', 'googlebot', 'googlebot-mobile', 'heritrix', 'ia_archiver', 'irlbot', + 'infoseek', 'jumpbot', 'lycos', 'mediapartners', 'mediobot', 'motionbot', 'msnbot', 'mshots', 'openbot', + 'pss-webkit-request', // See http://systemsrequests.wordpress.com/2013/07/30/log-request-to-help-us-with-this-issue + 'pythumbnail', 'scooter', 'slurp', 'snapbot', 'spider', 'taptubot', 'technoratisnoop', + 'teoma', 'twiceler', 'yahooseeker', 'yahooysmcm', 'yammybot', + ); + + foreach ( $bot_agents as $bot_agent ) { + if ( false !== stripos( $ua, $bot_agent ) ) { + return true; } } - return $is_bot; + return false; } + + + } |