Source for file collection.php

Documentation is available at collection.php

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

Documentation generated on Tue, 19 Nov 2013 14:56:04 +0100 by phpDocumentor 1.4.3