Source for file extension.php

Documentation is available at extension.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.  * Extension class for updater
  16.  *
  17.  * @package     Joomla.Platform
  18.  * @subpackage  Updater
  19.  * @since       11.1
  20.  *  */
  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.  
  38.         // Reset the data
  39.         if (isset($this->$tag))
  40.         {
  41.             $this->$tag->_data "";
  42.         }
  43.  
  44.         switch ($name)
  45.         {
  46.             case 'UPDATE':
  47.                 $this->currentUpdate JTable::getInstance('update');
  48.                 $this->currentUpdate->update_site_id $this->updateSiteId;
  49.                 $this->currentUpdate->detailsurl $this->_url;
  50.                 $this->currentUpdate->folder "";
  51.                 $this->currentUpdate->client_id 1;
  52.                 break;
  53.  
  54.             // Don't do anything
  55.             case 'UPDATES':
  56.                 break;
  57.             default:
  58.                 if (in_array($name$this->updatecols))
  59.                 {
  60.                     $name strtolower($name);
  61.                     $this->currentUpdate->$name '';
  62.                 }
  63.                 if ($name == 'TARGETPLATFORM')
  64.                 {
  65.                     $this->currentUpdate->targetplatform $attrs;
  66.                 }
  67.                 break;
  68.         }
  69.     }
  70.  
  71.     /**
  72.      * Character Parser Function
  73.      *
  74.      * @param   object  $parser  Parser object.
  75.      * @param   object  $name    The name of the element.
  76.      *
  77.      * @return  void 
  78.      *
  79.      * @since   11.1
  80.      */
  81.     protected function _endElement($parser$name)
  82.     {
  83.         array_pop($this->stack);
  84.  
  85.         // @todo remove code: echo 'Closing: '. $name .'<br />';
  86.         switch ($name)
  87.         {
  88.             case 'UPDATE':
  89.                 $ver new JVersion;
  90.  
  91.                 // Lower case and remove the exclamation mark
  92.                 $product strtolower(JFilterInput::getInstance()->clean($ver->PRODUCT'cmd'));
  93.  
  94.                 // Check that the product matches and that the version matches (optionally a regexp)
  95.                 // Check for optional min_dev_level and max_dev_level attributes to further specify targetplatform (e.g., 3.0.1)
  96.                 if ($product == $this->currentUpdate->targetplatform['NAME']
  97.                     && preg_match('/' $this->currentUpdate->targetplatform['VERSION''/'$ver->RELEASE)
  98.                     && ((!isset($this->currentUpdate->targetplatform->min_dev_level)) || $ver->DEV_LEVEL >= $this->currentUpdate->targetplatform->min_dev_level)
  99.                     && ((!isset($this->currentUpdate->targetplatform->max_dev_level)) || $ver->DEV_LEVEL <= $this->currentUpdate->targetplatform->max_dev_level))
  100.                 {
  101.                     // Target platform isn't a valid field in the update table so unset it to prevent J! from trying to store it
  102.                     unset($this->currentUpdate ->targetplatform);
  103.                     if (isset($this->latest))
  104.                     {
  105.                         if (version_compare($this->currentUpdate ->version$this->latest->version'>'== 1)
  106.                         {
  107.                             $this->latest $this->currentUpdate;
  108.                         }
  109.                     }
  110.                     else
  111.                     {
  112.                         $this->latest $this->currentUpdate;
  113.                     }
  114.                 }
  115.                 break;
  116.             case 'UPDATES':
  117.                 // :D
  118.                 break;
  119.         }
  120.     }
  121.  
  122.     /**
  123.      * Character Parser Function
  124.      *
  125.      * @param   object  $parser  Parser object.
  126.      * @param   object  $data    The data.
  127.      *
  128.      * @return  void 
  129.      *
  130.      * @note    This is public because its called externally.
  131.      * @since   11.1
  132.      */
  133.     protected function _characterData($parser$data)
  134.     {
  135.         $tag $this->_getLastTag();
  136.         /**
  137.          * @todo remove code
  138.          * if(!isset($this->$tag->_data)) $this->$tag->_data = '';
  139.          * $this->$tag->_data .= $data;
  140.          */
  141.         if (in_array($tag$this->updatecols))
  142.         {
  143.             $tag strtolower($tag);
  144.             $this->currentUpdate->$tag .= $data;
  145.         }
  146.     }
  147.  
  148.     /**
  149.      * Finds an update.
  150.      *
  151.      * @param   array  $options  Update options.
  152.      *
  153.      * @return  array  Array containing the array of update sites and array of updates
  154.      *
  155.      * @since   11.1
  156.      */
  157.     public function findUpdate($options)
  158.     {
  159.         $url $options['location'];
  160.         $this->_url &$url;
  161.         $this->updateSiteId = $options['update_site_id'];
  162.         if (substr($url-4!= '.xml')
  163.         {
  164.             if (substr($url-1!= '/')
  165.             {
  166.                 $url .= '/';
  167.             }
  168.             $url .= 'extension.xml';
  169.         }
  170.  
  171.         $db $this->parent->getDBO();
  172.  
  173.         $http JHttpFactory::getHttp();
  174.  
  175.         // JHttp transport throws an exception when there's no reponse.
  176.         try
  177.         {
  178.             $response $http->get($url);
  179.         }
  180.         catch (Exception $e)
  181.         {
  182.             $response null;
  183.         }
  184.  
  185.         if (!isset($response|| (!empty($response->code&& 200 != $response->code))
  186.         {
  187.             $query $db->getQuery(true)
  188.                 ->update('#__update_sites')
  189.                 ->set('enabled = 0')
  190.                 ->where('update_site_id = ' $this->updateSiteId);
  191.             $db->setQuery($query);
  192.             $db->execute();
  193.  
  194.             JLog::add("Error opening url: " $urlJLog::WARNING'updater');
  195.             $app JFactory::getApplication();
  196.             $app->enqueueMessage(JText::sprintf('JLIB_UPDATER_ERROR_EXTENSION_OPEN_URL'$url)'warning');
  197.             return false;
  198.         }
  199.  
  200.         $this->xmlParser = xml_parser_create('');
  201.         xml_set_object($this->xmlParser$this);
  202.         xml_set_element_handler($this->xmlParser'_startElement''_endElement');
  203.         xml_set_character_data_handler($this->xmlParser'_characterData');
  204.  
  205.         if (!xml_parse($this->xmlParser$response->body))
  206.         {
  207.             JLog::add("Error parsing url: " $urlJLog::WARNING'updater');
  208.             $app JFactory::getApplication();
  209.             $app->enqueueMessage(JText::sprintf('JLIB_UPDATER_ERROR_EXTENSION_PARSE_URL'$url)'warning');
  210.             return false;
  211.         }
  212.         xml_parser_free($this->xmlParser);
  213.         if (isset($this->latest))
  214.         {
  215.             if (isset($this->latest->client&& strlen($this->latest->client))
  216.             {
  217.                 if (is_numeric($this->latest->client))
  218.                 {
  219.                     $byName false;
  220.  
  221.                     // <client> has to be 'administrator' or 'site', numeric values are depreceated. See http://docs.joomla.org/Design_of_JUpdate
  222.                     JLog::add(
  223.                         'Using numeric values for <client> in the updater xml is deprecated. Use \'administrator\' or \'site\' instead.',
  224.                         JLog::WARNING'deprecated'
  225.                     );
  226.                 }
  227.                 else
  228.                 {
  229.                     $byName true;
  230.                 }
  231.                 $this->latest->client_id JApplicationHelper::getClientInfo($this->latest->client$byName)->id;
  232.                 unset($this->latest->client);
  233.             }
  234.             $updates array($this->latest);
  235.         }
  236.         else
  237.         {
  238.             $updates array();
  239.         }
  240.         return array('update_sites' => array()'updates' => $updates);
  241.     }
  242. }

Documentation generated on Tue, 19 Nov 2013 15:02:44 +0100 by phpDocumentor 1.4.3