1<?php 2/* 3 * Copyright (c) 2008-2012 Mark C. Prins <mprins@users.sf.net> 4* 5* Permission to use, copy, modify, and distribute this software for any 6* purpose with or without fee is hereby granted, provided that the above 7* copyright notice and this permission notice appear in all copies. 8* 9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*/ 17if (!defined('DOKU_INC')) die(); 18if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 19require_once DOKU_PLUGIN.'admin.php'; 20/** 21 * DokuWiki Plugin openlayersmap (Admin Component). 22 * This component purges the cached tiles and maps. 23 * 24 * @author Mark Prins 25 */ 26class admin_plugin_openlayersmap_purge extends DokuWiki_Admin_Plugin { 27 /** 28 * (non-PHPdoc) 29 * @see DokuWiki_Admin_Plugin::getMenuSort() 30 */ 31 public function getMenuSort() { 32 return 800; 33 } 34 /** 35 * (non-PHPdoc) 36 * @see DokuWiki_Admin_Plugin::forAdminOnly() 37 */ 38 public function forAdminOnly() { 39 return true; 40 } 41 42 /** 43 * (non-PHPdoc) 44 * @see DokuWiki_Admin_Plugin::handle() 45 */ 46 public function handle() { 47 global $conf; 48 if(!isset($_REQUEST['continue']) || !checkSecurityToken()) return; 49 if(isset($_REQUEST['purgetiles'])){ 50 $path = $conf['cachedir'].'/olmaptiles'; 51 if ($this->rrmdir($path)) msg($this->getLang('admin_purged_tiles'),0); 52 } 53 if(isset($_REQUEST['purgemaps'])){ 54 $path = $conf['mediadir'].'/olmapmaps'; 55 if ($this->rrmdir($path)) msg($this->getLang('admin_purged_maps'),0); 56 } 57 } 58 59 /** 60 * (non-PHPdoc) 61 * @see DokuWiki_Admin_Plugin::html() 62 */ 63 public function html() { 64 echo $this->locale_xhtml('admin_intro'); 65 $form = new Doku_Form(array('id'=>'olmap_purgeform', 'method'=>'post')); 66 $form->addHidden('continue','go'); 67 68 $form->startFieldset($this->getLang('admin_tiles')); 69 $form->addElement('<p>'); 70 $form->addElement('<input id="purgetiles" name="purgetiles" type="checkbox" value="1" class="checkbox" />'); 71 $form->addElement('<label for="purgetiles" class="label">'.$this->getLang('admin_purge_tiles').'</label>'); 72 $form->addElement('</p>'); 73 $form->endFieldset(); 74 75 $form->startFieldset($this->getLang('admin_maps')); 76 $form->addElement('<p>'); 77 $form->addElement('<input id="purgemaps" name="purgemaps" type="checkbox" value="1" class="checkbox" />'); 78 $form->addElement('<label for="purgemaps" class="label">'.$this->getLang('admin_purge_maps').'</label>'); 79 $form->addElement('</p>'); 80 $form->endFieldset(); 81 82 $form->addElement(form_makeButton('submit','admin',$this->getLang('admin_submit'), 83 array('accesskey'=>'p','title'=>$this->getLang('admin_submit')))); 84 $form->printForm(); 85 } 86 87 /** 88 * Recursively delete the directory. 89 * @param string $sDir directory path 90 * @return boolean true when succesful 91 */ 92 private function rrmdir($sDir) { 93 if (is_dir($sDir)) { 94 dbglog($sDir, 'admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: '); 95 $sDir = rtrim($sDir, '/'); 96 $oDir = dir($sDir); 97 while (($sFile = $oDir->read()) !== false) { 98 if ($sFile != '.' && $sFile != '..') { 99 (!is_link("$sDir/$sFile") && is_dir("$sDir/$sFile")) ? $this->rrmdir("$sDir/$sFile") : unlink("$sDir/$sFile"); 100 } 101 } 102 $oDir->close(); 103 rmdir($sDir); 104 return true; 105 } 106 return false; 107 } 108} 109