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

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

Add permissions on add tags widget
Use default theme jquery library
Add help

File size: 3.5 KB
Line 
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 setPermission($permission, $value) {
71    $this->config['permissions'][$permission] = $value;
72  }
73
74  public function getPermission($permission) {
75    return isset($this->config['permissions'][$permission])?$this->config['permissions'][$permission]:null;
76  }
77
78  public function plugin_admin_menu($menu) {
79    array_push($menu,
80               array('NAME' => $this->plugin_name,
81                     'URL' => get_admin_plugin_menu_link($this->plugin_dir.'/admin.php')                 
82                     )
83               );
84    return $menu;
85  }
86
87  public function get_admin_help($help_content, $page) {
88    return load_language('help/'.$page.'.html', $this->plugin_dir .'/', array('return'=>true) );
89  }
90
91  private function setDefaults() {
92    include_once $this->plugin_dir.'/include/default_values.inc.php';
93
94    foreach ($default_values as $key => $value) {
95      if (empty($this->config[$key])) {
96        $this->config[$key] = $value;
97      }
98    }
99  }
100}
101?>
Note: See TracBrowser for help on using the repository browser.