1<?php 2 3use dokuwiki\Extension\AdminPlugin; 4 5/** 6 * Cache/Revisions Eraser admin plugin 7 * Version : 1.6.6 8 * 9 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 10 * @author JustBurn <justburner@armail.pt> 11 */ 12 13if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 15require_once(DOKU_PLUGIN.'admin.php'); 16require_once(DOKU_INC.'inc/init.php'); 17define('CACHEREVISIONSERASER2_VER','1.6.7'); 18define('CACHEREVISIONSERASER2_CONFIGREVISION',2); 19define('CACHEREVISIONSERASER2_DATE','2010-11-22'); 20 21/** 22 * All DokuWiki plugins to extend the admin function 23 * need to inherit from this class 24 * 25 * The class name needs to be consistent with the name of the plugin page 26 */ 27class admin_plugin_cacherevisionseraser2 extends AdminPlugin { 28 29 var $cachedir = null; 30 var $revisdir = null; 31 var $pagesdir = null; 32 var $metadir = null; 33 var $configs = null; 34 var $filedels = 0; 35 var $dirdels = 0; 36 37 /** 38 * Constructor 39 */ 40 function __construct(){ 41 $this->setupLocale(); 42 @include(dirname(__FILE__).'/configs.php'); 43 } 44 45 /** 46 * Return plug-in info 47 */ 48 function getInfo(){ 49 return array( 50 'author' => 'JustBurn', 51 'email' => 'justburner@armail.pt', 52 'date' => CACHEREVISIONSERASER2_DATE, 53 'name' => html_entity_decode($this->lang['title']), 54 'desc' => html_entity_decode($this->lang['desc']), 55 'url' => 'http://wiki.splitbrain.org/plugin:cacherevisionseraser', 56 ); 57 } 58 59 /** 60 * Return prompt for admin menu 61 */ 62 function getMenuText($language) { 63 return $this->getLang('menu') . ' (v' . CACHEREVISIONSERASER2_VER . ')'; 64 } 65 66 /** 67 * Return sort order for position in admin menu 68 */ 69 function getMenuSort() { 70 if ($this->configs['menusort'] == null) return 67; 71 else return $this->configs['menusort']; 72 } 73 74 /** 75 * Handle user request 76 */ 77 function handle() { 78 global $conf; 79 $this->cachedir = $conf['cachedir']; // This configuration item is deprecated 80 $this->revisdir = $conf['olddir']; // This configuration item is deprecated 81 $this->pagesdir = $conf['datadir']; // This configuration item is deprecated 82 if ($this->pagesdir == null) $this->pagesdir = $conf['savedir']; // Olders versions compability? 83 $this->metadir = $conf['metadir']; // This configuration item is deprecated 84 if ($this->metadir == null) $this->metadir = $conf['meta']; // Olders versions compability? 85 $this->locksdir = $conf['lockdir']; // This configuration item is deprecated 86 if ($this->locksdir == null) $this->locksdir = $this->pagesdir; // Olders versions compability? 87 $this->lang_id = $conf['lang']; 88 if (!($this->configs['confrevision'] > 0)) $this->configs['confrevision'] = 0; 89 $this->locktime = $conf['locktime']; 90 } 91 92 /** 93 * Get request variable 94 */ 95 function get_req($reqvar, $defaultval) { 96 if (isset($_REQUEST[$reqvar])) { 97 return $_REQUEST[$reqvar]; 98 } else { 99 return $defaultval; 100 } 101 } 102 103 /** 104 * Compare request variable 105 */ 106 function cmp_req($reqvar, $strtocmp, $onequal, $ondifferent) { 107 if (isset($_REQUEST[$reqvar])) { 108 return strcmp($_REQUEST[$reqvar], $strtocmp) ? $ondifferent : $onequal; 109 } else { 110 return $ondifferent; 111 } 112 } 113 114 /** 115 * Output appropriate html 116 */ 117 function html() { 118 global $ID; 119 global $lang; 120 global $cacherevercfg; 121 global $conf; 122 123 $cmd = $this->get_req('cmd', 'main'); 124 125 // Plug-in title 126 ptln('<h1>'.$this->lang['title'].' '.$this->lang['version'].' '.CACHEREVISIONSERASER2_VER.'</h1>'); 127 128 // Make sure outputinfo level is valid 129 $theoutputinfo = intval($this->get_req('level_outputinfo', 0)); 130 if ($this->configs['allow_outputinfo']) { 131 if (($theoutputinfo < 0) || ($theoutputinfo > 2)) $theoutputinfo = 0; 132 } else { 133 $theoutputinfo = intval($this->configs['level_outputinfo']); 134 } 135 136 // Debugging only 137 if ($this->configs['debuglist']) { 138 ptln('<table class="inline">'); 139 ptln('<tr><th class="centeralign"><strong>Debugging information</strong></th></tr>'); 140 ptln('<tr><th>'); 141 ptln('config revision: <em>'.$this->configs['confrevision'].' (require '.CACHEREVISIONSERASER2_CONFIGREVISION.')</em><br />'); 142 ptln('admin menu position: <em>'.$this->configs['menusort'].'</em><br />'); 143 ptln('language (C/R E.): <em>'.$this->lang['language'].'</em><br />'); 144 ptln('cachedir: <em>'.$this->cachedir.'</em><br />'); 145 ptln('revisdir: <em>'.$this->revisdir.'</em><br />'); 146 ptln('pagesdir: <em>'.$this->pagesdir.'</em><br />'); 147 ptln('metadir: <em>'.$this->metadir.'</em><br />'); 148 ptln('locksdir: <em>'.$this->locksdir.'</em><br />'); 149 ptln('language id (Doku): <em>'.$this->lang_id.'</em><br />'); 150 ptln('</th></tr></table><br />'); 151 } 152 153 // Plug-in processing... 154 $this->filedels = 0; 155 $this->dirdels = 0; 156 if ($this->analyzecrpt($cmd)) 157 if ((strcmp($cmd, 'erasecache') == 0) && ($this->configs['allow_allcachedel'])) { 158 // Erase cache... 159 ptln('<table class="inline">'); 160 ptln('<tr><th class="leftalign">'); 161 clearstatcache(); 162 $succop = true; 163 $params = $this->cmp_req('delfl_UNK', 'yes', 0x01, 0) + $this->cmp_req('del_indexing', 'yes', 0x02, 0) + $this->cmp_req('delfl_i', 'yes', 0x04, 0) + $this->cmp_req('delfl_xhtml', 'yes', 0x08, 0) + $this->cmp_req('delfl_js', 'yes', 0x10, 0) + $this->cmp_req('delfl_css', 'yes', 0x20, 0) + $this->cmp_req('delfl_mediaP', 'yes', 0x40, 0); 164 $prmask = ($this->configs['cache_delext_UNK']==0 ? 0 : 0x01) + ($this->configs['cache_del_indexing']==0 ? 0 : 0x02) + ($this->configs['cache_delext_i']==0 ? 0 : 0x04) + ($this->configs['cache_delext_xhtml']==0 ? 0 : 0x08) + ($this->configs['cache_delext_js']==0 ? 0 : 0x10) + ($this->configs['cache_delext_css']==0 ? 0 : 0x20) + ($this->configs['cache_delext_mediaP']==0 ? 0 : 0x40); 165 if ($this->cmp_req('del_oldpagelocks', 'yes', true, false) && ($this->configs['cache_del_oldlocks'])) { 166 if ($this->rmeverything_oldlockpages($this->locksdir, $this->locksdir, $theoutputinfo) == false) $succop = false; 167 } 168 if ($this->rmeverything_cache($this->cachedir, $this->cachedir, $params & $prmask, $theoutputinfo) == false) $succop = false; 169 ptln('<strong>'.$this->lang['numfilesdel'].' '.$this->filedels.'<br />'.$this->lang['numdirsdel'].' '.$this->dirdels.'</strong><br />'); 170 ptln('</th></tr>'); 171 if ($succop) 172 ptln('<tr><th>'.$this->lang['successcache'].'</th></tr>'); 173 else 174 ptln('<tr><th>'.$this->lang['failedcache'].'</th></tr>'); 175 ptln('</table>'); 176 ptln('<table class="inline">'); 177 ptln('<tr><th class="centeralign">'); 178 ptln('<form method="post" action="'.wl($ID).'"><div class="no">'); 179 ptln('<input type="hidden" name="do" value="admin" />'); 180 ptln('<input type="hidden" name="page" value="cacherevisionserase" />'); 181 ptln('<input type="hidden" name="cmd" value="main" />'); 182 ptln('<input type="submit" class="button" value="'.$this->lang['backbtn'].'" />'); 183 ptln('</div></form></th></tr></table>'); 184 } else if ((strcmp($cmd, 'eraseallrevisions') == 0) && ($this->configs['allow_allrevisdel'])) { 185 // Erase old revisions... 186 ptln('<table class="inline">'); 187 ptln('<tr><th class="leftalign">'); 188 clearstatcache(); 189 $succop = true; 190 if ($this->cmp_req('del_metafiles', 'yes', true, false) && ($this->configs['cache_del_metafiles'])) { 191 if ($this->rmeverything_meta($this->metadir, $this->metadir, $theoutputinfo) == false) $succop = false; 192 } 193 if ($this->cmp_req('del_revisfiles', 'yes', true, false) && ($this->configs['cache_del_revisfiles'])) { 194 if ($this->rmeverything_revis($this->revisdir, $this->revisdir, $theoutputinfo) == false) $succop == false; 195 } 196 ptln('<strong>'.$this->lang['numfilesdel'].' '.$this->filedels.'<br />'.$this->lang['numdirsdel'].' '.$this->dirdels.'</strong><br />'); 197 ptln('</th></tr>'); 198 if ($succop) 199 ptln('<tr><th>'.$this->lang['successrevisions'].'</th></tr>'); 200 else 201 ptln('<tr><th>'.$this->lang['failedrevisions'].'</th></tr>'); 202 ptln('</table>'); 203 ptln('<table class="inline">'); 204 ptln('<tr><th class="centeralign">'); 205 ptln('<form method="post" action="'.wl($ID).'"><div class="no">'); 206 ptln('<input type="hidden" name="do" value="admin" />'); 207 ptln('<input type="hidden" name="page" value="cacherevisionserase" />'); 208 ptln('<input type="hidden" name="cmd" value="main" />'); 209 ptln('<input type="submit" class="button" value="'.$this->lang['backbtn'].'" />'); 210 ptln('</div></form></th></tr></table>'); 211 } else { 212 // Controls 213 ptln('<table class="inline">'); 214 ptln('<tr><th class="centeralign">'); 215 if ($this->configs['allow_allcachedel']) { 216 ptln($this->lang['cachedesc'].'</th></tr><tr><th class="leftalign"><br/>'); 217 ptln('<form method="post" action="'.wl($ID).'" onsubmit="return confirm(\''.str_replace('\\\\n','\\n',addslashes($this->lang['askcache'])).'\')">'); 218 ptln('<input type="hidden" name="do" value="admin" />'); 219 ptln('<input type="hidden" name="page" value="cacherevisionserase" />'); 220 ptln('<input type="hidden" name="cmd" value="erasecache" />'); 221 if ($this->configs['cache_delext_repo'] < 0) 222 ptln('<input type="checkbox" name="delfl_repo" value="yes" '.(($this->configs['cache_delext_repo']+2) ? 'checked="checked"' : '').' /> '.$this->lang['extdesc_repo'].'<br />'); 223 else 224 ptln('<input type="checkbox" name="delfl_repo" value="yes" '.($this->configs['cache_delext_repo'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['extdesc_repo'].'<br />'); 225 if ($this->configs['cache_delext_gz'] < 0) 226 ptln('<input type="checkbox" name="delfl_gz" value="yes" '.(($this->configs['cache_delext_gz']+2) ? 'checked="checked"' : '').' /> '.$this->lang['extdesc_gz'].'<br />'); 227 else 228 ptln('<input type="checkbox" name="delfl_gz" value="yes" '.($this->configs['cache_delext_gz'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['extdesc_gz'].'<br />'); 229 if ($this->configs['cache_delext_i'] < 0) 230 ptln('<input type="checkbox" name="delfl_i" value="yes" '.(($this->configs['cache_delext_i']+2) ? 'checked="checked"' : '').' /> '.$this->lang['extdesc_i'].'<br />'); 231 else 232 ptln('<input type="checkbox" name="delfl_i" value="yes" '.($this->configs['cache_delext_i'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['extdesc_i'].'<br />'); 233 if ($this->configs['cache_delext_xhtml'] < 0) 234 ptln('<input type="checkbox" name="delfl_xhtml" value="yes" '.(($this->configs['cache_delext_xhtml']+2) ? 'checked="checked"' : '').' /> '.$this->lang['extdesc_xhtml'].'<br />'); 235 else 236 ptln('<input type="checkbox" name="delfl_xhtml" value="yes" '.($this->configs['cache_delext_xhtml'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['extdesc_xhtml'].'<br />'); 237 if ($this->configs['cache_delext_js'] < 0) 238 ptln('<input type="checkbox" name="delfl_js" value="yes" '.(($this->configs['cache_delext_js']+2) ? 'checked="checked"' : '').' /> '.$this->lang['extdesc_js'].'<br />'); 239 else 240 ptln('<input type="checkbox" name="delfl_js" value="yes" '.($this->configs['cache_delext_js'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['extdesc_js'].'<br />'); 241 if ($this->configs['cache_delext_css'] < 0) 242 ptln('<input type="checkbox" name="delfl_css" value="yes" '.(($this->configs['cache_delext_css']+2) ? 'checked="checked"' : '').' /> '.$this->lang['extdesc_css'].'<br />'); 243 else 244 ptln('<input type="checkbox" name="delfl_css" value="yes" '.($this->configs['cache_delext_css'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['extdesc_css'].'<br />'); 245 if ($this->configs['cache_delext_mediaP'] < 0) 246 ptln('<input type="checkbox" name="delfl_mediaP" value="yes" '.(($this->configs['cache_delext_mediaP']+2) ? 'checked="checked"' : '').' /> '.$this->lang['extdesc_mediaP'].'<br />'); 247 else 248 ptln('<input type="checkbox" name="delfl_mediaP" value="yes" '.($this->configs['cache_delext_mediaP'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['extdesc_mediaP'].'<br />'); 249 if ($this->configs['cache_delext_UNK'] < 0) 250 ptln('<input type="checkbox" name="delfl_UNK" value="yes" '.(($this->configs['cache_delext_UNK']+2) ? 'checked="checked"' : '').' /> '.$this->lang['extdesc_UNK'].'<br />'); 251 else 252 ptln('<input type="checkbox" name="delfl_UNK" value="yes" '.($this->configs['cache_delext_UNK'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['extdesc_UNK'].'<br />'); 253 if ($this->configs['cache_del_oldlocks'] < 0) 254 ptln('<input type="checkbox" name="del_oldpagelocks" value="yes" '.(($this->configs['cache_del_oldlocks']+2) ? 'checked="checked"' : '').' /> '.$this->lang['deloldlockdesc'].'<br />'); 255 else 256 ptln('<input type="checkbox" name="del_oldpagelocks" value="yes" '.($this->configs['cache_del_oldlocks'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['deloldlockdesc'].'<br />'); 257 if ($this->configs['cache_del_indexing'] < 0) 258 ptln('<input type="checkbox" name="del_indexing" value="yes" '.(($this->configs['cache_del_indexing']+2) ? 'checked="checked"' : '').' /> '.$this->lang['delindexingdesc'].'<br />'); 259 else 260 ptln('<input type="checkbox" name="del_indexing" value="yes" '.($this->configs['cache_del_indexing'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['delindexingdesc'].'<br />'); 261 ptln('<br />'); 262 if ($this->configs['allow_outputinfo']) { 263 ptln($this->lang['outputinfo_text'].' <input type="radio" name="level_outputinfo" value="0" '.($this->configs['level_outputinfo']==0 ? 'checked="checked"' : '').' />'.$this->lang['outputinfo_lvl0']); 264 ptln('<input type="radio" name="level_outputinfo" value="1" '.($this->configs['level_outputinfo']==1 ? 'checked="checked"' : '').' />'.$this->lang['outputinfo_lvl1']); 265 ptln('<input type="radio" name="level_outputinfo" value="2" '.($this->configs['level_outputinfo']==2 ? 'checked="checked"' : '').' />'.$this->lang['outputinfo_lvl2']); 266 } else { 267 if ($this->configs['level_outputinfo'] == 0) { 268 ptln('<input type="hidden" name="level_outputinfo" value="0" />'.$this->lang['outputinfo_text'].' '.$this->lang['outputinfo_lvl0']); 269 } else if ($this->configs['level_outputinfo'] == 1) { 270 ptln('<input type="hidden" name="level_outputinfo" value="1" />'.$this->lang['outputinfo_text'].' '.$this->lang['outputinfo_lvl1']); 271 } else if ($this->configs['level_outputinfo'] == 2) { 272 ptln('<input type="hidden" name="level_outputinfo" value="2" />'.$this->lang['outputinfo_text'].' '.$this->lang['outputinfo_lvl2']); 273 } 274 } 275 ptln('<br /><br /><div class="centeralign"><input type="submit" class="button" value="'.$this->lang['erasecachebtn'].'" /></div>'); 276 ptln('</form>'); 277 } else { 278 ptln($this->lang['cachedisabled'].'<br />'); 279 } 280 ptln('</th></tr><tr><td style="border-style: none"> <br /></td></tr>'); 281 ptln('<tr><th class="centeralign">'); 282 if ($this->configs['allow_allrevisdel']) { 283 ptln($this->lang['revisionsdesc'].'</th></tr><tr><th class="leftalign"><br />'); 284 ptln('<form method="post" action="'.wl($ID).'" onsubmit="return confirm(\''.str_replace('\\\\n','\\n',addslashes($this->lang['askrevisions'])).'\')">'); 285 ptln('<input type="hidden" name="do" value="admin" />'); 286 ptln('<input type="hidden" name="page" value="cacherevisionserase" />'); 287 ptln('<input type="hidden" name="cmd" value="eraseallrevisions" />'); 288 if ($this->configs['cache_del_metafiles'] < 0) 289 ptln('<input type="checkbox" name="del_metafiles" value="yes" '.(($this->configs['cache_del_metafiles']+2) ? 'checked="checked"' : '').' /> '.$this->lang['delmetadesc'].'<br />'); 290 else 291 ptln('<input type="checkbox" name="del_metafiles" value="yes" '.($this->configs['cache_del_metafiles'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['delmetadesc'].'<br />'); 292 if ($this->configs['cache_del_revisfiles'] < 0) 293 ptln('<input type="checkbox" name="del_revisfiles" value="yes" '.(($this->configs['cache_del_revisfiles']+2) ? 'checked="checked"' : '').' /> '.$this->lang['delrevisdesc'].'<br />'); 294 else 295 ptln('<input type="checkbox" name="del_revisfiles" value="yes" '.($this->configs['cache_del_revisfiles'] ? 'checked="checked"' : '').' disabled /> '.$this->lang['delrevisdesc'].'<br />'); 296 ptln('<br />'); 297 if ($this->configs['allow_outputinfo']) { 298 ptln($this->lang['outputinfo_text'].' <input type="radio" name="level_outputinfo" value="0" '.($this->configs['level_outputinfo']==0 ? 'checked="checked"' : '').' />'.$this->lang['outputinfo_lvl0']); 299 ptln('<input type="radio" name="level_outputinfo" value="1" '.($this->configs['level_outputinfo']==1 ? 'checked="checked"' : '').' />'.$this->lang['outputinfo_lvl1']); 300 ptln('<input type="radio" name="level_outputinfo" value="2" '.($this->configs['level_outputinfo']==2 ? 'checked="checked"' : '').' />'.$this->lang['outputinfo_lvl2']); 301 } else { 302 if ($this->configs['level_outputinfo'] == 0) { 303 ptln('<input type="hidden" name="level_outputinfo" value="0" />'.$this->lang['outputinfo_text'].' '.$this->lang['outputinfo_lvl0']); 304 } else if ($this->configs['level_outputinfo'] == 1) { 305 ptln('<input type="hidden" name="level_outputinfo" value="1" />'.$this->lang['outputinfo_text'].' '.$this->lang['outputinfo_lvl1']); 306 } else if ($this->configs['level_outputinfo'] == 2) { 307 ptln('<input type="hidden" name="level_outputinfo" value="2" />'.$this->lang['outputinfo_text'].' '.$this->lang['outputinfo_lvl2']); 308 } 309 } 310 ptln('<br /><br /><p class="centeralign"><input type="submit" class="button" value="'.$this->lang['eraserevisionsbtn'].'" /></p>'); 311 ptln('<div class="centeralign"><em>'.$this->lang['revisionswarn'].'</em></div>'); 312 ptln('</form>'); 313 } else { 314 ptln($this->lang['revisdisabled'].'<br />'); 315 } 316 ptln('</th></tr></table>'); 317 } 318 ptln('<br /><a href="http://wiki.splitbrain.org/plugin:cacherevisionseraser" class="urlextern" target="_blank">'.$this->lang['searchyounewversionurl'].'</a> [English only]<br />'); 319 } 320 321 /** 322 * Delete all files into cache directory 323 */ 324 function rmeverything_cache($fileglob, $basedir, $params, $outputinfo) 325 { 326 $fileglob2 = substr($fileglob, strlen($basedir)); 327 if (strpos($fileglob, '*') !== false) { 328 foreach (glob($fileglob) as $filename) { 329 $this->rmeverything_cache($filename, $basedir, $params, $outputinfo); 330 } 331 } else if (is_file($fileglob)) { 332 if (strcmp($fileglob2, '/_dummy') == 0) return true; 333 $pathinfor = pathinfo($fileglob2); 334 if (strcmp($basedir, dirname($fileglob)) == 0) { 335 if (!($params & 0x02)) return true; 336 } else { 337 if (substr_count(strtolower($pathinfor['basename']), '.media.') > 0) { 338 if (!($params & 0x40)) return true; 339 } else if (strcmp(strtolower($pathinfor['extension']), 'i') == 0) { 340 if (!($params & 0x04)) return true; 341 } else if (strcmp(strtolower($pathinfor['extension']), 'xhtml') == 0) { 342 if (!($params & 0x08)) return true; 343 } else if (strcmp(strtolower($pathinfor['extension']), 'js') == 0) { 344 if (!($params & 0x10)) return true; 345 } else if (strcmp(strtolower($pathinfor['extension']), 'css') == 0) { 346 if (!($params & 0x20)) return true; 347 } else { 348 if (!($params & 0x01)) return true; 349 } 350 } 351 if (@unlink($fileglob)) { 352 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletefile'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['cache_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 353 $this->filedels++; 354 return true; 355 } else { 356 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletefileerr'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['cache_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 357 return false; 358 } 359 } else if (is_dir($fileglob)) { 360 $ok = $this->rmeverything_cache($fileglob.'/*', $basedir, $params, $outputinfo); 361 if (!$ok) return false; 362 if (strcmp($fileglob, $basedir) == 0) return true; 363 if (@rmdir($fileglob)) { 364 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletedir'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['cache_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 365 $this->dirdels++; 366 return true; 367 } else { 368 return true; 369 } 370 } else { 371 // Woha, this shouldn't never happen... 372 if ($outputinfo > 0) ptln('<strong>'.$this->lang['pathclasserror'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['cache_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 373 return false; 374 } 375 return true; 376 } 377 378 /** 379 * Delete all old lost locks into "data/pages" or "data/locks" directory 380 */ 381 function rmeverything_oldlockpages($fileglob, $basedir, $outputinfo) 382 { 383 $fileglob2 = substr($fileglob, strlen($basedir)); 384 if (strpos($fileglob, '*') !== false) { 385 foreach (glob($fileglob) as $filename) { 386 $this->rmeverything_oldlockpages($filename, $basedir, $outputinfo); 387 } 388 } else if (is_file($fileglob)) { 389 if (strcmp($fileglob2, '/_dummy') == 0) return true; 390 $pathinfor = pathinfo($fileglob2); 391 if (strcmp(strtolower($pathinfor['extension']), 'lock') != 0) return true; 392 if (time()-@filemtime($fileglob) < $this->locktime) { 393 if ($outputinfo > 0) ptln('<strong>'.$this->lang['lockexpirein'].' '.($this->locktime-(time()-@filemtime($fileglob))).' '.$this->lang['seconds'].'</strong> -> <em>"'.$fileglob2.'"</em>.<br />'); 394 return true; 395 } 396 if (@unlink($fileglob)) { 397 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletefile'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['lock_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 398 $this->filedels++; 399 return true; 400 } else { 401 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletefileerr'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['lock_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 402 return false; 403 } 404 } else if (is_dir($fileglob)) { 405 $ok = $this->rmeverything_oldlockpages($fileglob.'/*', $basedir, $outputinfo); 406 if (!$ok) return false; 407 if (strcmp($fileglob, $basedir) == 0) return true; 408 if (@rmdir($fileglob)) { 409 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletedir'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['lock_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 410 $this->dirdels++; 411 return true; 412 } else { 413 return true; 414 } 415 } else { 416 // Woha, this shouldn't never happen... 417 if ($outputinfo > 0) ptln('<strong>'.$this->lang['pathclasserror'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['lock_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 418 return false; 419 } 420 return true; 421 } 422 423 /** 424 * Delete all files into meta directory 425 */ 426 function rmeverything_meta($fileglob, $basedir, $outputinfo) 427 { 428 $fileglob2 = substr($fileglob, strlen($basedir)); 429 if (strpos($fileglob, '*') !== false) { 430 foreach (glob($fileglob) as $filename) { 431 $this->rmeverything_meta($filename, $basedir, $outputinfo); 432 } 433 } else if (is_file($fileglob)) { 434 if (strcmp($fileglob2, '/_dummy') == 0) return true; 435 $pathinfor = pathinfo($fileglob2); // For compatibility with the following: 436 if (strcmp(strtolower($pathinfor['extension']), 'comments') == 0) return true; // Discussion Plugin 437 if (strcmp(strtolower($pathinfor['extension']), 'doodle') == 0) return true; // Doodle & Doodle2 Plugins 438 if (@unlink($fileglob)) { 439 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletefile'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['meta_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 440 $this->filedels++; 441 return true; 442 } else { 443 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletefileerr'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['meta_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 444 return false; 445 } 446 } else if (is_dir($fileglob)) { 447 $ok = $this->rmeverything_meta($fileglob.'/*', $basedir, $outputinfo); 448 if (!$ok) return false; 449 if (strcmp($fileglob, $basedir) == 0) return true; 450 if (@rmdir($fileglob)) { 451 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletedir'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['meta_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 452 $this->dirdels++; 453 return true; 454 } else { 455 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletedirerr'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['meta_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 456 return false; 457 } 458 } else { 459 // Woha, this shouldn't never happen... 460 if ($outputinfo > 0) ptln('<strong>'.$this->lang['pathclasserror'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['meta_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 461 return false; 462 } 463 return true; 464 } 465 466 /** 467 * Delete all files into old revisions directory 468 */ 469 function rmeverything_revis($fileglob, $basedir, $outputinfo) 470 { 471 $fileglob2 = substr($fileglob, strlen($basedir)); 472 if (strpos($fileglob, '*') !== false) { 473 foreach (glob($fileglob) as $filename) { 474 $this->rmeverything_revis($filename, $basedir, $outputinfo); 475 } 476 } else if (is_file($fileglob)) { 477 if (strcmp($fileglob2, '/_dummy') == 0) return true; 478 if (@unlink($fileglob)) { 479 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletefile'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['revis_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 480 $this->filedels++; 481 return true; 482 } else { 483 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletefileerr'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['revis_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 484 return false; 485 } 486 } else if (is_dir($fileglob)) { 487 $ok = $this->rmeverything_revis($fileglob.'/*', $basedir, $outputinfo); 488 if (!$ok) return false; 489 if (strcmp($fileglob, $basedir) == 0) return true; 490 if (@rmdir($fileglob)) { 491 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletedir'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['revis_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 492 $this->dirdels++; 493 return true; 494 } else { 495 if ($outputinfo > 0) ptln('<strong>'.$this->lang['deletedirerr'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['revis_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 496 return false; 497 } 498 } else { 499 // Woha, this shouldn't never happen... 500 if ($outputinfo > 0) ptln('<strong>'.$this->lang['pathclasserror'].'</strong>'.(($outputinfo==2) ? ' ('.$this->lang['revis_word'].') ' : ' ').'<em>"'.$fileglob2.'"</em>.<br />'); 501 return false; 502 } 503 return true; 504 } 505 506 /** 507 * Routine to analyze configurations and directories 508 */ 509 function analyzecrpt($cmd) 510 { 511 global $ID; 512 513 $analizysucessy = true; 514 if ($this->configs['confrevision'] == 0) { 515 ptln('<strong>'.$this->lang['analyze_confmissingfailed'].' (ERR: 1)</strong><br />'); 516 $analizysucessy = false; 517 } 518 if (($this->configs['confrevision'] != CACHEREVISIONSERASER2_CONFIGREVISION) && ($analizysucessy)) { 519 ptln('<strong>'.$this->lang['analyze_confrevisionfailed'].' (ERR: 2)</strong><br />'); 520 $analizysucessy = false; 521 } 522 if ($analizysucessy == false) { 523 if (strcmp($cmd, 'createconf') == 0) { 524 $this->writeconfigs(); 525 ptln('<strong>'.$this->lang['analyze_creatingdefconfs']); 526 if (file_exists(dirname(__FILE__).'/configs.php')) { 527 ptln($this->lang['analyze_creatingdefconfs_o']); 528 } else ptln($this->lang['analyze_creatingdefconfs_x']); 529 ptln('</strong><br /><br /><form method="post" action="'.wl($ID).'">'); 530 ptln('<input type="hidden" name="do" value="admin" />'); 531 ptln('<input type="hidden" name="page" value="cacherevisionserase" />'); 532 ptln('<input type="hidden" name="cmd" value="main" />'); 533 ptln('<input type="submit" class="button" value="'.$this->lang['reanalyzebtn'].'" />'); 534 ptln('</form><br />'); 535 } else { 536 ptln('<br /><form method="post" action="'.wl($ID).'"><div class="no">'); 537 ptln('<input type="hidden" name="do" value="admin" />'); 538 ptln('<input type="hidden" name="page" value="cacherevisionserase" />'); 539 ptln('<input type="hidden" name="cmd" value="createconf" />'); 540 ptln('<table width="100%" class="inline"><tr>'); 541 ptln('<th width="100"> </th>'); 542 ptln('<th width="120"><strong>'.$this->lang['wordb_option'].'</strong></th>'); 543 ptln('<th><strong>'.$this->lang['wordb_optiondesc'].'</strong></th></tr><tr>'); 544 ptln('<td />'); 545 ptln('<td><input type="text" name="menusort" value="67" maxlength="2" size="2" /></td>'); 546 ptln('<td>'.$this->lang['cfgdesc_menusort'].'</td>'); 547 ptln('</tr><tr><th />'); 548 ptln('<th><strong>'.$this->lang['wordb_enable'].'</strong></th>'); 549 ptln('<th><strong>'.$this->lang['wordb_optiondesc'].'</strong></th>'); 550 ptln('</tr><tr><td />'); 551 ptln('<td><input type="checkbox" name="allow_allcachedel_E" value="yes" checked="checked" /></td>'); 552 ptln('<td>'.$this->lang['delxcacheclass'].'</td>'); 553 ptln('</tr><tr><td />'); 554 ptln('<td><input type="checkbox" name="allow_allrevisdel_E" value="yes" checked="checked" /></td>'); 555 ptln('<td>'.$this->lang['delxrevisclass'].'</td>'); 556 ptln('</tr><tr><td />'); 557 ptln('<td><input type="checkbox" name="allow_debug_E" value="yes" /></td>'); 558 ptln('<td>'.$this->lang['delxdebugmode'].'</td>'); 559 ptln('</tr><tr>'); 560 ptln('<th><strong>'.$this->lang['wordb_allowuserchag'].'</strong></th>'); 561 ptln('<th><strong>'.$this->lang['wordb_checkedasdef'].'</strong></th>'); 562 ptln('<th><strong>'.$this->lang['wordb_optiondesc'].'</strong></th>'); 563 ptln('</tr><tr>'); 564 ptln('<td><input type="checkbox" name="delext_i_A" value="yes" checked="checked" /></td>'); 565 ptln('<td><input type="checkbox" name="delext_i_C" value="yes" checked="checked" /></td>'); 566 ptln('<td>' . $this->lang['extdesc_i'] . '</td>'); 567 ptln('</tr><tr>'); 568 ptln('<td><input type="checkbox" name="delext_xhtml_A" value="yes" checked="checked" /></td>'); 569 ptln('<td><input type="checkbox" name="delext_xhtml_C" value="yes" checked="checked" /></td>'); 570 ptln('<td>' . $this->lang['extdesc_xhtml'] . '</td>'); 571 ptln('</tr><tr>'); 572 ptln('<td><input type="checkbox" name="delext_js_A" value="yes" checked="checked" /></td>'); 573 ptln('<td><input type="checkbox" name="delext_js_C" value="yes" checked="checked" /></td>'); 574 ptln('<td>' . $this->lang['extdesc_js'] . '</td>'); 575 ptln('</tr><tr>'); 576 ptln('<td><input type="checkbox" name="delext_css_A" value="yes" checked="checked" /></td>'); 577 ptln('<td><input type="checkbox" name="delext_css_C" value="yes" checked="checked" /></td>'); 578 ptln('<td>' . $this->lang['extdesc_css'] . '</td>'); 579 ptln('</tr><tr>'); 580 ptln('<td><input type="checkbox" name="delext_mediaP_A" value="yes" checked="checked" /></td>'); 581 ptln('<td><input type="checkbox" name="delext_mediaP_C" value="yes" checked="checked" /></td>'); 582 ptln('<td>' . $this->lang['extdesc_mediaP'] . '</td>'); 583 ptln('</tr><tr>'); 584 ptln('<td><input type="checkbox" name="delext_UNK_A" value="yes" checked="checked" /></td>'); 585 ptln('<td><input type="checkbox" name="delext_UNK_C" value="yes" checked="checked" /></td>'); 586 ptln('<td>' . $this->lang['extdesc_UNK'] . '</td>'); 587 ptln('</tr><tr>'); 588 ptln('<td><input type="checkbox" name="del_oldlock_A" value="yes" checked="checked" /></td>'); 589 ptln('<td><input type="checkbox" name="del_oldlock_C" value="yes" checked="checked" /></td>'); 590 ptln('<td>' . $this->lang['deloldlockdesc'] . '</td>'); 591 ptln('</tr><tr>'); 592 ptln('<td><input type="checkbox" name="del_indexing_A" value="yes" checked="checked" /></td>'); 593 ptln('<td><input type="checkbox" name="del_indexing_C" value="yes" /></td>'); 594 ptln('<td>' . $this->lang['delindexingdesc'] . '</td>'); 595 ptln('</tr><tr>'); 596 ptln('<td><input type="checkbox" name="del_meta_A" value="yes" checked="checked" /></td>'); 597 ptln('<td><input type="checkbox" name="del_meta_C" value="yes" checked="checked" /></td>'); 598 ptln('<td>' . $this->lang['delmetadesc'] . '</td>'); 599 ptln('</tr><tr>'); 600 ptln('<td><input type="checkbox" name="del_revis_A" value="yes" checked="checked" /></td>'); 601 ptln('<td><input type="checkbox" name="del_revis_C" value="yes" checked="checked" /></td>'); 602 ptln('<td>' . $this->lang['delrevisdesc'] . '</td>'); 603 ptln('</tr><tr>'); 604 ptln('<td><input type="checkbox" name="allow_outputinfo" value="yes" checked="checked" /></td>'); 605 ptln('<td><input type="radio" name="level_outputinfo" value="0" />'.$this->lang['outputinfo_lvl0'].'<br />'); 606 ptln('<input type="radio" name="level_outputinfo" value="1" />'.$this->lang['outputinfo_lvl1'].'<br />'); 607 ptln('<input type="radio" name="level_outputinfo" value="2" checked="checked" />'.$this->lang['outputinfo_lvl2']); 608 ptln('</td><td>'.$this->lang['delxverbose'].'</td>'); 609 ptln('</tr><tr><th /><th />'); 610 ptln('<th><input type="submit" class="button" value="'.$this->lang['createconfbtn'].'" /></th>'); 611 ptln('</tr></table></div></form>'); 612 } 613 } 614 if (!is_dir($this->cachedir)) { 615 ptln('<strong>'.$this->lang['analyze_cachedirfailed'].' (ERR: 3)</strong><br />'); 616 $analizysucessy = false; 617 } 618 if (!is_dir($this->revisdir)) { 619 ptln('<strong>'.$this->lang['analyze_revisdirfailed'].' (ERR: 4)</strong><br />'); 620 $analizysucessy = false; 621 } 622 if (!is_dir($this->pagesdir)) { 623 ptln('<strong>'.$this->lang['analyze_pagesdirfailed'].' (ERR: 5)</strong><br />'); 624 $analizysucessy = false; 625 } 626 if (!is_dir($this->metadir)) { 627 ptln('<strong>'.$this->lang['analyze_metadirfailed'].' (ERR: 6)</strong><br />'); 628 $analizysucessy = false; 629 } 630 if (!is_dir($this->locksdir)) { 631 ptln('<strong>'.$this->lang['analyze_locksdirfailed'].' (ERR: 7)</strong><br />'); 632 $analizysucessy = false; 633 } 634 if ($analizysucessy == false) { 635 ptln('<br /><strong>'.$this->lang['analyze_checkreadme'].'</strong><br />'); 636 } 637 return $analizysucessy; 638 } 639 640 /** 641 * Routine to create "configs.php" 642 */ 643 function writeconfigs() 644 { 645 global $lang; 646 $cahdelext_i = -2 + $this->cmp_req('delext_i_A', 'yes', 0, 2) + $this->cmp_req('delext_i_C', 'yes', 1, 0); 647 $cahdelext_xhtml = -2 + $this->cmp_req('delext_xhtml_A', 'yes', 0, 2) + $this->cmp_req('delext_xhtml_C', 'yes', 1, 0); 648 $cahdelext_js = -2 + $this->cmp_req('delext_js_A', 'yes', 0, 2) + $this->cmp_req('delext_js_C', 'yes', 1, 0); 649 $cahdelext_css = -2 + $this->cmp_req('delext_css_A', 'yes', 0, 2) + $this->cmp_req('delext_css_C', 'yes', 1, 0); 650 $cahdelext_mediaP = -2 + $this->cmp_req('delext_mediaP_A', 'yes', 0, 2) + $this->cmp_req('delext_mediaP_C', 'yes', 1, 0); 651 $cahdelext_UNK = -2 + $this->cmp_req('delext_UNK_A', 'yes', 0, 2) + $this->cmp_req('delext_UNK_C', 'yes', 1, 0); 652 $cahdel_oldlocks = -2 + $this->cmp_req('del_oldlock_A', 'yes', 0, 2) + $this->cmp_req('del_oldlock_C', 'yes', 1, 0); 653 $cahdel_indexing = -2 + $this->cmp_req('del_indexing_A', 'yes', 0, 2) + $this->cmp_req('del_indexing_C', 'yes', 1, 0); 654 $cahdel_metafiles = -2 + $this->cmp_req('del_meta_A', 'yes', 0, 2) + $this->cmp_req('del_meta_C', 'yes', 1, 0); 655 $cahdel_revisfiles = -2 + $this->cmp_req('del_revis_A', 'yes', 0, 2) + $this->cmp_req('del_revis_C', 'yes', 1, 0); 656 $wcnf = fopen(dirname(__FILE__).'/configs.php', 'w'); 657 fwrite($wcnf, "<?php\n/**\n * Cache/Revisions Eraser configuration file\n *\n * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)\n * @author JustBurn <justburner@armail.pt>\n *\n *\n"); 658 fwrite($wcnf, " * Generated automatically by the plug-in, Cache/Revisions Eraser v" . CACHEREVISIONSERASER2_VER . "\n *\n */\n\n"); 659 fwrite($wcnf, '$this->configs[\'confrevision\'] = 2;' . "\n"); 660 if ((intval($this->get_req('menusort','67')) >= 0) && (intval($this->get_req('menusort','67')) <= 99)) 661 fwrite($wcnf, '$this->configs[\'menusort\'] = ' . intval($this->get_req('menusort','67')) . ";\n"); 662 else 663 fwrite($wcnf, '$this->configs[\'menusort\'] = 67' . ";\n"); 664 fwrite($wcnf, '$this->configs[\'allow_allcachedel\'] = ' . $this->cmp_req('allow_allcachedel_E', 'yes', 'true', 'false') . ";\n"); 665 fwrite($wcnf, '$this->configs[\'allow_allrevisdel\'] = ' . $this->cmp_req('allow_allrevisdel_E', 'yes', 'true', 'false') . ";\n"); 666 fwrite($wcnf, '$this->configs[\'debuglist\'] = ' . $this->cmp_req('allow_debug_E', 'yes', 'true', 'false') . ";\n"); 667 fwrite($wcnf, '$this->configs[\'cache_delext_i\'] = ' . $cahdelext_i . ";\n"); 668 fwrite($wcnf, '$this->configs[\'cache_delext_xhtml\'] = ' . $cahdelext_xhtml . ";\n"); 669 fwrite($wcnf, '$this->configs[\'cache_delext_js\'] = ' . $cahdelext_js . ";\n"); 670 fwrite($wcnf, '$this->configs[\'cache_delext_css\'] = ' . $cahdelext_css . ";\n"); 671 fwrite($wcnf, '$this->configs[\'cache_delext_mediaP\'] = ' . $cahdelext_mediaP . ";\n"); 672 fwrite($wcnf, '$this->configs[\'cache_delext_UNK\'] = ' . $cahdelext_UNK . ";\n"); 673 fwrite($wcnf, '$this->configs[\'cache_del_oldlocks\'] = ' . $cahdel_oldlocks . ";\n"); 674 fwrite($wcnf, '$this->configs[\'cache_del_indexing\'] = ' . $cahdel_indexing . ";\n"); 675 fwrite($wcnf, '$this->configs[\'cache_del_metafiles\'] = ' . $cahdel_metafiles . ";\n"); 676 fwrite($wcnf, '$this->configs[\'cache_del_revisfiles\'] = ' . $cahdel_revisfiles . ";\n"); 677 fwrite($wcnf, '$this->configs[\'allow_outputinfo\'] = ' . $this->cmp_req('allow_outputinfo', 'yes', 'true', 'false') . ";\n"); 678 if ((intval($this->get_req('level_outputinfo','0')) >= 0) && (intval($this->get_req('level_outputinfo','0')) <= 2)) 679 fwrite($wcnf, '$this->configs[\'level_outputinfo\'] = ' . intval($this->get_req('level_outputinfo','0')) . ";\n"); 680 else 681 fwrite($wcnf, '$this->configs[\'level_outputinfo\'] = 0'.";\n"); 682 fwrite($wcnf, "\n\n?>"); 683 fclose($wcnf); 684 } 685 686} 687 688?> 689