PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/updater/update.php

https://github.com/rietn/minima
PHP | 180 lines | 117 code | 12 blank | 51 comment | 14 complexity | cbff25ad300fbf0636227f083bf7f9e6 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: update.php 20196 2011-01-09 02:40:25Z ian $
  4. * @package Joomla.Framework
  5. * @subpackage Update
  6. * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License, see LICENSE.php
  8. */
  9. // No direct access
  10. defined('JPATH_BASE') or die();
  11. /**
  12. * Update class.
  13. *
  14. * @package Joomla.Framework
  15. * @subpackage Update
  16. * @since 1.6
  17. */
  18. class JUpdate extends JObject
  19. {
  20. protected $name;
  21. protected $description;
  22. protected $element;
  23. protected $type;
  24. protected $version;
  25. protected $infourl;
  26. protected $client;
  27. protected $group;
  28. protected $downloads;
  29. protected $tags;
  30. protected $maintainer;
  31. protected $maintainerurl;
  32. protected $category;
  33. protected $relationships;
  34. protected $targetplatform;
  35. private $_xml_parser;
  36. private $_stack = Array('base');
  37. private $_state_store = Array();
  38. /**
  39. * Gets the reference to the current direct parent
  40. *
  41. * @return object
  42. */
  43. protected function _getStackLocation()
  44. {
  45. return implode('->', $this->_stack);
  46. }
  47. /**
  48. * Get the last position in stack count
  49. *
  50. * @return string
  51. */
  52. protected function _getLastTag()
  53. {
  54. return $this->_stack[count($this->_stack) - 1];
  55. }
  56. /**
  57. * XML Start Element callback
  58. * Note: This is public because it is called externally
  59. * @param object parser object
  60. * @param string name of the tag found
  61. * @param array attributes of the tag
  62. */
  63. public function _startElement($parser, $name, $attrs = Array())
  64. {
  65. array_push($this->_stack, $name);
  66. $tag = $this->_getStackLocation();
  67. // reset the data
  68. eval('$this->'. $tag .'->_data = "";');
  69. //echo 'Opened: '; print_r($this->_stack); echo '<br />';
  70. //print_r($attrs); echo '<br />';
  71. switch($name) {
  72. case 'UPDATE': // This is a new update; create a current update
  73. $this->_current_update = new stdClass();
  74. break;
  75. case 'UPDATES': // don't do anything
  76. break;
  77. default: // for everything else there's...the default!
  78. $name = strtolower($name);
  79. $this->_current_update->$name->_data = '';
  80. foreach($attrs as $key=>$data) {
  81. $key = strtolower($key);
  82. $this->_current_update->$name->$key = $data;
  83. }
  84. break;
  85. }
  86. }
  87. /**
  88. * Callback for closing the element
  89. * Note: This is public because it is called externally
  90. * @param object parser object
  91. * @param string name of element that was closed
  92. */
  93. public function _endElement($parser, $name)
  94. {
  95. array_pop($this->_stack);
  96. switch($name)
  97. {
  98. case 'UPDATE': // closing update, find the latest version and check
  99. $ver = new JVersion();
  100. $product = strtolower(JFilterInput::getInstance()->clean($ver->PRODUCT, 'cmd'));
  101. if($product == $this->_current_update->targetplatform->name && $ver->RELEASE == $this->_current_update->targetplatform->version)
  102. {
  103. if(isset($this->_latest))
  104. {
  105. if(version_compare($this->_current_update->version->_data, $this->_latest->version->_data, '>') == 1) {
  106. $this->_latest = $this->_current_update;
  107. }
  108. }
  109. else {
  110. $this->_latest = $this->_current_update;
  111. }
  112. }
  113. break;
  114. case 'UPDATES':
  115. // If the latest item is set then we transfer it to where we want to
  116. if(isset($this->_latest))
  117. {
  118. foreach(get_object_vars($this->_latest) as $key=>$val) {
  119. $this->$key = $val;
  120. }
  121. unset($this->_latest);
  122. unset($this->_current_update);
  123. }
  124. else if(isset($this->_current_update))
  125. {
  126. // the update might be for an older version of j!
  127. unset($this->_current_update);
  128. }
  129. break;
  130. }
  131. }
  132. /**
  133. * Character Parser Function
  134. * Note: This is public because its called externally
  135. */
  136. public function _characterData($parser, $data) {
  137. $tag = $this->_getLastTag();
  138. //if(!isset($this->$tag->_data)) $this->$tag->_data = '';
  139. //$this->$tag->_data .= $data;
  140. // Throw the data for this item together
  141. $tag = strtolower($tag);
  142. $this->_current_update->$tag->_data .= $data;
  143. }
  144. public function loadFromXML($url)
  145. {
  146. if (!($fp = @fopen($url, "r")))
  147. {
  148. // TODO: Add a 'mark bad' setting here somehow
  149. JError::raiseWarning('101', JText::sprintf('JLIB_UPDATER_ERROR_EXTENSION_OPEN_URL', $url));
  150. return false;
  151. }
  152. $this->xml_parser = xml_parser_create('');
  153. xml_set_object($this->xml_parser, $this);
  154. xml_set_element_handler($this->xml_parser, '_startElement', '_endElement');
  155. xml_set_character_data_handler($this->xml_parser, '_characterData');
  156. while ($data = fread($fp, 8192))
  157. {
  158. if (!xml_parse($this->xml_parser, $data, feof($fp)))
  159. {
  160. die(sprintf("XML error: %s at line %d",
  161. xml_error_string(xml_get_error_code($this->xml_parser)),
  162. xml_get_current_line_number($this->xml_parser)));
  163. }
  164. }
  165. xml_parser_free($this->xml_parser);
  166. return true;
  167. }
  168. }