1: <?php
2:
3:
4: if(!isset($config)) {
5: require_once '../util/AlphaConfig.inc';
6: $config = AlphaConfig::getInstance();
7:
8: require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
9: }
10:
11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: class CacheManager extends AlphaController implements AlphaControllerInterface {
57: 58: 59: 60: 61: 62:
63: private $dataDir;
64:
65: 66: 67: 68: 69: 70:
71: private static $logger = null;
72:
73: 74: 75: 76: 77:
78: public function __construct() {
79: self::$logger = new Logger('CacheManager');
80: self::$logger->debug('>>__construct()');
81:
82: global $config;
83:
84:
85: parent::__construct('Admin');
86:
87: $this->setTitle('Cache Manager');
88: $this->dataDir = $config->get('app.file.store.dir').'cache/';
89:
90: self::$logger->debug('<<__construct');
91: }
92:
93: 94: 95: 96: 97: 98: 99:
100: public function doGET($params) {
101: self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
102:
103: global $config;
104:
105: if(!is_array($params))
106: throw new IllegalArguementException('Bad $params ['.var_export($params, true).'] passed to doGET method!');
107:
108:
109: echo AlphaView::displayPageHead($this);
110:
111: $message = $this->getStatusMessage();
112: if(!empty($message))
113: echo $message;
114:
115: echo '<h3>Listing contents of cache directory: '.$this->dataDir.'</h3>';
116:
117: $fileCount = AlphaFileUtils::listDirectoryContents($this->dataDir, 0, array('.htaccess'));
118:
119: echo '<h3>Total of '.$fileCount.' files in the cache.</h3>';
120:
121: echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="post" name="clearForm" id="clearForm">';
122: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('clearCache')) : 'clearCache');
123: echo '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="false"/>';
124: $js = "if(window.jQuery) {
125: BootstrapDialog.show({
126: title: 'Confirmation',
127: message: 'Are you sure you want to delete all files in the cache?',
128: buttons: [
129: {
130: icon: 'glyphicon glyphicon-remove',
131: label: 'Cancel',
132: cssClass: 'btn btn-default btn-xs',
133: action: function(dialogItself){
134: dialogItself.close();
135: }
136: },
137: {
138: icon: 'glyphicon glyphicon-ok',
139: label: 'Okay',
140: cssClass: 'btn btn-default btn-xs',
141: action: function(dialogItself) {
142: $('[id=\"".$fieldname."\"]').attr('value', 'true');
143: $('#clearForm').submit();
144: dialogItself.close();
145: }
146: }
147: ]
148: });
149: }";
150: $button = new Button($js, "Clear cache", "clearBut");
151: echo $button->render();
152:
153: echo AlphaView::renderSecurityFields();
154: echo '</form>';
155:
156: echo AlphaView::displayPageFoot($this);
157:
158: self::$logger->debug('<<doGET');
159: }
160:
161: 162: 163: 164: 165: 166:
167: public function doPOST($params) {
168: self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
169:
170: try {
171:
172: if(!$this->checkSecurityFields())
173: throw new SecurityException('This page cannot accept post data from remote servers!');
174:
175: if(!is_array($params))
176: throw new IllegalArguementException('Bad $params ['.var_export($params, true).'] passed to doPOST method!');
177:
178: if (isset($params['clearCache']) && $params['clearCache'] == 'true') {
179: try {
180: AlphaFileUtils::deleteDirectoryContents($this->dataDir, array('.htaccess'));
181:
182: $this->setStatusMessage(AlphaView::displayUpdateMessage('Cache contents deleted successfully.'));
183:
184: self::$logger->info('Cache contents deleted successfully by user ['.$_SESSION['currentUser']->get('displayName').'].');
185: }catch (AlphaException $e) {
186: self::$logger->error($e->getMessage());
187: $this->setStatusMessage(AlphaView::displayErrorMessage($e->getMessage()));
188: }
189: }
190:
191: return $this->doGET($params);
192: }catch(SecurityException $e) {
193: $this->setStatusMessage(AlphaView::displayErrorMessage($e->getMessage()));
194:
195: self::$logger->warn($e->getMessage());
196: }catch(IllegalArguementException $e) {
197: self::$logger->error($e->getMessage());
198: $this->setStatusMessage(AlphaView::displayErrorMessage($e->getMessage()));
199: }
200:
201: echo AlphaView::displayPageHead($this);
202:
203: $message = $this->getStatusMessage();
204: if(!empty($message))
205: echo $message;
206:
207: echo AlphaView::displayPageFoot($this);
208: self::$logger->debug('<<doPOST');
209: }
210:
211: 212: 213: 214: 215:
216: public function after_displayPageHead_callback() {
217: $menu = AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
218:
219: return $menu;
220: }
221: }
222:
223:
224: if ('CacheManager.php' == basename($_SERVER['PHP_SELF'])) {
225: $controller = new CacheManager();
226:
227: if(!empty($_POST)) {
228: $controller->doPOST($_QUERY);
229: }else{
230: $controller->doGET($_GET);
231: }
232: }
233:
234: ?>