本文整理汇总了PHP中Util_Environment类的典型用法代码示例。如果您正苦于以下问题:PHP Util_Environment类的具体用法?PHP Util_Environment怎么用?PHP Util_Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Util_Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fix_in_wpadmin
/**
* Fixes environment
*
* @param Config $config
* @throws Util_Environment_Exceptions
*/
function fix_in_wpadmin($config, $force_all_checks = false)
{
$exs = new Util_Environment_Exceptions();
$fix_on_event = false;
if (Util_Environment::is_wpmu() && Util_Environment::blog_id() != 0) {
if (get_transient('w3tc_config_changes') != ($md5_string = $config->get_md5())) {
$fix_on_event = true;
set_transient('w3tc_config_changes', $md5_string, 3600);
}
}
// call plugin-related handlers
foreach ($this->get_handlers($config) as $h) {
try {
$h->fix_on_wpadmin_request($config, $force_all_checks);
if ($fix_on_event) {
$this->fix_on_event($config, 'admin_request');
}
} catch (Util_Environment_Exceptions $ex) {
$exs->push($ex);
}
}
try {
do_action('w3tc_environment_fix_on_wpadmin_request', $config, $force_all_checks);
} catch (Util_Environment_Exceptions $ex) {
$exs->push($ex);
}
if (count($exs->exceptions()) > 0) {
throw $exs;
}
}
示例2: instance
/**
* Returns object instance. Called by WP engine
*
* @return DbCache_Wpdb
*/
static function instance()
{
static $instance = null;
if (is_null($instance)) {
$processors = array();
$call_default_constructor = true;
// no caching during activation
$is_installing = defined('WP_INSTALLING') && WP_INSTALLING;
$config = Dispatcher::config();
if (!$is_installing && $config->get_boolean('dbcache.enabled')) {
$processors[] = new DbCache_WpdbInjection_QueryCaching();
}
if (Util_Environment::is_dbcluster()) {
$processors[] = new Enterprise_Dbcache_WpdbInjection_Cluster();
}
$processors[] = new DbCache_WpdbInjection();
$class = __CLASS__;
$o = new $class($processors);
$next_injection = new _CallUnderlying($o);
foreach ($processors as $processor) {
$processor->initialize_injection($o, $next_injection);
}
// initialize after processors configured
$o->initialize();
$instance = $o;
}
return $instance;
}
示例3: view
/**
* General tab
*
* @return void
*/
function view()
{
global $current_user;
$config_master = $this->_config_master;
/**
*
*
* @var $modules W3_ModuleStatus
*/
$modules = Dispatcher::component('ModuleStatus');
$pgcache_enabled = $modules->is_enabled('pgcache');
$dbcache_enabled = $modules->is_enabled('dbcache');
$objectcache_enabled = $modules->is_enabled('objectcache');
$browsercache_enabled = $modules->is_enabled('browsercache');
$minify_enabled = $modules->is_enabled('minify');
$cdn_enabled = $modules->is_enabled('cdn');
$varnish_enabled = $modules->is_enabled('varnish');
$enabled = $modules->plugin_is_enabled();
$enabled_checkbox = $modules->all_modules_enabled();
$check_rules = Util_Rule::can_check_rules();
$disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && Util_Environment::is_wpmu() && $config_master->get_string('pgcache.engine') != 'file_generic');
$can_empty_file = $modules->can_empty_file();
$can_empty_varnish = $modules->can_empty_varnish();
$cdn_mirror_purge = Cdn_Util::can_purge_all($modules->get_module_engine('cdn'));
$file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs');
$file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking');
$licensing_visible = (!Util_Environment::is_wpmu() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
$custom_areas = apply_filters("w3tc_settings_general_anchors", array());
include W3TC_INC_DIR . '/options/general.php';
}
示例4: log_filename
/**
* Return full path to log file for module
* Path used in priority
* 1) W3TC_DEBUG_DIR
* 2) WP_DEBUG_LOG
* 3) W3TC_CACHE_DIR
*
* @param unknown $module
* @param null $blog_id
* @return string
*/
public static function log_filename($module, $blog_id = null)
{
if (is_null($blog_id)) {
$blog_id = Util_Environment::blog_id();
}
$postfix = sprintf('%06d', $blog_id);
if (defined('W3TC_BLOG_LEVELS')) {
for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++) {
$postfix = substr($postfix, strlen($postfix) - 1 - $n, 1) . '/' . $postfix;
}
}
$from_dir = W3TC_CACHE_DIR;
if (defined('W3TC_DEBUG_DIR') && W3TC_DEBUG_DIR) {
$dir_path = W3TC_DEBUG_DIR;
if (!is_dir(W3TC_DEBUG_DIR)) {
$from_dir = dirname(W3TC_DEBUG_DIR);
}
} else {
$dir_path = Util_Environment::cache_dir('log');
}
$filename = $dir_path . '/' . $postfix . '/' . $module . '.log';
if (!is_dir(dirname($filename))) {
Util_File::mkdir_from(dirname($filename), $from_dir);
}
return $filename;
}
示例5: w3tc_config_save
public function w3tc_config_save($config)
{
// frontend activity
$engine = $config->get_string(array('fragmentcache', 'engine'));
$is_frontend_active = !empty($engine) && Util_Environment::is_w3tc_pro($config);
$config->set_extension_active_frontend('fragmentcache', $is_frontend_active);
}
示例6: get_current_blog_data
/**
* Returns blog_id by home url
* If database not initialized yet - returns 0
*
* @return integer
*/
public static function get_current_blog_data()
{
$host = Util_Environment::host();
// subdomain
if (Util_Environment::is_wpmu_subdomain()) {
$blog_data = Util_WpmuBlogmap::try_get_current_blog_data($host);
if (is_null($blog_data)) {
$GLOBALS['w3tc_blogmap_register_new_item'] = $host;
}
return $blog_data;
} else {
// try subdir blog
$url = $host . $_SERVER['REQUEST_URI'];
$pos = strpos($url, '?');
if ($pos !== false) {
$url = substr($url, 0, $pos);
}
$url = rtrim($url, '/');
$start_url = $url;
for (;;) {
$blog_data = Util_WpmuBlogmap::try_get_current_blog_data($url);
if (!is_null($blog_data)) {
return $blog_data;
}
$pos = strrpos($url, '/');
if ($pos === false) {
break;
}
$url = rtrim(substr($url, 0, $pos), '/');
}
$GLOBALS['w3tc_blogmap_register_new_item'] = $start_url;
return null;
}
}
示例7: run
function run()
{
add_filter('w3tc_config_default_values', array($this, 'w3tc_config_default_values'));
add_action('w3tc_register_fragment_groups', array($this, 'register_groups'));
$this->_config = Dispatcher::config();
if (Util_Environment::is_w3tc_pro($this->_config)) {
if (!is_admin()) {
/**
* Register the caching of content to specific hooks
*/
foreach (array('genesis_header', 'genesis_footer', 'genesis_sidebar', 'genesis_loop', 'wp_head', 'wp_footer', 'genesis_comments', 'genesis_pings') as $hook) {
add_action($hook, array($this, 'cache_genesis_start'), -999999999);
add_action($hook, array($this, 'cache_genesis_end'), 999999999);
}
foreach (array('genesis_do_subnav', 'genesis_do_nav') as $filter) {
add_filter($filter, array($this, 'cache_genesis_filter_start'), -999999999);
add_filter($filter, array($this, 'cache_genesis_filter_end'), 999999999);
}
}
/**
* Since posts pages etc are cached individually need to be able to flush just those and not all fragment
*/
add_action('clean_post_cache', array($this, 'flush_post_fragment'));
add_action('clean_post_cache', array($this, 'flush_terms_fragment'), 0, 0);
$this->_request_uri = $_SERVER['REQUEST_URI'];
}
}
示例8: process
/**
* Do logic
*/
function process()
{
/**
* Skip some pages
*/
switch (true) {
case defined('DOING_AJAX'):
case defined('DOING_CRON'):
case defined('APP_REQUEST'):
case defined('XMLRPC_REQUEST'):
case defined('WP_ADMIN'):
case defined('SHORTINIT') && SHORTINIT:
return;
}
/**
* Handle mobile or referrer redirects
*/
if ($this->_mobile || $this->_referrer) {
$mobile_redirect = $referrer_redirect = '';
if ($this->_mobile) {
$mobile_redirect = $this->_mobile->get_redirect();
}
if ($this->_referrer) {
$referrer_redirect = $this->_referrer->get_redirect();
}
$redirect = $mobile_redirect ? $mobile_redirect : $referrer_redirect;
if ($redirect) {
Util_Environment::redirect($redirect);
exit;
}
}
}
示例9: admin_head
/**
* Print JS required by the support nag.
*/
function admin_head()
{
$state = Dispatcher::config_state_master();
// support us
$support_reminder = $state->get_integer('common.support_us_invitations') < 3 && $state->get_integer('common.install') < time() - W3TC_SUPPORT_US_TIMEOUT && $state->get_integer('common.next_support_us_invitation') < time() && $this->_config->get_string('common.support') == '' && !$this->_config->get_boolean('common.tweeted');
if ($support_reminder) {
$state->set('common.next_support_us_invitation', time() + W3TC_SUPPORT_US_TIMEOUT);
$state->set('common.support_us_invitations', $state->get_integer('common.support_us_invitations') + 1);
$state->save();
do_action('w3tc_message_action_generic_support_us');
}
// edge mode
$edge_reminder = !$support_reminder && !Util_Environment::is_w3tc_edge($this->_config) && $state->get_integer('common.edge_invitations') < 3 && $state->get_integer('common.install') < time() - W3TC_EDGE_TIMEOUT && $state->get_integer('common.next_edge_invitation') < time();
if ($edge_reminder) {
if ($state->get_integer('common.edge_invitations') > 1) {
$next = time() + 30 * 24 * 60 * 60;
} else {
$next = time() + W3TC_EDGE_TIMEOUT;
}
$state->set('common.next_edge_invitation', $next);
$state->set('common.edge_invitations', $state->get_integer('common.edge_invitations') + 1);
$state->save();
do_action('w3tc_message_action_generic_edge');
}
}
示例10: __construct
/**
* Constructor
*
* @param array $config
*/
function __construct($config = array())
{
parent::__construct($config);
if (isset($config['cache_dir'])) {
$this->_cache_dir = trim($config['cache_dir']);
} else {
$this->_cache_dir = Util_Environment::cache_blog_dir($config['section'], $config['blog_id']);
}
$this->_exclude = isset($config['exclude']) ? (array) $config['exclude'] : array();
$this->_flush_timelimit = isset($config['flush_timelimit']) ? (int) $config['flush_timelimit'] : 180;
$this->_locking = isset($config['locking']) ? (bool) $config['locking'] : false;
if (isset($config['flush_dir'])) {
$this->_flush_dir = $config['flush_dir'];
} else {
if ($config['blog_id'] <= 0 && !isset($config['cache_dir'])) {
// clear whole section if we operate on master cache
// and in a mode when cache_dir not strictly specified
$this->_flush_dir = Util_Environment::cache_dir($config['section']);
} else {
$this->_flush_dir = $this->_cache_dir;
}
}
if (isset($config['use_wp_hash']) && $config['use_wp_hash']) {
$this->_use_wp_hash = true;
}
}
示例11: admin_init
public function admin_init()
{
$config = Dispatcher::config();
$groups = $config->get_array('mobile.rgroups');
if (Util_Environment::is_w3tc_edge($config) && isset($groups['google']) && sizeof($groups['google']['agents']) == 1 && $groups['google']['agents'][0] == 'googlebot') {
w3tc_delete_user_agent_group('google');
}
}
示例12: get_suggested_home_ip
public static function get_suggested_home_ip()
{
$ip = gethostbyname(Util_Environment::home_url_host());
// check if it resolves to local IP, means host cant know its real IP
if (substr($ip, 0, 4) == '127.' || substr($ip, 0, 3) == '10.' || substr($ip, 0, 8) == '192.168.') {
return '';
}
return $ip;
}
示例13: _request
/**
* Make API request
*
* @param string $url
* @return string
*/
function _request($url)
{
$request_url = Util_Environment::url_format(W3TC_PAGESPEED_API_URL, array('url' => $url, 'key' => $this->key));
$response = Util_Http::get($request_url, array('timeout' => 120));
if (!is_wp_error($response) && $response['response']['code'] == 200) {
return $response['body'];
}
return false;
}
示例14: instance
/**
* Returns cache engine instance
*
* @param string $engine
* @param array $config
* @return W3_Cache_Base
*/
static function instance($engine, $config = array())
{
static $instances = array();
// common configuration data
if (!isset($config['blog_id'])) {
$config['blog_id'] = Util_Environment::blog_id();
}
$instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
if (!isset($instances[$instance_key])) {
switch ($engine) {
case 'apc':
if (function_exists('apcu_store')) {
$instances[$instance_key] = new Cache_Apcu($config);
} else {
if (function_exists('apc_store')) {
$instances[$instance_key] = new Cache_Apc($config);
}
}
break;
case 'eaccelerator':
$instances[$instance_key] = new Cache_Eaccelerator($config);
break;
case 'file':
$instances[$instance_key] = new Cache_File($config);
break;
case 'file_generic':
$instances[$instance_key] = new Cache_File_Generic($config);
break;
case 'memcached':
if (class_exists('\\Memcached')) {
$instances[$instance_key] = new Cache_Memcached($config);
} else {
if (class_exists('\\Memcache')) {
$instances[$instance_key] = new Cache_Memcache($config);
}
}
break;
case 'redis':
$instances[$instance_key] = new Cache_Redis($config);
break;
case 'wincache':
$instances[$instance_key] = new Cache_Wincache($config);
break;
case 'xcache':
$instances[$instance_key] = new Cache_Xcache($config);
break;
default:
trigger_error('Incorrect cache engine ' . $engine, E_USER_WARNING);
$instances[$instance_key] = new Cache_Base($config);
break;
}
if (!isset($instances[$instance_key]) || !$instances[$instance_key]->available()) {
$instances[$instance_key] = new Cache_Base($config);
}
}
return $instances[$instance_key];
}
示例15: _get_origin
/**
* Returns origin
*
* @return string
*/
function _get_origin()
{
if ($this->type == W3TC_CDN_CF_TYPE_S3) {
$origin = sprintf('%s.s3.amazonaws.com', $this->_config['bucket']);
} else {
$origin = Util_Environment::host_port();
}
return $origin;
}