source: extensions/GrumPluginClasses/classes/GPCCore.class.inc.php @ 5919

Last change on this file since 5919 was 5919, checked in by grum, 14 years ago

Prepare release 3.1.0

File size: 6.5 KB
Line 
1<?php
2
3/* -----------------------------------------------------------------------------
4  class name     : GPCCore
5  class version  : 3.0.0
6  plugin version : 3.0.0
7  date           : 2010-03-30
8  ------------------------------------------------------------------------------
9  author: grum at piwigo.org
10  << May the Little SpaceFrog be with you >>
11  ------------------------------------------------------------------------------
12
13  :: HISTORY
14
15| release | date       |
16| 3.0.0   | 2010/03/30 | * Update class & function names
17|         |            |
18|         |            |
19|         |            |
20|         |            |
21|         |            |
22|         |            |
23
24  ------------------------------------------------------------------------------
25    no constructor, only static function are provided
26    - static function loadConfig
27    - static function saveConfig
28    - static function deleteConfig
29    - static function getRegistered
30    - static function getModulesInfos
31    - static function register
32    - static function unregister
33   ---------------------------------------------------------------------- */
34
35
36
37class GPCCore
38{
39  static public $pluginName = "GPCCore";
40
41  /* ---------------------------------------------------------------------------
42   * grum plugin classes informations functions
43   * -------------------------------------------------------------------------*/
44  static public function getModulesInfos()
45  {
46    return(
47      Array(
48        Array('name' => "CommonPlugin", 'version' => "2.1.0"),
49        Array('name' => "GPCAjax", 'version' => "3.0.0"),
50        Array('name' => "GPCCore", 'version' => "1.0.0"),
51        Array('name' => "GPCCss", 'version' => "3.0.0"),
52        Array('name' => "GPCPagesNavigations", 'version' => "2.0.0"),
53        Array('name' => "GPCPublicIntegration", 'version' => "2.0.0"),
54        Array('name' => "GPCTables", 'version' => "1.5.0"),
55        Array('name' => "GPCTabSheet", 'version' => "1.0.0"),
56        Array('name' => "GPCTranslate", 'version' => "2.1.0"),
57        Array('name' => "GPCUsersGroups", 'version' => "2.0.0"),
58      )
59    );
60  }
61
62
63  /* ---------------------------------------------------------------------------
64   * register oriented functions
65   * -------------------------------------------------------------------------*/
66
67  /**
68   * register a plugin using GPC
69   *
70   * @param String $pluginName : the plugin name
71   * @param String $release : the plugin version like "2.0.0"
72   * @param String $GPCNeed : the minimal version of GPC needed by the plugin to
73   *                          work
74   * @return Boolean : true if registering is Ok, otherwise false
75   */
76  static public function register($plugin, $release, $GPCneeded)
77  {
78    $config=Array();
79    if(self::loadConfig(self::$pluginName, $config))
80    {
81      $config['registered'][$plugin]=Array(
82        'name' => $plugin,
83        'release' => $release,
84        'needed' => $GPCneeded,
85        'date' => date("Y-m-d"),
86      );
87      return(self::saveConfig(self::$pluginName, $config));
88    }
89    return(false);
90  }
91
92  /**
93   * unregister a plugin using GPC
94   *
95   * assume that if the plugin was not registerd before, unregistering returns
96   * a true value
97   *
98   * @param String $pluginName : the plugin name
99   * @return Boolean : true if registering is Ok, otherwise false
100   */
101  static public function unregister($plugin)
102  {
103    $config=Array();
104    if(self::loadConfig(self::$pluginName, $config))
105    {
106      if(array_key_exists('registered', $config))
107      {
108        if(array_key_exists($plugin, $config['registered']))
109        {
110          unset($config['registered'][$plugin]);
111          return(self::saveConfig(self::$pluginName, $config));
112        }
113      }
114    }
115    // assume if the plugin was not registered before, unregistering it is OK
116    return(true);
117  }
118
119  /**
120   * @return Array : list of registered plugins
121   */
122  static public function getRegistered()
123  {
124    $config=Array();
125    if(self::loadConfig(self::$pluginName, $config))
126    {
127      if(array_key_exists('registered', $config))
128      {
129        return($config['registered']);
130      }
131    }
132    return(Array());
133  }
134
135
136
137  /* ---------------------------------------------------------------------------
138   * config oriented functions
139   * -------------------------------------------------------------------------*/
140
141  /**
142   *  load config from CONFIG_TABLE into an array
143   *
144   * @param String $pluginName : the plugin name, must contain only alphanumerical
145   *                             character
146   * @param Array $config : array, initialized or not with default values ; the
147   *                        config values are loaded in this value
148   * @return Boolean : true if config is loaded, otherwise false
149   */
150  static public function loadConfig($pluginName, &$config=Array())
151  {
152    if(!is_array($config))
153    {
154      return(false);
155    }
156
157    $sql="SELECT value FROM ".CONFIG_TABLE."
158          WHERE param = '".$pluginName."_config'";
159    $result=pwg_query($sql);
160    if($result)
161    {
162      $row=pwg_db_fetch_row($result);
163      if(is_string($row[0]))
164      {
165        $configValues = unserialize($row[0]);
166        reset($configValues);
167        while (list($key, $val) = each($configValues))
168        {
169          if(is_array($val))
170          {
171            foreach($val as $key2 => $val2)
172            {
173              $config[$key][$key2]=$val2;
174            }
175          }
176          else
177          {
178            $config[$key] =$val;
179          }
180        }
181      }
182      return(true);
183    }
184    return(false);
185  }
186
187  /**
188   * save var $my_config into CONFIG_TABLE
189   *
190   * @param String $pluginName : the plugin name, must contain only alphanumerical
191   *                             character
192   * @param Array $config : array of configuration values
193   * @return Boolean : true if config is saved, otherwise false
194   */
195  static public function saveConfig($pluginName, $config)
196  {
197    $sql="REPLACE INTO ".CONFIG_TABLE."
198           VALUES('".$pluginName."_config', '"
199           .serialize($config)."', '')";
200    $result=pwg_query($sql);
201    if($result)
202    { return true; }
203    else
204    { return false; }
205  }
206
207  /**
208   * delete config from CONFIG_TABLE
209   *
210   * @param String $pluginName : the plugin name, must contain only alphanumerical
211   *                             character
212   * @return Boolean : true if config is deleted, otherwise false
213   */
214  static public function deleteConfig($pluginName)
215  {
216    $sql="DELETE FROM ".CONFIG_TABLE."
217          WHERE param='".$pluginName."_config'";
218    $result=pwg_query($sql);
219    if($result)
220    { return true; }
221    else
222    { return false; }
223  }
224
225} //class
226
227?>
Note: See TracBrowser for help on using the repository browser.