1<?php 2 3 4class helper_plugin_stale extends DokuWiki_Plugin 5{ 6 7 8 const CONF_ADMIN_ONLY = 'admin_only'; 9 const PLUGIN_NAME = 'stale'; 10 11 /** 12 * Touching the configuration file will reset the cache 13 */ 14 function touchConfFiles() 15 { 16 17 touch(DOKU_CONF . "local.php"); 18 19 $dir = new DirectoryIterator(DOKU_PLUGIN); 20 foreach ($dir as $file) { 21 if ($file->isDir() && !$file->isDot()) { 22 $infoPlugin = $file->getPathname() . "/plugin.info.txt"; 23 if (file_exists($infoPlugin)) { 24 touch($infoPlugin); 25 } 26 } 27 } 28 29 } 30 31 /** 32 * @return bool true if the user can touch the file or the reason why it can't 33 * 34 * Because a non-empty string is also true 35 * Use it like this: 36 * $stale->canTouch()!==true 37 * 38 */ 39 public function canTouch() 40 { 41 $canTouch = true; 42 if ($this->getConf(self::CONF_ADMIN_ONLY)) { 43 global $USERINFO; 44 if (!auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { 45 return "Only admin can touch"; 46 } 47 } 48 return $canTouch; 49 } 50 51 public function getIcon() 52 { 53 return __DIR__ . '/images/hand-index-fill.svg'; 54 } 55 56 public function deleteSitemap() 57 { 58 global $conf; 59 $cacheDirectory = $conf['cachedir']; 60 $file = $cacheDirectory . "/sitemap.xml.gz"; 61 if (file_exists($file)) { 62 unlink($file); 63 return true; 64 } else { 65 return false; 66 } 67 68 } 69 70 public function stale() 71 { 72 $this->touchConfFiles(); 73 $message = "The configurations files were touched."; 74 $deleted = $this->deleteSitemap(); 75 if($deleted) { 76 $message .= "<br>The sitemap file was deleted."; 77 } else { 78 $message .= "<br>No sitemap was present."; 79 } 80 $message .= "<br>The cache is now stale."; 81 return $message; 82 } 83 84} 85