%s could not be created, please run following command:
chmod 777 %s
then re-activate plugin.', $path, dirname($path));
if ($die) {
die($error);
}
return $error;
}
/**
* Returns current microtime
*
* @return float
*/
function w3_microtime()
{
list ($usec, $sec) = explode(" ", microtime());
return ((float) $usec + (float) $sec);
}
/**
* Check if URL is valid
*
* @param string $url
* @return boolean
*/
function w3_is_url($url)
{
return preg_match('~^https?://~', $url);
}
/**
* Decodes gzip-encoded string
*
* @param string $data
* @return string
*/
function w3_gzdecode($data)
{
$flags = ord(substr($data, 3, 1));
$headerlen = 10;
$extralen = 0;
if ($flags & 4) {
$extralen = unpack('v', substr($data, 10, 2));
$extralen = $extralen[1];
$headerlen += 2 + $extralen;
}
if ($flags & 8) {
$headerlen = strpos($data, chr(0), $headerlen) + 1;
}
if ($flags & 16) {
$headerlen = strpos($data, chr(0), $headerlen) + 1;
}
if ($flags & 2) {
$headerlen += 2;
}
$unpacked = gzinflate(substr($data, $headerlen));
if ($unpacked === FALSE) {
$unpacked = $data;
}
return $unpacked;
}
/**
* Recursive creates directory
*
* @param string $path
* @param integer $mask
* @param string
* @return boolean
*/
function w3_mkdir($path, $mask = 0755, $curr_path = '')
{
$path = preg_replace('~[\\\/]+~', '/', $path);
$path = trim($path, '/');
$dirs = explode('/', $path);
foreach ($dirs as $dir) {
if (empty($dir)) {
return false;
}
$curr_path .= ($curr_path == '' ? '' : '/') . $dir;
if (! is_dir($curr_path)) {
if (@mkdir($curr_path, $mask)) {
@chmod($curr_path, $mask);
} else {
return false;
}
}
}
return true;
}
/**
* Recursive remove dir
*
* @param $path
* @return boolean
*/
function w3_rmdir($path, $empty = false)
{
$dir = @opendir($path);
if ($dir) {
while (($entry = readdir($dir))) {
if ($entry != '.' && $entry != '..') {
$full_path = $path . '/' . $entry;
if (is_dir($full_path)) {
$result = @w3_rmdir($full_path);
} else {
$result = @unlink($full_path);
}
if (! $result) {
@closedir($dir);
return false;
}
}
}
@closedir($dir);
return ($empty ? true : @rmdir($path));
}
return false;
}
/**
* Recursive empty dir
*
* @param $path
* @return boolean
*/
function w3_emptydir($path)
{
return w3_rmdir($path, true);
}
/**
* Check if content is HTML or XML
*
* @param string $content
* @return boolean
*/
function w3_is_xml($content)
{
return (stristr($content, ' $value) {
$count--;
$query_string .= urlencode($param) . (! empty($value) ? '=' . urlencode($value) : '') . ($count ? '&' : '');
}
$url .= (strpos($url, '?') === false ? '?' : '&') . $query_string;
}
$url .= (! empty($parse_url['fragment']) ? '#' . $parse_url['fragment'] : '');
@header('Location: ' . $url);
exit();
}
/**
* Returns caching engine name
* @param $engine
* @return string
*/
function w3_get_engine_name($engine)
{
switch ($engine) {
case 'memcached':
$engine_name = 'memcached';
break;
case 'apc':
$engine_name = 'apc';
break;
case 'file':
$engine_name = 'disk';
break;
default:
$engine_name = 'N/A';
break;
}
return $engine_name;
}
/**
* Converts value to boolean
* @param mixed $value
* @return boolean
*/
function w3_to_boolean($value)
{
if (is_string($value)) {
switch (strtolower($value)) {
case '+':
case '1':
case 'y':
case 'on':
case 'yes':
case 'true':
case 'enabled':
return true;
case '-':
case '0':
case 'n':
case 'no':
case 'off':
case 'false':
case 'disabled':
return false;
}
}
return (boolean) $value;
}
/**
* Download url via GET
* @param $url
* @return string
*/
function w3_url_get($url)
{
if (w3_to_boolean(ini_get('allow_url_fopen'))) {
ini_set('user_agent', W3TC_POWERED_BY);
return @file_get_contents($url);
} elseif (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, W3TC_POWERED_BY);
$contents = curl_exec($ch);
curl_close($ch);
return $contents;
} else {
$parse_url = @parse_url($url);
if (isset($parse_url['host'])) {
$host = $parse_url['host'];
$port = (isset($parse_url['port']) ? (int) $parse_url['path'] : 80);
$path = (isset($parse_url['path']) ? trim($parse_url['path']) : '/');
$query = (isset($parse_url['query']) ? trim($parse_url['query']) : '');
$request_uri = $path . ($query != '' ? '?' . $query : '');
$request = sprintf("GET %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\nUser-Agent: %s\r\n\r\n", $request_uri, $host, W3TC_POWERED_BY);
if (($fp = @fsockopen($host, $port))) {
$response = '';
@fputs($fp, $request);
while (! @feof($fp)) {
$response .= @fgets($fp, 4096);
}
@fclose($fp);
list (, $contents) = explode("\r\n\r\n", $response, 2);
return $contents;
}
}
}
}
/**
* Send powered by header
*/
@header('X-Powered-By: ' . W3TC_POWERED_BY);