1 | <?php |
---|
2 | |
---|
3 | /* ----------------------------------------------------------------------------- |
---|
4 | class name : GPCCore |
---|
5 | class version : 1.1.0 |
---|
6 | plugin version : 3.1.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 | | 1.0.0 | 2010/03/30 | * Update class & function names |
---|
17 | | | | |
---|
18 | | 1.1.0 | 2010/03/30 | * add the BBtoHTML function |
---|
19 | | | | |
---|
20 | | | | |
---|
21 | | | | |
---|
22 | | | | |
---|
23 | | | | |
---|
24 | |
---|
25 | ------------------------------------------------------------------------------ |
---|
26 | no constructor, only static function are provided |
---|
27 | - static function loadConfig |
---|
28 | - static function saveConfig |
---|
29 | - static function deleteConfig |
---|
30 | - static function getRegistered |
---|
31 | - static function getModulesInfos |
---|
32 | - static function register |
---|
33 | - static function unregister |
---|
34 | - static function BBtoHTML |
---|
35 | ---------------------------------------------------------------------- */ |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | class GPCCore |
---|
40 | { |
---|
41 | static public $pluginName = "GPCCore"; |
---|
42 | |
---|
43 | /* --------------------------------------------------------------------------- |
---|
44 | * grum plugin classes informations functions |
---|
45 | * -------------------------------------------------------------------------*/ |
---|
46 | static public function getModulesInfos() |
---|
47 | { |
---|
48 | return( |
---|
49 | Array( |
---|
50 | Array('name' => "CommonPlugin", 'version' => "2.1.0"), |
---|
51 | Array('name' => "GPCAjax", 'version' => "3.0.0"), |
---|
52 | Array('name' => "GPCCore", 'version' => "1.1.0"), |
---|
53 | Array('name' => "GPCCss", 'version' => "3.0.0"), |
---|
54 | Array('name' => "GPCPagesNavigations", 'version' => "2.0.0"), |
---|
55 | Array('name' => "GPCPublicIntegration", 'version' => "2.0.0"), |
---|
56 | Array('name' => "GPCTables", 'version' => "1.5.0"), |
---|
57 | Array('name' => "GPCTabSheet", 'version' => "1.0.0"), |
---|
58 | Array('name' => "GPCTranslate", 'version' => "2.1.0"), |
---|
59 | Array('name' => "GPCUsersGroups", 'version' => "2.0.0"), |
---|
60 | ) |
---|
61 | ); |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | /* --------------------------------------------------------------------------- |
---|
66 | * register oriented functions |
---|
67 | * -------------------------------------------------------------------------*/ |
---|
68 | |
---|
69 | /** |
---|
70 | * register a plugin using GPC |
---|
71 | * |
---|
72 | * @param String $pluginName : the plugin name |
---|
73 | * @param String $release : the plugin version like "2.0.0" |
---|
74 | * @param String $GPCNeed : the minimal version of GPC needed by the plugin to |
---|
75 | * work |
---|
76 | * @return Boolean : true if registering is Ok, otherwise false |
---|
77 | */ |
---|
78 | static public function register($plugin, $release, $GPCneeded) |
---|
79 | { |
---|
80 | $config=Array(); |
---|
81 | if(self::loadConfig(self::$pluginName, $config)) |
---|
82 | { |
---|
83 | $config['registered'][$plugin]=Array( |
---|
84 | 'name' => $plugin, |
---|
85 | 'release' => $release, |
---|
86 | 'needed' => $GPCneeded, |
---|
87 | 'date' => date("Y-m-d"), |
---|
88 | ); |
---|
89 | return(self::saveConfig(self::$pluginName, $config)); |
---|
90 | } |
---|
91 | return(false); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * unregister a plugin using GPC |
---|
96 | * |
---|
97 | * assume that if the plugin was not registerd before, unregistering returns |
---|
98 | * a true value |
---|
99 | * |
---|
100 | * @param String $pluginName : the plugin name |
---|
101 | * @return Boolean : true if registering is Ok, otherwise false |
---|
102 | */ |
---|
103 | static public function unregister($plugin) |
---|
104 | { |
---|
105 | $config=Array(); |
---|
106 | if(self::loadConfig(self::$pluginName, $config)) |
---|
107 | { |
---|
108 | if(array_key_exists('registered', $config)) |
---|
109 | { |
---|
110 | if(array_key_exists($plugin, $config['registered'])) |
---|
111 | { |
---|
112 | unset($config['registered'][$plugin]); |
---|
113 | return(self::saveConfig(self::$pluginName, $config)); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | // assume if the plugin was not registered before, unregistering it is OK |
---|
118 | return(true); |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * @return Array : list of registered plugins |
---|
123 | */ |
---|
124 | static public function getRegistered() |
---|
125 | { |
---|
126 | $config=Array(); |
---|
127 | if(self::loadConfig(self::$pluginName, $config)) |
---|
128 | { |
---|
129 | if(array_key_exists('registered', $config)) |
---|
130 | { |
---|
131 | return($config['registered']); |
---|
132 | } |
---|
133 | } |
---|
134 | return(Array()); |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | /* --------------------------------------------------------------------------- |
---|
140 | * config oriented functions |
---|
141 | * -------------------------------------------------------------------------*/ |
---|
142 | |
---|
143 | /** |
---|
144 | * load config from CONFIG_TABLE into an array |
---|
145 | * |
---|
146 | * @param String $pluginName : the plugin name, must contain only alphanumerical |
---|
147 | * character |
---|
148 | * @param Array $config : array, initialized or not with default values ; the |
---|
149 | * config values are loaded in this value |
---|
150 | * @return Boolean : true if config is loaded, otherwise false |
---|
151 | */ |
---|
152 | static public function loadConfig($pluginName, &$config=Array()) |
---|
153 | { |
---|
154 | if(!is_array($config)) |
---|
155 | { |
---|
156 | return(false); |
---|
157 | } |
---|
158 | |
---|
159 | $sql="SELECT value FROM ".CONFIG_TABLE." |
---|
160 | WHERE param = '".$pluginName."_config'"; |
---|
161 | $result=pwg_query($sql); |
---|
162 | if($result) |
---|
163 | { |
---|
164 | $row=pwg_db_fetch_row($result); |
---|
165 | if(is_string($row[0])) |
---|
166 | { |
---|
167 | $configValues = unserialize($row[0]); |
---|
168 | reset($configValues); |
---|
169 | while (list($key, $val) = each($configValues)) |
---|
170 | { |
---|
171 | if(is_array($val)) |
---|
172 | { |
---|
173 | foreach($val as $key2 => $val2) |
---|
174 | { |
---|
175 | $config[$key][$key2]=$val2; |
---|
176 | } |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | $config[$key] =$val; |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | return(true); |
---|
185 | } |
---|
186 | return(false); |
---|
187 | } |
---|
188 | |
---|
189 | /** |
---|
190 | * save var $my_config into CONFIG_TABLE |
---|
191 | * |
---|
192 | * @param String $pluginName : the plugin name, must contain only alphanumerical |
---|
193 | * character |
---|
194 | * @param Array $config : array of configuration values |
---|
195 | * @return Boolean : true if config is saved, otherwise false |
---|
196 | */ |
---|
197 | static public function saveConfig($pluginName, $config) |
---|
198 | { |
---|
199 | $sql="REPLACE INTO ".CONFIG_TABLE." |
---|
200 | VALUES('".$pluginName."_config', '" |
---|
201 | .serialize($config)."', '')"; |
---|
202 | $result=pwg_query($sql); |
---|
203 | if($result) |
---|
204 | { return true; } |
---|
205 | else |
---|
206 | { return false; } |
---|
207 | } |
---|
208 | |
---|
209 | /** |
---|
210 | * delete config from CONFIG_TABLE |
---|
211 | * |
---|
212 | * @param String $pluginName : the plugin name, must contain only alphanumerical |
---|
213 | * character |
---|
214 | * @return Boolean : true if config is deleted, otherwise false |
---|
215 | */ |
---|
216 | static public function deleteConfig($pluginName) |
---|
217 | { |
---|
218 | $sql="DELETE FROM ".CONFIG_TABLE." |
---|
219 | WHERE param='".$pluginName."_config'"; |
---|
220 | $result=pwg_query($sql); |
---|
221 | if($result) |
---|
222 | { return true; } |
---|
223 | else |
---|
224 | { return false; } |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | /** |
---|
229 | * convert (light) BB tag to HTML tag |
---|
230 | * |
---|
231 | * all BB codes are not recognized, only : |
---|
232 | * - [ul] [/ul] |
---|
233 | * - [li] [/li] |
---|
234 | * - [b] [/b] |
---|
235 | * - [i] [/i] |
---|
236 | * - [url] [/url] |
---|
237 | * - carriage return is replaced by a <br> |
---|
238 | * |
---|
239 | * @param String $text : text to convert |
---|
240 | * @return String : BB to HTML text |
---|
241 | */ |
---|
242 | static public function BBtoHTML($text) |
---|
243 | { |
---|
244 | $patterns = Array( |
---|
245 | '/\[li\](.*?)\[\/li\]\n*/im', |
---|
246 | '/\[b\](.*?)\[\/b\]/ism', |
---|
247 | '/\[i\](.*?)\[\/i\]/ism', |
---|
248 | '/\[url\]([\w]+?:\/\/[^ \"\n\r\t<]*?)\[\/url\]/ism', |
---|
249 | '/\[url=([\w]+?:\/\/[^ \"\n\r\t<]*?)\](.*?)\[\/url\]/ism', |
---|
250 | '/\n{0,1}\[ul\]\n{0,1}/im', |
---|
251 | '/\n{0,1}\[\/ul\]\n{0,1}/im', |
---|
252 | '/\n/im', |
---|
253 | ); |
---|
254 | $replacements = Array( |
---|
255 | '<li>\1</li>', |
---|
256 | '<b>\1</b>', |
---|
257 | '<i>\1</i>', |
---|
258 | '<a href="\1">\1</a>', |
---|
259 | '<a href="\1">\2</a>', |
---|
260 | '<ul>', |
---|
261 | '</ul>', |
---|
262 | '<br>', |
---|
263 | ); |
---|
264 | |
---|
265 | return(preg_replace($patterns, $replacements, $text)); |
---|
266 | } |
---|
267 | |
---|
268 | } //class |
---|
269 | |
---|
270 | ?> |
---|