예제 #1
0
 /**
  * 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
0
파일: File.php 프로젝트: rongandat/sallumeh
 /**
  * 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
0
/**
 * 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
0
/**
 * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * Send support request action
  *
  * @return void
  */
 function action_support_request()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_Request::get_string('request_type');
     $payment = W3_Request::get_boolean('payment');
     $request_id = W3_Request::get_string('request_id');
     $url = W3_Request::get_string('url');
     $name = W3_Request::get_string('name');
     $email = W3_Request::get_string('email');
     $twitter = W3_Request::get_string('twitter');
     $phone = W3_Request::get_string('phone');
     $subject = W3_Request::get_string('subject');
     $description = W3_Request::get_string('description');
     $templates = W3_Request::get_array('templates');
     $forum_url = W3_Request::get_string('forum_url');
     $wp_login = W3_Request::get_string('wp_login');
     $wp_password = W3_Request::get_string('wp_password');
     $ftp_host = W3_Request::get_string('ftp_host');
     $ftp_login = W3_Request::get_string('ftp_login');
     $ftp_password = W3_Request::get_string('ftp_password');
     $subscribe_releases = W3_Request::get_string('subscribe_releases');
     $subscribe_customer = W3_Request::get_string('subscribe_customer');
     $params = array('request_type' => $request_type, 'payment' => $payment, 'url' => $url, 'name' => $name, 'email' => $email, 'twitter' => $twitter, 'phone' => $phone, 'subject' => $subject, 'description' => $description, 'forum_url' => $forum_url, 'wp_login' => $wp_login, 'wp_password' => $wp_password, 'ftp_host' => $ftp_host, 'ftp_login' => $ftp_login, 'ftp_password' => $ftp_password, 'subscribe_releases' => $subscribe_releases, 'subscribe_customer' => $subscribe_customer);
     $post = $params;
     foreach ($templates as $template_index => $template) {
         $template_key = sprintf('templates[%d]', $template_index);
         $params[$template_key] = $template;
     }
     if (!isset($this->_request_types[$request_type])) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_type')), false);
     }
     $required = array('bug_report' => 'url,name,email,subject,description', 'new_feature' => 'url,name,email,subject,description', 'email_support' => 'url,name,email,subject,description', 'phone_support' => 'url,name,email,subject,description,phone', 'plugin_config' => 'url,name,email,subject,description,wp_login,wp_password', 'theme_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password', 'linux_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password');
     if (strstr($required[$request_type], 'url') !== false && $url == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_url')), false);
     }
     if (strstr($required[$request_type], 'name') !== false && $name == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_name')), false);
     }
     if (strstr($required[$request_type], 'email') !== false && !preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_email')), false);
     }
     if (strstr($required[$request_type], 'phone') !== false && !preg_match('~^[0-9\\-\\.\\ \\(\\)\\+]+$~', $phone)) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_phone')), false);
     }
     if (strstr($required[$request_type], 'subject') !== false && $subject == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_subject')), false);
     }
     if (strstr($required[$request_type], 'description') !== false && $description == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_description')), false);
     }
     if (strstr($required[$request_type], 'wp_login') !== false && $wp_login == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_login')), false);
     }
     if (strstr($required[$request_type], 'wp_password') !== false && $wp_password == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_password')), false);
     }
     if (strstr($required[$request_type], 'ftp_host') !== false && $ftp_host == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_host')), false);
     }
     if (strstr($required[$request_type], 'ftp_login') !== false && $ftp_login == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_login')), false);
     }
     if (strstr($required[$request_type], 'ftp_password') !== false && $ftp_password == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_password')), false);
     }
     /**
      * Add attachments
      */
     $attachments = array();
     $attach_files = array(w3_get_wp_config_path(), w3_cache_blog_dir('log') . '/minify.log', w3_get_pgcache_rules_core_path(), w3_get_pgcache_rules_cache_path(), w3_get_browsercache_rules_cache_path(), w3_get_browsercache_rules_no404wp_path(), w3_get_minify_rules_core_path(), w3_get_minify_rules_cache_path());
     /**
      * Attach config files
      */
     if ($handle = opendir(W3TC_CONFIG_DIR)) {
         while (($entry = @readdir($handle)) !== false) {
             if ($entry == '.' || $entry == '..' || $entry == 'index.html') {
                 continue;
             }
             $attachments[] = W3TC_CONFIG_DIR . '/' . $entry;
         }
         closedir($handle);
     }
     foreach ($attach_files as $attach_file) {
         if ($attach_file && file_exists($attach_file) && !in_array($attach_file, $attachments)) {
             $attachments[] = $attach_file;
         }
     }
     /**
      * Attach server info
      */
     $server_info = print_r($this->get_server_info(), true);
     $server_info = str_replace("\n", "\r\n", $server_info);
     $server_info_path = W3TC_CACHE_TMP_DIR . '/server_info.txt';
     if (@file_put_contents($server_info_path, $server_info)) {
         $attachments[] = $server_info_path;
     }
     /**
      * Attach phpinfo
      */
     ob_start();
     phpinfo();
     $php_info = ob_get_contents();
     ob_end_clean();
     $php_info_path = W3TC_CACHE_TMP_DIR . '/php_info.html';
     if (@file_put_contents($php_info_path, $php_info)) {
         $attachments[] = $php_info_path;
     }
     /**
      * Attach self-test
      */
     ob_start();
     $this->action_self_test();
     $self_test = ob_get_contents();
     ob_end_clean();
     $self_test_path = W3TC_CACHE_TMP_DIR . '/self_test.html';
     if (@file_put_contents($self_test_path, $self_test)) {
         $attachments[] = $self_test_path;
     }
     /**
      * Attach templates
      */
     foreach ($templates as $template) {
         if (!empty($template)) {
             $attachments[] = $template;
         }
     }
     /**
      * Attach other files
      */
     if (!empty($_FILES['files'])) {
         $files = (array) $_FILES['files'];
         for ($i = 0, $l = count($files); $i < $l; $i++) {
             if (isset($files['tmp_name'][$i]) && isset($files['name'][$i]) && isset($files['error'][$i]) && $files['error'][$i] == UPLOAD_ERR_OK) {
                 $path = W3TC_CACHE_TMP_DIR . '/' . $files['name'][$i];
                 if (@move_uploaded_file($files['tmp_name'][$i], $path)) {
                     $attachments[] = $path;
                 }
             }
         }
     }
     $data = array();
     if (!empty($wp_login) && !empty($wp_password)) {
         $data['WP Admin login'] = $wp_login;
         $data['WP Admin password'] = $wp_password;
     }
     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
0
파일: rule.php 프로젝트: easinewe/Avec2016
/**
 * @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
0
/**
 * 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
0
 /**
  * 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
0
/**
 * 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
0
 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
0
 /**
  * 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
0
/**
 * 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);
        }
    }
}
예제 #16
0
/**
 * @param $folder
 * @param string $method Which method to use when creating
 * @param string $url Where to redirect after creation
 * @param bool|string $context folder to create folder in
 * @throws FilesystemMkdirException
 */
function w3_wp_create_folder($folder, $from_folder)
{
    if (@is_dir($folder)) {
        return;
    }
    if (w3_mkdir_from($folder, $from_folder)) {
        return;
    }
    try {
        w3_wp_request_filesystem_credentials();
    } catch (FilesystemOperationException $ex) {
        throw new FilesystemMkdirException($ex->getMessage(), $ex->credentials_form(), $folder);
    }
    global $wp_filesystem;
    if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
        throw new FilesystemMkdirException('FTP credentials don\'t allow to create folder <strong>' . $folder . '</strong>', w3_get_filesystem_credentials_form(), $folder);
    }
}