/** * Checks if the current user is a robot. * * @return bool */ private static function is_robot() { // Variant determiner for caches. if (function_exists('vary_cache_on_function')) { vary_cache_on_function('return isset( $_SERVER[\'HTTP_USER_AGENT\'] ) && preg_match( \'/bot|crawl|slurp|spider/i\', $_SERVER[\'HTTP_USER_AGENT\'] );'); } return isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT']); }
private static function is_specific_os($osUAs) { if (function_exists('vary_cache_on_function')) { vary_cache_on_function('return (bool)preg_match("/(' . implode("|", $osUAs) . ')/i", $_SERVER["HTTP_USER_AGENT"]);'); } return (bool) preg_match('/(' . implode('|', $osUAs) . ')/i', $_SERVER['HTTP_USER_AGENT']); }
private static function run_vary_cache_on_function($test) { if (function_exists('vary_cache_on_function')) { vary_cache_on_function($test); } $test_func = create_function('', $test); return $test_func(); }
/** * Generating function for batCache */ private function varyCache() { if (function_exists('vary_cache_on_function')) { $cacheFunction = ' if ( preg_match( "/tinypass\\/callback/i", $_SERVER["HTTP_HOST"] ) ) { return true; } $host = parse_url( $_SERVER["HTTP_HOST"] ); $host = isset( $host["host"] ) ? $host["host"] : false; if ( $host ) { $ref = false; if ( ! empty( $_POST["_wp_http_referer"] ) ) { $ref = wp_unslash( $_POST["_wp_http_referer"] ); } else if ( ! empty( $_GET["_wp_http_referer"] ) ) { $ref = wp_unslash( $_GET["_wp_http_referer"] ); } else if ( ! empty( $_SERVER["HTTP_REFERER"] ) ) { $ref = wp_unslash( $_SERVER["HTTP_REFERER"] ); } if ( $ref && $ref !== wp_unslash( $_SERVER["REQUEST_URI"] ) ) { $location = trim( $ref ); // browsers will assume http is your protocol, and will obey a redirect to a URL starting with // if ( substr( $location, 0, 2 ) == "//" ) { $location = "http:" . $location; } // In php 5 parse_url may fail if the URL query part contains http://, bug #38143 $test = ( $cut = strpos( $location, "?" ) ) ? substr( $location, 0, $cut ) : $location; $lp = parse_url( $test ); // Give up if malformed URL if ( false !== $lp ) { // Allow only http and https schemes. No data:, etc. if ( isset( $lp["scheme"] ) && ( "http" == $lp["scheme"] || "https" == $lp["scheme"] ) ) { // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field. if ( isset( $lp["scheme"] ) && isset( $lp["host"] ) ) { // if referred from outside if ( ! preg_match( "/{$host}/", $location ) ) { return true; } } } } } } if ( array_key_exists( "__tac", $_COOKIE ) ) { return $_COOKIE["__tac"]; } return false; '; vary_cache_on_function($cacheFunction); } }
/** * Returns if the current visitor has a feed service user agent * * The function is batcache aware so that it does not serve matched user agents from cache. * * @author lloydbudd * @return bool Returns true if the current visitor has a feed service user agent. */ function wpcom_vip_is_feedservice_ua() { if (function_exists('wpcom_feed_cache_headers')) { // Workaround so that no feed request served from nginx wpcom-feed-cache // If you are checking you must already know is a feed // and don't want any requests cached // ASSUMPTION: you've already confirmed is_feed() b/f calling // wpcom_vip_is_feedservice_ua header("X-Accel-Expires: 0"); } if (function_exists('vary_cache_on_function')) { // batcache variant vary_cache_on_function('return (bool) preg_match("/feedburner|feedvalidator|MediafedMetrics/i", $_SERVER["HTTP_USER_AGENT"]);'); } return (bool) preg_match("/feedburner|feedvalidator|MediafedMetrics/i", $_SERVER["HTTP_USER_AGENT"]); }
/** * run_vary_cache_func - environment-neutral interface to batcache's "vary_cache_on_function" * * Establishes whether or not to use a new cache variant by * running an arbitrary function body provided via $test argument. * $test is run both locally and in the batcache. * * @access private * @param string [ $test ] function body used to determine user's * eligibility. Must be a string in order to work with * WP's batcache 'vary_cache_on_function' feature. Must * include one or more references to "$_" variables. * @return mixed (bool | string | int) */ private static function run_vary_cache_func($test) { if (preg_match('/include|require|echo|print|dump|export|open|sock|unlink|`|eval/i', $test)) { trigger_error('Illegal word in cache variant function determiner.', E_USER_ERROR); } if (!preg_match('/\\$_/', $test)) { trigger_error('Cache variant function should refer to at least one $_ variable.', E_USER_ERROR); } if (function_exists('vary_cache_on_function')) { vary_cache_on_function($test); } $test_func = create_function('', $test); return $test_func(); }