1<?php
2/**
3 * Federated Login for DokuWiki - restore default settings class
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @link       http://www.dokuwiki.org/plugin:fedauth
7 * @author     Aoi Karasu <aoikarasu@gmail.com>
8 */
9
10// config path must be defined
11if (!defined('CONFIG_PATH')) die('CONFIG_PATH is not defined!');
12
13/**
14 * Authorization providers management class responsible for restoring
15 * the default settings. Deletes local plugin cofiguration.
16 *
17 * @author     Aoi Karasu <aoikarasu@gmail.com>
18 */
19class fa_restore extends fa_manage {
20
21    /**
22     * Creates the class instance bound with the admin plugin and an authorization provider.
23     *
24     * @param objref $manager object reference to the admin plugin
25     * @param string $cmd name of the command to handle
26     * @param string $provid (optional) an authorization provider id
27     */
28    function __construct(&$manager, $cmd, $provid='') {
29        parent::__construct(&$manager, $cmd, $provid);
30    }
31
32    /**
33     * Performs the restore defaults action by deleting the local plugin config files.
34     */
35    function process_restore() {
36        global $ID;
37
38        if ($this->_deleteDir(CONFIG_PATH)) {
39            $location = wl($ID).'?do='.$_REQUEST['do'].'&page='.$_REQUEST['page'];
40            header('Location: '.$location);
41        }
42        return '';
43    }
44
45    /**
46     * Deletes a directory tree.
47     *
48     * @param string $dirPath directory path to delete
49     */
50    function _deleteDir($dirPath) {
51        if (! is_dir($dirPath)) {
52            return false;
53        }
54        if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
55            $dirPath .= '/';
56        }
57        $files = glob($dirPath . '*', GLOB_MARK);
58        foreach ($files as $file) {
59            if (is_dir($file)) {
60                self::deleteDir($file);
61            } else {
62                unlink($file);
63            }
64        }
65        rmdir($dirPath);
66        return true;
67    }
68
69} /* fa_restore */
70
71/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
72