[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/updater/adapters/ -> extension.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Platform
   4   * @subpackage  Updater
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  defined('JPATH_PLATFORM') or die;
  11  
  12  jimport('joomla.updater.updateadapter');
  13  /**
  14   * Extension class for updater
  15   *
  16   * @package     Joomla.Platform
  17   * @subpackage  Updater
  18   * @since       11.1
  19   * */
  20  class JUpdaterExtension extends JUpdateAdapter
  21  {
  22      /**
  23       * Start element parser callback.
  24       *
  25       * @param   object  $parser  The parser object.
  26       * @param   string  $name    The name of the element.
  27       * @param   array   $attrs   The attributes of the element.
  28       *
  29       * @return  void
  30       *
  31       * @since   11.1
  32       */
  33  	protected function _startElement($parser, $name, $attrs = array())
  34      {
  35          array_push($this->_stack, $name);
  36          $tag = $this->_getStackLocation();
  37          // reset the data
  38          eval('$this->' . $tag . '->_data = "";');
  39  
  40          switch ($name)
  41          {
  42              case 'UPDATE':
  43                  $this->current_update = JTable::getInstance('update');
  44                  $this->current_update->update_site_id = $this->_update_site_id;
  45                  $this->current_update->detailsurl = $this->_url;
  46                  $this->current_update->folder = "";
  47                  $this->current_update->client_id = 1;
  48                  break;
  49              // Don't do anything
  50              case 'UPDATES':
  51                  break;
  52              default:
  53                  if (in_array($name, $this->_updatecols))
  54                  {
  55                      $name = strtolower($name);
  56                      $this->current_update->$name = '';
  57                  }
  58                  if ($name == 'TARGETPLATFORM')
  59                  {
  60                      $this->current_update->targetplatform = $attrs;
  61                  }
  62                  break;
  63          }
  64      }
  65  
  66      /**
  67       * Character Parser Function
  68       *
  69       * @param   object  $parser  Parser object.
  70       * @param   object  $name    The name of the element.
  71       *
  72       * @return  void
  73       *
  74       * @since   11.1
  75       */
  76  	protected function _endElement($parser, $name)
  77      {
  78          array_pop($this->_stack);
  79          //echo 'Closing: '. $name .'<br />';
  80          switch ($name)
  81          {
  82              case 'UPDATE':
  83                  $ver = new JVersion;
  84                  $product = strtolower(JFilterInput::getInstance()->clean($ver->PRODUCT, 'cmd')); // lower case and remove the exclamation mark
  85                  // Check that the product matches and that the version matches (optionally a regexp)
  86                  if ($product == $this->current_update->targetplatform['NAME']
  87                      && preg_match('/' . $this->current_update->targetplatform['VERSION'] . '/', $ver->RELEASE))
  88                  {
  89                      // Target platform isn't a valid field in the update table so unset it to prevent J! from trying to store it
  90                      unset($this->current_update->targetplatform);
  91                      if (isset($this->latest))
  92                      {
  93                          if (version_compare($this->current_update->version, $this->latest->version, '>') == 1)
  94                          {
  95                              $this->latest = $this->current_update;
  96                          }
  97                      }
  98                      else
  99                      {
 100                          $this->latest = $this->current_update;
 101                      }
 102                  }
 103                  break;
 104              case 'UPDATES':
 105                  // :D
 106                  break;
 107          }
 108      }
 109  
 110      /**
 111       * Character Parser Function
 112       *
 113       * @param   object  $parser  Parser object.
 114       * @param   object  $data    The data.
 115       *
 116       * @return  void
 117       *
 118       * @note    This is public because its called externally.
 119       * @since   11.1
 120       */
 121  	protected function _characterData($parser, $data)
 122      {
 123          $tag = $this->_getLastTag();
 124          //if(!isset($this->$tag->_data)) $this->$tag->_data = '';
 125          //$this->$tag->_data .= $data;
 126          if (in_array($tag, $this->_updatecols))
 127          {
 128              $tag = strtolower($tag);
 129              $this->current_update->$tag .= $data;
 130          }
 131      }
 132  
 133      /**
 134       * Finds an update.
 135       *
 136       * @param   array  $options  Update options.
 137       *
 138       * @return  array  Array containing the array of update sites and array of updates
 139       *
 140       * @since   11.1
 141       */
 142  	public function findUpdate($options)
 143      {
 144          $url = $options['location'];
 145          $this->_url = &$url;
 146          $this->_update_site_id = $options['update_site_id'];
 147          if (substr($url, -4) != '.xml')
 148          {
 149              if (substr($url, -1) != '/')
 150              {
 151                  $url .= '/';
 152              }
 153              $url .= 'extension.xml';
 154          }
 155  
 156          $dbo = $this->parent->getDBO();
 157  
 158          if (!($fp = @fopen($url, "r")))
 159          {
 160              $query = $dbo->getQuery(true);
 161              $query->update('#__update_sites');
 162              $query->set('enabled = 0');
 163              $query->where('update_site_id = ' . $this->_update_site_id);
 164              $dbo->setQuery($query);
 165              $dbo->Query();
 166  
 167              JLog::add("Error opening url: " . $url, JLog::WARNING, 'updater');
 168              $app = JFactory::getApplication();
 169              $app->enqueueMessage(JText::sprintf('JLIB_UPDATER_ERROR_EXTENSION_OPEN_URL', $url), 'warning');
 170              return false;
 171          }
 172  
 173          $this->xml_parser = xml_parser_create('');
 174          xml_set_object($this->xml_parser, $this);
 175          xml_set_element_handler($this->xml_parser, '_startElement', '_endElement');
 176          xml_set_character_data_handler($this->xml_parser, '_characterData');
 177  
 178          while ($data = fread($fp, 8192))
 179          {
 180              if (!xml_parse($this->xml_parser, $data, feof($fp)))
 181              {
 182                  JLog::add("Error parsing url: " . $url, JLog::WARNING, 'updater');
 183                  $app = JFactory::getApplication();
 184                  $app->enqueueMessage(JText::sprintf('JLIB_UPDATER_ERROR_EXTENSION_PARSE_URL', $url), 'warning');
 185                  return false;
 186              }
 187          }
 188          xml_parser_free($this->xml_parser);
 189          if (isset($this->latest))
 190          {
 191              if (isset($this->latest->client) && strlen($this->latest->client))
 192              {
 193                  $this->latest->client_id = JApplicationHelper::getClientInfo($this->latest->client, 1)->id;
 194                  unset($this->latest->client);
 195              }
 196              $updates = array($this->latest);
 197          }
 198          else
 199          {
 200              $updates = array();
 201          }
 202          return array('update_sites' => array(), 'updates' => $updates);
 203      }
 204  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1