/** * Purges remote files * * @param array $files * @param array $results * @return boolean */ function purge($files, &$results) { if (empty($this->_config['apiid'])) { $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty API ID.'); return false; } if (empty($this->_config['apikey'])) { $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty API key.'); return false; } if ($this->_sha256('test') === false) { $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, "hash() or mhash() function doesn't exists."); return false; } if (!class_exists('IXR_Client')) { require_once ABSPATH . WPINC . '/class-IXR.php'; } if (function_exists('date_default_timezone_set')) { $timezone = date_default_timezone_get(); date_default_timezone_set(W3TC_CDN_MIRROR_NETDNA_TZ); } $date = date('c'); $auth_string = sprintf('%s:%s:purge', $date, $this->_config['apikey']); $auth_key = $this->_sha256($auth_string); $client = new IXR_Client(W3TC_CDN_MIRROR_NETDNA_URL); $client->timeout = 30; $results = array(); foreach ($files as $local_path => $remote_path) { $url = $this->format_url($remote_path); $client->query('cache.purge', $this->_config['apiid'], $auth_key, $date, $url); if (!$client->isError()) { $val = $client->getResponse(); if ($val) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_OK, 'OK'); } else { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, 'Unable to purge.'); } } else { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_HALT, sprintf('Unable to purge (%s).', $client->getErrorMessage())); } } if (function_exists('date_default_timezone_set')) { date_default_timezone_set($timezone); } return !$this->_is_error($results); }
function stats_get_blog_id($api_key) { $options = stats_get_options(); require_once ABSPATH . WPINC . '/class-IXR.php'; $client = new IXR_Client(STATS_XMLRPC_SERVER); extract(parse_url(get_option('home'))); $path = rtrim($path, '/'); if (empty($path)) { $path = '/'; } $client->query('wpStats.get_blog_id', $api_key, stats_get_blog()); if ($client->isError()) { if ($client->getErrorCode() == -32300) { $options['error'] = __('Your blog was unable to connect to WordPress.com. Please ask your host for help. (' . $client->getErrorMessage() . ')', 'stats'); } else { $options['error'] = $client->getErrorMessage(); } stats_set_options($options); return false; } else { $options['error'] = false; } $response = $client->getResponse(); $blog_id = isset($response['blog_id']) ? (int) $response['blog_id'] : false; $options['host'] = $host; $options['path'] = $path; $options['blog_id'] = $blog_id; stats_set_options($options); stats_set_api_key($api_key); return $blog_id; }