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 | |
---|
37 | class 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' => "GPCTranslate", 'version' => "2.1.0"), |
---|
56 | Array('name' => "GPCUsersGroups", 'version' => "2.0.0"), |
---|
57 | ) |
---|
58 | ); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | /* --------------------------------------------------------------------------- |
---|
63 | * register oriented functions |
---|
64 | * -------------------------------------------------------------------------*/ |
---|
65 | |
---|
66 | /** |
---|
67 | * register a plugin using GPC |
---|
68 | * |
---|
69 | * @param String $pluginName : the plugin name |
---|
70 | * @param String $release : the plugin version like "2.0.0" |
---|
71 | * @param String $GPCNeed : the minimal version of GPC needed by the plugin to |
---|
72 | * work |
---|
73 | * @return Boolean : true if registering is Ok, otherwise false |
---|
74 | */ |
---|
75 | static public function register($plugin, $release, $GPCneeded) |
---|
76 | { |
---|
77 | $config=Array(); |
---|
78 | if(self::loadConfig(self::$pluginName, $config)) |
---|
79 | { |
---|
80 | $config['registered'][$plugin]=Array( |
---|
81 | 'name' => $plugin, |
---|
82 | 'release' => $release, |
---|
83 | 'needed' => $GPCneeded, |
---|
84 | 'date' => date("Y-m-d"), |
---|
85 | ); |
---|
86 | return(self::saveConfig(self::$pluginName, $config)); |
---|
87 | } |
---|
88 | return(false); |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * unregister a plugin using GPC |
---|
93 | * |
---|
94 | * assume that if the plugin was not registerd before, unregistering returns |
---|
95 | * a true value |
---|
96 | * |
---|
97 | * @param String $pluginName : the plugin name |
---|
98 | * @return Boolean : true if registering is Ok, otherwise false |
---|
99 | */ |
---|
100 | static public function unregister($plugin) |
---|
101 | { |
---|
102 | $config=Array(); |
---|
103 | if(self::loadConfig(self::$pluginName, $config)) |
---|
104 | { |
---|
105 | if(array_key_exists('registered', $config)) |
---|
106 | { |
---|
107 | if(array_key_exists($plugin, $config['registered'])) |
---|
108 | { |
---|
109 | unset($config['registered'][$plugin]); |
---|
110 | return(self::saveConfig(self::$pluginName, $config)); |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | // assume if the plugin was not registered before, unregistering it is OK |
---|
115 | return(true); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * @return Array : list of registered plugins |
---|
120 | */ |
---|
121 | static public function getRegistered() |
---|
122 | { |
---|
123 | $config=Array(); |
---|
124 | if(self::loadConfig(self::$pluginName, $config)) |
---|
125 | { |
---|
126 | if(array_key_exists('registered', $config)) |
---|
127 | { |
---|
128 | return($config['registered']); |
---|
129 | } |
---|
130 | } |
---|
131 | return(Array()); |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | /* --------------------------------------------------------------------------- |
---|
137 | * config oriented functions |
---|
138 | * -------------------------------------------------------------------------*/ |
---|
139 | |
---|
140 | /** |
---|
141 | * load config from CONFIG_TABLE into an array |
---|
142 | * |
---|
143 | * @param String $pluginName : the plugin name, must contain only alphanumerical |
---|
144 | * character |
---|
145 | * @param Array $config : array, initialized or not with default values ; the |
---|
146 | * config values are loaded in this value |
---|
147 | * @return Boolean : true if config is loaded, otherwise false |
---|
148 | */ |
---|
149 | static public function loadConfig($pluginName, &$config=Array()) |
---|
150 | { |
---|
151 | if(!is_array($config)) |
---|
152 | { |
---|
153 | return(false); |
---|
154 | } |
---|
155 | |
---|
156 | $sql="SELECT value FROM ".CONFIG_TABLE." |
---|
157 | WHERE param = '".$pluginName."_config'"; |
---|
158 | $result=pwg_query($sql); |
---|
159 | if($result) |
---|
160 | { |
---|
161 | $row=pwg_db_fetch_row($result); |
---|
162 | if(is_string($row[0])) |
---|
163 | { |
---|
164 | $configValues = unserialize($row[0]); |
---|
165 | reset($configValues); |
---|
166 | while (list($key, $val) = each($configValues)) |
---|
167 | { |
---|
168 | if(is_array($val)) |
---|
169 | { |
---|
170 | foreach($val as $key2 => $val2) |
---|
171 | { |
---|
172 | $config[$key][$key2]=$val2; |
---|
173 | } |
---|
174 | } |
---|
175 | else |
---|
176 | { |
---|
177 | $config[$key] =$val; |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | return(true); |
---|
182 | } |
---|
183 | return(false); |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * save var $my_config into CONFIG_TABLE |
---|
188 | * |
---|
189 | * @param String $pluginName : the plugin name, must contain only alphanumerical |
---|
190 | * character |
---|
191 | * @param Array $config : array of configuration values |
---|
192 | * @return Boolean : true if config is saved, otherwise false |
---|
193 | */ |
---|
194 | static public function saveConfig($pluginName, $config) |
---|
195 | { |
---|
196 | $sql="REPLACE INTO ".CONFIG_TABLE." |
---|
197 | VALUES('".$pluginName."_config', '" |
---|
198 | .serialize($config)."', '')"; |
---|
199 | $result=pwg_query($sql); |
---|
200 | if($result) |
---|
201 | { return true; } |
---|
202 | else |
---|
203 | { return false; } |
---|
204 | } |
---|
205 | |
---|
206 | /** |
---|
207 | * delete config from CONFIG_TABLE |
---|
208 | * |
---|
209 | * @param String $pluginName : the plugin name, must contain only alphanumerical |
---|
210 | * character |
---|
211 | * @return Boolean : true if config is deleted, otherwise false |
---|
212 | */ |
---|
213 | static public function deleteConfig($pluginName) |
---|
214 | { |
---|
215 | $sql="DELETE FROM ".CONFIG_TABLE." |
---|
216 | WHERE param='".$pluginName."_config'"; |
---|
217 | $result=pwg_query($sql); |
---|
218 | if($result) |
---|
219 | { return true; } |
---|
220 | else |
---|
221 | { return false; } |
---|
222 | } |
---|
223 | |
---|
224 | } //class |
---|
225 | |
---|
226 | ?> |
---|