本文整理汇总了PHP中w3_mkdir_from函数的典型用法代码示例。如果您正苦于以下问题:PHP w3_mkdir_from函数的具体用法?PHP w3_mkdir_from怎么用?PHP w3_mkdir_from使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了w3_mkdir_from函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
/**
* Sets data
*
* @param string $key
* @param string $var
* @param int $expire
* @return boolean
*/
function set($key, $var, $expire = 0)
{
$key = $this->get_item_key($key);
$sub_path = $this->_get_path($key);
$path = $this->_cache_dir . '/' . $sub_path;
$sub_dir = dirname($sub_path);
$dir = dirname($path);
if (!@is_dir($dir)) {
if (!w3_mkdir_from($dir, W3TC_CACHE_DIR)) {
return false;
}
}
$fp = @fopen($path, 'w');
if (!$fp) {
return false;
}
if ($this->_locking) {
@flock($fp, LOCK_EX);
}
@fputs($fp, $var['content']);
@fclose($fp);
if ($this->_locking) {
@flock($fp, LOCK_UN);
}
// some hostings create files with restrictive permissions
// not allowing apache to read it later
@chmod($path, 0644);
$old_entry_path = $path . '.old';
@unlink($old_entry_path);
if (w3_is_apache() && isset($var['headers']) && isset($var['headers']['Content-Type']) && substr($var['headers']['Content-Type'], 0, 8) == 'text/xml') {
file_put_contents(dirname($path) . '/.htaccess', "<IfModule mod_mime.c>\n" . " RemoveType .html_gzip\n" . " AddType text/xml .html_gzip\n" . " RemoveType .html\n" . " AddType text/xml .html\n" . "</IfModule>");
}
return true;
}
示例2: store
/**
* Write data to cache.
*
* @param string $id cache id (e.g. a filename)
*
* @param string $data
*
* @return bool success
*/
public function store($id, $data)
{
$path = $this->_path . '/' . $id;
$flag = $this->_locking ? LOCK_EX : null;
if (is_file($path)) {
@unlink($path);
}
if (!@file_put_contents($path, $data, $flag)) {
// retry with make dir
w3_mkdir_from(dirname($path), W3TC_CACHE_DIR);
if (!@file_put_contents($path, $data, $flag)) {
return false;
}
if (is_file($path . '.old')) {
@unlink($path . '.old');
}
@file_put_contents($path . '.old', $data, $flag);
}
// write control
if ($data != $this->fetch($id)) {
@unlink($path);
return false;
}
return true;
}
示例3: w3_blogmap_register_new_item
/**
* Registers new blog url in url=>blog mapfile
*/
function w3_blogmap_register_new_item($blog_home_url, $config)
{
if (!isset($GLOBALS['current_blog'])) {
return false;
}
$filename = w3_blogmap_filename($blog_home_url);
if (!file_exists($filename)) {
$blog_ids = array();
} else {
$data = file_get_contents($filename);
$blog_ids = @eval($data);
if (!is_array($blog_ids)) {
$blog_ids = array();
}
}
if (isset($blog_ids[$blog_home_url])) {
return false;
}
$data = $config->get_boolean('common.force_master') ? 'm' : 'c';
$blog_id = $GLOBALS['current_blog']->blog_id;
$blog_ids_strings[] = "'" . $blog_home_url . "' => '" . $data . $blog_id . "'";
foreach ($blog_ids as $key => $value) {
$blog_ids_strings[] = "'" . $key . "' => '" . $value . "'";
}
$data = sprintf('return array(%s);', implode(', ', $blog_ids_strings));
if (!is_dir(dirname($filename))) {
w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
}
return @file_put_contents($filename, $data);
}
示例4: w3tc_file_log
/**
* Write log entry
*
* @param string message
* @param string $file
* @return bool|int
*/
function w3tc_file_log($message, $file)
{
if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
w3_require_once(W3TC_INC_DIR . '/functions/file.php');
$data = sprintf("[%s] %s %s\n", date('r'), $message, $file);
if (get_site_option('w3tc_support_request')) {
$blog_id = 0;
} else {
$blog_id = null;
}
$filename = w3_cache_blog_dir('log', $blog_id) . '/file-sender.log';
if (!is_dir(dirname($filename))) {
w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
}
@file_put_contents($filename, $data, FILE_APPEND);
}
}
示例5: _precache_file
/**
* Pre-caches external file
*
* @param string $url
* @param string $type
* @return string
*/
function _precache_file($url, $type)
{
$lifetime = $this->_config->get_integer('minify.lifetime');
$cache_path = sprintf('%s/minify_%s.%s', w3_cache_blog_dir('minify'), md5($url), $type);
if (!file_exists($cache_path) || @filemtime($cache_path) < time() - $lifetime) {
w3_require_once(W3TC_INC_DIR . '/functions/http.php');
if (!@is_dir(dirname($cache_path))) {
w3_require_once(W3TC_INC_DIR . '/functions/file.php');
w3_mkdir_from(dirname($cache_path), W3TC_CACHE_DIR);
}
w3_download($url, $cache_path);
}
return file_exists($cache_path) ? $this->_get_minify_source($cache_path, $url) : false;
}
示例6: set
/**
* Sets data
*
* @param string $key
* @param mixed $var
* @param integer $expire
* @param string $group Used to differentiate between groups of cache values
* @return boolean
*/
function set($key, $var, $expire = 0, $group = '')
{
$key = $this->get_item_key($key);
$sub_path = $this->_get_path($key);
$path = $this->_cache_dir . DIRECTORY_SEPARATOR . ($group ? $group . DIRECTORY_SEPARATOR : '') . $sub_path;
$dir = dirname($path);
if (!@is_dir($dir)) {
if (!w3_mkdir_from($dir, W3TC_CACHE_DIR)) {
return false;
}
}
$fp = @fopen($path, 'wb');
if (!$fp) {
return false;
}
if ($this->_locking) {
@flock($fp, LOCK_EX);
}
if ($expire <= 0 || $expire > W3TC_CACHE_FILE_EXPIRE_MAX) {
$expire = W3TC_CACHE_FILE_EXPIRE_MAX;
}
$expires_at = time() + $expire;
@fputs($fp, pack('L', $expires_at));
@fputs($fp, '<?php exit; ?>');
@fputs($fp, @serialize($var));
@fclose($fp);
if ($this->_locking) {
@flock($fp, LOCK_UN);
}
return true;
}
示例7: write_rules_cache
/**
* Writes rules to file cache .htaccess
* Throw exceptions
*
*/
function write_rules_cache()
{
w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
$path = w3_get_minify_rules_cache_path();
if (!file_exists(dirname($path))) {
w3_mkdir_from(dirname($path), W3TC_CACHE_DIR);
}
if (file_exists($path)) {
$data = @file_get_contents($path);
if ($data !== false) {
$data = $this->erase_rules_legacy($data);
} else {
w3_throw_on_read_error($path);
}
} else {
$data = '';
}
$replace_start = strpos($data, W3TC_MARKER_BEGIN_MINIFY_CACHE);
$replace_end = strpos($data, W3TC_MARKER_END_MINIFY_CACHE);
if ($replace_start !== false && $replace_end !== false && $replace_start < $replace_end) {
$replace_length = $replace_end - $replace_start + strlen(W3TC_MARKER_END_MINIFY_CACHE) + 1;
} else {
$replace_start = false;
$replace_length = 0;
$search = array(W3TC_MARKER_BEGIN_PGCACHE_CACHE => 0, W3TC_MARKER_BEGIN_BROWSERCACHE_CACHE => 0, W3TC_MARKER_BEGIN_MINIFY_CORE => 0, W3TC_MARKER_BEGIN_PGCACHE_CORE => 0, W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP => 0, W3TC_MARKER_BEGIN_WORDPRESS => 0);
foreach ($search as $string => $length) {
$replace_start = strpos($data, $string);
if ($replace_start !== false) {
$replace_start += $length;
break;
}
}
}
$rules = $this->generate_rules_cache();
if ($replace_start !== false) {
$data = w3_trim_rules(substr_replace($data, $rules, $replace_start, $replace_length));
} else {
$data = w3_trim_rules($data . $rules);
}
if (!@file_put_contents($path, $data)) {
w3_throw_on_write_error($path);
}
}
示例8: action_support_request
//.........这里部分代码省略.........
if (!empty($ftp_host) && !empty($ftp_login) && !empty($ftp_password)) {
$data['SSH / FTP host'] = $ftp_host;
$data['SSH / FTP login'] = $ftp_login;
$data['SSH / FTP password'] = $ftp_password;
}
/**
* Store request data for future access
*/
if (count($data)) {
$hash = md5(microtime());
$request_data = get_option('w3tc_request_data', array());
$request_data[$hash] = $data;
update_option('w3tc_request_data', $request_data);
$request_data_url = sprintf('%s/w3tc_request_data/%s', w3_get_home_url(), $hash);
} else {
$request_data_url = '';
}
$nonce = wp_create_nonce('w3tc_support_request');
if (is_network_admin()) {
update_site_option('w3tc_support_request', $nonce);
} else {
update_option('w3tc_support_request', $nonce);
}
$file_access = WP_PLUGIN_URL . '/' . dirname(W3TC_FILE) . '/pub/files.php';
if (w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url())) {
$file_access = str_replace(w3_get_domain(w3_get_home_url()), w3_get_domain(w3_get_site_url()), $file_access);
}
$post['file_access'] = $file_access;
$post['nonce'] = $nonce;
$post['request_data_url'] = $request_data_url;
$post['ip'] = $_SERVER['REMOTE_ADDR'];
$post['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$post['version'] = W3TC_VERSION;
$post['plugin'] = 'W3 Total Cache';
$post['request_id'] = $request_id;
$license_level = 'community';
if (w3_is_pro($this->_config)) {
$license_level = 'pro';
} elseif (w3_is_enterprise($this->_config)) {
$license_level = 'enterprise';
}
$post['license_level'] = $license_level;
$unset = array('wp_login', 'wp_password', 'ftp_host', 'ftp_login', 'ftp_password');
foreach ($unset as $key) {
unset($post[$key]);
}
foreach ($attachments as $attachment) {
if (is_network_admin()) {
update_site_option('attachment_' . md5($attachment), $attachment);
} else {
update_option('attachment_' . md5($attachment), $attachment);
}
}
$post = array_merge($post, array('files' => $attachments));
if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
$data = sprintf("[%s] Post support request\n", date('r'));
foreach ($post as $key => $value) {
$data .= sprintf("%s => %s\n", $key, is_array($value) ? implode(',', $value) : $value);
}
$filename = w3_cache_blog_dir('log') . '/support.log';
if (!is_dir(dirname($filename))) {
w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
}
@file_put_contents($filename, $data, FILE_APPEND);
}
$response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $this->_config->get_integer('timelimit.email_send')));
if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
$filename = w3_cache_blog_dir('log') . '/support.log';
$data = sprintf("[%s] Post response \n%s\n", date('r'), print_r($response, true));
@file_put_contents($filename, $data, FILE_APPEND);
}
if (!is_wp_error($response)) {
$result = $response['response']['code'] == 200 && $response['body'] == 'Ok';
} else {
$result = false;
}
/**
* Remove temporary files
*/
foreach ($attachments as $attachment) {
if (strstr($attachment, W3TC_CACHE_TMP_DIR) !== false) {
@unlink($attachment);
}
if (is_network_admin()) {
delete_site_option('attachment_' . md5($attachment));
} else {
delete_option('attachment_' . md5($attachment));
}
}
if (is_network_admin()) {
delete_site_option('w3tc_support_request');
} else {
delete_option('w3tc_support_request');
}
if ($result) {
w3_admin_redirect(array('tab' => 'general', 'w3tc_note' => 'support_request'), false);
} else {
w3_admin_redirect(array_merge($params, array('request_type' => $request_type, 'w3tc_error' => 'support_request')), false);
}
}
示例9: w3_add_rules
/**
* @param SelfTestExceptions $exs
* @param string $path
* @param string $rules
* @param string $start
* @param string $end
* @param array $order
*/
function w3_add_rules($exs, $path, $rules, $start, $end, $order)
{
$data = @file_get_contents($path);
if ($data === false) {
$data = '';
}
$rules_missing = !empty($rules) && strstr(w3_clean_rules($data), w3_clean_rules($rules)) === false;
if (!$rules_missing) {
return;
}
$replace_start = strpos($data, $start);
$replace_end = strpos($data, $end);
if ($replace_start !== false && $replace_end !== false && $replace_start < $replace_end) {
$replace_length = $replace_end - $replace_start + strlen($end) + 1;
} else {
$replace_start = false;
$replace_length = 0;
$search = $order;
foreach ($search as $string => $length) {
$replace_start = strpos($data, $string);
if ($replace_start !== false) {
$replace_start += $length;
break;
}
}
}
if ($replace_start !== false) {
$data = w3_trim_rules(substr_replace($data, $rules, $replace_start, $replace_length));
} else {
$data = w3_trim_rules($data . $rules);
}
if (strpos($path, W3TC_CACHE_DIR) === false || w3_is_nginx()) {
try {
w3_wp_write_to_file($path, $data);
} catch (FilesystemOperationException $ex) {
if ($replace_start !== false) {
$exs->push(new FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), sprintf(__('Edit file <strong>%s
</strong> and replace all lines between and including <strong>%s</strong> and
<strong>%s</strong> markers with:', 'w3-total-caceh'), $path, $start, $end), $path, $rules));
} else {
$exs->push(new FilesystemModifyException($ex->getMessage(), $ex->credentials_form(), sprintf(__('Edit file <strong>%s</strong> and add the following rules
above the WordPress directives:', 'w3-total-cache'), $path), $path, $rules));
}
}
} else {
if (!@file_exists(dirname($path))) {
w3_mkdir_from(dirname($path), W3TC_CACHE_DIR);
}
if (!@file_put_contents($path, $data)) {
try {
w3_wp_delete_folder(dirname($path), '', $_SERVER['REQUEST_URI']);
} catch (FilesystemOperationException $ex) {
$exs->push($ex);
}
}
}
}
示例10: w3_file_put_contents_atomic
/**
* Atomically writes file inside W3TC_CACHE_DIR dir
* @param $filename
* @param $content
* @throws Exception
* @return void
**/
function w3_file_put_contents_atomic($filename, $content)
{
if (!is_dir(W3TC_CACHE_TMP_DIR) || !is_writable(W3TC_CACHE_TMP_DIR)) {
w3_mkdir_from(W3TC_CACHE_TMP_DIR, W3TC_CACHE_DIR);
if (!is_dir(W3TC_CACHE_TMP_DIR) || !is_writable(W3TC_CACHE_TMP_DIR)) {
throw new Exception('Can\'t create folder <strong>' . W3TC_CACHE_TMP_DIR . '</strong>');
}
}
$temp = tempnam(W3TC_CACHE_TMP_DIR, 'temp');
try {
if (!($f = @fopen($temp, 'wb'))) {
if (file_exists($temp)) {
@unlink($temp);
}
throw new Exception('Can\'t write to temporary file <strong>' . $temp . '</strong>');
}
fwrite($f, $content);
fclose($f);
if (!@rename($temp, $filename)) {
@unlink($filename);
if (!@rename($temp, $filename)) {
w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
if (!@rename($temp, $filename)) {
throw new Exception('Can\'t write to file <strong>' . $filename . '</strong>');
}
}
}
$chmod = 0644;
if (defined('FS_CHMOD_FILE')) {
$chmod = FS_CHMOD_FILE;
}
@chmod($filename, $chmod);
} catch (Exception $ex) {
if (file_exists($temp)) {
@unlink($temp);
}
throw $ex;
}
}
示例11: save
/**
* Saves modified config
*/
function save()
{
$filename = $this->_get_config_filename();
if (!is_dir(dirname($filename))) {
w3_require_once(W3TC_INC_DIR . '/functions/file.php');
w3_mkdir_from(dirname($filename), WP_CONTENT_DIR);
}
$this->_data_object->write($filename);
}
示例12: w3_debug_log
/**
* 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 $module
* @param null $blog_id
* @return string
*/
function w3_debug_log($module, $blog_id = null)
{
if (is_null($blog_id)) {
$blog_id = w3_get_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 = w3_cache_dir('log');
}
$filename = $dir_path . '/' . $postfix . '/' . $module . '.log';
if (!is_dir(dirname($filename))) {
w3_require_once(W3TC_INC_DIR . '/functions/file.php');
w3_mkdir_from(dirname($filename), $from_dir);
}
return $filename;
}
示例13: _test_cache_folder
private function _test_cache_folder()
{
w3_require_once(W3TC_INC_DIR . '/functions/file.php');
$test_file = self::$test_dir . '/test.php';
return w3_mkdir_from(dirname($test_file), W3TC_CACHE_DIR);
}
示例14: save
/**
* Saves modified config
*/
function save()
{
$filename = $this->_get_config_filename();
if (!is_dir(dirname($filename))) {
w3_require_once(W3TC_INC_DIR . '/functions/file.php');
w3_mkdir_from(dirname($filename), WP_CONTENT_DIR);
}
if (!is_dir(dirname(W3TC_CACHE_TMP_DIR))) {
w3_require_once(W3TC_INC_DIR . '/functions/file.php');
w3_mkdir_from(dirname(W3TC_CACHE_TMP_DIR), WP_CONTENT_DIR);
}
if (!$this->_data_object->write($filename)) {
if (is_dir(W3TC_CONFIG_DIR)) {
w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
w3_throw_on_write_error($filename, array(dirname($filename), W3TC_CACHE_TMP_DIR));
}
}
}
示例15: w3_wp_create_folders
/**
* Create folders in wp content
* @param $folders array(folderpath1, folderpath2, ...)
* @param string $method
* @param string $url
* @param bool|string $context folder to create folders in
* @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
* @throws FileOperationException
*/
function w3_wp_create_folders($folders, $method = '', $url = '', $context = false)
{
if (empty($folders)) {
return;
}
$created = true;
foreach ($folders as $folder) {
if (!@is_dir($folder) && !@w3_mkdir_from($folder, WP_CONTENT_DIR)) {
$created = false;
break;
}
}
if ($created) {
return;
}
w3_wp_request_filesystem_credentials($method, $url, $context);
global $wp_filesystem;
foreach ($folders as $folder) {
if (!@is_dir($folder) && !$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
throw new FileOperationException('Could not create directory:' . $folder, 'create', 'folder', $folder);
}
}
}