summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/refnotes/config.php
blob: 80b09254de0f40134b3d30b00731a405a4488f6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

/**
 * Plugin RefNotes: Configuration
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Mykola Ostrovskyy <dwpforge@gmail.com>
 */

class refnotes_configuration {

    private static $section = array();
    private static $setting = array(
        'replace-footnotes' => array('general', false),
        'reference-db-enable' => array('general', false),
        'reference-db-namespace' => array('general', ':refnotes:')
    );

    /**
     *
     */
    public static function getSetting($name) {
        $result = null;

        if (array_key_exists($name, self::$setting)) {
            $sectionName = self::$setting[$name][0];
            $result = self::$setting[$name][1];

            if (!array_key_exists($sectionName, self::$section)) {
                self::$section[$sectionName] = self::load($sectionName);
            }

            if (array_key_exists($name, self::$section[$sectionName])) {
                $result = self::$section[$sectionName][$name];
            }
        }

        return $result;
    }

    /**
     *
     */
    public static function load($sectionName) {
        $fileName = DOKU_CONF . 'refnotes.' . $sectionName . '.local.dat';

        if (!file_exists($fileName)) {
            // TODO: This backward compatibility fix should be eventually removed
            $pluginRoot = DOKU_PLUGIN . 'refnotes/';
            $fileName = $pluginRoot . $sectionName . '.local.dat';
            if (!file_exists($fileName)) {
                $fileName = $pluginRoot . 'conf/' . $sectionName . '.dat';
                if (!file_exists($fileName)) {
                    $fileName = '';
                }
            }
        }

        if ($fileName != '') {
            $result = unserialize(io_readFile($fileName, false));
        }
        else {
            $result = array();
        }

        return $result;
    }

    /**
     *
     */
    public static function save($sectionName, $config) {
        $fileName = DOKU_CONF . 'refnotes.' . $sectionName . '.local.dat';

        return io_saveFile($fileName, serialize($config));
    }
}