[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/updater/adapters/ -> collection.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  /**
  15   * Collection Update Adapter Class
  16   *
  17   * @package     Joomla.Platform
  18   * @subpackage  Updater
  19   * @since       11.1
  20   * */
  21  
  22  class JUpdaterCollection extends JUpdateAdapter
  23  {
  24      /**
  25       * Root of the tree
  26       *
  27       * @var    object
  28       * @since  11.1
  29       */
  30      protected $base;
  31  
  32      /**
  33       * Tree of objects
  34       *
  35       * @var    array
  36       * @since  11.1
  37       */
  38      protected $parent = array(0);
  39  
  40      /**
  41       * Used to control if an item has a child or not
  42       *
  43       * @var    boolean
  44       * @since  11.1
  45       */
  46      protected $pop_parent = 0;
  47  
  48      /**
  49       * @var array A list of discovered update sites
  50       */
  51      protected $update_sites;
  52  
  53      /**
  54       * A list of discovered updates
  55       *
  56       * @var array
  57       */
  58      protected $updates;
  59  
  60      /**
  61       * Gets the reference to the current direct parent
  62       *
  63       * @return  object
  64       *
  65       * @since   11.1
  66       */
  67  	protected function _getStackLocation()
  68      {
  69  
  70          return implode('->', $this->_stack);
  71      }
  72  
  73      /**
  74       * Get the parent tag
  75       *
  76       * @return  string   parent
  77       *
  78       * @since   11.1
  79       */
  80  	protected function _getParent()
  81      {
  82          return end($this->parent);
  83      }
  84  
  85      /**
  86       * Opening an XML element
  87       *
  88       * @param   object  $parser  Parser object
  89       * @param   string  $name    Name of element that is opened
  90       * @param   array   $attrs   Array of attributes for the element
  91       *
  92       * @return  void
  93       *
  94       * @since   11.1
  95       */
  96  	public function _startElement($parser, $name, $attrs = array())
  97      {
  98          array_push($this->_stack, $name);
  99          $tag = $this->_getStackLocation();
 100          // Reset the data
 101          eval('$this->' . $tag . '->_data = "";');
 102          switch ($name)
 103          {
 104              case 'CATEGORY':
 105                  if (isset($attrs['REF']))
 106                  {
 107                      $this->update_sites[] = array('type' => 'collection', 'location' => $attrs['REF'], 'update_site_id' => $this->_update_site_id);
 108                  }
 109                  else
 110                  {
 111                      // This item will have children, so prepare to attach them
 112                      $this->pop_parent = 1;
 113                  }
 114                  break;
 115              case 'EXTENSION':
 116                  $update = JTable::getInstance('update');
 117                  $update->set('update_site_id', $this->_update_site_id);
 118                  foreach ($this->_updatecols as $col)
 119                  {
 120                      // Reset the values if it doesn't exist
 121                      if (!array_key_exists($col, $attrs))
 122                      {
 123                          $attrs[$col] = '';
 124                          if ($col == 'CLIENT')
 125                          {
 126                              $attrs[$col] = 'site';
 127                          }
 128                      }
 129                  }
 130                  $client = JApplicationHelper::getClientInfo($attrs['CLIENT'], 1);
 131                  $attrs['CLIENT_ID'] = $client->id;
 132                  // Lower case all of the fields
 133                  foreach ($attrs as $key => $attr)
 134                  {
 135                      $values[strtolower($key)] = $attr;
 136                  }
 137  
 138                  // Only add the update if it is on the same platform and release as we are
 139                  $ver = new JVersion;
 140                  $product = strtolower(JFilterInput::getInstance()->clean($ver->PRODUCT, 'cmd')); // lower case and remove the exclamation mark
 141                  // Set defaults, the extension file should clarify in case but it may be only available in one version
 142                  // This allows an update site to specify a targetplatform
 143                  // targetplatformversion can be a regexp, so 1.[56] would be valid for an extension that supports 1.5 and 1.6
 144                  // Note: Whilst the version is a regexp here, the targetplatform is not (new extension per platform)
 145                  //        Additionally, the version is a regexp here and it may also be in an extension file if the extension is
 146                  //        compatible against multiple versions of the same platform (e.g. a library)
 147                  if (!isset($values['targetplatform']))
 148                  {
 149                      $values['targetplatform'] = $product;
 150                  }
 151                  // set this to ourself as a default
 152                  if (!isset($values['targetplatformversion']))
 153                  {
 154                      $values['targetplatformversion'] = $ver->RELEASE;
 155                  }
 156                  // set this to ourself as a default
 157                  // validate that we can install the extension
 158                  if ($product == $values['targetplatform'] && preg_match('/' . $values['targetplatformversion'] . '/', $ver->RELEASE))
 159                  {
 160                      $update->bind($values);
 161                      $this->updates[] = $update;
 162                  }
 163                  break;
 164          }
 165      }
 166  
 167      /**
 168       * Closing an XML element
 169       * Note: This is a protected function though has to be exposed externally as a callback
 170       *
 171       * @param   object  $parser  Parser object
 172       * @param   string  $name    Name of the element closing
 173       *
 174       * @return  void
 175       *
 176       * @since   11.1
 177       */
 178  	protected function _endElement($parser, $name)
 179      {
 180          $lastcell = array_pop($this->_stack);
 181          switch ($name)
 182          {
 183              case 'CATEGORY':
 184                  if ($this->pop_parent)
 185                  {
 186                      $this->pop_parent = 0;
 187                      array_pop($this->parent);
 188                  }
 189                  break;
 190          }
 191      }
 192  
 193      // Note: we don't care about char data in collection because there should be none
 194  
 195      /**
 196       * Finds an update
 197       *
 198       * @param   array  $options  Options to use: update_site_id: the unique ID of the update site to look at
 199       *
 200       * @return  array  Update_sites and updates discovered
 201       *
 202       * @since   11.1
 203       */
 204  	public function findUpdate($options)
 205      {
 206          $url = $options['location'];
 207          $this->_update_site_id = $options['update_site_id'];
 208          if (substr($url, -4) != '.xml')
 209          {
 210              if (substr($url, -1) != '/')
 211              {
 212                  $url .= '/';
 213              }
 214              $url .= 'update.xml';
 215          }
 216  
 217          $this->base = new stdClass;
 218          $this->update_sites = array();
 219          $this->updates = array();
 220          $dbo = $this->parent->getDBO();
 221  
 222          if (!($fp = @fopen($url, "r")))
 223          {
 224              $query = $dbo->getQuery(true);
 225              $query->update('#__update_sites');
 226              $query->set('enabled = 0');
 227              $query->where('update_site_id = ' . $this->_update_site_id);
 228              $dbo->setQuery($query);
 229              $dbo->Query();
 230  
 231              JLog::add("Error parsing url: " . $url, JLog::WARNING, 'updater');
 232              $app = JFactory::getApplication();
 233              $app->enqueueMessage(JText::sprintf('JLIB_UPDATER_ERROR_COLLECTION_OPEN_URL', $url), 'warning');
 234              return false;
 235          }
 236  
 237          $this->xml_parser = xml_parser_create('');
 238          xml_set_object($this->xml_parser, $this);
 239          xml_set_element_handler($this->xml_parser, '_startElement', '_endElement');
 240  
 241          while ($data = fread($fp, 8192))
 242          {
 243              if (!xml_parse($this->xml_parser, $data, feof($fp)))
 244              {
 245                  JLog::add("Error parsing url: " . $url, JLog::WARNING, 'updater');
 246                  $app = JFactory::getApplication();
 247                  $app->enqueueMessage(JText::sprintf('JLIB_UPDATER_ERROR_COLLECTION_PARSE_URL', $url), 'warning');
 248                  return false;
 249              }
 250          }
 251          // TODO: Decrement the bad counter if non-zero
 252          return array('update_sites' => $this->update_sites, 'updates' => $this->updates);
 253      }
 254  }


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