PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/updater/update.php

https://github.com/chalosalvador/GDS
PHP | 297 lines | 117 code | 28 blank | 152 comment | 14 complexity | 1fb9dbe8f40ac155b603bb8058360dec 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. /**
  11. * Update class.
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Updater
  15. * @since 11.1
  16. */
  17. class JUpdate extends JObject
  18. {
  19. /**
  20. * @var string
  21. * @since 11.1
  22. */
  23. protected $name;
  24. /**
  25. * @var string
  26. * @since 11.1
  27. */
  28. protected $description;
  29. /**
  30. * @var string
  31. * @since 11.1
  32. */
  33. protected $element;
  34. /**
  35. * @var string
  36. * @since 11.1
  37. */
  38. protected $type;
  39. /**
  40. * @var string
  41. * @since 11.1
  42. */
  43. protected $version;
  44. /**
  45. * @var string
  46. * @since 11.1
  47. */
  48. protected $infourl;
  49. /**
  50. * @var string
  51. * @since 11.1
  52. */
  53. protected $client;
  54. /**
  55. * @var string
  56. * @since 11.1
  57. */
  58. protected $group;
  59. /**
  60. * @var string
  61. * @since 11.1
  62. */
  63. protected $downloads;
  64. /**
  65. * @var string
  66. * @since 11.1
  67. */
  68. protected $tags;
  69. /**
  70. * @var string
  71. * @since 11.1
  72. */
  73. protected $maintainer;
  74. /**
  75. * @var string
  76. * @since 11.1
  77. */
  78. protected $maintainerurl;
  79. /**
  80. * @var string
  81. * @since 11.1
  82. */
  83. protected $category;
  84. /**
  85. * @var string
  86. * @since 11.1
  87. */
  88. protected $relationships;
  89. /**
  90. * @var string
  91. * @since 11.1
  92. */
  93. protected $targetplatform;
  94. /**
  95. * @var string
  96. * @since 11.1
  97. */
  98. protected $_xml_parser;
  99. /**
  100. * @var array
  101. * @since 11.1
  102. */
  103. protected $_stack = Array('base');
  104. /**
  105. * @var array
  106. * @since 11.1
  107. */
  108. protected $_state_store = Array();
  109. /**
  110. * Gets the reference to the current direct parent
  111. *
  112. * @return object
  113. *
  114. * @since 11.1
  115. */
  116. protected function _getStackLocation()
  117. {
  118. return implode('->', $this->_stack);
  119. }
  120. /**
  121. * Get the last position in stack count
  122. *
  123. * @return string
  124. *
  125. * @since 11.1
  126. */
  127. protected function _getLastTag()
  128. {
  129. return $this->_stack[count($this->_stack) - 1];
  130. }
  131. /**
  132. * XML Start Element callback
  133. *
  134. * @param object $parser Parser object
  135. * @param string $name Name of the tag found
  136. * @param array $attrs Attributes of the tag
  137. *
  138. * @return void
  139. *
  140. * @note This is public because it is called externally
  141. * @since 11.1
  142. */
  143. public function _startElement($parser, $name, $attrs = Array())
  144. {
  145. array_push($this->_stack, $name);
  146. $tag = $this->_getStackLocation();
  147. // Reset the data
  148. eval('$this->'. $tag .'->_data = "";');
  149. switch($name) {
  150. // This is a new update; create a current update
  151. case 'UPDATE':
  152. $this->_current_update = new stdClass;
  153. break;
  154. // Don't do anything
  155. case 'UPDATES':
  156. break;
  157. // For everything else there's...the default!
  158. default:
  159. $name = strtolower($name);
  160. $this->_current_update->$name->_data = '';
  161. foreach($attrs as $key=>$data) {
  162. $key = strtolower($key);
  163. $this->_current_update->$name->$key = $data;
  164. }
  165. break;
  166. }
  167. }
  168. /**
  169. * Callback for closing the element
  170. *
  171. * @param object $parser Parser object
  172. * @param string $name Name of element that was closed
  173. *
  174. * @return void
  175. *
  176. * @note This is public because it is called externally
  177. * @since 11.1
  178. */
  179. public function _endElement($parser, $name)
  180. {
  181. array_pop($this->_stack);
  182. switch($name)
  183. {
  184. // Closing update, find the latest version and check
  185. case 'UPDATE':
  186. $ver = new JVersion;
  187. $product = strtolower(JFilterInput::getInstance()->clean($ver->PRODUCT, 'cmd'));
  188. if($product == $this->_current_update->targetplatform->name && $ver->RELEASE == $this->_current_update->targetplatform->version)
  189. {
  190. if(isset($this->_latest))
  191. {
  192. if(version_compare($this->_current_update->version->_data, $this->_latest->version->_data, '>') == 1) {
  193. $this->_latest = $this->_current_update;
  194. }
  195. }
  196. else {
  197. $this->_latest = $this->_current_update;
  198. }
  199. }
  200. break;
  201. case 'UPDATES':
  202. // If the latest item is set then we transfer it to where we want to
  203. if(isset($this->_latest))
  204. {
  205. foreach(get_object_vars($this->_latest) as $key=>$val) {
  206. $this->$key = $val;
  207. }
  208. unset($this->_latest);
  209. unset($this->_current_update);
  210. }
  211. else if(isset($this->_current_update))
  212. {
  213. // The update might be for an older version of j!
  214. unset($this->_current_update);
  215. }
  216. break;
  217. }
  218. }
  219. /**
  220. * Character Parser Function
  221. *
  222. * @param object $data
  223. * @param object $parser Parser object
  224. *
  225. * @return void
  226. *
  227. * @note This is public because its called externally
  228. * @since 11.1
  229. */
  230. public function _characterData($parser, $data) {
  231. $tag = $this->_getLastTag();
  232. //if(!isset($this->$tag->_data)) $this->$tag->_data = '';
  233. //$this->$tag->_data .= $data;
  234. // Throw the data for this item together
  235. $tag = strtolower($tag);
  236. $this->_current_update->$tag->_data .= $data;
  237. }
  238. /**
  239. * @param string $url
  240. *
  241. * @return boolean True on success
  242. *
  243. * @since 11.1
  244. */
  245. public function loadFromXML($url)
  246. {
  247. if (!($fp = @fopen($url, "r")))
  248. {
  249. // TODO: Add a 'mark bad' setting here somehow
  250. JError::raiseWarning('101', JText::sprintf('JLIB_UPDATER_ERROR_EXTENSION_OPEN_URL', $url));
  251. return false;
  252. }
  253. $this->xml_parser = xml_parser_create('');
  254. xml_set_object($this->xml_parser, $this);
  255. xml_set_element_handler($this->xml_parser, '_startElement', '_endElement');
  256. xml_set_character_data_handler($this->xml_parser, '_characterData');
  257. while ($data = fread($fp, 8192))
  258. {
  259. if (!xml_parse($this->xml_parser, $data, feof($fp)))
  260. {
  261. die(sprintf("XML error: %s at line %d",
  262. xml_error_string(xml_get_error_code($this->xml_parser)),
  263. xml_get_current_line_number($this->xml_parser)));
  264. }
  265. }
  266. xml_parser_free($this->xml_parser);
  267. return true;
  268. }
  269. }