function ewww_image_optimizer_w3tc_update_files($files) { // global $ewww_debug; global $ewww_attachment; list($file, $upload_path) = ewww_image_optimizer_attachment_path($ewww_attachment['meta'], $ewww_attachment['id']); $file_info = array(); $upload_info = w3_upload_info(); if ($upload_info) { $remote_file = ltrim($upload_info['baseurlpath'] . $ewww_attachment['meta']['file'], '/'); $home_url = get_site_url(); $original_url = $home_url . $file; $file_info[] = array('local_path' => $file, 'remote_path' => $remote_file, 'original_url' => $original_url); $files = array_merge($files, $file_info); // $ewww_debug .= "w3tc remote path: $remote_file<br>"; // $ewww_debug .= "w3tc original url: $original_url<br>"; //$ewww_debug .= print_r($files, true) . '<br>'; //ewww_image_optimizer_debug_log(); } return $files; }
/** * Returns server info * * @return array */ function get_server_info() { global $wp_version, $wp_db_version, $wpdb; $wordpress_plugins = get_plugins(); $wordpress_plugins_active = array(); foreach ($wordpress_plugins as $wordpress_plugin_file => $wordpress_plugin) { if (is_plugin_active($wordpress_plugin_file)) { $wordpress_plugins_active[$wordpress_plugin_file] = $wordpress_plugin; } } $mysql_version = $wpdb->get_var('SELECT VERSION()'); $mysql_variables_result = (array) $wpdb->get_results('SHOW VARIABLES', ARRAY_N); $mysql_variables = array(); foreach ($mysql_variables_result as $mysql_variables_row) { $mysql_variables[$mysql_variables_row[0]] = $mysql_variables_row[1]; } $server_info = array('w3tc' => array('version' => W3TC_VERSION, 'server' => !empty($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'Unknown', 'dir' => W3TC_DIR, 'cache_dir' => W3TC_CACHE_DIR, 'blog_id' => w3_get_blog_id(), 'document_root' => w3_get_document_root(), 'home_root' => w3_get_home_root(), 'site_root' => w3_get_site_root(), 'base_path' => w3_get_base_path(), 'home_path' => w3_get_home_path(), 'site_path' => w3_get_site_path()), 'wp' => array('version' => $wp_version, 'db_version' => $wp_db_version, 'abspath' => ABSPATH, 'home' => get_option('home'), 'siteurl' => get_option('siteurl'), 'email' => get_option('admin_email'), 'upload_info' => (array) w3_upload_info(), 'theme' => w3tc_get_current_theme(), 'wp_cache' => defined('WP_CACHE') && WP_CACHE ? 'true' : 'false', 'plugins' => $wordpress_plugins_active), 'mysql' => array('version' => $mysql_version, 'variables' => $mysql_variables)); return $server_info; }
function options() { $remove_results = array(); $w3tc_error = array(); w3_require_once(W3TC_INC_DIR . '/functions/activation.php'); $preview = $this->_config->is_preview(); if (w3_is_network() && !$this->is_master()) { $this->_config_master = new W3_Config(true); } else { $this->_config_master = $this->_config; } /** * Check for page cache availability */ $wp_config_edit = false; /** * Check memcached */ $memcaches_errors = array(); if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'memcached') { $pgcache_memcached_servers = $this->_config->get_array('pgcache.memcached.servers'); if (!$this->is_memcache_available($pgcache_memcached_servers)) { $memcaches_errors[] = sprintf(__('Page Cache: %s.', 'w3-total-cache'), implode(', ', $pgcache_memcached_servers)); } } if ($this->_config->get_boolean('minify.enabled') && $this->_config->get_string('minify.engine') == 'memcached') { $minify_memcached_servers = $this->_config->get_array('minify.memcached.servers'); if (!$this->is_memcache_available($minify_memcached_servers)) { $memcaches_errors[] = sprintf(__('Minify: %s.', 'w3-total-cache'), implode(', ', $minify_memcached_servers)); } } if ($this->_config->get_boolean('dbcache.enabled') && $this->_config->get_string('dbcache.engine') == 'memcached') { $dbcache_memcached_servers = $this->_config->get_array('dbcache.memcached.servers'); if (!$this->is_memcache_available($dbcache_memcached_servers)) { $memcaches_errors[] = sprintf(__('Database Cache: %s.', 'w3-total-cache'), implode(', ', $dbcache_memcached_servers)); } } if ($this->_config->get_boolean('objectcache.enabled') && $this->_config->get_string('objectcache.engine') == 'memcached') { $objectcache_memcached_servers = $this->_config->get_array('objectcache.memcached.servers'); if (!$this->is_memcache_available($objectcache_memcached_servers)) { $memcaches_errors[] = sprintf(__('Object Cache: %s.', 'w3-total-cache'), implode(', ', $objectcache_memcached_servers)); } } if (count($memcaches_errors)) { $memcache_error = __('The following memcached servers are not responding or not running:</p><ul>', 'w3-total-cache'); foreach ($memcaches_errors as $memcaches_error) { $memcache_error .= '<li>' . $memcaches_error . '</li>'; } $memcache_error .= __('</ul><p>This message will automatically disappear once the issue is resolved.', 'w3-total-cache'); $this->_errors[] = $memcache_error; } /** * Check CURL extension */ if ($this->_config->get_boolean('notes.no_curl') && $this->_config->get_boolean('cdn.enabled') && !function_exists('curl_init')) { $this->_notes[] = sprintf(__('The <strong>CURL PHP</strong> extension is not available. Please install it to enable S3 or CloudFront functionality. %s', 'w3-total-cache'), w3_button_hide_note('Hide this message', 'no_curl')); } /** * Check Zlib extension */ if ($this->_config->get_boolean('notes.no_zlib') && !function_exists('gzencode')) { $this->_notes[] = sprintf(__('Unfortunately the PHP installation is incomplete, the <strong>zlib module is missing</strong>. This is a core PHP module. Notify the server administrator. %s', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'no_zlib')); } /** * Check if Zlib output compression is enabled */ if ($this->_config->get_boolean('notes.zlib_output_compression') && w3_zlib_output_compression()) { $this->_notes[] = sprintf(__('Either the PHP configuration, web server configuration or a script in the WordPress installation has <strong>zlib.output_compression</strong> enabled.<br />Please locate and disable this setting to ensure proper HTTP compression behavior. %s', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'zlib_output_compression')); } /** * Check wp-content permissions */ if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_perms')) { w3_require_once(W3TC_INC_DIR . '/functions/file.php'); $wp_content_mode = w3_get_file_permissions(WP_CONTENT_DIR); if ($wp_content_mode > 0755) { $this->_notes[] = sprintf(__('<strong>%s</strong> is write-able. When finished installing the plugin, change the permissions back to the default: <strong>chmod 755 %s</strong>. Permissions are currently %s. %s', 'w3-total-cache'), WP_CONTENT_DIR, WP_CONTENT_DIR, base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'wp_content_perms')); } } /** * Check wp-content permissions */ if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_changed_perms')) { $perm = get_transient('w3tc_prev_permission'); $current_perm = w3_get_file_permissions(WP_CONTENT_DIR); if ($perm && $perm != base_convert($current_perm, 10, 8) && ($current_perm > 0755 || $perm < base_convert($current_perm, 10, 8))) { $this->_notes[] = sprintf(__('<strong>%s</strong> permissions were changed during the setup process. Permissions are currently %s.<br />To restore permissions run <strong>chmod %s %s</strong>. %s', 'w3-total-cache'), WP_CONTENT_DIR, base_convert($current_perm, 10, 8), $perm, WP_CONTENT_DIR, w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'wp_content_changed_perms')); } } /** * Check permalinks */ if ($this->_config->get_boolean('notes.no_permalink_rules') && ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'file_generic' || $this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.no404wp')) && !w3_is_permalink_rules()) { $this->_errors[] = sprintf(__('The required directives for fancy permalinks could not be detected, please confirm they are available: <a href="http://codex.wordpress.org/Using_Permalinks#Creating_and_editing_.28.htaccess.29">Creating and editing</a> %s', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'no_permalink_rules')); } /** * CDN */ if ($this->_config->get_boolean('cdn.enabled')) { /** * Check upload settings */ $upload_info = w3_upload_info(); if (!$upload_info) { $upload_path = get_option('upload_path'); $upload_path = trim($upload_path); if (empty($upload_path)) { $upload_path = WP_CONTENT_DIR . '/uploads'; $this->_errors[] = sprintf(__('The uploads directory is not available. Default WordPress directories will be created: <strong>%s</strong>.', 'w3-total-cache'), $upload_path); } if (!w3_is_multisite()) { $this->_errors[] = sprintf(__('The uploads path found in the database (%s) is inconsistent with the actual path. Please manually adjust the upload path either in miscellaneous settings or if not using a custom path %s automatically to resolve the issue.', 'w3-total-cache'), $upload_path, w3_button_link(__('update the path', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_update_upload_path', $this->_page), 'w3tc'))); } } /** * Check CDN settings */ $cdn_engine = $this->_config->get_string('cdn.engine'); $error = ''; switch (true) { case $cdn_engine == 'ftp' && !count($this->_config->get_array('cdn.ftp.domain')): $this->_errors[] = __('A configuration issue prevents <acronym title="Content Delivery Network">CDN</acronym> from working: The <strong>"Replace default hostname with"</strong> field cannot be empty. Enter <acronym title="Content Delivery Network">CDN</acronym> provider hostname <a href="?page=w3tc_cdn#configuration">here</a>. <em>(This is the hostname used in order to view objects in a browser.)</em>', 'w3-total-cache'); break; case $cdn_engine == 's3' && ($this->_config->get_string('cdn.s3.key') == '' || $this->_config->get_string('cdn.s3.secret') == '' || $this->_config->get_string('cdn.s3.bucket') == ''): $error = __('The <strong>"Access key", "Secret key" and "Bucket"</strong> fields cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'cf' && ($this->_config->get_string('cdn.cf.key') == '' || $this->_config->get_string('cdn.cf.secret') == '' || $this->_config->get_string('cdn.cf.bucket') == '' || $this->_config->get_string('cdn.cf.id') == '' && !count($this->_config->get_array('cdn.cf.cname'))): $error = __('The <strong>"Access key", "Secret key", "Bucket" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'cf2' && ($this->_config->get_string('cdn.cf2.key') == '' || $this->_config->get_string('cdn.cf2.secret') == '' || $this->_config->get_string('cdn.cf2.id') == '' && !count($this->_config->get_array('cdn.cf2.cname'))): $error = __('The <strong>"Access key", "Secret key" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'rscf' && ($this->_config->get_string('cdn.rscf.user') == '' || $this->_config->get_string('cdn.rscf.key') == '' || $this->_config->get_string('cdn.rscf.container') == '' || !count($this->_config->get_array('cdn.rscf.cname'))): $error = __('The <strong>"Username", "API key", "Container" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'azure' && ($this->_config->get_string('cdn.azure.user') == '' || $this->_config->get_string('cdn.azure.key') == '' || $this->_config->get_string('cdn.azure.container') == ''): $error = __('The <strong>"Account name", "Account key" and "Container"</strong> fields cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'mirror' && !count($this->_config->get_array('cdn.mirror.domain')): $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'netdna': $fields = array(); if ($this->_config->get_string('cdn.netdna.authorization_key') == '') { $fields[] = '"' . __('Authorization key', 'w3-total-cache') . '"'; } if (!count($this->_config->get_array('cdn.netdna.domain'))) { $fields[] = '"' . __('Replace default hostname with', 'w3-total-cache') . '"'; } if ($fields) { $error = sprintf(__('The <strong>%s</strong> field(s) cannot be empty.', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $fields)); } if ($this->_config->get_string('cdn.netdna.authorization_key') != '' && sizeof(explode('+', $this->_config->get_string('cdn.netdna.authorization_key'))) != 3) { $error .= __('The <strong>"Authorization key"</strong> is not correct.', 'w3-total-cache'); } elseif ($this->_config->get_integer('cdn.netdna.zone_id', 0) <= 0) { $error .= __('You need to select / create a pull zone.', 'w3-total-cache'); } break; case $cdn_engine == 'maxcdn': $fields = array(); if ($this->_config->get_string('cdn.maxcdn.authorization_key') == '') { $fields[] = '"' . __('Authorization key', 'w3-total-cache') . '"'; } if (!count($this->_config->get_array('cdn.maxcdn.domain'))) { $fields[] = '"' . __('Replace default hostname with', 'w3-total-cache') . '"'; } if ($fields) { $error = sprintf(__('The <strong>%s</strong> field(s) cannot be empty.', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $fields)); } if ($this->_config->get_string('cdn.maxcdn.authorization_key') != '' && sizeof(explode('+', $this->_config->get_string('cdn.maxcdn.authorization_key'))) != 3) { $error .= __('The <strong>"Authorization key"</strong> is not correct.', 'w3-total-cache'); } elseif ($this->_config->get_integer('cdn.maxcdn.zone_id', 0) <= 0) { $error .= __('You need to select / create a pull zone.', 'w3-total-cache'); } break; case $cdn_engine == 'cotendo' && !count($this->_config->get_array('cdn.cotendo.domain')): $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'edgecast' && !count($this->_config->get_array('cdn.edgecast.domain')): $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'att' && !count($this->_config->get_array('cdn.att.domain')): $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache'); break; case $cdn_engine == 'akamai' && !count($this->_config->get_array('cdn.akamai.domain')): $error = 'The <strong>"Replace default hostname with"</strong> field cannot be empty.'; break; } if ($error) { $this->_errors[] = __('A configuration issue prevents <acronym title="Content Delivery Network">CDN</acronym> from working: ', 'w3-total-cache') . $error . __(' <a href="?page=w3tc_cdn#configuration">Specify it here</a>.', 'w3-total-cache'); } } /** * Preview mode */ if ($this->_config->is_preview()) { $this->_notes[] = sprintf(__('Preview mode is active: Changed settings will not take effect until preview mode is %s or %s.', 'w3-total-cache'), w3_button_link(__('deploy', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_preview_deploy', $this->_page), 'w3tc')), w3_button_link(__('disable', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_preview_disable', $this->_page), 'w3tc'))) . '<br /><span class="description">' . sprintf(__('To preview any changed settings (without deploying): %s', 'w3-total-cache'), w3tc_get_preview_link()) . '</span>'; } /** * */ if ($this->_config->get_boolean('notes.root_rules') && count($this->_rule_errors_root) > 0) { $this->_rule_errors_root_hide = w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'root_rules'); } else { $this->_rule_errors_root = array(); } $this->_disable_file_operation_notification = $this->_disable_add_in_files_notification || $this->_disable_cache_write_notification; if (!$this->_disable_file_operation_notification && isset($file_operation_exception) && $file_operation_exception) { $tech_message = '<ul>'; $core_rules_perms = ''; if (w3_get_file_permissions(w3_get_wp_config_path()) != 0644) { $core_config_perms = sprintf(__('File permissions are <strong>%s</strong>, however they should be <strong>644</strong>.', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8)); } else { $core_config_perms = sprintf(__('File permissions are <strong>%s</strong>', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8)); } if (w3_get_file_permissions(w3_get_pgcache_rules_core_path()) != 0644) { $core_rules_perms = sprintf(__('File permissions are <strong>%s</strong>, however they should be <strong>644</strong>.', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_pgcache_rules_core_path()), 10, 8)); } else { $core_rules_perms = sprintf(__('File permissions are <strong>%s</strong>', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_pgcache_rules_core_path()), 10, 8)); } $wp_content_perms = ''; if (w3_get_file_permissions(WP_CONTENT_DIR) != 0755) { $wp_content_perms = sprintf(__('Directory permissions are <strong>%s</strong>, however they should be <strong>755</strong>.', 'w3-total-cache'), base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8)); } $tech_message .= '<li>' . sprintf(__('File: <strong>%s</strong> %s File owner: %s', 'w3-total-cache'), w3_get_wp_config_path(), $core_config_perms, w3_get_file_owner(w3_get_wp_config_path())) . '</li>'; $tech_message .= '<li>' . sprintf(__('File: <strong>%s</strong> %s File owner: %s', 'w3-total-cache'), w3_get_pgcache_rules_core_path(), $core_rules_perms, w3_get_file_owner(w3_get_pgcache_rules_core_path())) . '</li>'; $tech_message .= '<li>' . sprintf(__('Directory: <strong>%s</strong> %s File owner: %s', 'w3-total-cache'), WP_CONTENT_DIR, $wp_content_perms, w3_get_file_owner(WP_CONTENT_DIR)) . '</li>'; $tech_message .= '<li>' . sprintf(__('Owner of current file: %s', 'w3-total-cache'), w3_get_file_owner()) . '</li>'; if (!(w3_get_file_owner() == w3_get_file_owner(w3_get_pgcache_rules_core_path()) && w3_get_file_owner() == w3_get_file_owner(WP_CONTENT_DIR))) { $tech_message .= __('<li>The files and directories have different ownership, they should have the same ownership. </li>', 'w3-total-cache'); } $tech_message .= '</ul>'; $tech_message = '<div class="w3tc-technical-info" style="display:none">' . $tech_message . '</div>'; $w3tc_error[] = sprintf(__('<strong>W3 Total Cache Error:</strong> The plugin tried to edit, %s, but failed. Files and directories cannot be modified. Please review your <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions"> file permissions</a>. A common cause is %s and %s having different ownership or permissions. %s %s', 'w3-total-cache'), $wp_config_edit ? w3_get_wp_config_path() : w3_get_pgcache_rules_core_path(), $wp_config_edit ? basename(w3_get_wp_config_path()) : basename(w3_get_pgcache_rules_core_path()), WP_CONTENT_DIR, w3_button(__('View technical information', 'w3-total-cache'), '', 'w3tc-show-technical-info'), $tech_message); } /** * Remove functions results */ if ($remove_results) { foreach ($remove_results as $result) { $this->_errors = array_merge($this->_errors, $result['errors']); if (!isset($this->_ftp_form) && isset($result['ftp_form'])) { $extra_ftp_message = __('Please enter FTP details <a href="#ftp_upload_form">below</a> to remove the disabled modules. ', 'w3-total-cache'); $this->_ftp_form = $result['ftp_form']; $this->_use_ftp_form = true; } } if (isset($extra_ftp_message)) { $this->_errors[] = $extra_ftp_message; } } foreach ($w3tc_error as $error) { array_unshift($this->_errors, $error); } if (isset($this->_ftp_form)) { $this->_use_ftp_form = true; } $this->view(); }
function ewww_image_optimizer_w3tc_update_files($files) { global $ewww_attachment; list($file, $upload_path) = ewww_image_optimizer_attachment_path($ewww_attachment['meta'], $ewww_attachment['id']); $file_info = array(); if (function_exists('w3_upload_info')) { $upload_info = w3_upload_info(); } else { $upload_info = ewww_image_optimizer_upload_info(); } if ($upload_info) { $remote_file = ltrim($upload_info['baseurlpath'] . $ewww_attachment['meta']['file'], '/'); $home_url = get_site_url(); $original_url = $home_url . $file; $file_info[] = array('local_path' => $file, 'remote_path' => $remote_file, 'original_url' => $original_url); $files = array_merge($files, $file_info); } return $files; }
/** * Normalizes attachment file * * @param string $file * @return string */ function normalize_attachment_file($file) { w3_require_once(W3TC_INC_DIR . '/functions/http.php'); $upload_info = w3_upload_info(); if ($upload_info) { $file = ltrim(str_replace($upload_info['basedir'], '', $file), '/\\'); $matches = null; if (preg_match('~(\\d{4}/\\d{2}/)?[^/]+$~', $file, $matches)) { $file = $matches[0]; } } return $file; }
/** * Rename domain * * @param array $names * @param integer $limit * @param integer $offset * @param integer $count * @param integer $total * @param integer $results * @return void */ function rename_domain($names, $limit, $offset, &$count, &$total, &$results) { global $wpdb; @set_time_limit($this->_config->get_integer('timelimit.domain_rename')); $count = 0; $total = 0; $results = array(); $upload_info = w3_upload_info(); foreach ($names as $index => $name) { $names[$index] = str_ireplace('www.', '', $name); } if ($upload_info) { $sql = sprintf('SELECT ID, post_content, post_date FROM %sposts WHERE post_status = "publish" AND (post_type = "post" OR post_type = "page") AND (post_content LIKE "%%src=%%" OR post_content LIKE "%%href=%%") ', $wpdb->prefix); if ($limit) { $sql .= sprintf(' LIMIT %d', $limit); if ($offset) { $sql .= sprintf(' OFFSET %d', $offset); } } $posts = $wpdb->get_results($sql); if ($posts) { $count = count($posts); $total = $this->get_rename_posts_count(); $names_quoted = array_map('w3_preg_quote', $names); foreach ($posts as $post) { $matches = null; $post_content = $post->post_content; $regexp = '~(href|src)=[\'"]?(https?://(www\\.)?(' . implode('|', $names_quoted) . ')' . w3_preg_quote($upload_info['baseurlpath']) . '([^\'"<>\\s]+))[\'"]~'; if (preg_match_all($regexp, $post_content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $old_url = $match[2]; $new_url = sprintf('%s/%s', $upload_info['baseurl'], $match[5]); $post_content = str_replace($old_url, $new_url, $post_content); $results[] = array('old' => $old_url, 'new' => $new_url, 'result' => true, 'error' => 'OK'); } } if ($post_content != $post->post_content) { wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content)); } } } } }
/** * OB Callback * * @param string $buffer * @return string */ function ob_callback(&$buffer) { if ($buffer != '' && w3_is_xml($buffer)) { if ($this->can_cdn2($buffer)) { $regexps = array(); $site_path = w3_get_site_path(); $domain_url_regexp = w3_get_domain_url_regexp(); if ($this->_config->get_boolean('cdn.uploads.enable')) { require_once W3TC_INC_DIR . '/functions/http.php'; $upload_info = w3_upload_info(); if ($upload_info) { if (preg_match('~' . $domain_url_regexp . '~i', $upload_info['baseurl'])) { $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($upload_info['baseurlpath']) . '([^"\'>]+)))~'; } else { $regexps[] = '~(["\'])((' . w3_preg_quote($upload_info['baseurl']) . ')(([^"\'>]+)))~'; } } } if ($this->_config->get_boolean('cdn.includes.enable')) { $mask = $this->_config->get_string('cdn.includes.files'); if ($mask != '') { $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . WPINC) . '/(' . $this->get_regexp_by_mask($mask) . ')))~'; } } if ($this->_config->get_boolean('cdn.theme.enable')) { $theme_dir = preg_replace('~' . $domain_url_regexp . '~i', '', get_theme_root_uri()); $mask = $this->_config->get_string('cdn.theme.files'); if ($mask != '') { $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($theme_dir) . '/(' . $this->get_regexp_by_mask($mask) . ')))~'; } } if ($this->_config->get_boolean('cdn.minify.enable')) { if ($this->_config->get_boolean('minify.auto')) { $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . W3TC_CONTENT_MINIFY_DIR_NAME) . '/[a-f0-9]+\\.[a-f0-9]+\\.(css|js)))~U'; } else { $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . W3TC_CONTENT_MINIFY_DIR_NAME) . '/[a-f0-9]+/.+\\.include(-(footer|body))?(-nb)?\\.[a-f0-9]+\\.(css|js)))~U'; } } if ($this->_config->get_boolean('cdn.custom.enable')) { $masks = $this->_config->get_array('cdn.custom.files'); $masks = array_map('w3_parse_path', $masks); if (count($masks)) { $mask_regexps = array(); foreach ($masks as $mask) { if ($mask != '') { $mask = w3_normalize_file($mask); $mask_regexps[] = $this->get_regexp_by_mask($mask); } } $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path) . '(' . implode('|', $mask_regexps) . ')))~i'; } } foreach ($regexps as $regexp) { $buffer = preg_replace_callback($regexp, array(&$this, 'link_replace_callback'), $buffer); } } if ($this->_config->get_boolean('cdn.debug')) { $buffer .= "\r\n\r\n" . $this->get_debug_info(); } } return $buffer; }
/** * Tests FTP server * * @param string $error * @return boolean */ function test(&$error) { $rand = md5(time()); $upload_info = w3_upload_info(); $tmp_dir = 'test_dir_' . $rand; $tmp_file = 'test_file_' . $rand; $tmp_path = $upload_info['path'] . '/' . $tmp_file; if (!@file_put_contents($tmp_path, $rand)) { $error = sprintf('Unable to create file: %s.', $tmp_path); return false; } if (!$this->_connect($error)) { return false; } if (!@ftp_mkdir($this->_ftp, $tmp_dir)) { $this->_disconnect(); $error = sprintf('Unable to make directory: %s.', $tmp_dir); return false; } else { @ftp_chmod($this->_ftp, 0755, $tmp_dir); } if (!@ftp_chdir($this->_ftp, $tmp_dir)) { $this->_disconnect(); $error = sprintf('Unable to change directory to: %s.', $tmp_dir); return false; } if (!@ftp_put($this->_ftp, $tmp_file, $tmp_path, FTP_BINARY)) { @ftp_cdup($this->_ftp); @ftp_rmdir($this->_ftp, $tmp_dir); @unlink($tmp_path); $this->_disconnect(); $error = sprintf('Unable to upload file: %s.', $tmp_path); return false; } @ftp_delete($this->_ftp, $tmp_file); @ftp_cdup($this->_ftp); @ftp_rmdir($this->_ftp, $tmp_dir); @unlink($tmp_path); $this->_disconnect(); return true; }
/** * OB Callback * * @param string $buffer * @return string */ function ob_callback(&$buffer) { if ($buffer != '' && w3_is_xml($buffer)) { if ($this->can_cdn2($buffer)) { $regexps = array(); $site_path = w3_get_site_path(); $domain_url_regexp = w3_get_domain_url_regexp(); if ($this->_config->get_boolean('cdn.uploads.enable')) { w3_require_once(W3TC_INC_DIR . '/functions/http.php'); $upload_info = w3_upload_info(); if ($upload_info) { if (preg_match('~' . $domain_url_regexp . '~i', $upload_info['baseurl'])) { $regexps[] = '~(["\'(])\\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($upload_info['baseurlpath']) . '([^"\')>]+)))~'; } else { $parsed = @parse_url($upload_info['baseurl']); $upload_url_domain_regexp = isset($parsed['host']) ? w3_get_url_regexp($parsed['scheme'] . '://' . $parsed['host']) : ''; $baseurlpath = isset($parsed['path']) ? rtrim($parsed['path'], '/') : ''; if ($baseurlpath) { $regexps[] = '~(["\'])\\s*((' . $upload_url_domain_regexp . ')?(' . w3_preg_quote($baseurlpath) . '([^"\'>]+)))~'; } else { $regexps[] = '~(["\'])\\s*((' . $upload_url_domain_regexp . ')([^"\'>]+))~'; } } } } if ($this->_config->get_boolean('cdn.includes.enable')) { $mask = $this->_config->get_string('cdn.includes.files'); if ($mask != '') { $regexps[] = '~(["\'(])\\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . WPINC) . '/(' . $this->get_regexp_by_mask($mask) . ')))~'; } } if ($this->_config->get_boolean('cdn.theme.enable')) { $theme_dir = preg_replace('~' . $domain_url_regexp . '~i', '', get_theme_root_uri()); $mask = $this->_config->get_string('cdn.theme.files'); if ($mask != '') { $regexps[] = '~(["\'(])\\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($theme_dir) . '/(' . $this->get_regexp_by_mask($mask) . ')))~'; } } if ($this->_config->get_boolean('cdn.custom.enable')) { $masks = $this->_config->get_array('cdn.custom.files'); $masks = array_map('w3_parse_path', $masks); if (count($masks)) { $mask_regexps = array(); foreach ($masks as $mask) { if ($mask != '') { $mask = w3_normalize_file($mask); $mask_regexps[] = $this->get_regexp_by_mask($mask); } } $regexps[] = '~(["\'(])\\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path) . '(' . implode('|', $mask_regexps) . ')))~i'; } } foreach ($regexps as $regexp) { $buffer = preg_replace_callback($regexp, array(&$this, 'link_replace_callback'), $buffer); } if ($this->_config->get_boolean('cdn.minify.enable')) { if ($this->_config->get_boolean('minify.auto')) { $regexp = '~(["\'(])\\s*' . $this->_minify_url_regexp('/[a-zA-Z0-9-_]+\\.(css|js)') . '~U'; if (w3_is_cdn_mirror($this->_config->get_string('cdn.engine'))) { $processor = 'link_replace_callback'; } else { $processor = 'minify_auto_pushcdn_link_replace_callback'; } } else { $regexp = '~(["\'(])\\s*' . $this->_minify_url_regexp('/[a-z0-9]+/.+\\.include(-(footer|body))?(-nb)?\\.[a-f0-9]+\\.(css|js)') . '~U'; $processor = 'link_replace_callback'; } $buffer = preg_replace_callback($regexp, array(&$this, $processor), $buffer); } } if ($this->_config->get_boolean('cdn.debug')) { $buffer .= "\r\n\r\n" . $this->get_debug_info(); } } return $buffer; }
/** * Returns server info */ function get_server_info() { global $wp_version, $wp_db_version, $wpdb; $wordpress_plugins = get_plugins(); $wordpress_plugins_active = array(); foreach ($wordpress_plugins as $wordpress_plugin_file => $wordpress_plugin) { if (is_plugin_active($wordpress_plugin_file)) { $wordpress_plugins_active[$wordpress_plugin_file] = $wordpress_plugin; } } $w3tc_config = (array) @(include W3TC_CONFIG_PATH); $mysql_version = (array) $wpdb->get_var('SELECT VERSION()'); $mysql_variables_result = (array) $wpdb->get_results('SHOW VARIABLES', ARRAY_N); $mysql_variables = array(); foreach ($mysql_variables_result as $mysql_variables_row) { $mysql_variables[$mysql_variables_row[0]] = $mysql_variables_row[1]; } return array('wp' => array('version' => $wp_version, 'db_version' => $wp_db_version, 'w3tc_version' => W3TC_VERSION, 'url' => w3_get_domain_url(), 'path' => ABSPATH, 'email' => get_option('admin_email'), 'upload_info' => (array) w3_upload_info(), 'theme' => get_theme(get_current_theme()), 'plugins' => $wordpress_plugins_active, 'wp_cache' => defined('WP_CACHE') ? 'true' : 'false'), 'mysql' => array('version' => $mysql_version, 'variables' => $mysql_variables)); }