/** * Returns full urls for frontpage including older pages * @param int $limit_post_pages default is 10 * @return array */ function get_frontpage_urls($limit_post_pages = 10) { if (!isset($this->frontpage_urls[$limit_post_pages])) { $front_page = get_option('show_on_front'); $full_urls = array(); $home_path = w3_get_home_path(); $site_path = w3_get_site_path(); $full_urls[] = $this->home_url . '/'; if ($site_path != $home_path) { $full_urls[] = w3_get_site_url() . '/'; } if ($front_page == 'posts') { $full_urls = array_merge($full_urls, $this->get_older_pages($home_path, $limit_post_pages)); } $this->frontpage_urls[$limit_post_pages] = $full_urls; } return $this->frontpage_urls[$limit_post_pages]; }
/** * Returns blog path * * Example: * * siteurl=http://domain.com/site/blog * return /site/blog/ * * With trailing slash! * * @return string */ function w3_get_site_path() { $site_url = w3_get_site_url(); $parse_url = @parse_url($site_url); if ($parse_url && isset($parse_url['path'])) { $site_path = '/' . ltrim($parse_url['path'], '/'); } else { $site_path = '/'; } if (substr($site_path, -1) != '/') { $site_path .= '/'; } return $site_path; }
/** * 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); } }
/** * Returns the sitepath for multisite subfolder or subdomain path for multisite subdomain * @return string */ private function _get_multisite_url_identifier() { if (defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) { $parsedUrl = parse_url(w3_get_site_url()); return $parsedUrl['host']; } elseif (w3_is_subdomain_install()) { $parsedUrl = parse_url(w3_get_domain_url()); $urlparts = explode('.', $parsedUrl['host']); if (sizeof($urlparts) > 2) { $subdomain = array_shift($urlparts); return trim($subdomain, '/'); } } return trim(w3_get_site_path(), '/'); }
/** * Returns upload info * * @return array */ function w3_upload_info() { static $upload_info = null; if ($upload_info === null) { $upload_info = @wp_upload_dir(); if (empty($upload_info['error'])) { $site_url = w3_get_site_url(); $upload_info['upload_url'] = trim(str_replace($site_url, '', $upload_info['baseurl']), '/'); $upload_info['upload_dir'] = trim(str_replace(ABSPATH, '', $upload_info['basedir']), '/'); } else { $upload_info = false; } } return $upload_info; }
function print_script() { ?> <script type="text/javascript"> var w3_use_network_link = <?php echo is_network_admin() || w3_is_multisite() && w3_force_master() ? 'true' : 'false'; ?> ; function w3tc_start_minify_try_solve() { var testUrl = '<?php echo w3_filename_to_url(w3_cache_blog_dir('minify') . '/', w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url())); ?> '; w3tc_filename_auto_solve(testUrl); } </script> <?php }
/** * 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; $count = 0; $total = 0; $results = array(); $site_url = w3_get_site_url(); $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['upload_url']) . '([^\'"<>\\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%s', $site_url, $upload_info['upload_url'], $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)); } } } } }
/** * Returns minify groups * @param string $group * @param string $type * @return array */ function get_groups($group, $type) { $result = array(); switch ($type) { case 'css': $groups = $this->_config->get_array('minify.css.groups'); break; case 'js': $groups = $this->_config->get_array('minify.js.groups'); break; default: return $result; } if (isset($groups['default'])) { $locations = (array) $groups['default']; } else { $locations = array(); } if ($group != 'default' && isset($groups[$group])) { $locations = array_merge_recursive($locations, (array) $groups[$group]); } $site_url = w3_get_site_url(); foreach ($locations as $location => $config) { if (!empty($config['files'])) { foreach ((array) $config['files'] as $file) { $file = $this->_normalize_file($file); if (w3_is_url($file)) { $precached_file = $this->_precache_file($file, $type); if ($precached_file) { $result[$location][$file] = $precached_file; } } else { $result[$location][$file] = '//' . $file; } } } } return $result; }
/** * Send support request */ function support_request() { require_once W3TC_LIB_W3_DIR . '/Request.php'; $url = W3_Request::get_string('url'); $name = W3_Request::get_string('name'); $email = W3_Request::get_string('email'); $request_type = W3_Request::get_string('request_type'); $description = W3_Request::get_string('description'); $templates = W3_Request::get_array('templates'); $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'); $params = array('url' => $url, 'name' => $name, 'email' => $email, 'request_type' => $request_type, 'description' => $description, 'wp_login' => $wp_login, 'wp_password' => $wp_password, 'ftp_host' => $ftp_host, 'ftp_login' => $ftp_login, 'ftp_password' => $ftp_password); foreach ($templates as $template_index => $template) { $template_key = sprintf('templates[%d]', $template_index); $params[$template_key] = $template; } if ($url == '') { $this->redirect(array_merge($params, array('error' => 'support_request_url'))); } if ($name == '') { $this->redirect(array_merge($params, array('error' => 'support_request_name'))); } if (!preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) { $this->redirect(array_merge($params, array('error' => 'support_request_email'))); } if ($request_type == '') { $this->redirect(array_merge($params, array('error' => 'support_request_type'))); } if ($description == '') { $this->redirect(array_merge($params, array('error' => 'support_request_description'))); } if ($wp_login != '' || $wp_password != '') { if ($wp_login == '') { $this->redirect(array_merge($params, array('error' => 'support_request_wp_login'))); } if ($wp_password == '') { $this->redirect(array_merge($params, array('error' => 'support_request_wp_password'))); } } if ($ftp_host != '' || $ftp_login != '' || $ftp_password != '') { if ($ftp_host == '') { $this->redirect(array_merge($params, array('error' => 'support_request_ftp_host'))); } if ($ftp_login == '') { $this->redirect(array_merge($params, array('error' => 'support_request_ftp_login'))); } if ($ftp_password == '') { $this->redirect(array_merge($params, array('error' => 'support_request_ftp_password'))); } } /** * Add attachments */ $attachments = array(W3TC_CONFIG_PATH); /** * 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_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_TMP_DIR . '/php_info.html'; if (@file_put_contents($php_info_path, $php_info)) { $attachments[] = $php_info_path; } /** * Attach minify log */ if (file_exists(W3TC_MINIFY_LOG_FILE)) { $attachments[] = W3TC_MINIFY_LOG_FILE; } /** * 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_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('%sw3tc_request_data/%s', w3_get_site_url(), $hash); } else { $request_data_url = null; } /** * Get body contents */ ob_start(); include W3TC_DIR . '/inc/options/support_email.phtml'; $body = ob_get_contents(); ob_end_clean(); /** * Send email */ $subject = sprintf('W3TC Support Request: %s', $request_type); $headers = array(sprintf('From: "%s" <%s>', addslashes($name), $email), sprintf('Reply-To: "%s" <%s>', addslashes($name), $email), 'Content-Type: text/html; charset=UTF-8'); $this->_phpmailer_sender = $email; add_action('phpmailer_init', array(&$this, 'phpmailer_init')); set_time_limit(600); $result = @wp_mail(W3TC_EMAIL, $subject, $body, implode("\n", $headers), $attachments); /** * Remove temporary files */ foreach ($attachments as $attachment) { if (strstr($attachment, W3TC_TMP_DIR) !== false) { @unlink($attachment); } } if ($result) { $this->redirect(array('note' => 'support_request')); } else { $this->redirect(array_merge($params, array('error' => 'support_request'))); } }
/** * 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(); $site_domain_url_regexp = false; if ($domain_url_regexp != w3_get_url_regexp(w3_get_domain(w3_get_site_url()))) { $site_domain_url_regexp = w3_get_url_regexp(w3_get_domain(w3_get_site_url())); } 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) { $baseurl = $upload_info['baseurl']; if (defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) { $parsed = @parse_url($upload_info['baseurl']); $baseurl = home_url() . $parsed['path']; } $regexps = $this->make_uploads_regexes($domain_url_regexp, $baseurl, $upload_info, $regexps); if ($site_domain_url_regexp) { $regexps = $this->make_uploads_regexes($site_domain_url_regexp, $baseurl, $upload_info, $regexps); } } } 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 ($site_domain_url_regexp) { $regexps[] = '~(["\'(])\\s*((' . $site_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 ($site_domain_url_regexp) { $theme_dir2 = preg_replace('~' . $site_domain_url_regexp . '~i', '', get_theme_root_uri()); $regexps[] = '~(["\'(])\\s*((' . $site_domain_url_regexp . ')?(' . w3_preg_quote($theme_dir) . '/(' . $this->get_regexp_by_mask($mask) . ')))~'; $regexps[] = '~(["\'(])\\s*((' . $site_domain_url_regexp . ')?(' . w3_preg_quote($theme_dir2) . '/(' . $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(array($this, '_replace_folder_placeholders'), $masks); $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'; if ($site_domain_url_regexp) { $regexps[] = '~(["\'(])\\s*((' . $site_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; }