source: extensions/database_migration/include/config.class.php @ 32821

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

Database migration plugin : first public version

File size: 3.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | database_migration - 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 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 dmConfig
23{
24  private $config = array(), $plugin_dir;
25
26  public function __construct($plugin_dir, $plugin_name) {
27    $this->plugin_dir = $plugin_dir;
28    $this->plugin_name = $plugin_name;
29
30    if (!file_exists($this->get_config_file_dir())) {
31      mkgetdir($this->get_config_file_dir());
32    }
33
34    if (!file_exists($this->get_config_filename())) {
35      $this->save_config();
36    }
37  }
38
39  public function load_config() {
40    $x = file_get_contents($this->get_config_filename());
41    if ($x!==false) {
42      $c = unserialize($x);
43      $this->config = $c;
44    }
45
46    if (!isset($this->config['connections'])) {
47      $this->config['connections'] = array();
48    }
49  }
50
51  public function save_config() {
52    file_put_contents($this->get_config_filename(), serialize($this->config));
53  }
54
55  private function get_config_file_dir() {
56    return $GLOBALS['conf']['local_data_dir'].'/plugins/';
57  }
58
59  private function get_config_filename() {
60    return $this->get_config_file_dir().basename($this->plugin_dir).'.dat';
61  }
62
63  public function __set($key, $value) {
64    $this->config[$key] = $value;
65  }
66
67  public function __get($key) {
68    return isset($this->config[$key])?$this->config[$key]:null;
69  }
70
71  public function plugin_admin_menu($menu) {
72    array_push($menu,
73               array('NAME' => $this->plugin_name,
74                     'URL' => get_admin_plugin_menu_link($this->plugin_dir.'/admin.php')                 
75                     )
76               );
77
78    return $menu;
79  }
80
81  public function addConnection($dblayer, $params) {
82    $this->config['connections'][$dblayer] = $params;
83  }
84
85  public function removeConnection($dblayer) {
86    if (isset($this->config['connections'][$dblayer])) {
87      unset($this->config['connections'][$dblayer]);
88    }
89  }
90
91  public function getConnection($dblayer) {
92    return isset($this->config['connections'][$dblayer])?$this->config['connections'][$dblayer]:null;
93  }
94
95  public function getAllConnections() {
96    $allConnections = $this->config['connections'];
97    if (isset($allConnections['mysql'])) {
98      unset($allConnections['mysql']);
99    }
100
101    return $allConnections;
102  }
103}
104?>
Note: See TracBrowser for help on using the repository browser.