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

/public/shop/admin/controller/pages/tool/cache.php

https://bitbucket.org/rusbal/club4causes
PHP | 202 lines | 159 code | 19 blank | 24 comment | 21 complexity | ad066634b540db7ccd66f66aac0e090e MD5 | raw file
  1. <?php
  2. /*------------------------------------------------------------------------------
  3. $Id$
  4. Shopping Cart
  5. http://dev.club4causes.com/shop
  6. Club4Causes v1.0
  7. This source file is subject to Open Software License (OSL 3.0)
  8. License details is bundled with this package in the file LICENSE.txt.
  9. It is also available at this URL:
  10. <http://www.opensource.org/licenses/OSL-3.0>
  11. UPGRADE NOTE:
  12. Do not edit or add to this file if you wish to upgrade Shopping Cart to newer
  13. versions in the future. If you wish to customize Shopping Cart for your
  14. needs please refer to http://dev.club4causes.com/shop for more information.
  15. ------------------------------------------------------------------------------*/
  16. if (! defined ( 'DIR_CORE' ) || !IS_ADMIN) {
  17. header ( 'Location: static_pages/' );
  18. }
  19. class ControllerPagesToolCache extends AController {
  20. private $error = array();
  21. public $data;
  22. public function main() {
  23. //init controller data
  24. $this->extensions->hk_InitData($this,__FUNCTION__);
  25. $this->document->setTitle($this->language->get('heading_title'));
  26. $this->document->initBreadcrumb( array (
  27. 'href' => $this->html->getSecureURL('index/home'),
  28. 'text' => $this->language->get('text_home'),
  29. 'separator' => FALSE
  30. ));
  31. $this->document->addBreadcrumb( array (
  32. 'href' => $this->html->getSecureURL('tool/cache'),
  33. 'text' => $this->language->get('heading_title'),
  34. 'separator' => ' :: '
  35. ));
  36. $this->data['sections'] = array(
  37. array(
  38. 'id' => 'configuration',
  39. 'text' => $this->language->get('text_configuration'),
  40. 'description' => $this->language->get('desc_configuration'),
  41. 'keywords' => 'settings,store,stores,attribute,attributes,length_class,contents,tax_class,order_status,stock_status,weight_class,storefront_menu,tables' // separated by comma
  42. ),
  43. array(
  44. 'id' => 'layout',
  45. 'text' => $this->language->get('text_layouts_blocks'),
  46. 'description' => $this->language->get('desc_layouts_blocks'),
  47. 'keywords' => 'layout'
  48. ),
  49. array(
  50. 'id' => 'flexyforms',
  51. 'text' => $this->language->get('text_flexyforms'),
  52. 'description' => $this->language->get('desc_flexyforms'),
  53. 'keywords' => 'forms'
  54. ),
  55. array(
  56. 'id' => 'translation',
  57. 'text' => $this->language->get('text_translations'),
  58. 'description' => $this->language->get('desc_translations'),
  59. 'keywords' => 'lang'
  60. ),
  61. array(
  62. 'id' => 'image',
  63. 'text' => $this->language->get('text_images'),
  64. 'description' => $this->language->get('desc_images'),
  65. 'keywords' => 'image,resources'
  66. ),
  67. array(
  68. 'id' => 'product',
  69. 'text' => $this->language->get('text_products'),
  70. 'description' => $this->language->get('desc_products'),
  71. 'keywords' => 'product'
  72. ),
  73. array(
  74. 'id' => 'category',
  75. 'text' => $this->language->get('text_categories'),
  76. 'description' => $this->language->get('desc_categories'),
  77. 'keywords' => 'category'
  78. ),
  79. array(
  80. 'id' => 'manufacturer',
  81. 'text' => $this->language->get('text_manufacturers'),
  82. 'description' => $this->language->get('desc_manufacturers'),
  83. 'keywords' => 'manufacturer'
  84. ),
  85. array(
  86. 'id' => 'localisation',
  87. 'text' => $this->language->get('text_localisations'),
  88. 'description' => $this->language->get('desc_localisations'),
  89. 'keywords' => 'currency,country,zone,language'
  90. ),
  91. array(
  92. 'id' => 'error_log',
  93. 'text' => $this->language->get('text_error_log'),
  94. 'description' => $this->language->get('desc_error_log'),
  95. 'keywords' => 'error_log'
  96. ),
  97. );
  98. $form = new AForm('ST');
  99. $form->setForm( array('form_name' => 'cacheFrm'));
  100. $this->data['form']['form_open'] = $form->getFieldHtml(array(
  101. 'type' => 'form',
  102. 'name' => 'cacheFrm',
  103. 'action' => $this->html->getSecureURL('tool/cache/delete')));
  104. $this->data['form']['submit'] = $form->getFieldHtml ( array ('type' => 'button',
  105. 'name' => 'submit',
  106. 'text' => $this->language->get ( 'text_clear_cache' ),
  107. 'style' => 'button1') );
  108. if (isset($this->error['warning'])) {
  109. $this->data['error_warning'] = $this->error['warning'];
  110. } else {
  111. $this->data['error_warning'] = '';
  112. }
  113. if (isset($this->session->data['success'])) {
  114. $this->data['success'] = $this->session->data['success'];
  115. unset($this->session->data['success']);
  116. } else {
  117. $this->data['success'] = '';
  118. }
  119. $this->view->batchAssign($this->data);
  120. $this->view->assign('help_url', $this->gen_help_url() );
  121. $this->processTemplate('pages/tool/cache.tpl' );
  122. //update controller data
  123. $this->extensions->hk_UpdateData($this,__FUNCTION__);
  124. }
  125. public function delete() {
  126. //init controller data
  127. $this->extensions->hk_InitData($this,__FUNCTION__);
  128. if (isset($this->request->post['selected']) && $this->request->post['selected'] && $this->_validateDelete()) {
  129. foreach ($this->request->post['selected'] as $cache) {
  130. if($cache == 'image') {
  131. $this->deleteThumbnails();
  132. } else {
  133. if($cache=='error_log'){
  134. @unlink(DIR_LOGS.$this->config->get('config_error_filename'));
  135. }
  136. $keywords = explode(',', $cache);
  137. if($keywords){
  138. foreach($keywords as $keyword) {
  139. $this->cache->delete($keyword);
  140. }
  141. }
  142. }
  143. }
  144. $this->session->data['success'] = $this->language->get('text_success');
  145. }
  146. //update controller data
  147. $this->extensions->hk_UpdateData($this,__FUNCTION__);
  148. $this->redirect($this->html->getSecureURL('tool/cache'));
  149. }
  150. public function deleteThumbnails() {
  151. //init controller data
  152. $this->extensions->hk_InitData($this,__FUNCTION__);
  153. $path = DIR_IMAGE . 'thumbnails/';
  154. $iterator = new RecursiveDirectoryIterator($path);
  155. foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
  156. if(is_int(strpos($file->getPathname(),'/.svn')) || is_int(strpos($file->getPathname(),'/index.html'))){
  157. continue;
  158. }
  159. if ($file->isDir()) {
  160. rmdir($file->getPathname());
  161. } else {
  162. unlink($file->getPathname());
  163. }
  164. }
  165. //update controller data
  166. $this->extensions->hk_UpdateData($this,__FUNCTION__);
  167. }
  168. private function _validateDelete() {
  169. if (!$this->user->canModify('tool/cache')) {
  170. $this->error['warning'] = $this->language->get('error_permission');
  171. }
  172. if (!$this->error) {
  173. return TRUE;
  174. } else {
  175. return FALSE;
  176. }
  177. }
  178. }
  179. ?>