/**
  * Extensions view
  *
  * @return void
  */
 function view()
 {
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/compat.php');
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php');
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/extensions.php');
     $extension = '';
     $extension_status = 'all';
     if (isset($_GET['extension_status'])) {
         if (in_array($_GET['extension_status'], array('all', 'active', 'inactive', 'core'))) {
             $extension_status = $_GET['extension_status'];
         }
     }
     if (isset($_GET['extension'])) {
         $extension = $_GET['extension'];
     }
     $extensions_active = w3_get_active_extensions($this->_config);
     if ($extension) {
         $all_settings = $this->_config->get_array('extensions.settings');
         $extensions_active = w3_get_active_extensions($this->_config);
         $meta = $extensions_active[$extension];
         $sub_view = 'settings';
     } else {
         $extensions_all = w3_get_extensions($this->_config);
         $extensions_inactive = w3_get_inactive_extensions($this->_config);
         $var = "extensions_{$extension_status}";
         $extensions = ${$var};
         $sub_view = 'list';
         $page = 1;
     }
     include W3TC_INC_OPTIONS_DIR . '/extensions.php';
 }
 /**
  * Activate plugin action
  *
  * @return void
  */
 function activate($network_wide)
 {
     w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
     if (w3_is_network()) {
         if ($network_wide) {
             // we are in network activation
         } else {
             if ($_GET['action'] == 'error_scrape' && strpos($_SERVER['REQUEST_URI'], '/network/') !== false) {
                 // workaround for error_scrape page called after error
                 // really we are in network activation and going to throw some error
             } else {
                 echo 'Please <a href="' . network_admin_url('plugins.php') . '">network activate</a> W3 Total Cache when using WordPress Multisite.';
                 die;
             }
         }
     }
     /**
      * Create cache folder and extension files
      */
     try {
         w3_activation_create_required_files();
         if (!$this->_config->own_config_exists()) {
             $this->_config->save();
         }
         // save admin config
         $admin_config = w3_instance('W3_ConfigAdmin');
         if (!$admin_config->own_config_exists()) {
             $admin_config->save();
         }
     } catch (Exception $e) {
         w3_activation_error_on_exception($e);
     }
     delete_option('w3tc_request_data');
     add_option('w3tc_request_data', '', null, 'no');
 }
Example #3
0
 function run()
 {
     add_action('w3tc_dashboard_setup', array(&$this, 'wp_dashboard_setup'));
     add_action('w3tc_network_dashboard_setup', array(&$this, 'wp_dashboard_setup'));
     // Configure authorize and have_zone
     $this->_setup($this->_config);
     /**
      * Retry setup with main blog
      */
     if (w3_is_network() && is_network_admin() && !$this->authorized) {
         $this->_config = new W3_Config(false, 1);
         $this->_setup($this->_config);
     }
     if (w3_is_network()) {
         $conig_admin = w3_instance('W3_ConfigAdmin');
         $this->_sealed = $conig_admin->get_boolean('cdn.configuration_sealed');
     }
     if ($this->have_zone && $this->authorized && isset($_GET['page']) && strpos($_GET['page'], 'w3tc_dashboard') !== false) {
         w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php');
         w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNAPresentation.php');
         $authorization_key = $this->_config->get_string('cdn.netdna.authorization_key');
         $alias = $consumerkey = $consumersecret = '';
         $keys = explode('+', $authorization_key);
         if (sizeof($keys) == 3) {
             list($alias, $consumerkey, $consumersecret) = $keys;
         }
         $this->api = new NetDNA($alias, $consumerkey, $consumersecret);
         add_action('admin_head', array(&$this, 'admin_head'));
     }
 }
