* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7541 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminPerformance extends AdminTab { public function postProcess() { global $currentIndex; if (Tools::isSubmit('submitCaching')) { if ($this->tabAccess['edit'] === '1') { $settings = file_get_contents(dirname(__FILE__).'/../../config/settings.inc.php'); if (!Tools::getValue('active')) $cache_active = 0; else $cache_active = 1; if (!$caching_system = Tools::getValue('caching_system')) $this->_errors[] = Tools::displayError('Caching system is missing'); else $settings = preg_replace('/define\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\/+-_]+)\'\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \''.$caching_system.'\');', $settings); if ($cache_active AND $caching_system == 'MCached' AND !extension_loaded('memcache')) $this->_errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.').' http://www.php.net/manual/en/memcache.installation.php'; elseif ($cache_active AND $caching_system == 'CacheFS' AND !is_writable(_PS_CACHEFS_DIRECTORY_)) $this->_errors[] = Tools::displayError('To use CacheFS the directory').' '.realpath(_PS_CACHEFS_DIRECTORY_).' '.Tools::displayError('must be writable'); if ($caching_system == 'CacheFS') { if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) $this->_errors[] = Tools::displayError('Please set a directory depth'); if (!sizeof($this->_errors)) { CacheFS::deleteCacheDirectory(); CacheFS::createCacheDirectories((int)$depth); Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int)$depth); } } if (!sizeof($this->_errors)) { $settings = preg_replace('/define\(\'_PS_CACHE_ENABLED_\', \'([0-9])\'\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \''.(int)$cache_active.'\');', $settings); if (file_put_contents(dirname(__FILE__).'/../../config/settings.inc.php', $settings)) Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4'); else $this->_errors[] = Tools::displayError('Cannot overwrite settings file.'); } } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } if (Tools::isSubmit('submitAddServer')) { if ($this->tabAccess['add'] === '1') { if (!Tools::getValue('memcachedIp')) $this->_errors[] = Tools::displayError('Memcached IP is missing'); if (!Tools::getValue('memcachedPort')) $this->_errors[] = Tools::displayError('Memcached port is missing'); if (!Tools::getValue('memcachedWeight')) $this->_errors[] = Tools::displayError('Memcached weight is missing'); if (!sizeof($this->_errors)) { if (MCached::addServer(pSQL(Tools::getValue('memcachedIp')), (int)Tools::getValue('memcachedPort'), (int)Tools::getValue('memcachedWeight'))) Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4'); else $this->_errors[] = Tools::displayError('Cannot add Memcached server'); } } else $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } if (Tools::getValue('deleteMemcachedServer')) { if ($this->tabAccess['add'] === '1') { if (MCached::deleteServer((int)Tools::getValue('deleteMemcachedServer'))) Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4'); else $this->_errors[] = Tools::displayError('Error in deleting Memcached server'); } else $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } if (Tools::isSubmit('submitCiphering') AND Configuration::get('PS_CIPHER_ALGORITHM') != (int)Tools::getValue('PS_CIPHER_ALGORITHM')) { if ($this->tabAccess['edit'] === '1') { $algo = (int)Tools::getValue('PS_CIPHER_ALGORITHM'); $settings = file_get_contents(dirname(__FILE__).'/../../config/settings.inc.php'); if ($algo) { if (!function_exists('mcrypt_encrypt')) $this->_errors[] = Tools::displayError('Mcrypt is not activated on this server.'); else { if (!strstr($settings, '_RIJNDAEL_KEY_')) { $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $key = Tools::passwdGen($key_size); $settings = preg_replace('/define\(\'_COOKIE_KEY_\', \'([a-z0-9=\/+-_]+)\'\);/i', 'define(\'_COOKIE_KEY_\', \'\1\');'."\n".'define(\'_RIJNDAEL_KEY_\', \''.$key.'\');', $settings); } if (!strstr($settings, '_RIJNDAEL_IV_')) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND)); $settings = preg_replace('/define\(\'_COOKIE_IV_\', \'([a-z0-9=\/+-_]+)\'\);/i', 'define(\'_COOKIE_IV_\', \'\1\');'."\n".'define(\'_RIJNDAEL_IV_\', \''.$iv.'\');', $settings); } } } if (!count($this->_errors)) { if (file_put_contents(dirname(__FILE__).'/../../config/settings.inc.php', $settings)) { Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo); Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4'); } else $this->_errors[] = Tools::displayError('Cannot overwrite settings file.'); } } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } if (Tools::isSubmit('submitCCC')) { if ($this->tabAccess['edit'] === '1') { if ( !Configuration::updateValue('PS_CSS_THEME_CACHE', (int)Tools::getValue('PS_CSS_THEME_CACHE')) OR !Configuration::updateValue('PS_JS_THEME_CACHE', (int)Tools::getValue('PS_JS_THEME_CACHE')) OR !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int)Tools::getValue('PS_HTML_THEME_COMPRESSION')) OR !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int)Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) OR !Configuration::updateValue('PS_HIGH_HTML_THEME_COMPRESSION', (int)Tools::getValue('PS_HIGH_HTML_THEME_COMPRESSION')) ) $this->_errors[] = Tools::displayError('Unknown error.'); else Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4'); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } if (Tools::isSubmit('submitMediaServers')) { if ($this->tabAccess['edit'] === '1') { if (Tools::getValue('_MEDIA_SERVER_1_') != NULL AND !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) $this->_errors[] = Tools::displayError('Media server #1 is invalid'); if (Tools::getValue('_MEDIA_SERVER_2_') != NULL AND !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) $this->_errors[] = Tools::displayError('Media server #2 is invalid'); if (Tools::getValue('_MEDIA_SERVER_3_') != NULL AND !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) $this->_errors[] = Tools::displayError('Media server #3 is invalid'); if (!sizeof($this->_errors)) { $baseUrls = array(); $baseUrls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_'); $baseUrls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_'); $baseUrls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_'); rewriteSettingsFile($baseUrls, NULL, NULL); unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']); unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']); Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4'); } } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } if (Tools::isSubmit('submitSmartyConfig')) { if ($this->tabAccess['edit'] === '1') { Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', 0)); Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0)); Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4'); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } return parent::postProcess(); } public function display() { global $currentIndex; $warnings = array(); if (!extension_loaded('memcache')) $warnings[] = $this->l('To use Memcached, you must install the Memcache PECL extension on your server.').' http://www.php.net/manual/en/memcache.installation.php'; if (!is_writable(_PS_CACHEFS_DIRECTORY_)) $warnings[] = $this->l('To use CacheFS the directory').' '.realpath(_PS_CACHEFS_DIRECTORY_).' '.$this->l('must be writable'); if ($warnings) $this->displayWarning($warnings); echo ' '; echo '
'.$this->l('Smarty').'

'.$this->l('This forces Smarty to (re)compile templates on every invocation. This is handy for development and debugging. It should never be used in a production environment.').'

'.$this->l('Should be enabled except for debugging.').'

'; echo '
'.$this->l('CCC (Combine, Compress and Cache)').'

'.$this->l('CCC allows you to reduce the loading time of your page. With these settings you will gain performance without even touching the code of your theme. Make sure, however, that your theme is compatible with PrestaShop 1.4+. Otherwise, CCC will cause problems.').'






'; echo '
'.$this->l('Media servers (used only with CCC)').'

'.$this->l('You must enter another domain or subdomain in order to use cookieless static content.').'

'.$this->l('Name of the second domain of your shop, (e.g., myshop-media-server-1.com). If you do not have another domain, leave this field blank').'

'.$this->l('Name of the third domain of your shop, (e.g., myshop-media-server-2.com). If you do not have another domain, leave this field blank').'

'.$this->l('Name of the fourth domain of your shop, (e.g., myshop-media-server-3.com). If you do not have another domain, leave this field blank').'

'; echo '
'.$this->l('Ciphering').'

'.$this->l('Mcrypt is faster than our custom BlowFish class, but requires the PHP extension "mcrypt". If you change this configuration, all cookies will be reset.').'


'; $depth = Configuration::get('PS_CACHEFS_DIRECTORY_DEPTH'); echo '
'.$this->l('Caching').'

'.$this->l('Enable or disable caching system').'

'; $servers = MCached::getMemcachedServers(); if ($servers) { echo '
'; foreach($servers AS $server) echo ''; echo '
'.$this->l('Id').' '.$this->l('Ip').' '.$this->l('Port').' '.$this->l('Weight').'  
'.$server['id_memcached_server'].' '.$server['ip'].' '.$server['port'].' '.$server['weight'].'
'; } echo '
'; } }