source: extensions/akBookStyle/trunk/include/akConfig.class.php @ 3791

Last change on this file since 3791 was 3791, checked in by nikrou, 15 years ago

Allow admin to change number of column
Use $confdir_thumbnail and $confprefix_thumbnail in ak_jquery-load.js for replace('thumbnail\/TN-', )

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