MagpieRSS::feed_start_element( $p,  $element,  $attrs )

In this article

Source

function feed_start_element($p, $element, &$attrs) {
	$el = $element = strtolower($element);
	$attrs = array_change_key_case($attrs, CASE_LOWER);

	// check for a namespace, and split if found
	$ns	= false;
	if ( strpos( $element, ':' ) ) {
		list($ns, $el) = explode( ':', $element, 2);
	}
	if ( $ns and $ns != 'rdf' ) {
		$this->current_namespace = $ns;
	}

	# if feed type isn't set, then this is first element of feed
	# identify feed from root element
	#
	if (!isset($this->feed_type) ) {
		if ( $el == 'rdf' ) {
			$this->feed_type = RSS;
			$this->feed_version = '1.0';
		}
		elseif ( $el == 'rss' ) {
			$this->feed_type = RSS;
			$this->feed_version = $attrs['version'];
		}
		elseif ( $el == 'feed' ) {
			$this->feed_type = ATOM;
			$this->feed_version = $attrs['version'];
			$this->inchannel = true;
		}
		return;
	}

	if ( $el == 'channel' )
	{
		$this->inchannel = true;
	}
	elseif ($el == 'item' or $el == 'entry' )
	{
		$this->initem = true;
		if ( isset($attrs['rdf:about']) ) {
			$this->current_item['about'] = $attrs['rdf:about'];
		}
	}

	// if we're in the default namespace of an RSS feed,
	//  record textinput or image fields
	elseif (
		$this->feed_type == RSS and
		$this->current_namespace == '' and
		$el == 'textinput' )
	{
		$this->intextinput = true;
	}

	elseif (
		$this->feed_type == RSS and
		$this->current_namespace == '' and
		$el == 'image' )
	{
		$this->inimage = true;
	}

	# handle atom content constructs
	elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
	{
		// avoid clashing w/ RSS mod_content
		if ($el == 'content' ) {
			$el = 'atom_content';
		}

		$this->incontent = $el;

	}

	// if inside an Atom content construct (e.g. content or summary) field treat tags as text
	elseif ($this->feed_type == ATOM and $this->incontent )
	{
		// if tags are inlined, then flatten
		$attrs_str = join(' ',
				array_map(array('MagpieRSS', 'map_attrs'),
				array_keys($attrs),
				array_values($attrs) ) );

		$this->append_content( "<$element $attrs_str>"  );

		array_unshift( $this->stack, $el );
	}

	// Atom support many links per containing element.
	// Magpie treats link elements of type rel='alternate'
	// as being equivalent to RSS's simple link element.
	//
	elseif ($this->feed_type == ATOM and $el == 'link' )
	{
		if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' )
		{
			$link_el = 'link';
		}
		else {
			$link_el = 'link_' . $attrs['rel'];
		}

		$this->append($link_el, $attrs['href']);
	}
	// set stack[0] to current element
	else {
		array_unshift($this->stack, $el);
	}
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.