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

Last change on this file since 11081 was 11081, checked in by nikrou, 13 years ago

Fix incompatibility with piwigo 2.2
Change jquery plugin from fcbkcomplete to tokeninput

File size: 4.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | User Tags  - a plugin for Piwigo                                      |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2010-2011 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
79  public function hasPermission($permission='add') {
80    return 
81      (($this->getPermission($permission)!='')
82       and is_autorize_status(get_access_type_status($this->getPermission($permission))));
83  }
84
85  public function plugin_admin_menu($menu) {
86    array_push($menu,
87               array('NAME' => $this->plugin_name,
88                     'URL' => get_admin_plugin_menu_link($this->plugin_dir.'/admin.php')                 
89                     )
90               );
91    return $menu;
92  }
93
94  public function get_admin_help($help_content, $page) {
95    return load_language('help/'.$page.'.html', 
96                         $this->plugin_dir .'/', 
97                         array('return'=>true) 
98                         );
99  }
100 
101  public function getActionUrl($action, $method='POST') {
102    $url = get_root_url().'admin.php?page=plugin';
103    $file = basename($this->plugin_dir) . '/' .'admin.php';
104    if (strtoupper($method)=='POST') {
105        $url .= '&amp;section='.urlencode($file);
106        $url .= '&amp;action='.urlencode($action);
107    } else {
108        $url .= '&section='.$file;
109        $url .= '&action='.$action;
110    }
111
112    return $url;
113  }
114
115  private function setDefaults() {
116    include_once $this->plugin_dir.'/include/default_values.inc.php';
117
118    foreach ($default_values as $key => $value) {
119      if (empty($this->config[$key])) {
120        $this->config[$key] = $value;
121      }
122    }
123  }
124}
125?>
Note: See TracBrowser for help on using the repository browser.