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