[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Updater\Adapter; 11 12 use Joomla\CMS\Application\ApplicationHelper; 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Filter\InputFilter; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Table\Table; 17 use Joomla\CMS\Updater\UpdateAdapter; 18 use Joomla\CMS\Updater\Updater; 19 use Joomla\CMS\Version; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('JPATH_PLATFORM') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * Extension class for updater 27 * 28 * @since 1.7.0 29 */ 30 class ExtensionAdapter extends UpdateAdapter 31 { 32 /** 33 * Start element parser callback. 34 * 35 * @param object $parser The parser object. 36 * @param string $name The name of the element. 37 * @param array $attrs The attributes of the element. 38 * 39 * @return void 40 * 41 * @since 1.7.0 42 */ 43 protected function _startElement($parser, $name, $attrs = array()) 44 { 45 $this->stack[] = $name; 46 $tag = $this->_getStackLocation(); 47 48 // Reset the data 49 if (isset($this->$tag)) { 50 $this->$tag->_data = ''; 51 } 52 53 switch ($name) { 54 case 'UPDATE': 55 $this->currentUpdate = Table::getInstance('update'); 56 $this->currentUpdate->update_site_id = $this->updateSiteId; 57 $this->currentUpdate->detailsurl = $this->_url; 58 $this->currentUpdate->folder = ''; 59 $this->currentUpdate->client_id = 1; 60 $this->currentUpdate->infourl = ''; 61 break; 62 63 // Don't do anything 64 case 'UPDATES': 65 break; 66 67 default: 68 if (\in_array($name, $this->updatecols)) { 69 $name = strtolower($name); 70 $this->currentUpdate->$name = ''; 71 } 72 73 if ($name === 'TARGETPLATFORM') { 74 $this->currentUpdate->targetplatform = $attrs; 75 } 76 77 if ($name === 'PHP_MINIMUM') { 78 $this->currentUpdate->php_minimum = ''; 79 } 80 81 if ($name === 'SUPPORTED_DATABASES') { 82 $this->currentUpdate->supported_databases = $attrs; 83 } 84 break; 85 } 86 } 87 88 /** 89 * Character Parser Function 90 * 91 * @param object $parser Parser object. 92 * @param object $name The name of the element. 93 * 94 * @return void 95 * 96 * @since 1.7.0 97 */ 98 protected function _endElement($parser, $name) 99 { 100 array_pop($this->stack); 101 102 switch ($name) { 103 case 'UPDATE': 104 // Lower case and remove the exclamation mark 105 $product = strtolower(InputFilter::getInstance()->clean(Version::PRODUCT, 'cmd')); 106 107 // Check that the product matches and that the version matches (optionally a regexp) 108 if ( 109 $product == $this->currentUpdate->targetplatform['NAME'] 110 && preg_match('/^' . $this->currentUpdate->targetplatform['VERSION'] . '/', JVERSION) 111 ) { 112 // Check if PHP version supported via <php_minimum> tag, assume true if tag isn't present 113 if (!isset($this->currentUpdate->php_minimum) || version_compare(PHP_VERSION, $this->currentUpdate->php_minimum, '>=')) { 114 $phpMatch = true; 115 } else { 116 // Notify the user of the potential update 117 $msg = Text::sprintf( 118 'JLIB_INSTALLER_AVAILABLE_UPDATE_PHP_VERSION', 119 $this->currentUpdate->name, 120 $this->currentUpdate->version, 121 $this->currentUpdate->php_minimum, 122 PHP_VERSION 123 ); 124 125 Factory::getApplication()->enqueueMessage($msg, 'warning'); 126 127 $phpMatch = false; 128 } 129 130 $dbMatch = false; 131 132 // Check if DB & version is supported via <supported_databases> tag, assume supported if tag isn't present 133 if (isset($this->currentUpdate->supported_databases)) { 134 $db = Factory::getDbo(); 135 $dbType = strtolower($db->getServerType()); 136 $dbVersion = $db->getVersion(); 137 $supportedDbs = $this->currentUpdate->supported_databases; 138 139 // MySQL and MariaDB use the same database driver but not the same version numbers 140 if ($dbType === 'mysql') { 141 // Check whether we have a MariaDB version string and extract the proper version from it 142 if (stripos($dbVersion, 'mariadb') !== false) { 143 // MariaDB: Strip off any leading '5.5.5-', if present 144 $dbVersion = preg_replace('/^5\.5\.5-/', '', $dbVersion); 145 $dbType = 'mariadb'; 146 } 147 } 148 149 // $supportedDbs has uppercase keys because they are XML attribute names 150 $dbTypeUcase = strtoupper($dbType); 151 152 // Do we have an entry for the database? 153 if (\array_key_exists($dbTypeUcase, $supportedDbs)) { 154 $minimumVersion = $supportedDbs[$dbTypeUcase]; 155 $dbMatch = version_compare($dbVersion, $minimumVersion, '>='); 156 157 if (!$dbMatch) { 158 // Notify the user of the potential update 159 $dbMsg = Text::sprintf( 160 'JLIB_INSTALLER_AVAILABLE_UPDATE_DB_MINIMUM', 161 $this->currentUpdate->name, 162 $this->currentUpdate->version, 163 Text::_('JLIB_DB_SERVER_TYPE_' . $dbTypeUcase), 164 $dbVersion, 165 $minimumVersion 166 ); 167 168 Factory::getApplication()->enqueueMessage($dbMsg, 'warning'); 169 } 170 } else { 171 // Notify the user of the potential update 172 $dbMsg = Text::sprintf( 173 'JLIB_INSTALLER_AVAILABLE_UPDATE_DB_TYPE', 174 $this->currentUpdate->name, 175 $this->currentUpdate->version, 176 Text::_('JLIB_DB_SERVER_TYPE_' . $dbTypeUcase) 177 ); 178 179 Factory::getApplication()->enqueueMessage($dbMsg, 'warning'); 180 } 181 } else { 182 // Set to true if the <supported_databases> tag is not set 183 $dbMatch = true; 184 } 185 186 // Check minimum stability 187 $stabilityMatch = true; 188 189 if (isset($this->currentUpdate->stability) && ($this->currentUpdate->stability < $this->minimum_stability)) { 190 $stabilityMatch = false; 191 } 192 193 // Some properties aren't valid fields in the update table so unset them to prevent J! from trying to store them 194 unset($this->currentUpdate->targetplatform); 195 196 if (isset($this->currentUpdate->php_minimum)) { 197 unset($this->currentUpdate->php_minimum); 198 } 199 200 if (isset($this->currentUpdate->supported_databases)) { 201 unset($this->currentUpdate->supported_databases); 202 } 203 204 if (isset($this->currentUpdate->stability)) { 205 unset($this->currentUpdate->stability); 206 } 207 208 // If the PHP version and minimum stability checks pass, consider this version as a possible update 209 if ($phpMatch && $stabilityMatch && $dbMatch) { 210 if (isset($this->latest)) { 211 // We already have a possible update. Check the version. 212 if (version_compare($this->currentUpdate->version, $this->latest->version, '>') == 1) { 213 $this->latest = $this->currentUpdate; 214 } 215 } else { 216 // We don't have any possible updates yet, assume this is an available update. 217 $this->latest = $this->currentUpdate; 218 } 219 } 220 } 221 break; 222 223 case 'UPDATES': 224 // :D 225 break; 226 } 227 } 228 229 /** 230 * Character Parser Function 231 * 232 * @param object $parser Parser object. 233 * @param object $data The data. 234 * 235 * @return void 236 * 237 * @note This is public because its called externally. 238 * @since 1.7.0 239 */ 240 protected function _characterData($parser, $data) 241 { 242 $tag = $this->_getLastTag(); 243 244 if (\in_array($tag, $this->updatecols)) { 245 $tag = strtolower($tag); 246 $this->currentUpdate->$tag .= $data; 247 } 248 249 if ($tag === 'PHP_MINIMUM') { 250 $this->currentUpdate->php_minimum = $data; 251 } 252 253 if ($tag === 'TAG') { 254 $this->currentUpdate->stability = $this->stabilityTagToInteger((string) $data); 255 } 256 } 257 258 /** 259 * Finds an update. 260 * 261 * @param array $options Update options. 262 * 263 * @return array|boolean Array containing the array of update sites and array of updates. False on failure 264 * 265 * @since 1.7.0 266 */ 267 public function findUpdate($options) 268 { 269 $response = $this->getUpdateSiteResponse($options); 270 271 if ($response === false) { 272 return false; 273 } 274 275 if (\array_key_exists('minimum_stability', $options)) { 276 $this->minimum_stability = $options['minimum_stability']; 277 } 278 279 $this->xmlParser = xml_parser_create(''); 280 xml_set_object($this->xmlParser, $this); 281 xml_set_element_handler($this->xmlParser, '_startElement', '_endElement'); 282 xml_set_character_data_handler($this->xmlParser, '_characterData'); 283 284 if (!xml_parse($this->xmlParser, $response->body)) { 285 // If the URL is missing the .xml extension, try appending it and retry loading the update 286 if (!$this->appendExtension && (substr($this->_url, -4) !== '.xml')) { 287 $options['append_extension'] = true; 288 289 return $this->findUpdate($options); 290 } 291 292 $app = Factory::getApplication(); 293 $app->getLogger()->warning("Error parsing url: {$this->_url}", array('category' => 'updater')); 294 $app->enqueueMessage(Text::sprintf('JLIB_UPDATER_ERROR_EXTENSION_PARSE_URL', $this->_url), 'warning'); 295 296 return false; 297 } 298 299 xml_parser_free($this->xmlParser); 300 301 if (isset($this->latest)) { 302 if (isset($this->latest->client) && \strlen($this->latest->client)) { 303 $this->latest->client_id = ApplicationHelper::getClientInfo($this->latest->client, true)->id; 304 305 unset($this->latest->client); 306 } 307 308 $updates = array($this->latest); 309 } else { 310 $updates = array(); 311 } 312 313 return array('update_sites' => array(), 'updates' => $updates); 314 } 315 316 /** 317 * Converts a tag to numeric stability representation. If the tag doesn't represent a known stability level (one of 318 * dev, alpha, beta, rc, stable) it is ignored. 319 * 320 * @param string $tag The tag string, e.g. dev, alpha, beta, rc, stable 321 * 322 * @return integer 323 * 324 * @since 3.4 325 */ 326 protected function stabilityTagToInteger($tag) 327 { 328 $constant = '\\Joomla\\CMS\\Updater\\Updater::STABILITY_' . strtoupper($tag); 329 330 if (\defined($constant)) { 331 return \constant($constant); 332 } 333 334 return Updater::STABILITY_STABLE; 335 } 336 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |