PageRenderTime 30ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/adminstrator/tabs/AdminPerformance.php

http://marocmall.googlecode.com/
PHP | 458 lines | 417 code | 16 blank | 25 comment | 52 complexity | ad5b8c068068b617b9f6914371c27bcf MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. * 2007-2011 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2011 PrestaShop SA
  23. * @version Release: $Revision: 8949 $
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. * International Registered Trademark & Property of PrestaShop SA
  26. */
  27. class AdminPerformance extends AdminTab
  28. {
  29. public function postProcess()
  30. {
  31. global $currentIndex;
  32. if (Tools::isSubmit('submitCaching'))
  33. {
  34. if ($this->tabAccess['edit'] === '1')
  35. {
  36. $settings = file_get_contents(dirname(__FILE__).'/../../config/settings.inc.php');
  37. if (!Tools::getValue('active'))
  38. $cache_active = 0;
  39. else
  40. $cache_active = 1;
  41. if (!$caching_system = Tools::getValue('caching_system'))
  42. $this->_errors[] = Tools::displayError('Caching system is missing');
  43. else
  44. $settings = preg_replace('/define\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\/+-_]+)\'\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \''.$caching_system.'\');', $settings);
  45. if ($cache_active AND $caching_system == 'MCached' AND !extension_loaded('memcache'))
  46. $this->_errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.').' <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
  47. elseif ($cache_active AND $caching_system == 'CacheFS' AND !is_writable(_PS_CACHEFS_DIRECTORY_))
  48. $this->_errors[] = Tools::displayError('To use CacheFS the directory').' '.realpath(_PS_CACHEFS_DIRECTORY_).' '.Tools::displayError('must be writable');
  49. if ($caching_system == 'CacheFS')
  50. {
  51. if (!($depth = Tools::getValue('ps_cache_fs_directory_depth')))
  52. $this->_errors[] = Tools::displayError('Please set a directory depth');
  53. if (!sizeof($this->_errors))
  54. {
  55. CacheFS::deleteCacheDirectory();
  56. CacheFS::createCacheDirectories((int)$depth);
  57. Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int)$depth);
  58. }
  59. }
  60. if (!sizeof($this->_errors))
  61. {
  62. $settings = preg_replace('/define\(\'_PS_CACHE_ENABLED_\', \'([0-9])\'\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \''.(int)$cache_active.'\');', $settings);
  63. if (file_put_contents(dirname(__FILE__).'/../../config/settings.inc.php', $settings))
  64. Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  65. else
  66. $this->_errors[] = Tools::displayError('Cannot overwrite settings file.');
  67. }
  68. }
  69. else
  70. $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
  71. }
  72. if (Tools::isSubmit('submitAddServer'))
  73. {
  74. if ($this->tabAccess['add'] === '1')
  75. {
  76. if (!Tools::getValue('memcachedIp'))
  77. $this->_errors[] = Tools::displayError('Memcached IP is missing');
  78. if (!Tools::getValue('memcachedPort'))
  79. $this->_errors[] = Tools::displayError('Memcached port is missing');
  80. if (!Tools::getValue('memcachedWeight'))
  81. $this->_errors[] = Tools::displayError('Memcached weight is missing');
  82. if (!sizeof($this->_errors))
  83. {
  84. if (MCached::addServer(pSQL(Tools::getValue('memcachedIp')), (int)Tools::getValue('memcachedPort'), (int)Tools::getValue('memcachedWeight')))
  85. Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  86. else
  87. $this->_errors[] = Tools::displayError('Cannot add Memcached server');
  88. }
  89. }
  90. else
  91. $this->_errors[] = Tools::displayError('You do not have permission to add here.');
  92. }
  93. if (Tools::getValue('deleteMemcachedServer'))
  94. {
  95. if ($this->tabAccess['add'] === '1')
  96. {
  97. if (MCached::deleteServer((int)Tools::getValue('deleteMemcachedServer')))
  98. Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  99. else
  100. $this->_errors[] = Tools::displayError('Error in deleting Memcached server');
  101. }
  102. else
  103. $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
  104. }
  105. if (Tools::isSubmit('submitCiphering') AND Configuration::get('PS_CIPHER_ALGORITHM') != (int)Tools::getValue('PS_CIPHER_ALGORITHM'))
  106. {
  107. if ($this->tabAccess['edit'] === '1')
  108. {
  109. $algo = (int)Tools::getValue('PS_CIPHER_ALGORITHM');
  110. $settings = file_get_contents(dirname(__FILE__).'/../../config/settings.inc.php');
  111. if ($algo)
  112. {
  113. if (!function_exists('mcrypt_encrypt'))
  114. $this->_errors[] = Tools::displayError('Mcrypt is not activated on this server.');
  115. else
  116. {
  117. if (!strstr($settings, '_RIJNDAEL_KEY_'))
  118. {
  119. $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
  120. $key = Tools::passwdGen($key_size);
  121. $settings = preg_replace('/define\(\'_COOKIE_KEY_\', \'([a-z0-9=\/+-_]+)\'\);/i', 'define(\'_COOKIE_KEY_\', \'\1\');'."\n".'define(\'_RIJNDAEL_KEY_\', \''.$key.'\');', $settings);
  122. }
  123. if (!strstr($settings, '_RIJNDAEL_IV_'))
  124. {
  125. $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
  126. $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND));
  127. $settings = preg_replace('/define\(\'_COOKIE_IV_\', \'([a-z0-9=\/+-_]+)\'\);/i', 'define(\'_COOKIE_IV_\', \'\1\');'."\n".'define(\'_RIJNDAEL_IV_\', \''.$iv.'\');', $settings);
  128. }
  129. }
  130. }
  131. if (!count($this->_errors))
  132. {
  133. if (file_put_contents(dirname(__FILE__).'/../../config/settings.inc.php', $settings))
  134. {
  135. Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo);
  136. Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  137. }
  138. else
  139. $this->_errors[] = Tools::displayError('Cannot overwrite settings file.');
  140. }
  141. }
  142. else
  143. $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
  144. }
  145. if (Tools::isSubmit('submitCCC'))
  146. {
  147. if ($this->tabAccess['edit'] === '1')
  148. {
  149. if (
  150. !Configuration::updateValue('PS_CSS_THEME_CACHE', (int)Tools::getValue('PS_CSS_THEME_CACHE')) OR
  151. !Configuration::updateValue('PS_JS_THEME_CACHE', (int)Tools::getValue('PS_JS_THEME_CACHE')) OR
  152. !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int)Tools::getValue('PS_HTML_THEME_COMPRESSION')) OR
  153. !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int)Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) OR
  154. !Configuration::updateValue('PS_HIGH_HTML_THEME_COMPRESSION', (int)Tools::getValue('PS_HIGH_HTML_THEME_COMPRESSION'))
  155. )
  156. $this->_errors[] = Tools::displayError('Unknown error.');
  157. else
  158. Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  159. }
  160. else
  161. $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
  162. }
  163. if (Tools::isSubmit('submitMediaServers'))
  164. {
  165. if ($this->tabAccess['edit'] === '1')
  166. {
  167. if (Tools::getValue('_MEDIA_SERVER_1_') != NULL AND !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_')))
  168. $this->_errors[] = Tools::displayError('Media server #1 is invalid');
  169. if (Tools::getValue('_MEDIA_SERVER_2_') != NULL AND !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_')))
  170. $this->_errors[] = Tools::displayError('Media server #2 is invalid');
  171. if (Tools::getValue('_MEDIA_SERVER_3_') != NULL AND !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_')))
  172. $this->_errors[] = Tools::displayError('Media server #3 is invalid');
  173. if (!sizeof($this->_errors))
  174. {
  175. $baseUrls = array();
  176. $baseUrls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_');
  177. $baseUrls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_');
  178. $baseUrls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_');
  179. rewriteSettingsFile($baseUrls, NULL, NULL);
  180. unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']);
  181. unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']);
  182. unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']);
  183. Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  184. }
  185. }
  186. else
  187. $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
  188. }
  189. if (Tools::isSubmit('submitSmartyConfig'))
  190. {
  191. if ($this->tabAccess['edit'] === '1')
  192. {
  193. Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', 0));
  194. Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
  195. Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  196. }
  197. else
  198. $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
  199. }
  200. return parent::postProcess();
  201. }
  202. public function display()
  203. {
  204. global $currentIndex;
  205. $warnings = array();
  206. if (!extension_loaded('memcache'))
  207. $warnings[] = $this->l('To use Memcached, you must install the Memcache PECL extension on your server.').' <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
  208. if (!is_writable(_PS_CACHEFS_DIRECTORY_))
  209. $warnings[] = $this->l('To use CacheFS the directory').' '.realpath(_PS_CACHEFS_DIRECTORY_).' '.$this->l('must be writable');
  210. if ($warnings)
  211. $this->displayWarning($warnings);
  212. echo '<script type="text/javascript">
  213. $(document).ready(function() {
  214. showMemcached();
  215. $(\'#caching_system\').change(function() {
  216. showMemcached();
  217. });
  218. function showMemcached()
  219. {
  220. if ($(\'#caching_system option:selected\').val() == \'MCached\')
  221. {
  222. $(\'#memcachedServers\').show();
  223. $(\'#directory_depth\').hide();
  224. }
  225. else
  226. {
  227. $(\'#memcachedServers\').hide();
  228. $(\'#directory_depth\').show();
  229. }
  230. }
  231. $(\'#addMemcachedServer\').click(function() {
  232. $(\'#formMemcachedServer\').show();
  233. return false;
  234. });
  235. });
  236. </script>
  237. ';
  238. echo '
  239. <form action="'.$currentIndex.'&token='.Tools::getValue('token').'" method="post" style="margin-top:10px;">
  240. <fieldset>
  241. <legend><img src="../img/admin/prefs.gif" /> '.$this->l('Smarty').'</legend>
  242. <label>'.$this->l('Force compile:').'</label>
  243. <div class="margin-form">
  244. <input type="radio" name="smarty_force_compile" id="smarty_force_compile_1" value="1" '.(Configuration::get('PS_SMARTY_FORCE_COMPILE') ? 'checked="checked"' : '').' /> <label class="t"><img src="../img/admin/enabled.gif" alt="" /> '.$this->l('Yes').'</label>
  245. <input type="radio" name="smarty_force_compile" id="smarty_force_compile_0" value="0" '.(!Configuration::get('PS_SMARTY_FORCE_COMPILE') ? 'checked="checked"' : '').' /> <label class="t"><img src="../img/admin/disabled.gif" alt="" /> '.$this->l('No').'</label>
  246. <p>'.$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.').'</p>
  247. </div>
  248. <label>'.$this->l('Cache:').'</label>
  249. <div class="margin-form">
  250. <input type="radio" name="smarty_cache" id="smarty_cache_1" value="1" '.(Configuration::get('PS_SMARTY_CACHE') ? 'checked="checked"' : '').' /> <label class="t"><img src="../img/admin/enabled.gif" alt="" /> '.$this->l('Yes').'</label>
  251. <input type="radio" name="smarty_cache" id="smarty_cache_0" value="0" '.(!Configuration::get('PS_SMARTY_CACHE') ? 'checked="checked"' : '').' /> <label class="t"><img src="../img/admin/disabled.gif" alt="" /> '.$this->l('No').'</label>
  252. <p>'.$this->l('Should be enabled except for debugging.').'</p>
  253. </div>
  254. <div class="margin-form">
  255. <input type="submit" value="'.$this->l(' Save ').'" name="submitSmartyConfig" class="button" />
  256. </div>
  257. </fieldset>
  258. </form>';
  259. echo '
  260. <form action="'.$currentIndex.'&token='.Tools::getValue('token').'" method="post" style="margin-top:10px;">
  261. <fieldset>
  262. <legend><img src="../img/admin/arrow_in.png" /> '.$this->l('CCC (Combine, Compress and Cache)').'</legend>
  263. <p>'.$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.').'</p>
  264. <label>'.$this->l('Smart cache for CSS').' </label>
  265. <div class="margin-form">
  266. <input type="radio" value="1" name="PS_CSS_THEME_CACHE" id="PS_CSS_THEME_CACHE_1" '.(Configuration::get('PS_CSS_THEME_CACHE') ? 'checked="checked"' : '').' />
  267. <label class="t" for="PS_CSS_THEME_CACHE_1">'.$this->l('Use CCC for CSS.').'</label>
  268. <br />
  269. <input type="radio" value="0" name="PS_CSS_THEME_CACHE" id="PS_CSS_THEME_CACHE_0" '.(Configuration::get('PS_CSS_THEME_CACHE') ? '' : 'checked="checked"').' />
  270. <label class="t" for="PS_CSS_THEME_CACHE_0">'.$this->l('Keep CSS as original').'</label>
  271. </div>
  272. <label>'.$this->l('Smart cache for JavaScript').' </label>
  273. <div class="margin-form">
  274. <input type="radio" value="1" name="PS_JS_THEME_CACHE" id="PS_JS_THEME_CACHE_1" '.(Configuration::get('PS_JS_THEME_CACHE') ? 'checked="checked"' : '').' />
  275. <label class="t" for="PS_JS_THEME_CACHE_1">'.$this->l('Use CCC for JavaScript.').'</label>
  276. <br />
  277. <input type="radio" value="0" name="PS_JS_THEME_CACHE" id="PS_JS_THEME_CACHE_0" '.(Configuration::get('PS_JS_THEME_CACHE') ? '' : 'checked="checked"').' />
  278. <label class="t" for="PS_JS_THEME_CACHE_0">'.$this->l('Keep JavaScript as original').'</label>
  279. </div>
  280. <label>'.$this->l('Minify HTML').' </label>
  281. <div class="margin-form">
  282. <input type="radio" value="1" name="PS_HTML_THEME_COMPRESSION" id="PS_HTML_THEME_COMPRESSION_1" '.(Configuration::get('PS_HTML_THEME_COMPRESSION') ? 'checked="checked"' : '').' />
  283. <label class="t" for="PS_HTML_THEME_COMPRESSION_1">'.$this->l('Minify HTML after "smarty compile" execution.').'</label>
  284. <br />
  285. <input type="radio" value="0" name="PS_HTML_THEME_COMPRESSION" id="PS_HTML_THEME_COMPRESSION_0" '.(Configuration::get('PS_HTML_THEME_COMPRESSION') ? '' : 'checked="checked"').' />
  286. <label class="t" for="PS_HTML_THEME_COMPRESSION_0">'.$this->l('Keep HTML as original').'</label>
  287. </div>
  288. <label>'.$this->l('Compress inline JavaScript in HTML').' </label>
  289. <div class="margin-form">
  290. <input type="radio" value="1" name="PS_JS_HTML_THEME_COMPRESSION" id="PS_JS_HTML_THEME_COMPRESSION_1" '.(Configuration::get('PS_JS_HTML_THEME_COMPRESSION') ? 'checked="checked"' : '').' />
  291. <label class="t" for="PS_JS_HTML_THEME_COMPRESSION_1">'.$this->l('Compress inline JavaScript in HTML after "smarty compile" execution').'</label>
  292. <br />
  293. <input type="radio" value="0" name="PS_JS_HTML_THEME_COMPRESSION" id="PS_JS_HTML_THEME_COMPRESSION_0" '.(Configuration::get('PS_JS_HTML_THEME_COMPRESSION') ? '' : 'checked="checked"').' />
  294. <label class="t" for="PS_JS_HTML_THEME_COMPRESSION_0">'.$this->l('Keep inline JavaScript in HTML as original').'</label>
  295. </div>
  296. <label>'.$this->l('High risk HTML compression').' </label>
  297. <div class="margin-form">
  298. <input type="radio" value="1" name="PS_HIGH_HTML_THEME_COMPRESSION" id="PS_HIGH_HTML_THEME_COMPRESSION_1" '.(Configuration::get('PS_HIGH_HTML_THEME_COMPRESSION') ? 'checked="checked"' : '').' />
  299. <label class="t" for="PS_HIGH_HTML_THEME_COMPRESSION_1">'.$this->l('HTML is compressed but cancels the W3C validation (only when "Minify HTML" is enabled)').'</label>
  300. <br />
  301. <input type="radio" value="0" name="PS_HIGH_HTML_THEME_COMPRESSION" id="PS_HIGH_HTML_THEME_COMPRESSION_0" '.(Configuration::get('PS_HIGH_HTML_THEME_COMPRESSION') ? '' : 'checked="checked"').' />
  302. <label class="t" for="PS_HIGH_HTML_THEME_COMPRESSION_0">'.$this->l('Keep W3C validation').'</label>
  303. </div>
  304. <div class="margin-form">
  305. <input type="submit" value="'.$this->l(' Save ').'" name="submitCCC" class="button" />
  306. </div>
  307. </fieldset>
  308. </form>';
  309. echo '<form action="'.$currentIndex.'&token='.Tools::getValue('token').'" method="post" style="margin-top:10px;">
  310. <fieldset>
  311. <legend><img src="../img/admin/subdomain.gif" /> '.$this->l('Media servers (used only with CCC)').'</legend>
  312. <p>'.$this->l('You must enter another domain or subdomain in order to use cookieless static content.').'</p>
  313. <label for="_MEDIA_SERVER_1_">'.$this->l('Media server #1').'</label>
  314. <div class="margin-form">
  315. <input type="text" name="_MEDIA_SERVER_1_" id="_MEDIA_SERVER_1_" value="'.htmlentities(Tools::getValue('_MEDIA_SERVER_1_', _MEDIA_SERVER_1_), ENT_QUOTES, 'UTF-8').'" size="30" />
  316. <p>'.$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').'</p>
  317. </div>
  318. <label for="_MEDIA_SERVER_2_">'.$this->l('Media server #2').'</label>
  319. <div class="margin-form">
  320. <input type="text" name="_MEDIA_SERVER_2_" id="_MEDIA_SERVER_2_" value="'.htmlentities(Tools::getValue('_MEDIA_SERVER_2_', _MEDIA_SERVER_2_), ENT_QUOTES, 'UTF-8').'" size="30" />
  321. <p>'.$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').'</p>
  322. </div>
  323. <label for="_MEDIA_SERVER_3_">'.$this->l('Media server #3').'</label>
  324. <div class="margin-form">
  325. <input type="text" name="_MEDIA_SERVER_3_" id="_MEDIA_SERVER_3_" value="'.htmlentities(Tools::getValue('_MEDIA_SERVER_3_', _MEDIA_SERVER_3_), ENT_QUOTES, 'UTF-8').'" size="30" />
  326. <p>'.$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').'</p>
  327. </div>
  328. <div class="margin-form">
  329. <input type="submit" value="'.$this->l(' Save ').'" name="submitMediaServers" class="button" />
  330. </div>
  331. </fieldset>
  332. </form>';
  333. echo '
  334. <fieldset style="margin-top:10px;">
  335. <legend><img src="../img/admin/computer_key.png" /> '.$this->l('Ciphering').'</legend>
  336. <form action="'.$currentIndex.'&token='.Tools::getValue('token').'" method="post">
  337. <p>'.$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.').'</p>
  338. <label>'.$this->l('Algorithm').' </label>
  339. <div class="margin-form">
  340. <input type="radio" value="1" name="PS_CIPHER_ALGORITHM" id="PS_CIPHER_ALGORITHM_1" '.(Configuration::get('PS_CIPHER_ALGORITHM') ? 'checked="checked"' : '').' />
  341. <label class="t" for="PS_CIPHER_ALGORITHM_1">'.$this->l('Use Rijndael with mcrypt lib.').'</label>
  342. <br />
  343. <input type="radio" value="0" name="PS_CIPHER_ALGORITHM" id="PS_CIPHER_ALGORITHM_0" '.(Configuration::get('PS_CIPHER_ALGORITHM') ? '' : 'checked="checked"').' />
  344. <label class="t" for="PS_CIPHER_ALGORITHM_0">'.$this->l('Keep the custom BlowFish class.').'</label>
  345. </div>
  346. <div class="margin-form">
  347. <input type="submit" value="'.$this->l(' Save ').'" name="submitCiphering" class="button" />
  348. </div>
  349. </form>
  350. </fieldset>
  351. ';
  352. $depth = Configuration::get('PS_CACHEFS_DIRECTORY_DEPTH');
  353. echo '<fieldset style="margin-top: 10px;">
  354. <legend><img src="../img/admin/computer_key.png" /> '.$this->l('Caching').'</legend>
  355. <form action="'.$currentIndex.'&token='.Tools::getValue('token').'" method="post">
  356. <label>'.$this->l('Use cache:').' </label>
  357. <div class="margin-form">
  358. <input type="radio" name="active" id="active_on" value="1" '.(_PS_CACHE_ENABLED_ ? 'checked="checked" ' : '').'/>
  359. <label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
  360. <input type="radio" name="active" id="active_off" value="0" '.(!_PS_CACHE_ENABLED_ ? 'checked="checked" ' : '').'/>
  361. <label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
  362. <p>'.$this->l('Enable or disable caching system').'</p>
  363. </div>
  364. <label>'.$this->l('Caching system:').' </label>
  365. <div class="margin-form">
  366. <select name="caching_system" id="caching_system">
  367. <option value="MCached" '.(_PS_CACHING_SYSTEM_ == 'MCached' ? 'selected="selected"' : '' ).'>'.$this->l('Memcached').'</option>
  368. <option value="CacheFS" '.(_PS_CACHING_SYSTEM_ == 'CacheFS' ? 'selected="selected"' : '' ).'>'.$this->l('File System').'</option>
  369. </select>
  370. </div>
  371. <div id="directory_depth">
  372. <div class="warn">'.$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.').'</div>
  373. <label>'.$this->l('Directory depth:').' </label>
  374. <div class="margin-form">
  375. <input type="text" name="ps_cache_fs_directory_depth" value="'.($depth ? $depth : 1).'" />
  376. </div>
  377. </div>
  378. <div class="margin-form">
  379. <input type="submit" value="'.$this->l(' Save ').'" name="submitCaching" class="button" />
  380. </div>
  381. </form>
  382. <div id="memcachedServers">
  383. <div class="margin-form">
  384. <a id="addMemcachedServer" href="#" ><img src="../img/admin/add.gif" />'.$this->l('Add server').'</a>
  385. </div>
  386. <div id="formMemcachedServer" style="margin-top: 10px; display:none;">
  387. <form action="'.$currentIndex.'&token='.Tools::getValue('token').'" method="post">
  388. <label>'.$this->l('IP Address:').' </label>
  389. <div class="margin-form">
  390. <input type="text" name="memcachedIp" />
  391. </div>
  392. <label>'.$this->l('Port:').' </label>
  393. <div class="margin-form">
  394. <input type="text" name="memcachedPort" value="11211" />
  395. </div>
  396. <label>'.$this->l('Weight:').' </label>
  397. <div class="margin-form">
  398. <input type="text" name="memcachedWeight" value="1" />
  399. </div>
  400. <div class="margin-form">
  401. <input type="submit" value="'.$this->l(' Add Server ').'" name="submitAddServer" class="button" />
  402. </div>
  403. </form>
  404. </div>';
  405. $servers = MCached::getMemcachedServers();
  406. if ($servers)
  407. {
  408. echo '<div class="margin-form">
  409. <table style="width: 320px;" cellspacing="0" cellpadding="0" class="table">
  410. <tr>
  411. <th style="width: 20px; text-align: center">'.$this->l('Id').'</th>
  412. <th style="width: 200px; text-align: center">'.$this->l('Ip').'</th>
  413. <th style="width: 50px; text-align: center">'.$this->l('Port').'</th>
  414. <th style="width: 30px; text-align: right; font-weight: bold;">'.$this->l('Weight').'</th>
  415. <th style="width: 20px; text-align: right;">&nbsp;</th>
  416. </tr>';
  417. foreach($servers AS $server)
  418. echo '<tr>
  419. <td>'.$server['id_memcached_server'].'</td>
  420. <td>'.$server['ip'].'</td>
  421. <td>'.$server['port'].'</td>
  422. <td>'.$server['weight'].'</td>
  423. <td>
  424. <a href="'.$currentIndex.'&token='.Tools::getValue('token').'&deleteMemcachedServer='.(int)$server['id_memcached_server'].'" ><img src="../img/admin/delete.gif" /></a>
  425. </td>
  426. </tr>';
  427. echo '
  428. </table>
  429. </div>';
  430. }
  431. echo '
  432. </div>
  433. </fieldset>';
  434. }
  435. }