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