source: extensions/CommentEditor/classes/ce_config.class.php @ 3462

Last change on this file since 3462 was 3462, checked in by Criss, 15 years ago

Display edit block on picture page if request comes from this page
Add simple administration configuration management
Add and remove default configuration from databaseon plugin install / uninstall

  • Property svn:eol-style set to LF
File size: 2.5 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4/**
5 * CE_Config class
6 */
7class CE_Config {
8
9  var $config_values;
10  var $default_config;
11
12  /* ************************ */
13  /* ** Constructor        ** */
14  /* ************************ */
15
16  function CE_Config($default_config = array()) {
17    $this->default_config = $default_config;
18  }
19
20  /* ************************ */
21  /* ** Get/Set methods    ** */
22  /* ************************ */
23
24  function getValue($key) {
25      if (isset($this->config_values[$key])) {
26          return $this->config_values[$key];
27      }
28      return null;
29  }
30
31  function setValue($key, $value) {
32      $this->config_values[$key] = $value;
33  }
34
35  /* ************************ */
36  /* ** Loading methods    ** */
37  /* ************************ */
38
39  function loadConfig() {
40    $query = '
41        SELECT value
42        FROM '.CONFIG_TABLE.'
43        WHERE param = \''.CE_CFG_DB_KEY.'\'
44        ;';
45    $result = pwg_query($query);
46    if($result) {
47      $row = mysql_fetch_row($result);
48      if(is_string($row[0])) {
49        $this->config_values = unserialize($row[0]);
50      }
51    }
52    $this->loadDefaultConfig();
53  }
54
55  private function loadDefaultConfig() {
56    foreach ($this->default_config as $key => $value) {
57      if (!isset($this->config_values[$key])) {
58        $this->config_values[$key] = $value;
59      }
60    }
61  }
62
63  /* ************************ */
64  /* ** Saving  methods    ** */
65  /* ************************ */
66
67  function saveConfig() {
68    $query = '
69        REPLACE INTO '.CONFIG_TABLE.'
70        VALUES(
71          \''.CE_CFG_DB_KEY.'\',
72          \''.serialize($this->config_values).'\',
73          \''. CE_CFG_DB_COMMENT . '\')
74        ;';
75    $result = pwg_query($query);
76    if($result) {
77      return true;
78    } else {
79      return false;
80    }
81  }
82
83  /* ************************ */
84  /* ** Maintain  methods  ** */
85  /* ************************ */
86
87  static function install($plugin_id, $default_config = array()) {
88    $query = '
89        REPLACE INTO '.CONFIG_TABLE.'
90        VALUES(
91          \''.$plugin_id.'\',
92          \''.serialize($default_config).'\',
93          \'Factory settings for '. $plugin_id . '\')
94        ;';
95    $result = pwg_query($query);
96    if($result) {
97      return true;
98    } else {
99      return false;
100    }
101  }
102
103  static function uninstall($plugin_id) {
104    $query = '
105        DELETE FROM '.CONFIG_TABLE.'
106        WHERE param = \''.$plugin_id.'\'
107        ;';
108    $result = pwg_query($query);
109    if($result) {
110      return true;
111    } else {
112      return false;
113    }
114  }
115}
116?>
Note: See TracBrowser for help on using the repository browser.