1<?php
2
3/**
4 * Plugin RefNotes: Configuration
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Mykola Ostrovskyy <dwpforge@gmail.com>
8 */
9
10class refnotes_configuration {
11
12    private static $section = array();
13    private static $setting = array(
14        'replace-footnotes' => array('general', false),
15        'reference-db-enable' => array('general', false),
16        'reference-db-namespace' => array('general', ':refnotes:')
17    );
18
19    /**
20     *
21     */
22    public static function getSetting($name) {
23        $result = null;
24
25        if (array_key_exists($name, self::$setting)) {
26            $sectionName = self::$setting[$name][0];
27            $result = self::$setting[$name][1];
28
29            if (!array_key_exists($sectionName, self::$section)) {
30                self::$section[$sectionName] = self::load($sectionName);
31            }
32
33            if (array_key_exists($name, self::$section[$sectionName])) {
34                $result = self::$section[$sectionName][$name];
35            }
36        }
37
38        return $result;
39    }
40
41    /**
42     *
43     */
44    public static function load($sectionName) {
45        $fileName = DOKU_CONF . 'refnotes.' . $sectionName . '.local.dat';
46
47        if (!file_exists($fileName)) {
48            // TODO: This backward compatibility fix should be eventually removed
49            $pluginRoot = DOKU_PLUGIN . 'refnotes/';
50            $fileName = $pluginRoot . $sectionName . '.local.dat';
51            if (!file_exists($fileName)) {
52                $fileName = $pluginRoot . 'conf/' . $sectionName . '.dat';
53                if (!file_exists($fileName)) {
54                    $fileName = '';
55                }
56            }
57        }
58
59        if ($fileName != '') {
60            $result = unserialize(io_readFile($fileName, false));
61        }
62        else {
63            $result = array();
64        }
65
66        return $result;
67    }
68
69    /**
70     *
71     */
72    public static function save($sectionName, $config) {
73        $fileName = DOKU_CONF . 'refnotes.' . $sectionName . '.local.dat';
74
75        return io_saveFile($fileName, serialize($config));
76    }
77}
78