1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | photoWidget - a plugin for Piwigo | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2010 Nicolas Roudaire http://www.nikrou.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | This program is free software; you can redistribute it and/or modify | |
---|
8 | // | it under the terms of the GNU General Public License as published by | |
---|
9 | // | the Free Software Foundation | |
---|
10 | // | | |
---|
11 | // | This program is distributed in the hope that it will be useful, but | |
---|
12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
14 | // | General Public License for more details. | |
---|
15 | // | | |
---|
16 | // | You should have received a copy of the GNU General Public License | |
---|
17 | // | along with this program; if not, write to the Free Software | |
---|
18 | // | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
---|
19 | // | MA 02110-1301 USA. | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | class photoWidgetConfig |
---|
23 | { |
---|
24 | private |
---|
25 | $config = array(), |
---|
26 | $plugin_dir; |
---|
27 | |
---|
28 | public function __construct($plugin_dir, $plugin_name) { |
---|
29 | $this->plugin_dir = $plugin_dir; |
---|
30 | $this->plugin_name = $plugin_name; |
---|
31 | |
---|
32 | if (!file_exists($this->get_config_file_dir())) { |
---|
33 | mkgetdir($this->get_config_file_dir()); |
---|
34 | } |
---|
35 | |
---|
36 | if (!file_exists($this->get_config_filename())) { |
---|
37 | $this->save_config(); |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | public function load_config() { |
---|
42 | $x = file_get_contents($this->get_config_filename()); |
---|
43 | if ($x!==false) { |
---|
44 | $c = unserialize($x); |
---|
45 | $this->config = $c; |
---|
46 | } |
---|
47 | $this->setDefaults(); |
---|
48 | } |
---|
49 | |
---|
50 | public function save_config() { |
---|
51 | file_put_contents($this->get_config_filename(), serialize($this->config)); |
---|
52 | } |
---|
53 | |
---|
54 | private function get_config_file_dir() { |
---|
55 | return $GLOBALS['conf']['local_data_dir'].'/plugins/'; |
---|
56 | } |
---|
57 | |
---|
58 | private function get_config_filename() { |
---|
59 | return $this->get_config_file_dir().basename($this->plugin_dir).'.dat'; |
---|
60 | } |
---|
61 | |
---|
62 | public function __set($key, $value) { |
---|
63 | // need filters ?? |
---|
64 | $this->config[$key] = $value; |
---|
65 | } |
---|
66 | |
---|
67 | public function __get($key) { |
---|
68 | return isset($this->config[$key])?$this->config[$key]:null; |
---|
69 | } |
---|
70 | |
---|
71 | public function plugin_admin_menu($menu) { |
---|
72 | array_push($menu, |
---|
73 | array('NAME' => $this->plugin_name, |
---|
74 | 'URL' => get_admin_plugin_menu_link($this->plugin_dir.'/admin.php') |
---|
75 | ) |
---|
76 | ); |
---|
77 | return $menu; |
---|
78 | } |
---|
79 | |
---|
80 | private function setDefaults() { |
---|
81 | include_once $this->plugin_dir.'/default_values.inc.php'; |
---|
82 | |
---|
83 | foreach ($default_values as $key => $value) { |
---|
84 | if (!isset($this->config[$key])) { |
---|
85 | $this->config[$key] = $value; |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | } |
---|
90 | ?> |
---|