PageRenderTime 56ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/controllers/admin/AdminPerformanceController.php

https://gitlab.com/staging06/myproject
PHP | 997 lines | 901 code | 62 blank | 34 comment | 134 complexity | 36508591f230c1ed256bacbc5c3bd33d MD5 | raw file
  1. <?php
  2. /*
  3. * 2007-2015 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-2015 PrestaShop SA
  23. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. /**
  27. * @property Configuration $object
  28. */
  29. class AdminPerformanceControllerCore extends AdminController
  30. {
  31. public function __construct()
  32. {
  33. $this->bootstrap = true;
  34. $this->className = 'Configuration';
  35. parent::__construct();
  36. }
  37. public function initFieldsetSmarty()
  38. {
  39. $this->fields_form[0]['form'] = array(
  40. 'legend' => array(
  41. 'title' => $this->l('Smarty'),
  42. 'icon' => 'icon-briefcase'
  43. ),
  44. 'input' => array(
  45. array(
  46. 'type' => 'hidden',
  47. 'name' => 'smarty_up'
  48. ),
  49. array(
  50. 'type' => 'radio',
  51. 'label' => $this->l('Template compilation'),
  52. 'name' => 'smarty_force_compile',
  53. 'values' => array(
  54. array(
  55. 'id' => 'smarty_force_compile_'._PS_SMARTY_NO_COMPILE_,
  56. 'value' => _PS_SMARTY_NO_COMPILE_,
  57. 'label' => $this->l('Never recompile template files'),
  58. 'hint' => $this->l('This option should be used in a production environment.')
  59. ),
  60. array(
  61. 'id' => 'smarty_force_compile_'._PS_SMARTY_CHECK_COMPILE_,
  62. 'value' => _PS_SMARTY_CHECK_COMPILE_,
  63. 'label' => $this->l('Recompile templates if the files have been updated'),
  64. 'hint' => $this->l('Templates are recompiled when they are updated. If you experience compilation troubles when you update your template files, you should use Force Compile instead of this option. It should never be used in a production environment.')
  65. ),
  66. array(
  67. 'id' => 'smarty_force_compile_'._PS_SMARTY_FORCE_COMPILE_,
  68. 'value' => _PS_SMARTY_FORCE_COMPILE_,
  69. 'label' => $this->l('Force compilation'),
  70. 'hint' => $this->l('This forces Smarty to (re)compile templates on every invocation. This is handy for development and debugging. Note: This should never be used in a production environment.')
  71. )
  72. )
  73. ),
  74. array(
  75. 'type' => 'switch',
  76. 'label' => $this->l('Cache'),
  77. 'name' => 'smarty_cache',
  78. 'is_bool' => true,
  79. 'values' => array(
  80. array(
  81. 'id' => 'smarty_cache_1',
  82. 'value' => 1,
  83. 'label' => $this->l('Yes'),
  84. ),
  85. array(
  86. 'id' => 'smarty_cache_0',
  87. 'value' => 0,
  88. 'label' => $this->l('No')
  89. )
  90. ),
  91. 'hint' => $this->l('Should be enabled except for debugging.')
  92. ),
  93. array(
  94. 'type' => 'radio',
  95. 'label' => $this->l('Caching type'),
  96. 'name' => 'smarty_caching_type',
  97. 'values' => array(
  98. array(
  99. 'id' => 'smarty_caching_type_filesystem',
  100. 'value' => 'filesystem',
  101. 'label' => $this->l('File System').(is_writable(_PS_CACHE_DIR_.'smarty/cache') ? '' : ' '.sprintf($this->l('(the directory %s must be writable)'), realpath(_PS_CACHE_DIR_.'smarty/cache')))
  102. ),
  103. array(
  104. 'id' => 'smarty_caching_type_mysql',
  105. 'value' => 'mysql',
  106. 'label' => $this->l('MySQL')
  107. ),
  108. )
  109. ),
  110. array(
  111. 'type' => 'radio',
  112. 'label' => $this->l('Clear cache'),
  113. 'name' => 'smarty_clear_cache',
  114. 'values' => array(
  115. array(
  116. 'id' => 'smarty_clear_cache_never',
  117. 'value' => 'never',
  118. 'label' => $this->l('Never clear cache files'),
  119. ),
  120. array(
  121. 'id' => 'smarty_clear_cache_everytime',
  122. 'value' => 'everytime',
  123. 'label' => $this->l('Clear cache everytime something has been modified'),
  124. ),
  125. )
  126. ),
  127. ),
  128. 'submit' => array(
  129. 'title' => $this->l('Save')
  130. )
  131. );
  132. $this->fields_value['smarty_force_compile'] = Configuration::get('PS_SMARTY_FORCE_COMPILE');
  133. $this->fields_value['smarty_cache'] = Configuration::get('PS_SMARTY_CACHE');
  134. $this->fields_value['smarty_caching_type'] = Configuration::get('PS_SMARTY_CACHING_TYPE');
  135. $this->fields_value['smarty_clear_cache'] = Configuration::get('PS_SMARTY_CLEAR_CACHE');
  136. $this->fields_value['smarty_console'] = Configuration::get('PS_SMARTY_CONSOLE');
  137. $this->fields_value['smarty_console_key'] = Configuration::get('PS_SMARTY_CONSOLE_KEY');
  138. }
  139. public function initFieldsetDebugMode()
  140. {
  141. $this->fields_form[1]['form'] = array(
  142. 'legend' => array(
  143. 'title' => $this->l('Debug mode'),
  144. 'icon' => 'icon-bug'
  145. ),
  146. 'input' => array(
  147. array(
  148. 'type' => 'switch',
  149. 'label' => $this->l('Disable non PrestaShop modules'),
  150. 'name' => 'native_module',
  151. 'class' => 't',
  152. 'is_bool' => true,
  153. 'values' => array(
  154. array(
  155. 'id' => 'native_module_on',
  156. 'value' => 1,
  157. 'label' => $this->l('Enabled')
  158. ),
  159. array(
  160. 'id' => 'native_module_off',
  161. 'value' => 0,
  162. 'label' => $this->l('Disabled')
  163. )
  164. ),
  165. 'hint' => $this->l('Enable or disable non PrestaShop Modules.')
  166. ),
  167. array(
  168. 'type' => 'switch',
  169. 'label' => $this->l('Disable all overrides'),
  170. 'name' => 'overrides',
  171. 'class' => 't',
  172. 'is_bool' => true,
  173. 'values' => array(
  174. array(
  175. 'id' => 'overrides_module_on',
  176. 'value' => 1,
  177. 'label' => $this->l('Enabled')
  178. ),
  179. array(
  180. 'id' => 'overrides_module_off',
  181. 'value' => 0,
  182. 'label' => $this->l('Disabled')
  183. )
  184. ),
  185. 'hint' => $this->l('Enable or disable all classes and controllers overrides.')
  186. ),
  187. ),
  188. 'submit' => array(
  189. 'title' => $this->l('Save')
  190. )
  191. );
  192. $this->fields_value['native_module'] = Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
  193. $this->fields_value['overrides'] = Configuration::get('PS_DISABLE_OVERRIDES');
  194. }
  195. public function initFieldsetFeaturesDetachables()
  196. {
  197. $this->fields_form[2]['form'] = array(
  198. 'legend' => array(
  199. 'title' => $this->l('Optional features'),
  200. 'icon' => 'icon-puzzle-piece'
  201. ),
  202. 'description' => $this->l('Some features can be disabled in order to improve performance.'),
  203. 'input' => array(
  204. array(
  205. 'type' => 'hidden',
  206. 'name' => 'features_detachables_up'
  207. ),
  208. array(
  209. 'type' => 'switch',
  210. 'label' => $this->l('Combinations'),
  211. 'name' => 'combination',
  212. 'is_bool' => true,
  213. 'disabled' => Combination::isCurrentlyUsed(),
  214. 'values' => array(
  215. array(
  216. 'id' => 'combination_1',
  217. 'value' => 1,
  218. 'label' => $this->l('Yes'),
  219. ),
  220. array(
  221. 'id' => 'combination_0',
  222. 'value' => 0,
  223. 'label' => $this->l('No')
  224. )
  225. ),
  226. 'hint' => $this->l('Choose "No" to disable Product Combinations.'),
  227. 'desc' => Combination::isCurrentlyUsed() ? $this->l('You cannot set this parameter to No when combinations are already used by some of your products') : null
  228. ),
  229. array(
  230. 'type' => 'switch',
  231. 'label' => $this->l('Features'),
  232. 'name' => 'feature',
  233. 'is_bool' => true,
  234. 'values' => array(
  235. array(
  236. 'id' => 'feature_1',
  237. 'value' => 1,
  238. 'label' => $this->l('Yes'),
  239. ),
  240. array(
  241. 'id' => 'feature_0',
  242. 'value' => 0,
  243. 'label' => $this->l('No')
  244. )
  245. ),
  246. 'hint' => $this->l('Choose "No" to disable Product Features.')
  247. ),
  248. array(
  249. 'type' => 'switch',
  250. 'label' => $this->l('Customer Groups'),
  251. 'name' => 'customer_group',
  252. 'is_bool' => true,
  253. 'disabled' => Group::isCurrentlyUsed(),
  254. 'values' => array(
  255. array(
  256. 'id' => 'group_1',
  257. 'value' => 1,
  258. 'label' => $this->l('Yes'),
  259. ),
  260. array(
  261. 'id' => 'group_0',
  262. 'value' => 0,
  263. 'label' => $this->l('No')
  264. )
  265. ),
  266. 'hint' => $this->l('Choose "No" to disable Customer Groups.')
  267. )
  268. ),
  269. 'submit' => array(
  270. 'title' => $this->l('Save')
  271. )
  272. );
  273. $this->fields_value['combination'] = Combination::isFeatureActive();
  274. $this->fields_value['feature'] = Feature::isFeatureActive();
  275. $this->fields_value['customer_group'] = Group::isFeatureActive();
  276. }
  277. public function initFieldsetCCC()
  278. {
  279. $this->fields_form[3]['form'] = array(
  280. 'legend' => array(
  281. 'title' => $this->l('CCC (Combine, Compress and Cache)'),
  282. 'icon' => 'icon-fullscreen'
  283. ),
  284. 'description' => $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.'),
  285. 'input' => array(
  286. array(
  287. 'type' => 'hidden',
  288. 'name' => 'ccc_up',
  289. ),
  290. array(
  291. 'type' => 'switch',
  292. 'label' => $this->l('Smart cache for CSS'),
  293. 'name' => 'PS_CSS_THEME_CACHE',
  294. 'values' => array(
  295. array(
  296. 'id' => 'PS_CSS_THEME_CACHE_1',
  297. 'value' => 1,
  298. 'label' => $this->l('Use CCC for CSS')
  299. ),
  300. array(
  301. 'id' => 'PS_CSS_THEME_CACHE_0',
  302. 'value' => 0,
  303. 'label' => $this->l('Keep CSS as original')
  304. )
  305. )
  306. ),
  307. array(
  308. 'type' => 'switch',
  309. 'label' => $this->l('Smart cache for JavaScript'),
  310. 'name' => 'PS_JS_THEME_CACHE',
  311. 'values' => array(
  312. array(
  313. 'id' => 'PS_JS_THEME_CACHE_1',
  314. 'value' => 1,
  315. 'label' => $this->l('Use CCC for JavaScript')
  316. ),
  317. array(
  318. 'id' => 'PS_JS_THEME_CACHE_0',
  319. 'value' => 0,
  320. 'label' => $this->l('Keep JavaScript as original')
  321. )
  322. )
  323. ),
  324. array(
  325. 'type' => 'switch',
  326. 'label' => $this->l('Minify HTML'),
  327. 'name' => 'PS_HTML_THEME_COMPRESSION',
  328. 'values' => array(
  329. array(
  330. 'id' => 'PS_HTML_THEME_COMPRESSION_1',
  331. 'value' => 1,
  332. 'label' => $this->l('Minify HTML after "Smarty compile" execution')
  333. ),
  334. array(
  335. 'id' => 'PS_HTML_THEME_COMPRESSION_0',
  336. 'value' => 0,
  337. 'label' => $this->l('Keep HTML as original')
  338. )
  339. )
  340. ),
  341. array(
  342. 'type' => 'switch',
  343. 'label' => $this->l('Compress inline JavaScript in HTML'),
  344. 'name' => 'PS_JS_HTML_THEME_COMPRESSION',
  345. 'values' => array(
  346. array(
  347. 'id' => 'PS_JS_HTML_THEME_COMPRESSION_1',
  348. 'value' => 1,
  349. 'label' => $this->l('Compress inline JavaScript in HTML after "Smarty compile" execution')
  350. ),
  351. array(
  352. 'id' => 'PS_JS_HTML_THEME_COMPRESSION_0',
  353. 'value' => 0,
  354. 'label' => $this->l('Keep inline JavaScript in HTML as original')
  355. )
  356. )
  357. ),
  358. array(
  359. 'type' => 'switch',
  360. 'label' => $this->l('Move JavaScript to the end'),
  361. 'name' => 'PS_JS_DEFER',
  362. 'values' => array(
  363. array(
  364. 'id' => 'PS_JS_DEFER_1',
  365. 'value' => 1,
  366. 'label' => $this->l('Move JavaScript to the end of the HTML document')
  367. ),
  368. array(
  369. 'id' => 'PS_JS_DEFER_0',
  370. 'value' => 0,
  371. 'label' => $this->l('Keep JavaScript in HTML at its original position')
  372. )
  373. )
  374. ),
  375. ),
  376. 'submit' => array(
  377. 'title' => $this->l('Save')
  378. )
  379. );
  380. if (!defined('_PS_HOST_MODE_')) {
  381. $this->fields_form[3]['form']['input'][] = array(
  382. 'type' => 'switch',
  383. 'label' => $this->l('Apache optimization'),
  384. 'name' => 'PS_HTACCESS_CACHE_CONTROL',
  385. 'hint' => $this->l('This will add directives to your .htaccess file, which should improve caching and compression.'),
  386. 'values' => array(
  387. array(
  388. 'id' => 'PS_HTACCESS_CACHE_CONTROL_1',
  389. 'value' => 1,
  390. 'label' => $this->l('Yes'),
  391. ),
  392. array(
  393. 'id' => 'PS_HTACCESS_CACHE_CONTROL_0',
  394. 'value' => 0,
  395. 'label' => $this->l('No'),
  396. ),
  397. ),
  398. );
  399. }
  400. $this->fields_value['PS_CSS_THEME_CACHE'] = Configuration::get('PS_CSS_THEME_CACHE');
  401. $this->fields_value['PS_JS_THEME_CACHE'] = Configuration::get('PS_JS_THEME_CACHE');
  402. $this->fields_value['PS_HTML_THEME_COMPRESSION'] = Configuration::get('PS_HTML_THEME_COMPRESSION');
  403. $this->fields_value['PS_JS_HTML_THEME_COMPRESSION'] = Configuration::get('PS_JS_HTML_THEME_COMPRESSION');
  404. $this->fields_value['PS_HTACCESS_CACHE_CONTROL'] = Configuration::get('PS_HTACCESS_CACHE_CONTROL');
  405. $this->fields_value['PS_JS_DEFER'] = Configuration::get('PS_JS_DEFER');
  406. $this->fields_value['ccc_up'] = 1;
  407. }
  408. public function initFieldsetMediaServer()
  409. {
  410. $this->fields_form[4]['form'] = array(
  411. 'legend' => array(
  412. 'title' => $this->l('Media servers (use only with CCC)'),
  413. 'icon' => 'icon-link'
  414. ),
  415. 'description' => $this->l('You must enter another domain, or subdomain, in order to use cookieless static content.'),
  416. 'input' => array(
  417. array(
  418. 'type' => 'hidden',
  419. 'name' => 'media_server_up'
  420. ),
  421. array(
  422. 'type' => 'text',
  423. 'label' => $this->l('Media server #1'),
  424. 'name' => '_MEDIA_SERVER_1_',
  425. 'hint' => $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.')
  426. ),
  427. array(
  428. 'type' => 'text',
  429. 'label' => $this->l('Media server #2'),
  430. 'name' => '_MEDIA_SERVER_2_',
  431. 'hint' => $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.')
  432. ),
  433. array(
  434. 'type' => 'text',
  435. 'label' => $this->l('Media server #3'),
  436. 'name' => '_MEDIA_SERVER_3_',
  437. 'hint' => $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.')
  438. ),
  439. ),
  440. 'submit' => array(
  441. 'title' => $this->l('Save')
  442. )
  443. );
  444. $this->fields_value['_MEDIA_SERVER_1_'] = Configuration::get('PS_MEDIA_SERVER_1');
  445. $this->fields_value['_MEDIA_SERVER_2_'] = Configuration::get('PS_MEDIA_SERVER_2');
  446. $this->fields_value['_MEDIA_SERVER_3_'] = Configuration::get('PS_MEDIA_SERVER_3');
  447. }
  448. public function initFieldsetCiphering()
  449. {
  450. $phpdoc_langs = array('en', 'zh', 'fr', 'de', 'ja', 'pl', 'ro', 'ru', 'fa', 'es', 'tr');
  451. $php_lang = in_array($this->context->language->iso_code, $phpdoc_langs) ? $this->context->language->iso_code : 'en';
  452. $warning_mcrypt = ' '.$this->l('(you must install the [a]Mcrypt extension[/a])');
  453. $warning_mcrypt = str_replace('[a]', '<a href="http://www.php.net/manual/'.substr($php_lang, 0, 2).'/book.mcrypt.php" target="_blank">', $warning_mcrypt);
  454. $warning_mcrypt = str_replace('[/a]', '</a>', $warning_mcrypt);
  455. if (defined('_RIJNDAEL_KEY_') && defined('_RIJNDAEL_IV_')) {
  456. $this->fields_form[5]['form'] = array(
  457. 'legend' => array(
  458. 'title' => $this->l('Ciphering'),
  459. 'icon' => 'icon-desktop'
  460. ),
  461. 'input' => array(
  462. array(
  463. 'type' => 'hidden',
  464. 'name' => 'ciphering_up'
  465. ),
  466. array(
  467. 'type' => 'radio',
  468. 'label' => $this->l('Algorithm'),
  469. 'name' => 'PS_CIPHER_ALGORITHM',
  470. 'hint' => $this->l('Mcrypt is faster than our custom BlowFish class, but requires the "mcrypt" PHP extension. If you change this configuration, all cookies will be reset.'),
  471. 'values' => array(
  472. array(
  473. 'id' => 'PS_CIPHER_ALGORITHM_1',
  474. 'value' => 1,
  475. 'label' => $this->l('Use Rijndael with mcrypt lib.').(!function_exists('mcrypt_encrypt') ? '' : $warning_mcrypt)
  476. ),
  477. array(
  478. 'id' => 'PS_CIPHER_ALGORITHM_0',
  479. 'value' => 0,
  480. 'label' => $this->l('Use the custom BlowFish class.')
  481. )
  482. )
  483. )
  484. ),
  485. 'submit' => array(
  486. 'title' => $this->l('Save')
  487. )
  488. );
  489. }
  490. $this->fields_value['PS_CIPHER_ALGORITHM'] = Configuration::get('PS_CIPHER_ALGORITHM');
  491. }
  492. public function initFieldsetCaching()
  493. {
  494. $phpdoc_langs = array('en', 'zh', 'fr', 'de', 'ja', 'pl', 'ro', 'ru', 'fa', 'es', 'tr');
  495. $php_lang = in_array($this->context->language->iso_code, $phpdoc_langs) ? $this->context->language->iso_code : 'en';
  496. $warning_memcache = ' '.$this->l('(you must install the [a]Memcache PECL extension[/a])');
  497. $warning_memcache = str_replace('[a]', '<a href="http://www.php.net/manual/'.substr($php_lang, 0, 2).'/memcache.installation.php" target="_blank">', $warning_memcache);
  498. $warning_memcache = str_replace('[/a]', '</a>', $warning_memcache);
  499. $warning_memcached = ' '.$this->l('(you must install the [a]Memcached PECL extension[/a])');
  500. $warning_memcached = str_replace('[a]', '<a href="http://www.php.net/manual/'.substr($php_lang, 0, 2).'/memcached.installation.php" target="_blank">', $warning_memcached);
  501. $warning_memcached = str_replace('[/a]', '</a>', $warning_memcached);
  502. $warning_apc = ' '.$this->l('(you must install the [a]APC PECL extension[/a])');
  503. $warning_apc = str_replace('[a]', '<a href="http://php.net/manual/'.substr($php_lang, 0, 2).'/apc.installation.php" target="_blank">', $warning_apc);
  504. $warning_apc = str_replace('[/a]', '</a>', $warning_apc);
  505. $warning_xcache = ' '.$this->l('(you must install the [a]Xcache extension[/a])');
  506. $warning_xcache = str_replace('[a]', '<a href="http://xcache.lighttpd.net" target="_blank">', $warning_xcache);
  507. $warning_xcache = str_replace('[/a]', '</a>', $warning_xcache);
  508. $warning_fs = ' '.sprintf($this->l('(the directory %s must be writable)'), realpath(_PS_CACHEFS_DIRECTORY_));
  509. $this->fields_form[6]['form'] = array(
  510. 'legend' => array(
  511. 'title' => $this->l('Caching'),
  512. 'icon' => 'icon-desktop'
  513. ),
  514. 'input' => array(
  515. array(
  516. 'type' => 'hidden',
  517. 'name' => 'cache_up'
  518. ),
  519. array(
  520. 'type' => 'switch',
  521. 'label' => $this->l('Use cache'),
  522. 'name' => 'cache_active',
  523. 'is_bool' => true,
  524. 'values' => array(
  525. array(
  526. 'id' => 'cache_active_on',
  527. 'value' => 1,
  528. 'label' => $this->l('Enabled')
  529. ),
  530. array(
  531. 'id' => 'cache_active_off',
  532. 'value' => 0,
  533. 'label' => $this->l('Disabled')
  534. )
  535. )
  536. ),
  537. array(
  538. 'type' => 'radio',
  539. 'label' => $this->l('Caching system'),
  540. 'name' => 'caching_system',
  541. 'hint' => $this->l('The CacheFS system should be used only when the infrastructure contains one front-end server. If you are not sure, ask your hosting company.'),
  542. 'values' => array(
  543. array(
  544. 'id' => 'CacheFs',
  545. 'value' => 'CacheFs',
  546. 'label' => $this->l('File System').(is_writable(_PS_CACHEFS_DIRECTORY_) ? '' : $warning_fs)
  547. ),
  548. array(
  549. 'id' => 'CacheMemcache',
  550. 'value' => 'CacheMemcache',
  551. 'label' => $this->l('Memcached via PHP::Memcache').(extension_loaded('memcache') ? '' : $warning_memcache)
  552. ),
  553. array(
  554. 'id' => 'CacheMemcached',
  555. 'value' => 'CacheMemcached',
  556. 'label' => $this->l('Memcached via PHP::Memcached').(extension_loaded('memcached') ? '' : $warning_memcached)
  557. ),
  558. array(
  559. 'id' => 'CacheApc',
  560. 'value' => 'CacheApc',
  561. 'label' => $this->l('APC').(extension_loaded('apc') ? '' : $warning_apc)
  562. ),
  563. array(
  564. 'id' => 'CacheXcache',
  565. 'value' => 'CacheXcache',
  566. 'label' => $this->l('Xcache').(extension_loaded('xcache') ? '' : $warning_xcache)
  567. ),
  568. )
  569. ),
  570. array(
  571. 'type' => 'text',
  572. 'label' => $this->l('Directory depth'),
  573. 'name' => 'ps_cache_fs_directory_depth'
  574. ),
  575. ),
  576. 'submit' => array(
  577. 'title' => $this->l('Save')
  578. ),
  579. 'memcachedServers' => true
  580. );
  581. $depth = Configuration::get('PS_CACHEFS_DIRECTORY_DEPTH');
  582. $this->fields_value['cache_active'] = _PS_CACHE_ENABLED_;
  583. $this->fields_value['caching_system'] = _PS_CACHING_SYSTEM_;
  584. $this->fields_value['ps_cache_fs_directory_depth'] = $depth ? $depth : 1;
  585. $this->tpl_form_vars['servers'] = CacheMemcache::getMemcachedServers();
  586. $this->tpl_form_vars['_PS_CACHE_ENABLED_'] = _PS_CACHE_ENABLED_;
  587. }
  588. public function renderForm()
  589. {
  590. $this->initFieldsetSmarty();
  591. $this->initFieldsetDebugMode();
  592. $this->initFieldsetFeaturesDetachables();
  593. $this->initFieldsetCCC();
  594. if (!defined('_PS_HOST_MODE_')) {
  595. $this->initFieldsetMediaServer();
  596. $this->initFieldsetCiphering();
  597. $this->initFieldsetCaching();
  598. }
  599. // Reindex fields
  600. $this->fields_form = array_values($this->fields_form);
  601. // Activate multiple fieldset
  602. $this->multiple_fieldsets = true;
  603. return parent::renderForm();
  604. }
  605. public function initContent()
  606. {
  607. $this->initTabModuleList();
  608. $this->initToolbar();
  609. $this->initPageHeaderToolbar();
  610. $this->display = '';
  611. $this->content .= $this->renderForm();
  612. $this->context->smarty->assign(array(
  613. 'content' => $this->content,
  614. 'url_post' => self::$currentIndex.'&token='.$this->token,
  615. 'show_page_header_toolbar' => $this->show_page_header_toolbar,
  616. 'page_header_toolbar_title' => $this->page_header_toolbar_title,
  617. 'page_header_toolbar_btn' => $this->page_header_toolbar_btn,
  618. 'title' => $this->page_header_toolbar_title,
  619. 'toolbar_btn' => $this->page_header_toolbar_btn
  620. ));
  621. }
  622. public function initPageHeaderToolbar()
  623. {
  624. parent::initPageHeaderToolbar();
  625. $this->page_header_toolbar_btn['clear_cache'] = array(
  626. 'href' => self::$currentIndex.'&token='.$this->token.'&empty_smarty_cache=1',
  627. 'desc' => $this->l('Clear cache'),
  628. 'icon' => 'process-icon-eraser'
  629. );
  630. }
  631. public function postProcess()
  632. {
  633. /* PrestaShop demo mode */
  634. if (_PS_MODE_DEMO_) {
  635. $this->errors[] = Tools::displayError('This functionality has been disabled.');
  636. return;
  637. }
  638. Hook::exec('action'.get_class($this).ucfirst($this->action).'Before', array('controller' => $this));
  639. if (Tools::isSubmit('submitAddServer')) {
  640. if ($this->tabAccess['add'] === '1') {
  641. if (!Tools::getValue('memcachedIp')) {
  642. $this->errors[] = Tools::displayError('The Memcached IP is missing.');
  643. }
  644. if (!Tools::getValue('memcachedPort')) {
  645. $this->errors[] = Tools::displayError('The Memcached port is missing.');
  646. }
  647. if (!Tools::getValue('memcachedWeight')) {
  648. $this->errors[] = Tools::displayError('The Memcached weight is missing.');
  649. }
  650. if (!count($this->errors)) {
  651. if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')),
  652. (int)Tools::getValue('memcachedPort'),
  653. (int)Tools::getValue('memcachedWeight'))) {
  654. Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  655. } else {
  656. $this->errors[] = Tools::displayError('The Memcached server cannot be added.');
  657. }
  658. }
  659. } else {
  660. $this->errors[] = Tools::displayError('You do not have permission to add this.');
  661. }
  662. }
  663. if (Tools::getValue('deleteMemcachedServer')) {
  664. if ($this->tabAccess['add'] === '1') {
  665. if (CacheMemcache::deleteServer((int)Tools::getValue('deleteMemcachedServer'))) {
  666. Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  667. } else {
  668. $this->errors[] = Tools::displayError('There was an error when attempting to delete the Memcached server.');
  669. }
  670. } else {
  671. $this->errors[] = Tools::displayError('You do not have permission to delete this.');
  672. }
  673. }
  674. $redirectAdmin = false;
  675. if ((bool)Tools::getValue('smarty_up')) {
  676. if ($this->tabAccess['edit'] === '1') {
  677. Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
  678. if (Configuration::get('PS_SMARTY_CACHE') != Tools::getValue('smarty_cache') || Configuration::get('PS_SMARTY_CACHING_TYPE') != Tools::getValue('smarty_caching_type')) {
  679. Tools::clearSmartyCache();
  680. }
  681. Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
  682. Configuration::updateValue('PS_SMARTY_CACHING_TYPE', Tools::getValue('smarty_caching_type'));
  683. Configuration::updateValue('PS_SMARTY_CLEAR_CACHE', Tools::getValue('smarty_clear_cache'));
  684. $redirectAdmin = true;
  685. } else {
  686. $this->errors[] = Tools::displayError('You do not have permission to edit this.');
  687. }
  688. }
  689. if ((bool)Tools::getValue('features_detachables_up')) {
  690. if ($this->tabAccess['edit'] === '1') {
  691. if (Tools::isSubmit('combination')) {
  692. if ((!Tools::getValue('combination') && Combination::isCurrentlyUsed()) === false) {
  693. Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', (bool)Tools::getValue('combination'));
  694. }
  695. }
  696. if (Tools::isSubmit('customer_group')) {
  697. if ((!Tools::getValue('customer_group') && Group::isCurrentlyUsed()) === false) {
  698. Configuration::updateValue('PS_GROUP_FEATURE_ACTIVE', (bool)Tools::getValue('customer_group'));
  699. }
  700. }
  701. Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', (bool)Tools::getValue('feature'));
  702. $redirectAdmin = true;
  703. } else {
  704. $this->errors[] = Tools::displayError('You do not have permission to edit this.');
  705. }
  706. }
  707. if ((bool)Tools::getValue('ccc_up')) {
  708. if ($this->tabAccess['edit'] === '1') {
  709. $theme_cache_directory = _PS_ALL_THEMES_DIR_.$this->context->shop->theme_directory.'/cache/';
  710. if (((bool)Tools::getValue('PS_CSS_THEME_CACHE') || (bool)Tools::getValue('PS_JS_THEME_CACHE')) && !is_writable($theme_cache_directory)) {
  711. $this->errors[] = sprintf(Tools::displayError('To use Smart Cache directory %s must be writable.'), realpath($theme_cache_directory));
  712. }
  713. if ($tmp = (int)Tools::getValue('PS_CSS_THEME_CACHE')) {
  714. $version = (int)Configuration::get('PS_CCCCSS_VERSION');
  715. if (Configuration::get('PS_CSS_THEME_CACHE') != $tmp) {
  716. Configuration::updateValue('PS_CCCCSS_VERSION', ++$version);
  717. }
  718. }
  719. if ($tmp = (int)Tools::getValue('PS_JS_THEME_CACHE')) {
  720. $version = (int)Configuration::get('PS_CCCJS_VERSION');
  721. if (Configuration::get('PS_JS_THEME_CACHE') != $tmp) {
  722. Configuration::updateValue('PS_CCCJS_VERSION', ++$version);
  723. }
  724. }
  725. if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int)Tools::getValue('PS_CSS_THEME_CACHE')) ||
  726. !Configuration::updateValue('PS_JS_THEME_CACHE', (int)Tools::getValue('PS_JS_THEME_CACHE')) ||
  727. !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int)Tools::getValue('PS_HTML_THEME_COMPRESSION')) ||
  728. !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int)Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) ||
  729. !Configuration::updateValue('PS_JS_DEFER', (int)Tools::getValue('PS_JS_DEFER')) ||
  730. !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int)Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) {
  731. $this->errors[] = Tools::displayError('Unknown error.');
  732. } else {
  733. $redirectAdmin = true;
  734. if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) {
  735. if (is_writable(_PS_ROOT_DIR_.'/.htaccess')) {
  736. Tools::generateHtaccess();
  737. } else {
  738. $message = $this->l('Before being able to use this tool, you need to:');
  739. $message .= '<br />- '.$this->l('Create a blank .htaccess in your root directory.');
  740. $message .= '<br />- '.$this->l('Give it write permissions (CHMOD 666 on Unix system).');
  741. $this->errors[] = Tools::displayError($message, false);
  742. Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', false);
  743. }
  744. }
  745. }
  746. } else {
  747. $this->errors[] = Tools::displayError('You do not have permission to edit this.');
  748. }
  749. }
  750. if ((bool)Tools::getValue('media_server_up') && !defined('_PS_HOST_MODE_')) {
  751. if ($this->tabAccess['edit'] === '1') {
  752. if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) {
  753. $this->errors[] = Tools::displayError('Media server #1 is invalid');
  754. }
  755. if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) {
  756. $this->errors[] = Tools::displayError('Media server #2 is invalid');
  757. }
  758. if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) {
  759. $this->errors[] = Tools::displayError('Media server #3 is invalid');
  760. }
  761. if (!count($this->errors)) {
  762. $base_urls = array();
  763. $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_');
  764. $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_');
  765. $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_');
  766. if ($base_urls['_MEDIA_SERVER_1_'] || $base_urls['_MEDIA_SERVER_2_'] || $base_urls['_MEDIA_SERVER_3_']) {
  767. Configuration::updateValue('PS_MEDIA_SERVERS', 1);
  768. } else {
  769. Configuration::updateValue('PS_MEDIA_SERVERS', 0);
  770. }
  771. rewriteSettingsFile($base_urls, null, null);
  772. Configuration::updateValue('PS_MEDIA_SERVER_1', Tools::getValue('_MEDIA_SERVER_1_'));
  773. Configuration::updateValue('PS_MEDIA_SERVER_2', Tools::getValue('_MEDIA_SERVER_2_'));
  774. Configuration::updateValue('PS_MEDIA_SERVER_3', Tools::getValue('_MEDIA_SERVER_3_'));
  775. Tools::clearSmartyCache();
  776. Media::clearCache();
  777. if (is_writable(_PS_ROOT_DIR_.'/.htaccess')) {
  778. Tools::generateHtaccess(null, null, null, '', null, array($base_urls['_MEDIA_SERVER_1_'], $base_urls['_MEDIA_SERVER_2_'], $base_urls['_MEDIA_SERVER_3_']));
  779. unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']);
  780. unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']);
  781. unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']);
  782. $redirectAdmin = true;
  783. } else {
  784. $message = $this->l('Before being able to use this tool, you need to:');
  785. $message .= '<br />- '.$this->l('Create a blank .htaccess in your root directory.');
  786. $message .= '<br />- '.$this->l('Give it write permissions (CHMOD 666 on Unix system).');
  787. $this->errors[] = Tools::displayError($message, false);
  788. Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', false);
  789. }
  790. }
  791. } else {
  792. $this->errors[] = Tools::displayError('You do not have permission to edit this.');
  793. }
  794. }
  795. if ((bool)Tools::getValue('ciphering_up') && Configuration::get('PS_CIPHER_ALGORITHM') != (int)Tools::getValue('PS_CIPHER_ALGORITHM')) {
  796. if ($this->tabAccess['edit'] === '1') {
  797. $algo = (int)Tools::getValue('PS_CIPHER_ALGORITHM');
  798. $prev_settings = file_get_contents(_PS_ROOT_DIR_.'/config/settings.inc.php');
  799. $new_settings = $prev_settings;
  800. if ($algo) {
  801. if (!function_exists('mcrypt_encrypt')) {
  802. $this->errors[] = Tools::displayError('The "Mcrypt" PHP extension is not activated on this server.');
  803. } else {
  804. if (!strstr($new_settings, '_RIJNDAEL_KEY_')) {
  805. $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
  806. $key = Tools::passwdGen($key_size);
  807. $new_settings = preg_replace(
  808. '/define\(\'_COOKIE_KEY_\', \'([a-z0-9=\/+-_]+)\'\);/i',
  809. 'define(\'_COOKIE_KEY_\', \'\1\');'."\n".'define(\'_RIJNDAEL_KEY_\', \''.$key.'\');',
  810. $new_settings
  811. );
  812. }
  813. if (!strstr($new_settings, '_RIJNDAEL_IV_')) {
  814. $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
  815. $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND));
  816. $new_settings = preg_replace(
  817. '/define\(\'_COOKIE_IV_\', \'([a-z0-9=\/+-_]+)\'\);/i',
  818. 'define(\'_COOKIE_IV_\', \'\1\');'."\n".'define(\'_RIJNDAEL_IV_\', \''.$iv.'\');',
  819. $new_settings
  820. );
  821. }
  822. }
  823. }
  824. if (!count($this->errors)) {
  825. // If there is not settings file modification or if the backup and replacement of the settings file worked
  826. if ($new_settings == $prev_settings || (
  827. copy(_PS_ROOT_DIR_.'/config/settings.inc.php', _PS_ROOT_DIR_.'/config/settings.old.php')
  828. && (bool)file_put_contents(_PS_ROOT_DIR_.'/config/settings.inc.php', $new_settings)
  829. )) {
  830. Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo);
  831. $redirectAdmin = true;
  832. } else {
  833. $this->errors[] = Tools::displayError('The settings file cannot be overwritten.');
  834. }
  835. }
  836. } else {
  837. $this->errors[] = Tools::displayError('You do not have permission to edit this.');
  838. }
  839. }
  840. if ((bool)Tools::getValue('cache_up')) {
  841. if ($this->tabAccess['edit'] === '1') {
  842. $new_settings = $prev_settings = file_get_contents(_PS_ROOT_DIR_.'/config/settings.inc.php');
  843. $cache_active = (bool)Tools::getValue('cache_active');
  844. if ($caching_system = preg_replace('[^a-zA-Z0-9]', '', Tools::getValue('caching_system'))) {
  845. $new_settings = preg_replace(
  846. '/define\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\/+-_]*)\'\);/Ui',
  847. 'define(\'_PS_CACHING_SYSTEM_\', \''.$caching_system.'\');',
  848. $new_settings
  849. );
  850. } else {
  851. $cache_active = false;
  852. $this->errors[] = Tools::displayError('The caching system is missing.');
  853. }
  854. if ($cache_active) {
  855. if ($caching_system == 'CacheMemcache' && !extension_loaded('memcache')) {
  856. $this->errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.').'
  857. <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
  858. } elseif ($caching_system == 'CacheMemcached' && !extension_loaded('memcached')) {
  859. $this->errors[] = Tools::displayError('To use Memcached, you must install the Memcached PECL extension on your server.').'
  860. <a href="http://www.php.net/manual/en/memcached.installation.php">http://www.php.net/manual/en/memcached.installation.php</a>';
  861. } elseif ($caching_system == 'CacheApc' && !extension_loaded('apc')) {
  862. $this->errors[] = Tools::displayError('To use APC cache, you must install the APC PECL extension on your server.').'
  863. <a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>';
  864. } elseif ($caching_system == 'CacheXcache' && !extension_loaded('xcache')) {
  865. $this->errors[] = Tools::displayError('To use Xcache, you must install the Xcache extension on your server.').'
  866. <a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>';
  867. } elseif ($caching_system == 'CacheXcache' && !ini_get('xcache.var_size')) {
  868. $this->errors[] = Tools::displayError('To use Xcache, you must configure "xcache.var_size" for the Xcache extension (recommended value 16M to 64M).').'
  869. <a href="http://xcache.lighttpd.net/wiki/XcacheIni">http://xcache.lighttpd.net/wiki/XcacheIni</a>';
  870. } elseif ($caching_system == 'CacheFs') {
  871. if (!is_dir(_PS_CACHEFS_DIRECTORY_)) {
  872. @mkdir(_PS_CACHEFS_DIRECTORY_, 0777, true);
  873. } elseif (!is_writable(_PS_CACHEFS_DIRECTORY_)) {
  874. $this->errors[] = sprintf(Tools::displayError('To use CacheFS, the directory %s must be writable.'), realpath(_PS_CACHEFS_DIRECTORY_));
  875. }
  876. }
  877. if ($caching_system == 'CacheFs') {
  878. if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) {
  879. $this->errors[] = Tools::displayError('Please set a directory depth.');
  880. }
  881. if (!count($this->errors)) {
  882. CacheFs::deleteCacheDirectory();
  883. CacheFs::createCacheDirectories((int)$depth);
  884. Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int)$depth);
  885. }
  886. } elseif ($caching_system == 'CacheMemcache' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache') {
  887. Cache::getInstance()->flush();
  888. } elseif ($caching_system == 'CacheMemcached' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcached') {
  889. Cache::getInstance()->flush();
  890. }
  891. }
  892. if (!count($this->errors)) {
  893. $new_settings = preg_replace('/define\(\'_PS_CACHE_ENABLED_\', \'([01]?)\'\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \''.(int)$cache_active.'\');', $new_settings);
  894. // If there is not settings file modification or if the backup and replacement of the settings file worked
  895. if ($new_settings == $prev_settings || (
  896. copy(_PS_ROOT_DIR_.'/config/settings.inc.php', _PS_ROOT_DIR_.'/config/settings.old.php')
  897. && (bool)file_put_contents(_PS_ROOT_DIR_.'/config/settings.inc.php', $new_settings)
  898. )) {
  899. if (function_exists('opcache_invalidate')) {
  900. opcache_invalidate(_PS_ROOT_DIR_.'/config/settings.inc.php');
  901. }
  902. $redirectAdmin = true;
  903. } else {
  904. $this->errors[] = Tools::displayError('The settings file cannot be overwritten.');
  905. }
  906. }
  907. } else {
  908. $this->errors[] = Tools::displayError('You do not have permission to edit this.');
  909. }
  910. }
  911. if ((bool)Tools::getValue('empty_smarty_cache')) {
  912. $redirectAdmin = true;
  913. Tools::clearSmartyCache();
  914. Tools::clearXMLCache();
  915. Media::clearCache();
  916. Tools::generateIndex();
  917. }
  918. if (Tools::isSubmit('submitAddconfiguration')) {
  919. Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int)Tools::getValue('native_module'));
  920. Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', (int)Tools::getValue('overrides'));
  921. Tools::generateIndex();
  922. }
  923. if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) {
  924. Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => ''));
  925. Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4');
  926. }
  927. }
  928. public function displayAjaxTestServer()
  929. {
  930. /* PrestaShop demo mode */
  931. if (_PS_MODE_DEMO_) {
  932. die(Tools::displayError('This functionality has been disabled.'));
  933. }
  934. /* PrestaShop demo mode*/
  935. if (Tools::isSubmit('action') && Tools::getVal