source: extensions/ContactForm/classes/cf_config.class.php @ 9070

Last change on this file since 9070 was 9070, checked in by plg, 13 years ago

feature 2180: remove the localization configuration tab

File size: 3.0 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4/**
5 * CF_Config class
6 */
7class CF_Config {
8  static $default_config = array();
9 
10  protected $config_values;
11  protected $db_key = null;
12  protected $db_comment = null;
13 
14  /* ************************ */
15  /* ** Constructor        ** */
16  /* ************************ */
17
18  function CF_Config() {
19  }
20 
21  /* ************************ */
22  /* ** Accessors          ** */
23  /* ************************ */
24 
25  function get_value($key) {
26      if (isset($this->config_values[$key])) {
27          return $this->config_values[$key];
28      }
29      return null;
30  }
31
32  function set_value($key, $value) {
33      $this->config_values[$key] = $value;
34  }
35
36  function set_db_key($key) {
37    $this->db_key = $key;
38  }
39 
40  /* ************************ */
41  /* ** Loading methods    ** */
42  /* ************************ */
43 
44  function load_config() {
45    if (null != $this->db_key) {
46      $query = '
47          SELECT value
48          FROM '.CONFIG_TABLE.'
49          WHERE param = \''. $this->db_key .'\'
50          ;';
51      $result = pwg_query($query);
52      if($result) {
53        $row = mysql_fetch_row($result);
54        if(is_string($row[0])) {
55          $this->config_values = unserialize($row[0]);
56        }
57      }
58    }
59    $this->load_default_config();
60  }
61 
62  protected function load_default_config() {
63    foreach (CF_Config::$default_config as $key => $value) {
64      if (!isset($this->config_values[$key])) {
65        $this->config_values[$key] = $value;
66      }
67    }
68  }
69 
70  /* ************************ */
71  /* ** Saving  methods    ** */
72  /* ************************ */
73
74  function save_config() {
75    if (null == $this->db_key) {
76      return false;
77    }
78
79    unset($this->config_values['config_lang']);
80   
81    if (!isset($this->config_values[CF_CFG_COMMENT])) {
82      $this->set_value(CF_CFG_COMMENT, CF_CFG_DB_COMMENT);
83    }
84    $db_comment = sprintf($this->config_values[CF_CFG_COMMENT],
85                          $this->db_key);
86    $query = '
87        REPLACE INTO '.CONFIG_TABLE.'
88        VALUES(
89          \''. $this->db_key .'\',
90          \''.serialize($this->config_values).'\',
91          \''. $db_comment . '\')
92        ;';
93    $result = pwg_query($query);
94    if($result) {
95      return true;
96    } else {
97      return false;
98    }
99  }
100 
101  /* ************************ */
102  /* ** Maintain  methods  ** */
103  /* ************************ */
104 
105  static function install($plugin_id) {
106    $config = new CF_Config();
107    $config->set_db_key($plugin_id);
108    $config->load_config();
109    $default_config = CF_Config::$default_config;
110    if (isset($default_config[CF_CFG_COMMENT])) {
111      // Override comment
112      $config->set_value(CF_CFG_COMMENT, $default_config[CF_CFG_COMMENT]);
113    }
114    $result = $config->save_config();
115    return $result;
116  }
117
118  static function uninstall($plugin_id) {
119    $query = '
120        DELETE FROM '.CONFIG_TABLE.'
121        WHERE param = \'' . $plugin_id . '\'
122        ;';
123    $result = pwg_query($query);
124    if($result) {
125      return true;
126    } else {
127      return false;
128    }
129  } 
130}
131?>
Note: See TracBrowser for help on using the repository browser.