1<?php
2/**
3 * @license    http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
4 * @author     Francois Merciol <dokuplugin@merciol.fr>
5 *
6 * TiledBlog Plugin: manage clear action action
7*/
8if (!defined ('DOKU_INC'))
9  define ('DOKU_INC', realpath (dirname (__FILE__).'/../../../').'/');
10require_once (DOKU_INC.'inc/init.php');
11require_once (DOKU_INC.'inc/common.php');
12require_once (DOKU_INC.'inc/auth.php');
13{
14  global $INFO;
15  if (isset ($_SERVER['REMOTE_USER']))
16    $INFO['userinfo'] = $auth->getUserData ($auth->cleanUser ($_SERVER['REMOTE_USER']));
17  $tiledblogPug =& plugin_load ('syntax', 'tiledblog');
18  if (!$tiledblogPug->isAdmin ())
19    die ();
20
21  global $conf;
22  $savedir = ((!$conf['savedir'] || strpos ($conf['savedir'], '.') === 0) ? DOKU_INC : "").$conf['savedir']."/";
23  $cacheDir = $savedir."cache/tiledblog/";
24  switch ($_REQUEST ['tiledblog']['action']) {
25  case 'clear':
26    $baseName = $cacheDir.md5 ($_REQUEST ['tiledblog']['ns']);
27    @unlink ($baseName."-tile.cache");
28    @unlink ($baseName."-sample.cache");
29    break;
30
31  case 'clearAll':
32    $exclude = ".|..";
33    $exclude_array = explode("|", $exclude);
34    $pathDir = rtrim ($cacheDir, "/") . "/";
35    if (!is_dir($pathDir))
36      break;
37    $pathDirObj = opendir ($pathDir);
38    while (false !== ($file = readdir ($pathDirObj))) {
39      if (in_array (strtolower ($file), $exclude_array))
40	continue;
41      $pathFile = $pathDir.$file;
42      if (!is_file ($pathFile))
43	continue;
44      if (eregi ('.*-tile\.cache$', $file, $b) ||
45	  eregi ('.*-sample\.cache$', $file, $b))
46	@unlink ($pathFile);
47    }
48    break;
49  }
50}
51