<?php error_reporting(E_ALL);
/**
* This file is part of the Dynamic Networks RSS Framework for PHP
*
* @author Gordon Oheim (hide@address.com)
* @copyright Copyright 2005, Dynamic Networks
* @link http://www.dynamicnetworks.de
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License
* @filesource
* @version 1.0.0
*/
/**
* A class offering XML-DOM functions for creating an RSS Feed.
*
* @package rssFramework
* @author Gordon Oheim (hide@address.com)
* @abstract
*/
class parser {
/**
* @var domdocument
* @access private
*/
var $dom;
/**
* initializes $parser::$dom with a new domdocument.
*
* @access public
* @see $dom
*/
function parser() {
$this->dom = domxml_new_doc("1.0");
}
/**
* Returns the Document Object Model of the RSS feed created by the parser
*
* @return DomDocument
* @access public
*/
function get_dom() {
return $this->dom;
}
/**
* Adds a semantic resolution module element to the feed.
*
* The function will add a node referencing the Simple Semantic Resolution
* Module created by Danny Ayers. Follow the link below for more details on
* that.
*
* @link http://purl.org/stuff/ssrsr
*/
function add_semanticresolutionmodule(&$dom) {
$rdf = $dom->create_element("rdf");
$namespace = "http://purl.org/stuff/ssr";
$rdf->set_namespace($namespace, "ssr");
$rdf->set_attribute("transform", "http://w3future.com/weblog/gems/rss2rdf.xsl");
/* apply the license tag to channel and items */
$node = $dom->get_elements_by_tagname("channel");
$dom->insert_before($rdf, $node[0]);
/* send $dom back to user */
return $dom;
}
/**
* Sets a creative commons license to channel and items
*
* This function adds the a Creative Commons license tag to the RSS feed by
* adding a tag called license with a creativeCommons namespace to the XML
* document. The content for the text is supposed to be an URL pointing to
* the site holding the license agreement.
*
* The function takes up to three arguments, first is the license URL,
* second is the DomDocument and third is a boolean indicating whether the
* license should be applied to all item of the channel.
*
* Note: the DomDocument is passed by reference, meaning you do not have to
* use the return value. See the example for different types of implementing
* this function.
*
* @example /docs/examples/add_creativecommonslicense.php
* @link http://www.creativecommons.org
* @link http://backend.userland.com/creativeCommonsRssModule
* @param url $license
* @param DomDocument $dom
* @param bool $channelOnly
* @return domdocument
* @access public
*/
function add_creativecommonslicense($license, &$dom, $channelOnly = false) {
/* create a new nodeset containing the license */
$creativeCommons = $dom->create_element("license");
$namespace = "http://backend.userland.com/creativeCommonsRssModule";
$creativeCommons->set_namespace($namespace, "creativeCommons");
$license = $dom->create_text_node($license->get_url());
$creativeCommons->append_child($license);
/* apply the license tag to channel and items */
$node = $dom->get_elements_by_tagname("description");
$dom->insert_before($creativeCommons, $node[0]->next_sibling());
if ($channelOnly == false) {
$items = $dom->get_elements_by_tagname("item");
for ($i = 0; $i<count($items); $i++) {
$items[$i]->append_child($creativeCommons->clone_node(true));
}
}
/* send $dom back to user */
return $dom;
}
/**
* Transforms the DomDocument
*
* This function applies the specified XSL Transformation to the
* DomDocument. The default transformation is from dump to RSS, but you can
* specify whatever xslt file you need. If you pass transformer->get_dom()
* to the function as the first param, the transformer will overwrite your
* dump DomDocument with the DomDocument from the Transformation. If you do
* not want that to happen, copy the dump DomDocument into a variable first.
*
* @param DomDocument $dom
* @param file $xslt
* @return DomDocument
* @access public
*/
function transform(&$dom, $xslt = './src/xslt/RSS20/to_rss20.xslt') {
$xsldoc = domxml_xslt_stylesheet_file($xslt);
return $dom = $xsldoc->process($dom);
}
}
?>