/libraries/joomla/updater/adapters/extension.php

https://github.com/cladjidane/D-mo-HTML5-CSS3 · PHP · 128 lines · 100 code · 12 blank · 16 comment · 20 complexity · 096e19b63de6d902687a7b4848647af2 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Updater
  5. *
  6. * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. jimport('joomla.updater.updateadapter');
  11. class JUpdaterExtension extends JUpdateAdapter
  12. {
  13. protected function _startElement($parser, $name, $attrs = Array()) {
  14. array_push($this->_stack, $name);
  15. $tag = $this->_getStackLocation();
  16. // reset the data
  17. eval('$this->'. $tag .'->_data = "";');
  18. switch($name) {
  19. case 'UPDATE':
  20. $this->current_update = JTable::getInstance('update');
  21. $this->current_update->update_site_id = $this->_update_site_id;
  22. $this->current_update->detailsurl = $this->_url;
  23. break;
  24. // Don't do anything
  25. case 'UPDATES':
  26. break;
  27. default:
  28. if(in_array($name, $this->_updatecols)) {
  29. $name = strtolower($name);
  30. $this->current_update->$name = '';
  31. }
  32. if($name == 'TARGETPLATFORM') {
  33. $this->current_update->targetplatform = $attrs;
  34. }
  35. break;
  36. }
  37. }
  38. protected function _endElement($parser, $name)
  39. {
  40. array_pop($this->_stack);
  41. //echo 'Closing: '. $name .'<br />';
  42. switch($name) {
  43. case 'UPDATE':
  44. $ver = new JVersion;
  45. $product = strtolower(JFilterInput::getInstance()->clean($ver->PRODUCT, 'cmd')); // lower case and remove the exclamation mark
  46. // Check that the product matches and that the version matches (optionally a regexp)
  47. if($product == $this->current_update->targetplatform['NAME'] && preg_match('/'.$this->current_update->targetplatform['VERSION'].'/',$ver->RELEASE)) {
  48. // Target platform isn't a valid field in the update table so unset it to prevent J! from trying to store it
  49. unset($this->current_update->targetplatform);
  50. if(isset($this->latest)) {
  51. if(version_compare($this->current_update->version, $this->latest->version, '>') == 1) {
  52. $this->latest = $this->current_update;
  53. }
  54. } else {
  55. $this->latest = $this->current_update;
  56. }
  57. }
  58. break;
  59. case 'UPDATES':
  60. // :D
  61. break;
  62. }
  63. }
  64. protected function _characterData($parser, $data)
  65. {
  66. $tag = $this->_getLastTag();
  67. //if(!isset($this->$tag->_data)) $this->$tag->_data = '';
  68. //$this->$tag->_data .= $data;
  69. if(in_array($tag, $this->_updatecols)) {
  70. $tag = strtolower($tag);
  71. $this->current_update->$tag .= $data;
  72. }
  73. }
  74. public function findUpdate($options)
  75. {
  76. $url = $options['location'];
  77. $this->_url =& $url;
  78. $this->_update_site_id = $options['update_site_id'];
  79. //echo '<p>Find update for extension run on <a href="'. $url .'">'. $url .'</a></p>';
  80. if(substr($url, -4) != '.xml') {
  81. if(substr($url, -1) != '/') {
  82. $url .= '/';
  83. }
  84. $url .= 'extension.xml';
  85. }
  86. $dbo = $this->parent->getDBO();
  87. if (!($fp = @fopen($url, "r"))) {
  88. $query = $dbo->getQuery(true);
  89. $query->update('#__update_sites');
  90. $query->set('enabled = 0');
  91. $query->where('update_site_id = '. $this->_update_site_id);
  92. $dbo->setQuery($query);
  93. $dbo->Query();
  94. JError::raiseWarning('101', JText::sprintf('JLIB_UPDATER_ERROR_EXTENSION_OPEN_URL', $url));
  95. return false;
  96. }
  97. $this->xml_parser = xml_parser_create('');
  98. xml_set_object($this->xml_parser, $this);
  99. xml_set_element_handler($this->xml_parser, '_startElement', '_endElement');
  100. xml_set_character_data_handler($this->xml_parser, '_characterData');
  101. while ($data = fread($fp, 8192)) {
  102. if (!xml_parse($this->xml_parser, $data, feof($fp))) {
  103. die(sprintf("XML error: %s at line %d",
  104. xml_error_string(xml_get_error_code($this->xml_parser)),
  105. xml_get_current_line_number($this->xml_parser)));
  106. }
  107. }
  108. xml_parser_free($this->xml_parser);
  109. if(isset($this->latest)) {
  110. $updates = Array($this->latest);
  111. } else {
  112. $updates = Array();
  113. }
  114. return Array('update_sites'=>Array(),'updates'=>$updates);
  115. }
  116. }