Example #4
0
 /**
  * Add line numbers in C-style comments
  *
  * This uses a very basic parser easily fooled by comment tokens inside
  * strings or regexes, but, otherwise, generally clean code will not be
  * mangled. URI rewriting can also be performed.
  *
  * @param string $content
  *
  * @param array $options available options:
  *
  * 'id': (optional) string to identify file. E.g. file name/path
  *
  * 'currentDir': (default null) if given, this is assumed to be the
  * directory of the current CSS file. Using this, minify will rewrite
  * all relative URIs in import/url declarations to correctly point to
  * the desired files, and prepend a comment with debugging information about
  * this process.
  *
  * @return string
  */
 public static function minify($content, $options = array())
 {
     $id = isset($options['id']) && $options['id'] ? $options['id'] : '';
     $content = str_replace("\r\n", "\n", $content);
     $lines = explode("\n", $content);
     $numLines = count($lines);
     // determine left padding
     $padTo = strlen($numLines);
     $inComment = false;
     $i = 0;
     $newLines = array();
     while (null !== ($line = array_shift($lines))) {
         if ('' !== $id && 0 == $i % 50) {
             array_push($newLines, '', "/* {$id} */", '');
         }
         ++$i;
         $newLines[] = self::_addNote($line, $i, $inComment, $padTo);
         $inComment = self::_eolInComment($line, $inComment);
     }
     $content = implode("\n", $newLines) . "\n";
     // check for desired URI rewriting
     w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php');
     $content = Minify_CSS_UriRewriter::rewrite($content, $options);
     return $content;
 }
 public static function minifyCss($css, $options = array())
 {
     w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php');
     $css = self::_minify('css', $css, $options);
     $css = Minify_CSS_UriRewriter::rewrite($css, $options);
     return $css;
 }
 /**
  * Support tab
  *
  * @return void
  */
 function view()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_Request::get_string('request_type');
     $payment = W3_Request::get_boolean('payment');
     include W3TC_INC_DIR . '/options/support.php';
 }
 /**
  * Dashboard tab
  */
 function view()
 {
     w3_require_once(W3TC_INC_DIR . '/functions/widgets.php');
     /**
      * @var $module_status W3_ModuleStatus
      */
     $module_status = w3_instance('W3_ModuleStatus');
     w3tc_dashboard_setup();
     global $current_user;
     $config_master = $this->_config_master;
     $browsercache_enabled = $module_status->is_enabled('browsercache');
     $cloudflare_enabled = $module_status->is_enabled('cloudflare');
     $enabled = $module_status->plugin_is_enabled();
     $can_empty_memcache = $module_status->can_empty_memcache();
     $can_empty_opcode = $module_status->can_empty_opcode();
     $can_empty_apc_system = $module_status->can_empty_apc_system();
     $can_empty_file = $module_status->can_empty_file();
     $can_empty_varnish = $module_status->can_empty_varnish();
     $cdn_enabled = $module_status->is_enabled('cdn');
     $cdn_mirror_purge = w3_cdn_can_purge_all($module_status->get_module_engine('cdn'));
     if ($cloudflare_enabled && $this->_config->get_string('cloudflare.email') && $this->_config->get_string('cloudflare.key')) {
         $can_empty_cloudflare = true;
     } else {
         $can_empty_cloudflare = false;
     }
     // Required for Update Media Query String button
     $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace');
     include W3TC_INC_DIR . '/options/dashboard.php';
 }
Example #8
0
function w3tc_cancel_button($note, $classes = '', $custom_method = 'w3tc_default_hide_note')
{
    w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
    $page = W3_Request::get_string('page', 'w3tc_dashboard');
    $url = sprintf('admin.php?page=%s&%s&note=%s', $page, $custom_method, $note);
    $url = wp_nonce_url($url, 'w3tc');
    return w3_button_link(__('Cancel'), $url, false, $classes);
}
Example #9
0
 /**
  * General tab
  *
  * @return void
  */
 function view()
 {
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php');
     global $current_user;
     $config_master = $this->_config_master;
     /**
      * @var $modules W3_ModuleStatus
      */
     $modules = w3_instance('W3_ModuleStatus');
     $pgcache_enabled = $modules->is_enabled('pgcache');
     $dbcache_enabled = $modules->is_enabled('dbcache');
     $objectcache_enabled = $modules->is_enabled('objectcache');
     $browsercache_enabled = $modules->is_enabled('browsercache');
     $minify_enabled = $modules->is_enabled('minify');
     $cdn_enabled = $modules->is_enabled('cdn');
     $varnish_enabled = $modules->is_enabled('varnish');
     $fragmentcache_enabled = $modules->is_enabled('fragmentcache');
     $enabled = $modules->plugin_is_enabled();
     $enabled_checkbox = $modules->all_modules_enabled();
     $check_rules = w3_can_check_rules();
     $check_apc = function_exists('apc_store');
     $check_eaccelerator = function_exists('eaccelerator_put');
     $check_xcache = function_exists('xcache_set');
     $check_wincache = function_exists('wincache_ucache_set');
     $check_curl = function_exists('curl_init');
     $check_memcached = class_exists('Memcache');
     $check_ftp = function_exists('ftp_connect');
     $check_tidy = class_exists('tidy');
     $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && w3_is_network() && $config_master->get_string('pgcache.engine') != 'file_generic');
     $can_empty_file = $modules->can_empty_file();
     $can_empty_varnish = $modules->can_empty_varnish();
     $cdn_mirror_purge = w3_cdn_can_purge_all($modules->get_module_engine('cdn'));
     $file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs');
     $file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking');
     w3_require_once(W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php');
     $newrelic_conf_appname = NewRelicWrapper::get_wordpress_appname($this->_config, $this->_config_master, false);
     $newrelic_applications = array();
     $nerser = w3_instance('W3_NewRelicService');
     $new_relic_installed = $nerser->module_is_enabled();
     $new_relic_running = true;
     if ($this->_config->get_boolean('newrelic.enabled')) {
         $new_relic_configured = $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.account_id');
         $newrelic_prefix = '';
         if ($new_relic_configured) {
             if (w3_is_network()) {
                 $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix');
             }
             try {
                 $newrelic_applications = $nerser->get_applications();
             } catch (Exception $ex) {
             }
             $newrelic_application = $this->_config->get_string('newrelic.application_id');
         }
     }
     $licensing_visible = (!w3_is_multisite() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
     $custom_areas = apply_filters("{$this->_page}_anchors", array());
     include W3TC_INC_DIR . '/options/general.php';
 }
 /**
  * @throws Exception
  */
 function action_extensions_activate()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $extension = W3_Request::get_string('w3tc_extensions_activate');
     if ($extension) {
         w3tc_activate_extension($extension, $this->_config);
     }
     w3_admin_redirect(array('w3tc_note' => 'extension_activated'));
 }
Example #11
0
 /**
  * Latest widget control
  *
  * @param integer $widget_id
  * @param array $form_inputs
  * @return void
  */
 function widget_pagespeed_control($widget_id, $form_inputs = array())
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
         $this->_config->set('widget.pagespeed.key', W3_Request::get_string('w3tc_widget_pagespeed_key'));
         $this->_config->save();
     }
     include W3TC_INC_DIR . '/widget/pagespeed_control.php';
 }
Example #12
0
/**
 * Updates the plugin from older version.
 */
function w3_run_legacy_update()
{
    w3_require_once(W3TC_LIB_W3_DIR . '/ConfigWriter.php');
    $writer = new W3_ConfigWriter(w3_get_blog_id(), w3_is_preview_mode());
    $writer->import_legacy_config_and_save();
    // Only remove folders when master blog is running.
    if (w3_get_blog_id() == 0) {
        w3_remove_old_folders();
    }
}
Example #13
0
 function cleanup()
 {
     $engine = $this->_config->get_string('fragmentcache.engine');
     switch ($engine) {
         case 'file':
             w3_require_once(W3TC_LIB_W3_DIR . '/Cache/File/Cleaner.php');
             $w3_cache_file_cleaner = new W3_Cache_File_Cleaner(array('cache_dir' => w3_cache_blog_dir('fragment'), 'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')));
             $w3_cache_file_cleaner->clean();
             break;
     }
 }
Example #14
0
 function action_payment_code()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_Request::get_string('request_type');
     $request_id = date('YmdHi');
     $return_url = admin_url('admin.php?page=w3tc_support&request_type=' . $request_type . '&payment=1&request_id=' . $request_id);
     $cancel_url = admin_url('admin.php?page=w3tc_dashboard');
     $form_values = array("cmd" => "_xclick", "business" => W3TC_PAYPAL_BUSINESS, "item_name" => esc_attr(sprintf('%s: %s (#%s)', ucfirst(w3_get_host()), $this->_json_request_types[$request_type], $request_id)), "amount" => sprintf('%.2f', $this->_request_prices[$request_type]), "currency_code" => "USD", "no_shipping" => "1", "rm" => "2", "return" => esc_attr($return_url), "cancel_return" => esc_attr($cancel_url));
     echo json_encode($form_values);
     die;
 }
Example #15
0
 /**
  * @see Minify_Controller_Base::loadMinifier()
  */
 public function loadMinifier($minifierCallback)
 {
     if ($this->_loadCssJsMinifiers) {
         // Minify will not call for these so we must manually load
         // them when Minify/HTML.php is called for.
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSS.php');
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/JSMin.php');
     }
     parent::loadMinifier($minifierCallback);
     // load Minify/HTML.php
 }
Example #16
0
 /**
  * Make API request
  *
  * @param string $url
  * @return string
  */
 function _request($url)
 {
     w3_require_once(W3TC_INC_DIR . '/functions/http.php');
     w3_require_once(W3TC_INC_DIR . '/functions/url.php');
     $request_url = w3_url_format(W3TC_PAGESPEED_API_URL, array('url' => $url, 'key' => $this->key));
     $response = w3_http_get($request_url);
     if (!is_wp_error($response) && $response['response']['code'] == 200) {
         return $response['body'];
     }
     return false;
 }
Example #17
0
 function action_widget_link_support()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $value = W3_Request::get_string('w3tc_common_support_us');
     $this->_config->set('common.support', $value);
     $this->_config->save();
     if ($value) {
         _e('Thank you for linking to us!', 'w3-total-cache');
     } else {
         _e('You are no longer linking to us. Please support us in other ways instead.', 'w3-total-cache');
     }
     die;
 }
Example #18
0
 /**
  * Minify a CSS string
  *
  * @param string $css
  *
  * @param array $options available options:
  *
  * 'preserveComments': (default true) multi-line comments that begin
  * with "/*!" will be preserved with newlines before and after to
  * enhance readability.
  *
  * 'prependRelativePath': (default null) if given, this string will be
  * prepended to all relative URIs in import/url declarations
  *
  * 'currentDir': (default null) if given, this is assumed to be the
  * directory of the current CSS file. Using this, minify will rewrite
  * all relative URIs in import/url declarations to correctly point to
  * the desired files. For this to work, the files *must* exist and be
  * visible by the PHP process.
  *
  * 'symlinks': (default = array()) If the CSS file is stored in
  * a symlink-ed directory, provide an array of link paths to
  * target paths, where the link paths are within the document root. Because
  * paths need to be normalized for this to work, use "//" to substitute
  * the doc root in the link paths (the array keys). E.g.:
  * <code>
  * array('//symlink' => '/real/target/path') // unix
  * array('//static' => 'D:\\staticStorage')  // Windows
  * </code>
  *
  * @return string
  */
 public static function minify($css, $options = array())
 {
     w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSS/Compressor.php');
     if (isset($options['preserveComments']) && $options['preserveComments']) {
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CommentPreserver.php');
         $css = Minify_CommentPreserver::process($css, array('Minify_CSS_Compressor', 'process'), array($options));
     } else {
         $css = Minify_CSS_Compressor::process($css, $options);
     }
     w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php');
     $css = Minify_CSS_UriRewriter::rewrite($css, $options);
     return $css;
 }
Example #19
0
 /**
  * Returns cache engine instance
  *
  * @param string $engine
  * @param array $config
  * @return W3_Cache_Base
  */
 static function instance($engine, $config = array())
 {
     static $instances = array();
     // common configuration data
     if (!isset($config['blog_id'])) {
         $config['blog_id'] = w3_get_blog_id();
     }
     $instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
     if (!isset($instances[$instance_key])) {
         switch ($engine) {
             case W3TC_CACHE_MEMCACHED:
                 w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Memcached.php');
                 $instances[$instance_key] = new W3_Cache_Memcached($config);
                 break;
             case W3TC_CACHE_APC:
                 w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Apc.php');
                 $instances[$instance_key] = new W3_Cache_Apc($config);
                 break;
             case W3TC_CACHE_EACCELERATOR:
                 w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Eaccelerator.php');
                 $instances[$instance_key] = new W3_Cache_Eaccelerator($config);
                 break;
             case W3TC_CACHE_XCACHE:
                 w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Xcache.php');
                 $instances[$instance_key] = new W3_Cache_Xcache($config);
                 break;
             case W3TC_CACHE_WINCACHE:
                 w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Wincache.php');
                 $instances[$instance_key] = new W3_Cache_Wincache($config);
                 break;
             case W3TC_CACHE_FILE:
                 w3_require_once(W3TC_LIB_W3_DIR . '/Cache/File.php');
                 $instances[$instance_key] = new W3_Cache_File($config);
                 break;
             case W3TC_CACHE_FILE_GENERIC:
                 w3_require_once(W3TC_LIB_W3_DIR . '/Cache/File/Generic.php');
                 $instances[$instance_key] = new W3_Cache_File_Generic($config);
                 break;
             default:
                 trigger_error('Incorrect cache engine', E_USER_WARNING);
                 w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Base.php');
                 $instances[$instance_key] = new W3_Cache_Base($config);
                 break;
         }
         if (!$instances[$instance_key]->available()) {
             w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Base.php');
             $instances[$instance_key] = new W3_Cache_Base($config);
         }
     }
     return $instances[$instance_key];
 }
Example #20
0
 /**
  * Purges remote files
  *
  * @param array $files
  * @param array $results
  * @return boolean
  */
 function purge($files, &$results)
 {
     if (empty($this->_config['username'])) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, __('Empty username.', 'w3-total-cache'));
         return false;
     }
     if (empty($this->_config['password'])) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, __('Empty password.', 'w3-total-cache'));
         return false;
     }
     w3_require_once(W3TC_LIB_NUSOAP_DIR . '/nusoap.php');
     $client = new nusoap_client(W3TC_CDN_MIRROR_AKAMAI_WSDL, 'wsdl');
     $error = $client->getError();
     if ($error) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf(__('Constructor error (%s).', 'w3-total-cache'), $error));
         return false;
     }
     $zone = $this->_config['zone'];
     $expressions = array();
     foreach ($files as $file) {
         $remote_path = $file['remote_path'];
         $expressions[] = $this->_format_url($remote_path);
     }
     $action = $this->_config['action'];
     $email = $this->_config['email_notification'];
     $email = implode(',', $email);
     $options = array('action=' . $action, 'domain=' . $zone, 'type=arl');
     if ($email) {
         $options[] = 'email-notification=' . $email;
     }
     $params = array($this->_config['username'], $this->_config['password'], '', $options, $expressions);
     $result = $client->call('purgeRequest', $params, W3TC_CDN_MIRROR_AKAMAI_NAMESPACE);
     if ($client->fault) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, __('Invalid response.', 'w3-total-cache'));
         return false;
     }
     $result_code = $result['resultCode'];
     $result_message = $result['resultMsg'];
     $error = $client->getError();
     if ($error) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf(__('Unable to purge (%s).', 'w3-total-cache'), $error));
         return false;
     }
     if ($result_code >= 300) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf(__('Unable to purge (%s).', 'w3-total-cache'), $result_message));
         return false;
     }
     $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, __('OK', 'w3-total-cache'));
     return true;
 }
Example #21
0
 /**
  * Purge the CloudFlare cache
  * @return void
  */
 function flush_cloudflare()
 {
     $response = null;
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $email = $this->_config->get_string('email');
     $key = $this->_config->get_string('key');
     $zone = $this->_config->get_string('zone');
     if ($email && $key && $zone) {
         $config = array('email' => $email, 'key' => $key, 'zone' => $zone);
         w3_require_once(W3TC_CORE_EXTENSION_DIR . '/CloudFlare/CloudFlareAPI.php');
         @($cloudflareAPI = new CloudFlareAPI($config));
         $cloudflareAPI->purge();
     }
 }
Example #22
0
 /**
  * @param W3_Config $config
  * @param W3_ConfigAdmin|null $config_admin
  * @return array
  */
 function notifications($config, $config_admin)
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $page = W3_Request::get_string('page');
     $notes = array();
     if (!w3_is_cdn_mirror($config->get_string('cdn.engine'))) {
         /**
          * Show notification after theme change
          */
         if ($config->get_boolean('notes.theme_changed')) {
             $notes[] = sprintf(__('The active theme has changed, please %s now to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup(__('upload active theme files', 'w3-total-cache'), 'cdn_export', 'cdn_export_type=theme'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'theme_changed'));
         }
         /**
          * Show notification after WP upgrade
          */
         if ($config->get_boolean('notes.wp_upgraded')) {
             $notes[] = sprintf(__('Upgraded WordPress? Please %s files now to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup('upload wp-includes', 'cdn_export', 'cdn_export_type=includes'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'wp_upgraded'));
         }
         /**
          * Show notification after CDN enable
          */
         if ($config->get_boolean('notes.cdn_upload') || $config->get_boolean('notes.cdn_reupload')) {
             $cdn_upload_buttons = array();
             if ($config->get_boolean('cdn.includes.enable')) {
                 $cdn_upload_buttons[] = w3_button_popup('wp-includes', 'cdn_export', 'cdn_export_type=includes');
             }
             if ($config->get_boolean('cdn.theme.enable')) {
                 $cdn_upload_buttons[] = w3_button_popup('theme files', 'cdn_export', 'cdn_export_type=theme');
             }
             if ($config->get_boolean('minify.enabled') && $config->get_boolean('cdn.minify.enable') && !$config->get_boolean('minify.auto')) {
                 $cdn_upload_buttons[] = w3_button_popup('minify files', 'cdn_export', 'cdn_export_type=minify');
             }
             if ($config->get_boolean('cdn.custom.enable')) {
                 $cdn_upload_buttons[] = w3_button_popup('custom files', 'cdn_export', 'cdn_export_type=custom');
             }
             if ($config->get_boolean('notes.cdn_upload')) {
                 $notes[] = sprintf(__('Make sure to %s and upload the %s, files to the <acronym title="Content Delivery Network">CDN</acronym> to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup('export the media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), w3_button_hide_note('Hide this message', 'cdn_upload'));
             }
             if ($config->get_boolean('notes.cdn_reupload')) {
                 $notes[] = sprintf(__('Settings that affect Browser Cache settings for files hosted by the CDN have been changed. To apply the new settings %s and %s. %s', 'w3-total-cache'), w3_button_popup(__('export the media library', 'w3-total-cache'), 'cdn_export_library'), implode(', ', $cdn_upload_buttons), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'cdn_reupload'));
             }
         }
     }
     if (in_array($config->get_string('cdn.engine'), array('netdna', 'maxcdn')) && $config_admin->get_boolean('notes.maxcdn_whitelist_ip') && $config_admin->get_integer('track.maxcdn_authorize') == 0 && $config->get_string('cdn.' . $config->get_string('cdn.engine') . '.authorization_key')) {
         $notes[] = sprintf(__('Make sure to whitelist your servers IPs. Follow the instructions on %s. The IP for this server is %s. %s', 'w3-total-cache'), '<a href="http://support.maxcdn.com/tutorials/how-to-whitelist-your-server-ip-to-use-the-api/">MaxCDN</a>', $_SERVER['SERVER_ADDR'], w3_button_hide_note('Hide this message', 'maxcdn_whitelist_ip', '', true));
     }
     return $notes;
 }
Example #23
0
/**
 * Returns hide note button html
 *
 * @param string $text
 * @param string $note
 * @param string $redirect
 * @param boolean $admin if to use config admin
 * @param string $page
 * @return string
 */
function w3_button_hide_note($text, $note, $redirect = '', $admin = false, $page = '')
{
    if ($page == '') {
        w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
        $page = W3_Request::get_string('page', 'w3tc_dashboard');
    }
    $url = sprintf('admin.php?page=%s&w3tc_default_hide_note&note=%s', $page, $note);
    if ($admin) {
        $url .= '&admin=1';
    }
    if ($redirect != '') {
        $url .= '&redirect=' . urlencode($redirect);
    }
    $url = wp_nonce_url($url, 'w3tc');
    return w3_button_link($text, $url);
}
Example #24
0
 public static function minify($css, $options = array())
 {
     $options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
     set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_CSSTIDY_DIR);
     require_once 'class.csstidy.php';
     $csstidy = new csstidy();
     foreach ($options as $option => $value) {
         $csstidy->set_cfg($option, $value);
     }
     $csstidy->load_template($options['template']);
     $csstidy->parse($css);
     $css = $csstidy->print->plain();
     w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php');
     $css = Minify_CSS_UriRewriter::rewrite($css, $options);
     return $css;
 }
Example #25
0
 /**
  * Purges remote files
  *
  * @param array $files
  * @param array $results
  * @return boolean
  */
 function purge($files, &$results)
 {
     if (empty($this->_config['username'])) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty username.');
         return false;
     }
     if (empty($this->_config['password'])) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty password.');
         return false;
     }
     if (empty($this->_config['zones'])) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty zones list.');
         return false;
     }
     w3_require_once(W3TC_LIB_NUSOAP_DIR . '/nusoap.php');
     $client = new nusoap_client(W3TC_CDN_MIRROR_COTENDO_WSDL, 'wsdl');
     $error = $client->getError();
     if ($error) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Constructor error (%s).', $error));
         return false;
     }
     $client->authtype = 'basic';
     $client->username = $this->_config['username'];
     $client->password = $this->_config['password'];
     $client->forceEndpoint = W3TC_CDN_MIRROR_COTENDO_ENDPOINT;
     foreach ((array) $this->_config['zones'] as $zone) {
         $expressions = array();
         foreach ($files as $file) {
             $remote_path = $file['remote_path'];
             $expressions[] = '/' . $remote_path;
         }
         $expression = implode("\n", $expressions);
         $params = array('cname' => $zone, 'flushExpression' => $expression, 'flushType' => 'hard');
         $client->call('doFlush', $params, W3TC_CDN_MIRROR_COTENDO_NAMESPACE);
         if ($client->fault) {
             $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Invalid response.');
             return false;
         }
         $error = $client->getError();
         if ($error) {
             $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Unable to purge (%s).', $error));
             return false;
         }
     }
     $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
     return true;
 }
Example #26
0
 /**
  * @throws Exception
  */
 function action_aws_sns_subscribe()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $topic_arn = W3_Request::get_string('cluster_messagebus_sns_topic_arn_subscribe');
     /**
      * @var W3_Enterprise_SnsClient $sns_client
      */
     $sns_client = w3_instance('W3_Enterprise_SnsClient');
     $sns_client->subscribe(plugins_url('pub/sns.php', W3TC_FILE), $topic_arn);
     try {
         $this->_config->set('cluster.messagebus.sns.topic_arn', $topic_arn);
         $this->_config->save();
     } catch (Exception $ex) {
         throw new Exception('<strong>Can\'t change configuration</strong>: ' . $ex->getMessage());
     }
     w3_admin_redirect(array('w3tc_note' => 'sns_subscribed'));
 }
Example #27
0
 /**
  * Returns API object
  *
  * @throws Exception
  * @return AmazonSNS
  */
 protected function _get_api()
 {
     if (is_null($this->_api)) {
         if ($this->_api_key == '') {
             throw new Exception('API Key is not configured');
         }
         if ($this->_api_secret == '') {
             throw new Exception('API Secret is not configured');
         }
         w3_require_once(W3TC_LIB_DIR . '/SNS/sdk.class.php');
         $this->_api = new AmazonSNS($this->_api_key, $this->_api_secret);
         if ($this->_region != '') {
             $this->_api->set_region($this->_region);
         }
     }
     return $this->_api;
 }
Example #28
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);
    }
}
Example #29
0
 function change_filename_length()
 {
     try {
         w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
         $new = W3_Request::get_integer('maxlength');
         $this->_config->set('minify.auto.filename_length', $new);
         set_transient('w3tc_minify_tested_filename_length', true, 3600 * 24);
         $this->_config->save();
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php');
         $cache = new Minify_Cache_File(w3_cache_blog_dir('minify'), array('.htaccess', 'index.php', '*.old'), $this->_config->get_boolean('minify.file.locking'), $this->_config->get_integer('timelimit.cache_flush'), w3_get_blog_id() == 0 ? W3TC_CACHE_MINIFY_DIR : null);
         $cache->flush();
         echo 1;
     } catch (Exception $ex) {
         echo $ex->getMessage();
     }
     exit;
 }
Example #30
0
 /**
  * @throws FilesystemWriteException
  * @throws FilesystemWriteException
  */
 public function create()
 {
     $path = trim(w3_get_wp_sitepath(), "/");
     if ($path) {
         $path .= '/';
     }
     $file_data = "\n<?php\n    if (W3TC_WP_LOADING)\n        require_once '" . w3_get_document_root() . '/' . $path . "wp-load.php';\n";
     $filename = W3TC_WP_LOADER;
     $data = $file_data;
     w3_require_once(W3TC_INC_DIR . '/functions/rule.php');
     $current_data = @file_get_contents($filename);
     if (strstr(w3_clean_rules($current_data), w3_clean_rules($data)) !== false) {
         return;
     }
     w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
     w3_wp_write_to_file($filename, $data, '', $_SERVER['REQUEST_URI']);
 }