All pastes #216994 Raw Edit

7 moi

public php v1 · immutable
#216994 ·published 2006-10-23 12:14 UTC
rendered paste body
<?php/*** @package     jelix* @subpackage  core* @version     $Id$* @author      Loic Mathaud* @contributor* @copyright   2005-2006 Loic Mathaud* @link        http://www.jelix.org* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html*//****/require_once(JELIX_LIB_TPL_PATH.'jTpl.class.php');require_once(JELIX_LIB_RESPONSE_PATH.'jResponseXMLFeed.class.php');require_once(JELIX_LIB_UTILS_PATH.'jRss20Item.class.php');/*** Rss2.0 response* @package  jelix* @subpackage core*/class jResponseRss20 extends jResponseXMLFeed {    protected $_type = 'rss2.0';    /**    * elements in <channel>    */		protected $_main = array (		'mandatory' => array (			'title' => null,			'link' => null, 			'description' => null),		'optionnal' => array (			'language' => null,			'copyright' => null, 			'managingEditor' => null,			'webMaster' => null,			'pubDate' => null,			'lastBuildDate' => null,			'category' => null,			'generator' => null,			'docs' => null,			'cloud' => array (				'mandatory' => array (					'_domain' => null,					'_port' => null,					'_path' => null,					'_registerProcedure' => null,					'_protocol' => null					)						),			'ttl' => null,			'image' => array (				'mandatory' => array (					'image' => null,					'url' => null,					'link' => null					),				'optionnal' => array (					'height' => null,					'width' => null,					'description' => null					)				),			'rating' => null,			'textInput' => array (				'mandatory' => array (					'title' => null,					'description' => null,					'name' => null,					'link' => null					)				),			'skipHours' => null,			'skipDays' => null));			    /**    * Array containing the XSL stylesheets links    */    private $_xsl = array ();            /**     * Class constructor	 *	 * @param  array     * @return void     */        function __construct ($attributes = array()) 	{		$this->_xml_base_node_name = 'rss';		$this->_xml_base_node_name_attributes = array (			'version' => '2.0');		$this->_xml_main_node_name = 'channel';		        parent::__construct ($attributes);				$this->set ('language', $this->_lang);    }        /**     * Generate the content and send it     * Errors are managed     * @return boolean true if generation is ok, else false     */	     final public function output () 	{        $this->_headSent = false;		        $this->_httpHeaders['Content-Type'] = 			'application/rss+xml; charset=' . $this->_charset;        $this->sendHttpHeaders ();        $this->_outputXmlHeader ();        $this->_headSent = true;		        // $this->_outputOptionals();		$this->_deleteOptionnalEmptyNodes ();				print $this->_xml_dom->saveXML();		        if ($this->hasErrors ()) 		{            echo $this->getFormatedErrorMsg ();        }		        return true;    }        final public function outputErrors() {        if (!$this->_headSent) {             if ($this->_sendHttpHeader) {                header('Content-Type: text/xml;charset='.$this->_charset);             }             echo '<?xml version="1.0" encoding="'. $this->_charset .'"?>';        }        echo '<errors xmlns="http://jelix.org/ns/xmlerror/1.0">';        if ($this->hasErrors()) {            echo $this->getFormatedErrorMsg();        } else {            echo '<error>Unknow Error</error>';        }        echo '</errors>';    }    /**     * Format error messages     * @return string formated errors     */    protected function getFormatedErrorMsg(){        $errors = '';        foreach ($GLOBALS['gJCoord']->errorMessages  as $e) {            // FIXME : Pourquoi utiliser htmlentities() ?           $errors .=  '<error type="'. $e[0] .'" code="'. $e[1] .'" file="'. $e[3] .'" line="'. $e[4] .'">'.htmlentities($e[2], ENT_NOQUOTES, $this->_charset). '</error>'. "\n";        }        return $errors;    }        public function addOptionals($content) {        if (is_array($content)) {            $this->_optionals = $content;        }    }        public function addXSLStyleSheet($src, $params=array ()) {        if (!isset($this->_xsl[$src])){            $this->_xsl[$src] = $params;        }    }        public function addItem ($item) 	{        $this->_item_list[] = 			new jRSSItem (				$this->_xml_dom,				$this->_xml_main_node, 				$item);    }        protected function _outputXmlHeader() {        // XSL stylesheet        foreach ($this->_xsl as $src => $params) {            //the extra params we may found in there.            $more = '';            foreach ($params as $param_name => $param_value) {                $more .= $param_name.'="'. htmlspecialchars($param_value).'" ';            }            echo ' <?xml-stylesheet type="text/xsl" href="', $src,'" ', $more,' ?>';        }    }        protected function _outputOptionals() {        if (is_array($this->_optionals)) {            foreach ($this->_optionals as $name => $value) {                echo '<'. $name .'>'. $value .'</'. $name .'>', "\n";            }        }    }}class jRSSItem extends jXMLFeedItem{    /**    * elements in <item>    */		protected $_item = array (		'mandatory' => array (			'title' => null,			'description' => null),		'optionnal' => array (			'link' => null, 			'author' => null,			'category' => array (				'optionnal' => array (					'_domain' => null)),			'comments' => null,			'enclosure' => array (				'optionnal' => array (					'_url' => null,					'_length' => null,					'_type' => null)),			'guid' => array (				'optionnal' => array (					'_isPermaLink' => null)),			'docs' => null,			'pubDate' => null,			'source' => array (				'optionnal' => array (					'_url' => null))));	    function __construct (		$DOMDocument,		$parentNode,		$dataArray) 	{		$this->_xml_item_node = 'item';		        parent::__construct (				$DOMDocument,				$parentNode,				$dataArray);    }	}?>