source: extensions/user_tags/include/t4u_config.class.php @ 6798

Last change on this file since 6798 was 6798, checked in by nikrou, 14 years ago

First public release User Tags

File size: 3.0 KB
RevLine 
[6798]1<?php
2// +-----------------------------------------------------------------------+
3// | User Tags  - 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
22class t4u_Config
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    $this->config[$key] = $value;
64  }
65
66  public function __get($key) {
67    return isset($this->config[$key])?$this->config[$key]:null;
68  }
69
70  public function plugin_admin_menu($menu) {
71    array_push($menu,
72               array('NAME' => $this->plugin_name,
73                     'URL' => get_admin_plugin_menu_link($this->plugin_dir.'/admin.php')                 
74                     )
75               );
76    return $menu;
77  }
78
79  private function setDefaults() {
80    include_once $this->plugin_dir.'/include/default_values.inc.php';
81
82    foreach ($default_values as $key => $value) {
83      if (empty($this->config[$key])) {
84        $this->config[$key] = $value;
85      }
86    }
87  }
88}
89?>
Note: See TracBrowser for help on using the repository browser.