Changeset 2214:6d7d4c3f60d9 for inc/core/class.dc.repository.php
- Timestamp:
- 10/02/13 01:42:40 (12 years ago)
- Branch:
- dcRepo
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.repository.php
r2156 r2214 1 1 <?php 2 2 # -- BEGIN LICENSE BLOCK --------------------------------------- 3 # 4 # This file is part of Dotclear 2. 5 # 6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 7 # Licensed under the GPL version 2.0 license. 8 # See LICENSE file or 9 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 10 # 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return; } 13 14 /** 15 @ingroup DC_CORE 16 @brief Repository modules XML feed reader 17 18 Provides an object to parse XML feed of modules from repository. 19 */ 3 20 class dcRepository 4 21 { 22 /** @var object dcCore instance */ 5 23 public $core; 24 /** @var object dcModules instance */ 6 25 public $modules; 7 26 27 /** @var string User agent used to query repository */ 28 protected $user_agent = 'DotClear.org RepoBrowser/0.1'; 29 /** @var string XML feed URL */ 8 30 protected $xml_url; 31 /** @var array Array of new/update modules from repository */ 9 32 protected $data; 10 33 34 /** 35 * Constructor. 36 * 37 * @param object $modules dcModules instance 38 * @param string $xml_url XML feed URL 39 */ 11 40 public function __construct(dcModules $modules, $xml_url) 12 41 { … … 14 43 $this->modules = $modules; 15 44 $this->xml_url = $xml_url; 16 } 17 45 $this->user_agent = sprintf('Dotclear/%s)', DC_VERSION); 46 } 47 48 /** 49 * Check repository. 50 * 51 * @param boolean $force Force query repository 52 * @return boolean True if get feed or cache 53 */ 18 54 public function check($force=false) 19 55 { … … 58 94 } 59 95 96 /** 97 * Get a list of modules. 98 * 99 * @param boolean $update True to get update modules, false for new ones 100 * @return array List of update/new modules 101 */ 60 102 public function get($update=false) 61 103 { … … 63 105 } 64 106 107 /** 108 * Search a module. 109 * 110 * Search string is cleaned, split and compare to split: 111 * - module id and clean id, 112 * - module name, clean name, 113 * - module desccription. 114 * 115 * Every time a part of query is find on module, 116 * result accuracy grow. Result is sorted by acuracy. 117 * 118 * @param string $pattern String to search 119 * @return array Match modules 120 */ 65 121 public function search($pattern) 66 122 { … … 100 156 } 101 157 158 /** 159 * Quick download and install module. 160 * 161 * @param string $url Module package URL 162 * @param string $dest Path to install module 163 * @return integer 1 = installed, 2 = update 164 */ 102 165 public function process($url, $dest) 103 166 { … … 106 169 } 107 170 171 /** 172 * Download a module. 173 * 174 * @param string $url Module package URL 175 * @param string $dest Path to put module package 176 */ 108 177 public function download($url, $dest) 109 178 { … … 123 192 } 124 193 194 /** 195 * Install a previously downloaded module. 196 * 197 * @param string $path Module package URL 198 * @param string $path Path to module package 199 * @return integer 1 = installed, 2 = update 200 */ 125 201 public function install($path) 126 202 { … … 128 204 } 129 205 130 public static function agent() 131 { 132 return sprintf('Dotclear/%s)', DC_VERSION); 133 } 134 206 /** 207 * User Agent String. 208 * 209 * @param string $str User agent string 210 */ 211 public function agent($str) 212 { 213 $this->user_agent = $str; 214 } 215 216 /** 217 * Sanitize string. 218 * 219 * @param string $str String to sanitize 220 * @param null $_ Unused param 221 */ 135 222 public static function sanitize(&$str, $_) 136 223 { … … 138 225 } 139 226 140 private static function compare($v1,$v2,$op) 141 { 142 $v1 = preg_replace('!-r(\d+)$!','-p$1',$v1); 143 $v2 = preg_replace('!-r(\d+)$!','-p$1',$v2); 144 return version_compare($v1,$v2,$op); 145 } 146 227 /** 228 * Compare version. 229 * 230 * @param string $v1 Version 231 * @param string $v2 Version 232 * @param string $op Comparison operator 233 * @return boolean True is comparison is true, dude! 234 */ 235 private static function compare($v1, $v2, $op) 236 { 237 return version_compare( 238 preg_replace('!-r(\d+)$!', '-p$1', $v1), 239 preg_replace('!-r(\d+)$!', '-p$1', $v2), 240 $op 241 ); 242 } 243 244 /** 245 * Sort modules list. 246 * 247 * @param array $a A module 248 * @param array $b A module 249 * @return integer 250 */ 147 251 private static function sort($a,$b) 148 252 {
Note: See TracChangeset
for help on using the changeset viewer.