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: echo '<h2>Listing contents of cache directory: '.$this->dataDir.'</h2>';
112:
113: $fileCount = AlphaFileUtils::listDirectoryContents($this->dataDir, 0, array('.htaccess'));
114:
115: echo '<h2>Total of '.$fileCount.' files in the cache.</h2>';
116:
117: echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="post" name="clearForm" id="clearForm">';
118: echo '<input type="hidden" name="clearCache" id="clearCache" value="false"/>';
119: $js = "$('#dialogDiv').text('Are you sure you want to delete all files in the cache?');
120: $('#dialogDiv').dialog({
121: buttons: {
122: 'OK': function(event, ui) {
123: $('#clearCache').attr('value', 'true');
124: $('#clearForm').submit();
125: },
126: 'Cancel': function(event, ui) {
127: $(this).dialog('close');
128: }
129: }
130: })
131: $('#dialogDiv').dialog('open');
132: return false;";
133: $button = new Button($js, "Clear cache", "clearBut");
134: echo $button->render();
135:
136: echo AlphaView::renderSecurityFields();
137: echo '</form>';
138:
139: echo AlphaView::displayPageFoot($this);
140:
141: self::$logger->debug('<<doGET');
142: }
143:
144: 145: 146: 147: 148: 149: 150: 151:
152: public function doPOST($params) {
153: self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
154:
155: try {
156:
157: if(!$this->checkSecurityFields())
158: throw new SecurityException('This page cannot accept post data from remote servers!');
159:
160: if(!is_array($params))
161: throw new IllegalArguementException('Bad $params ['.var_export($params, true).'] passed to doPOST method!');
162:
163: if (isset($params['clearCache']) && $params['clearCache'] == 'true') {
164: try {
165: AlphaFileUtils::deleteDirectoryContents($this->dataDir, array('.htaccess'));
166:
167: $this->setStatusMessage(AlphaView::displayUpdateMessage('Cache contents deleted successfully.'));
168:
169: self::$logger->info('Cache contents deleted successfully by user ['.$_SESSION['currentUser']->get('displayName').'].');
170: }catch (AlphaException $e) {
171: self::$logger->error($e->getMessage());
172: $this->setStatusMessage(AlphaView::displayErrorMessage($e->getMessage()));
173: }
174: }
175:
176: $this->doGET($params);
177: }catch(SecurityException $e) {
178: $this->setStatusMessage(AlphaView::displayErrorMessage($e->getMessage()));
179:
180: self::$logger->warn($e->getMessage());
181: }catch(IllegalArguementException $e) {
182: self::$logger->error($e->getMessage());
183: $this->setStatusMessage(AlphaView::displayErrorMessage($e->getMessage()));
184: }
185:
186: echo AlphaView::displayPageFoot($this);
187: self::$logger->debug('<<doPOST');
188: }
189:
190: 191: 192: 193: 194:
195: public function after_displayPageHead_callback() {
196: $menu = AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
197:
198: return $menu;
199: }
200: }
201:
202:
203: if ('CacheManager.php' == basename($_SERVER['PHP_SELF'])) {
204: $controller = new CacheManager();
205:
206: if(!empty($_POST)) {
207: $controller->doPOST($_QUERY);
208: }else{
209: $controller->doGET($_GET);
210: }
211: }
212:
213: ?>