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

Last change on this file since 31844 was 20762, checked in by nikrou, 11 years ago

Fix issue that altering picture page content
Fix possible sql injections issues

File size: 4.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | User Tags  - a plugin for Piwigo                                      |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2010-2013 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 version 2 as     |
9// | published by 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 $config = array();
25  protected static $instance; 
26
27  public function __construct($plugin_dir, $plugin_name) {
28    $this->plugin_dir = $plugin_dir;
29    $this->plugin_name = $plugin_name;
30
31    if (!file_exists($this->get_config_file_dir())) {
32      mkgetdir($this->get_config_file_dir());
33    }
34
35    if (!file_exists($this->get_config_filename())) {
36      $this->setDefaults();
37      $this->save_config();
38    }
39  }
40
41  public static function getInstance() { 
42    if (!isset(self::$instance)) { 
43      self::$instance = new t4u_Config(T4U_PLUGIN_ROOT, T4U_PLUGIN_NAME); 
44    } 
45    return self::$instance; 
46  }
47
48
49  public function load_config() {
50    $x = file_get_contents($this->get_config_filename());
51    if ($x!==false) {
52      $c = unserialize($x);
53      $this->config = $c;
54    }
55  }
56
57  public function save_config() {
58    file_put_contents($this->get_config_filename(), serialize($this->config));
59  }
60
61  private function get_config_file_dir() {
62    return PHPWG_ROOT_PATH . $GLOBALS['conf']['data_location'].'plugins/';
63  }
64
65  private function get_config_filename() {
66    return $this->get_config_file_dir().basename($this->plugin_dir).'.dat';
67  }
68
69  public function __set($key, $value) {
70    $this->config[$key] = $value;
71  }
72
73  public function __get($key) {
74    return isset($this->config[$key])?$this->config[$key]:null;
75  }
76
77  public function setPermission($permission, $value) {
78    $this->config['permissions'][$permission] = $value;
79  }
80
81  public function getPermission($permission) {
82    return isset($this->config['permissions'][$permission])?$this->config['permissions'][$permission]:null;
83  }
84
85
86  public function hasPermission($permission='add') {
87    return 
88      (($this->getPermission($permission)!='')
89       and is_autorize_status(get_access_type_status($this->getPermission($permission))));
90  }
91 
92  public static function plugin_admin_menu($menu) {
93    $menu[] = array('NAME' => T4U_PLUGIN_NAME,
94                    'URL' => get_admin_plugin_menu_link(T4U_PLUGIN_ROOT .'/admin.php')
95                    );
96   
97    return $menu;
98  }
99
100  public static function get_admin_help($help_content, $page) {
101    return load_language('help/'.$page.'.html', 
102                         T4U_PLUGIN_ROOT .'/', 
103                         array('return' => true) 
104                         );
105  }
106 
107  public function getActionUrl($action, $method='POST') {
108    $ws = get_root_url();
109    $ws .= 'ws.php?format=json&method=user_tags.tags.list';
110
111    return $ws;
112  }
113
114  private function setDefaults() {
115    include_once $this->plugin_dir.'/include/default_values.inc.php';
116   
117    foreach ($default_values as $key => $value) {
118      if (empty($this->config[$key])) {
119        $this->config[$key] = $value;
120      }
121    }
122  }
123}
Note: See TracBrowser for help on using the repository browser.