* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6844 $ * @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() { 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 && $caching_system == 'CacheMemcache' && !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'; else if ($cache_active && $caching_system == 'CacheApc' && !extension_loaded('apc')) $this->_errors[] = Tools::displayError('To use APC cache, you must install the APC PECL extension on your server.').' http://fr.php.net/manual/fr/apc.installation.php'; else if ($cache_active && $caching_system == 'CacheXcache' && !extension_loaded('xcache')) $this->_errors[] = Tools::displayError('To use Xcache, you must install the Xcache extension on your server.').' http://xcache.lighttpd.net'; else if ($cache_active && $caching_system == 'CacheFs' && !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(self::$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 (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int)Tools::getValue('memcachedPort'), (int)Tools::getValue('memcachedWeight'))) Tools::redirectAdmin(self::$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 (CacheMemcache::deleteServer((int)Tools::getValue('deleteMemcachedServer'))) Tools::redirectAdmin(self::$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(self::$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(self::$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(self::$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', _PS_SMARTY_NO_COMPILE_)); Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0)); Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4'); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } if (Tools::isSubmit('submitFeaturesDetachables')) { if ($this->tabAccess['edit'] === '1') { if (!Combination::isCurrentlyUsed()) Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', Tools::getValue('combination')); Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', Tools::getValue('feature')); Tools::redirectAdmin(self::$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() { $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 (!extension_loaded('apc')) $warnings[] = $this->l('To use APC, you must install the APC PECL extension on your server.').' http://fr.php.net/manual/fr/apc.installation.php'; if (!extension_loaded('xcache')) $warnings[] = $this->l('To use Xcache, you must install the Xcache extension on your server.').' http://xcache.lighttpd.net'; 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('Templates are never recompiled, performance are better and this option should be used in production environement').'



'.$this->l('Templates are recompiled when they are updated, if you experience compilation troubles when you update your templates files, you should use force compile instead of this option. It should never be used in a production environment.').'



'.$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('Features detachables').'

'.$this->l('Some features can be disabled in order to improve performance.').'

'; if (Combination::isCurrentlyUsed()) $this->displayWarning($this->l('This feature can\'t be disabled because this is currently in use.')); echo '

'.$this->l('These features are going to be disabled:').'

  • '.$this->l('Combinations tab on product page').'
  • '.$this->l('Attribute').'
  • '.$this->l('Group of attribute').'

'.$this->l('These features are going to be disabled:').'

  • '.$this->l('Features tab on product page').'
  • '.$this->l('Feature').'
  • '.$this->l('Feature value').'

'; 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').'

'.$this->l('The system CacheFS should be used only when the infrastructure contain only one front-end server. Ask your hosting company if you don\'t know.').'
'; $servers = CacheMemcache::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 '
'; } }