[ Index ] |
|
Code source de Plume CMS 1.2.2 |
1 <?php 2 /* 3 # ***** BEGIN LICENSE BLOCK ***** 4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1 5 # 6 # The contents of this file are subject to the Mozilla Public License Version 7 # 1.1 (the "License"); you may not use this file except in compliance with 8 # the License. You may obtain a copy of the License at 9 # http://www.mozilla.org/MPL/ 10 # 11 # Software distributed under the License is distributed on an "AS IS" basis, 12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 # for the specific language governing rights and limitations under the 14 # License. 15 # 16 # The Original Code is DotClear Weblog. 17 # 18 # The Initial Developer of the Original Code is 19 # Olivier Meunier. 20 # Portions created by the Initial Developer are Copyright (C) 2003 21 # the Initial Developer. All Rights Reserved. 22 # 23 # Contributor(s): 24 # Extended by loic d'Anterroches 25 # 26 # Alternatively, the contents of this file may be used under the terms of 27 # either the GNU General Public License Version 2 or later (the "GPL"), or 28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 29 # in which case the provisions of the GPL or the LGPL are applicable instead 30 # of those above. If you wish to allow use of your version of this file only 31 # under the terms of either the GPL or the LGPL, and not to allow others to 32 # use your version of this file under the terms of the MPL, indicate your 33 # decision by deleting the provisions above and replace them with the notice 34 # and other provisions required by the GPL or the LGPL. If you do not delete 35 # the provisions above, a recipient may use your version of this file under 36 # the terms of any one of the MPL, the GPL or the LGPL. 37 # 38 # ***** END LICENSE BLOCK ***** */ 39 40 /* 41 Classe de gestion des plugins et des thèmes 42 */ 43 44 class plugins extends CError 45 { 46 var $name = ''; 47 var $list = array(); //simple list of plugins, used to do a batch load 48 //of the lang files. 49 50 function plugins($location) 51 { 52 53 if (is_dir($location)) { 54 $this->location = $location.'/'; 55 } else { 56 $this->location = NULL; 57 } 58 } 59 60 /* 61 Obtenir les plugins et les infos de ces plugins 62 */ 63 function getPlugins($root='plugin',$active_only=true) 64 { 65 include_once dirname(__FILE__).'/../inc/class.l10n.php'; 66 $l = new l10n(config::f('locale_lang')); 67 $res = $tmp = array(); 68 69 if (($list_files = $this->_readDir()) !== false) 70 { 71 foreach ($this->list as $pl) { 72 $l->loadPlugin(config::f('locale_lang'), $pl); 73 } 74 foreach ($list_files as $entry => $pfile) 75 { 76 $desc = implode('',file($pfile)); 77 78 if (preg_match('/<'.$root.'(.*)>(.*)<\/'.$root.'>/msU',$desc,$matches)) 79 { 80 $this->_xmlParser($matches[1],$matches[2],$tmp[$entry],$active_only); 81 } 82 } 83 84 /* On supprime les éléments NULL */ 85 foreach ($tmp as $k => $v) { 86 if (is_array($v)) { 87 $res[$k] = $v; 88 } 89 } 90 ksort($res); 91 return $res; 92 } 93 else 94 { 95 return false; 96 } 97 } 98 99 /* Installation d'un plugin */ 100 function install($url) 101 { 102 $dest = $this->location.'/'.basename($url); 103 $this->name = basename($url,'.ext.gz'); 104 105 if (($err = $this->_copyRemote($url,$dest)) !== true) 106 { 107 return $err; 108 } 109 else 110 { 111 if (!function_exists('gzfile')) { 112 return __('The automatic install is not available on your system, do the manual install.'); 113 } 114 if (($content = @implode('',@gzfile($dest))) === false) { 115 return __('Impossible to open the file'); 116 } else { 117 if (($list = unserialize($content)) === false) 118 { 119 return __('Invalid plugin'); 120 } 121 else 122 { 123 if (is_dir($this->location.'/'.$list['name'])) 124 { 125 if ($this->_deldir($this->location.'/'.$list['name']) === false) 126 { 127 return __('Impossible de delete the existing plugin'); 128 } 129 } 130 131 foreach ($list['dirs'] as $d) 132 { 133 $d = str_replace('..','',$d); 134 mkdir ($this->location.'/'.$d); 135 @chmod($this->location.'/'.$d,0777); 136 } 137 138 foreach ($list['files'] as $f => $v) 139 { 140 $f = str_replace('..','',$f); 141 $v = base64_decode($v); 142 if (preg_match('/[A-Za-Z]{2}\_[A-Za-Z]{2}/',$f)) { 143 if (!file_exists(dirname(__FILE__).'/../locale/'.$f)) { 144 mkdir (dirname(__FILE__).'/../locale/'.$f); 145 @chmod(dirname(__FILE__).'/../locale/'.$f,0777); 146 } 147 $fp = fopen(dirname(__FILE__).'/../locale/'.$f.'/'.$this->name.'.php','w'); 148 fwrite($fp,$v,strlen($v)); 149 fclose($fp); 150 } else { 151 $fp = fopen($this->location.'/'.$f,'w'); 152 fwrite($fp,$v,strlen($v)); 153 fclose($fp); 154 } 155 } 156 157 unlink ($dest); 158 } 159 } 160 } 161 return true; 162 } 163 164 /* Lecture d'un répertoire à la recherche des desc.xml */ 165 function _readDir() 166 { 167 if ($this->location === NULL) { 168 return false; 169 } 170 171 $res = array(); 172 173 $d = dir($this->location); 174 175 # Liste du répertoire des plugins 176 while (($entry = $d->read()) !== false) 177 { 178 if ($entry != '.' && $entry != '..' && 179 is_dir($this->location.$entry) && file_exists($this->location.$entry.'/desc.xml')) 180 { 181 $res[$entry] = $this->location.$entry.'/desc.xml'; 182 $this->list[] = $entry; 183 } 184 } 185 186 return $res; 187 } 188 189 /* Analyse des information plugin/theme */ 190 function _xmlParser($attr,$content,&$res,$active_only=true) 191 { 192 # Vérification du nom 193 if (preg_match('/name="(.+)"/msU',$attr,$name)) 194 { 195 # Actif 196 if (preg_match('/active="(true|yes|1)"/msU',$attr)) { 197 $active = true; 198 } else { 199 $active = false; 200 } 201 202 if (!$active && $active_only) { 203 return true; 204 } 205 206 $res['active'] = $active; 207 208 # Nom 209 $res['name'] = __(trim($name[1])); 210 211 # Root only 212 if (preg_match('/rootonly="(true|yes|1)"/msUi',$attr,$rootonly)) { 213 $res['rootonly'] = true; 214 } else { 215 $res['rootonly'] = false; 216 } 217 218 # Version 219 if (preg_match('/version="(.*)"/msU',$attr,$version)) { 220 $res['version'] = trim($version[1]); 221 } 222 223 # Auteur 224 if (preg_match('/<author>(.+)<\/author>/msU',$content,$author)) { 225 $res['author'] = trim($author[1]); 226 } 227 228 # Label 229 if (preg_match('/<label>(.+)<\/label>/msU',$content,$label)) { 230 $res['label'] = __(trim($label[1])); 231 } 232 233 # Description 234 if (preg_match('/<desc>(.+)<\/desc>/msU',$content,$description)) { 235 $res['desc'] = __(trim($description[1])); 236 } 237 238 } 239 } 240 241 # Copier d'un fichier binaire distant 242 function _copyRemote($src,$dest) 243 { 244 if (($fp1 = @fopen($src,'r')) === false) 245 { 246 return __('An error occured during the download of the file.'); 247 } 248 else 249 { 250 if (($fp2 = @fopen($dest,'w')) === false) 251 { 252 fclose($fp1); 253 return __('An error occured when writing the file.'); 254 } 255 else 256 { 257 while (($buffer = fgetc($fp1)) !== false) { 258 fwrite($fp2,$buffer); 259 } 260 fclose($fp1); 261 fclose($fp2); 262 return true; 263 } 264 } 265 } 266 267 function _deldir($dir) 268 { 269 $current_dir = opendir($dir); 270 while($entryname = readdir($current_dir)) 271 { 272 if(is_dir($dir.'/'.$entryname) and ($entryname != '.' and $entryname!='..')) 273 { 274 $this->_deldir($dir.'/'.$entryname); 275 } 276 elseif($entryname != '.' and $entryname!='..') 277 { 278 if (@unlink($dir.'/'.$entryname) === false) { 279 return false; 280 } 281 } 282 } 283 closedir($current_dir); 284 if (@rmdir($dir) === false) { 285 return false; 286 } 287 } 288 } 289 290 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 11:57:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |