Back to CollectionAdapter class

Method _startElement

public void
_startElement
(mixed $parser, mixed $name, mixed $attrs = array())
Opening an XML element
Parameters
  • object $parser Parser object
  • string $name Name of element that is opened
  • array $attrs Array of attributes for the element
Returns
  • void
Since
  • 1.7.0

Method _startElement - Source code

/**
 * Opening an XML element
 *
 * @param   object  $parser  Parser object
 * @param   string  $name    Name of element that is opened
 * @param   array   $attrs   Array of attributes for the element
 *
 * @return  void
 *
 * @since   1.7.0
 */
public function _startElement($parser, $name, $attrs = array())
{
    $this->stack[] = $name;
    $tag = $this->_getStackLocation();
    // Reset the data
    if (isset($this->{$tag})) {
        $this->{$tag}->_data = '';
    }
    switch ($name) {
        case 'CATEGORY':
            if (isset($attrs['REF'])) {
                $this->update_sites[] = array('type' => 'collection', 'location' => $attrs['REF'], 'update_site_id' => $this->updateSiteId);
            } else {
                // This item will have children, so prepare to attach them
                $this->pop_parent = 1;
            }
            break;
        case 'EXTENSION':
            $update = Table::getInstance('update');
            $update->set('update_site_id', $this->updateSiteId);
            foreach ($this->updatecols as $col) {
                // Reset the values if it doesn't exist
                if (!\array_key_exists($col, $attrs)) {
                    $attrs[$col] = '';
                    if ($col === 'CLIENT') {
                        $attrs[$col] = 'site';
                    }
                }
            }
            $client = ApplicationHelper::getClientInfo($attrs['CLIENT'], 1);
            if (isset($client->id)) {
                $attrs['CLIENT_ID'] = $client->id;
            }
            // Lower case all of the fields
            foreach ($attrs as $key => $attr) {
                $values[strtolower($key)] = $attr;
            }
            // Only add the update if it is on the same platform and release as we are
            $ver = new Version();
            // Lower case and remove the exclamation mark
            $product = strtolower(InputFilter::getInstance()->clean($ver::PRODUCT, 'cmd'));
            /*
             * Set defaults, the extension file should clarify in case but it may be only available in one version
             * This allows an update site to specify a targetplatform
             * targetplatformversion can be a regexp, so 1.[56] would be valid for an extension that supports 1.5 and 1.6
             * Note: Whilst the version is a regexp here, the targetplatform is not (new extension per platform)
             * Additionally, the version is a regexp here and it may also be in an extension file if the extension is
             * compatible against multiple versions of the same platform (e.g. a library)
             */
            if (!isset($values['targetplatform'])) {
                $values['targetplatform'] = $product;
            }
            // Set this to ourself as a default
            if (!isset($values['targetplatformversion'])) {
                $values['targetplatformversion'] = $ver::MAJOR_VERSION . '.' . $ver::MINOR_VERSION;
            }
            // Set this to ourselves as a default
            // validate that we can install the extension
            if ($product == $values['targetplatform'] && preg_match('/^' . $values['targetplatformversion'] . '/', JVERSION)) {
                $update->bind($values);
                $this->updates[] = $update;
            }
            break;
    }
}