-<?php\r
-/* $Id: rdf.class.php,v 1.40 2003/07/06 20:33:58 sts Exp $ */\r
-\r
-//\r
-// +----------------------------------------------------------------------+\r
-// | rss Parser |\r
-// | Copyright (c) 2001 Stefan Saasen |\r
-// +----------------------------------------------------------------------+\r
-// | The contents of this file are subject to the Mozilla Public License |\r
-// | Version 1.1 (the "License"); you may not use this file except in |\r
-// | compliance with the License. You may obtain a copy of the License at |\r
-// | http://www.mozilla.org/MPL/ |\r
-// | |\r
-// | Software distributed under the License is distributed on an "AS IS" |\r
-// | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |\r
-// | the License for the specific language governing rights and |\r
-// | limitations under the License. |\r
-// +----------------------------------------------------------------------+\r
-// | |\r
-// | Maintainer and initial developer: |\r
-// | Stefan Saasen <s@fase4.com> |\r
-// | |\r
-// | Proxy and authentication methods added by: |\r
-// | Marco Kraus <marco.kraus@siemens.com> |\r
-// | |\r
-// | Decoding of data by htmlentities or utf8_decode added by: |\r
-// | Roland Haeder <webmaster@mxchange.org> |\r
-// | |\r
-// +----------------------------------------------------------------------+\r
-// | Ref: |\r
-// | @link http://www.fase4.com/rdf/ Latest release |\r
-// +----------------------------------------------------------------------+\r
-\r
-/**\r
-* Class RSS Parser\r
-*\r
-* This class offers methods to parse RSS Files\r
-*\r
-* @link http://www.fase4.com/rdf/ Latest release of this class\r
-* @package rss\r
-* @copyright Copyright (c) 2001 fase4.com. All rights reserved.\r
-* @author Stefan Saasen <s@fase4.com>\r
-* @version 1.7 ($Date: 2003/07/06 20:33:58 $) $Revision: 1.40 $\r
-* @access public\r
-*/\r
-\r
-class fase4_rdf {\r
-\r
- /**\r
- * Word-wrapping mode for description, set it to 0 do disable this feature! Ommits _use_nl2br!\r
- *\r
- * @access private\r
- * @var integer\r
- */\r
- var $_word_wrap = 0;\r
-\r
- /**\r
- * Wether to recode \n -> <BR> or not in description\r
- *\r
- * @access private\r
- * @var boolean\r
- */\r
- var $_use_nl2br = true;\r
-\r
- /**\r
- * Sets the decoding mode of the read data (UTF8 scrambles some german umlauts here!)\r
- *\r
- * "htmlentities" - Use the function htmlentities()\r
- * "utf8_decode" - Use the function ut8_decode() when you have UTF8 encoded text\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_decoding_mode = "utf8_decode";\r
-\r
- /**\r
- * If $_link_target is set a target='xxx' attribute in each <a /> and <form /> html tag will be added\r
- *\r
- * Possible values are "_blank", "_content", "_parent", "_self", "_top"\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_link_target = "_blank";\r
-\r
- /**\r
- * vars for proxy settings - Prox Host\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_phost = "";\r
-\r
- /**\r
- * vars for proxy settings - Prox Port\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_pport = "";\r
-\r
- /**\r
- * vars for proxy settings - Prox Username\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_pname = "";\r
-\r
- /**\r
- * vars for proxy settings - Prox Password\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_ppasswd = "";\r
-\r
- /**\r
- * just a flag for checking if proxy-support should be enabled\r
- * set default to false (will be enabled if set_proxy is called)\r
- *\r
- * @access private\r
- * @see set_proxy()\r
- * @var bool\r
- */\r
- var $_use_proxy = false;\r
-\r
- /**\r
- * just a flag for checking if proxy-support with authentication\r
- * should be enabled\r
- * set default to false (will be enabled if set_proxy is called)\r
- *\r
- * @access private\r
- * @see set_proxy()\r
- * @var boolean\r
- */\r
- var $_use_proxy_auth = false;\r
-\r
- /**\r
- * The time the Files will be cached (in seconds).\r
- *\r
- * @access private\r
- * @var int\r
- */\r
- var $_refresh = 60; // int\r
-\r
- /**\r
- * The Name of the cached File.\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_cached_file = ""; // String\r
-\r
- /**\r
- * Indicates whether the cached or the remote file was used.\r
- *\r
- * @access private\r
- * @var boolean\r
- */\r
- var $_use_cached_file = true;\r
-\r
- /**\r
- * (fast|normal) depends on _use_dynamic_display(). _use_dynamic_display( TRUE ) -> 'normal', otherwise 'fast'\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_cache_type = "fast";\r
-\r
- /**\r
- * The Name of the Remote File.\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_remote_file = "";\r
-\r
- /**\r
- * Path to the Cache Directory.\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_cache_dir = "cache/"; // String\r
-\r
- /**\r
- * Indicates whether the Creating of the Cache Directory needs to be done or not.\r
- *\r
- * @access private\r
- * @var boolean\r
- */\r
- var $_cache_dir_ok = false;\r
-\r
- /**\r
- * Type of the file to be parsed (RSS or RDF).\r
- *\r
- * The Type depends on the root node\r
- *\r
- * @access private\r
- * @var string\r
- */\r
- var $_type = "rss"; // string (rss or rdf)\r
-\r
- /**\r
- * Array of Display Settings.\r
- *\r
- * Specific Parameters can be set to hidden. These are:\r
- * image, channel and textinput. If set to "hidden" those elements won't be displayed.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_display_opt = array(\r
- 'build' => '',\r
- 'image' => '',\r
- 'channel' => '',\r
- 'textinput' => '',\r
- 'cache_update' => '',\r
- 'sitelink' => '',\r
- 'refid' => '',\r
- 'reflink' => '',\r
- );\r
-\r
- /**\r
- * Defines the width attribute in the table that holds the rdf/rss representation\r
- *\r
- * @access private\r
- * @var int\r
- * @see see_table_width()\r
- */\r
- var $_table_width = "100%";\r
-\r
- /**\r
- * Indicates whether or not to use dynamic Display Settings\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_use_dynamic_display = false;\r
-\r
- /**\r
- * <item> count\r
- *\r
- * @access private\r
- * @var int\r
- */\r
- var $_item_count = 0;\r
-\r
- /**\r
- * No of max <item>s\r
- *\r
- * @access private\r
- * @var boolean\r
- */\r
- var $_max_count = false;\r
-\r
- /**\r
- * Array containing the content of <channel />\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_array_channel = array();\r
-\r
- /**\r
- * Array containing the content of each <item />\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_array_item = array();\r
-\r
- /**\r
- * Array containing the content of <textinput />\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_array_textinput = array();\r
-\r
- /**\r
- * Array containing the content of <image />\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_array_image = array();\r
-\r
- /**\r
- * Array containing the Channel content. Just For internal XML Parser Purposes.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_citem = array();\r
-\r
- /**\r
- * Array containing the Channel Parser Depth. Just For internal XML Parser Purposes.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_cdepth = array();\r
-\r
- /**\r
- * Array containing the Channel tags. Just For internal XML Parser Purposes.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_ctags = array( "x" );\r
-\r
- /**\r
- * Array containing the Channel content. Just For internal XML Parser Purposes.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_item = array(); // Array\r
-\r
- /**\r
- * Array containing the Channel Parser Depth. Just For internal XML Parser Purposes.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_depth = array(); // Array\r
-\r
- /**\r
- * Array containing the tags. Just For internal XML Parser Purposes.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
- var $_tags = array( "x" ); // Array\r
-\r
- /**\r
- * Garbage collection: probability in percent\r
- *\r
- * @var integer 0 => never\r
- * @access public\r
- */\r
- var $gc_probability = 1;\r
-\r
- /**\r
- * HTML Output\r
- *\r
- * @var string\r
- * @access private\r
- */\r
- var $_output = "";\r
-\r
- /**\r
- * @var string\r
- */\r
- var $_parse_mode = "";\r
-\r
- // Output variable\r
- var $out = "";\r
-\r
- // Salt for hashing\r
- var $salt = "";\r
-\r
- /**\r
- * Constructor of our Class\r
- *\r
- * This Method checks if the Cache Directory can be found. Otherwise it tries to creat the Cache Directory at the specified Path.\r
- * Additionally the Refresh Time is set to a default Value of 1200s (20 min).\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @see _refresh\r
- */\r
- function fase4_rdf()\r
- {\r
- // default Value, to be overwritten in set_refresh()\r
- $this->_refresh = (time() - 1200);\r
- $this->_clear_cItems();\r
- $this->_clear_Items();\r
- }\r
-\r
- /**\r
- * This Method starts the parsing of the specified RDF File. The File can be a local or a remote File.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $rdf RDF File (Location)\r
- * @return string Displays RDF Content ( using _display() )\r
- * @see _remote_file, cache()\r
- */\r
- function parse_RDF( $rdf )\r
- {\r
- unset($this->_array_item);\r
- $this->_remote_file = $rdf;\r
- $this->out .= "<!-- http://www.fase4.com/rdf/ -->";\r
- $this->out .= "<table width=\"".$this->_table_width."\">";\r
- $this->out .= $this->cache();\r
- $this->out .= "</table>";\r
- $this->_output = "";\r
- $this->_item_count = 0;\r
- return true;\r
- }\r
-\r
- /**\r
- * This Method is called when all parsing is finished to use the garbage collection\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $rdf RDF File (Location)\r
- * @return string Displays RDF Content ( using _display() )\r
- * @see _remote_file, cache()\r
- */\r
- function finish($return = false)\r
- {\r
- if (!$return) {\r
- echo $this->out;\r
- } else {\r
- return $this->out;\r
- }\r
- flush();\r
- $this->_garbage_collection();\r
- }\r
-\r
- /**\r
- * With this method you can decide whether to use the normal cache and dynamic display Options or to use a static cache.\r
- *\r
- * In the first case the rdf/rss File will be stored locally, in the second case the html output of the specified source will be stored.\r
- * In this case you can not modify the display settings.\r
- * processing time: ( 1.4792) --> remote file\r
- * processing time: ( 0.0313) --> using 'normal cache' with display Modification turned on.\r
- * processing time: ( 0.0019) --> using 'fast cache'\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $rdf RDF File (Location)\r
- * @return string Displays RDF Content ( using _display() )\r
- * @see _remote_file, cache()\r
- */\r
- function use_dynamic_display( $bool )\r
- {\r
- $this->_use_dynamic_display = $bool;\r
- return true;\r
- }\r
-\r
- /**\r
- * This Method avtually parses the XML data.\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $data RDF File XML Data\r
- * @see _clear_Items()\r
- */\r
- function _parse_xRDF( $data )\r
- {\r
- $this->_clear_Items();\r
- $xml_parser = xml_parser_create();\r
- xml_set_object($xml_parser,$this);\r
- xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);\r
- xml_set_element_handler($xml_parser, "_startElement", "_endElement");\r
- xml_set_character_data_handler($xml_parser, "_parseData");\r
- if (!xml_parse($xml_parser, trim($data))) {\r
- $this->_throw_exception(sprintf("XML error: %s at line %d",\r
- xml_error_string(xml_get_error_code($xml_parser)),\r
- xml_get_current_line_number($xml_parser))."<br /><br />Exception in function parse_RDF().");\r
- }\r
- xml_parser_free($xml_parser);\r
- }\r
-\r
-\r
- /**\r
- * This Methods allows you to set the Refresh Time\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param int $seconds time files will be cached (in seconds).\r
- * @return boolean\r
- * @see _refresh\r
- */\r
- function set_refresh( $seconds )\r
- {\r
- $this->_refresh = (time() - $seconds);\r
- return true;\r
- }\r
-\r
- function set_salt( $saltPara )\r
- {\r
- $this->salt = $saltPara;\r
- return true;\r
- }\r
-\r
- /**\r
- * This Methods allows you to set the No. of <item>s to display\r
- *\r
- * @access public\r
- * @param int $int No of max <item>s\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @return boolean\r
- * @see _max_count, _endElement()\r
- */\r
- function set_max_item( $int )\r
- {\r
- $this->_max_count = $int;\r
- return true;\r
- }\r
-\r
- /**\r
- * This Methods allows you to set the Cache Directory\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $dir Path to Directory.\r
- * @return boolean\r
- * @see _cache_dir\r
- */\r
- function set_CacheDir( $dir )\r
- {\r
- if(substr($dir, -1) != "/") {\r
- $dir = $dir."/";\r
- }\r
- $this->_cache_dir = $dir;\r
- }\r
-\r
- /**\r
- * This Method displays Error Messages and terminates the Execution of the Script\r
- *\r
- * @access private\r
- * @param string $msg Message to display on failure\r
- * @author Stefan Saasen <s@fase4.com>\r
- */\r
- function _throw_exception( $msg )\r
- {\r
- $this->out .= "<div style=\"font-family: verdana, helvetica, arial, sans-serif;font-size:11px; color: #6699cc;margin-top:10px;margin-bottom:10px;\" align=\"center\">fase4 RDF Error: ".$msg."</div>";\r
- return true;\r
- }\r
-\r
- /**\r
- * This Method clears the Array containig the Items.\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @see _item\r
- */\r
- function _clear_Items( ) {\r
- $this->_item = array(\r
- 'title'=>"",\r
- 'link'=>"",\r
- 'description'=>"",\r
- 'url'=>"",\r
- 'language'=>"",\r
- 'pubDate'=>"",\r
- 'lastBuildDate'=>"",\r
- 'width'=>'',\r
- 'height'=>''\r
- );\r
- }\r
- /**\r
- * This Method clears the Array containig the Channel Items.\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @see _item\r
- */\r
- function _clear_cItems( ) {\r
- $this->_citem = array(\r
- 'title'=>"",\r
- 'link'=>"",\r
- 'description'=>"",\r
- 'url'=>"",\r
- 'language'=>"",\r
- 'copyright'=>"",\r
- 'managingEditor'=>"",\r
- 'webMaster'=>"",\r
- 'pubDate'=>"",\r
- 'lastBuildDate'=>"",\r
- 'category'=>"",\r
- 'generator'=>"",\r
- 'docs'=>"",\r
- 'cloud'=>"",\r
- 'ttl'=>"",\r
- 'image'=>"",\r
- 'textinput'=>"",\r
- 'skipHours'=>"",\r
- 'skipDays' =>"",\r
- 'sitelink'=>"",\r
- 'refid'=>"",\r
- 'reflink'=>"",\r
- );\r
- }\r
-\r
- /**\r
- * XML Parser Start Element Handler\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param mixed $parser a reference to the XML parser calling the handler.\r
- * @param string $name contains the name of the element for which this handler is called.\r
- * @param string $attrs contains an associative array with the element's attributes (if any).\r
- * @see _get_ChannelData(), _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags\r
- */\r
- function _startElement($parser, $name, $attrs) {\r
- // We have to determine, which type of xml data we have to parse\r
- if($name == "rss") {\r
- $this->_type = "rss";\r
- } elseif($name == "rdf:RDF" OR $name == "rdf") {\r
- $this->_type = "rdf";\r
- }\r
-\r
-\r
- if ( $name == "channel" AND $this->_type != "rdf" ) {\r
- $this->_parse_mode = "channel";\r
- } elseif ( ($name=="item")\r
- ||($name=="image")\r
- ||($name=="textinput")\r
- ||(($name=="channel") && ($this->_type != "rss")) ) {\r
- if($this->_parse_mode=="channel") {\r
- $this->_get_ChannelData( $parser );\r
- }\r
- $this->_parse_mode = "all";\r
- }\r
-\r
- if( !isset( $this->_depth[$parser] ) ) {\r
- $this->_depth[$parser] = 0;\r
- }\r
- $this->_depth[$parser]++;\r
- array_push($this->_tags, $name);\r
-\r
- if( !isset( $this->_cdepth[$parser] ) ) {\r
- $this->_cdepth[$parser] = 0;\r
- }\r
- $this->_cdepth[$parser]++;\r
- array_push($this->_ctags, $name);\r
- } // END _startElement()\r
-\r
- /**\r
- * Retrives the Channel Data in <rss> File\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param mixed $parser a reference to the XML parser calling the handler.\r
- * @see _output, _display_opt, _citem\r
- */\r
- function _get_ChannelData( $parser )\r
- {\r
- $this->_citem["link"] = trim($this->_citem["link"]);\r
- if (($this->_display_opt["sitelink"] == $this->_citem["link"]) && (!empty($this->_display_opt["reflink"])) && (!empty($this->_display_opt["refid"])))\r
- {\r
- $this->_citem["link"] .= $this->_display_opt["reflink"].$this->_display_opt["refid"];\r
- }\r
-\r
- if( empty($this->_display_opt["channel"]) OR\r
- $this->_display_opt["channel"] != "hidden") {\r
- $this->_output .= "<tr><td>\n";\r
- $this->_output .= "<table border=\"0\" width=\"100%\" class=\"fase4_rdf_meta\" cellspacing=\"5\" cellpadding=\"2\">\n";\r
- $this->_output .= "<tr><td class=\"fase4_rdf_main_title\"><div class=\"fase4_rdf_main_title\">".htmlspecialchars($this->_citem["title"])."</div></td></tr>\n";\r
- $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_citem["description"], "<a>, <img>")."</td></tr>\n";\r
- $this->_output .= "<tr><td> </td></tr>\n";\r
- $this->_output .= "<tr><td class=\"fase4_rdf\">\n";\r
- if(isset($this->_display_opt["build"]) && $this->_display_opt["build"] != "hidden") {\r
- if($this->_citem["lastBuildDate"]){$this->_output .= "build: ". $this->_citem["lastBuildDate"]."<br />";}\r
- }\r
- if(isset($this->_display_opt["cache_update"]) && $this->_display_opt["cache_update"] != "hidden" && ( $_update = $this->get_cache_update_time()) ) {\r
- $this->_output .= "cache update: ".$_update."<br />\n";\r
- }\r
- $this->_output .= "<a href=\"".$this->_citem["link"]."\" ";\r
- if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }\r
- $this->_output .= ">".$this->_cut_string($this->_citem["link"])."</a>";\r
- $this->_output .= "</td></tr>\n";\r
- $this->_output .= "<tr><td><hr noshade width=\"100%\" size=\"1\"></td></tr>\n";\r
- $this->_output .= "</table></td></tr>";\r
- }\r
- $this->_array_channel = array( "title"=>$this->_citem["title"],\r
- "link"=>$this->_citem["link"],\r
- "description"=>$this->_citem["description"],\r
- "lastBuildDate"=>$this->_citem["lastBuildDate"]);\r
- }\r
-\r
- /**\r
- * XML Parser End Element Handler\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param mixed $parser a reference to the XML parser calling the handler.\r
- * @param string $name contains the name of the element for which this handler is called.\r
- * @see _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags, _item, _output, _display_opt\r
- */\r
- function _endElement($parser, $name) {\r
- array_pop($this->_tags);\r
- $this->_depth[$parser]--;\r
- array_pop($this->_ctags);\r
- $this->_cdepth[$parser]--;\r
- $this->_item["link"] = trim($this->_item["link"]);\r
- if ((!empty($this->_display_opt["refid"])) && (!empty($this->_item["link"])))\r
- {\r
- if (!ereg("refid=", $this->_item["link"])) $this->_item["link"] .= "?refid=" . $this->_display_opt["refid"];\r
- }\r
- switch ($name) {\r
- case "item":\r
- if(empty($this->_max_count) OR $this->_item_count < $this->_max_count) {\r
- if($this->_item["title"] != $this->_item["description"]\r
- AND $this->_item["description"]) {\r
-\r
- // word-wrapping added by Roland Haeder <webmaster@mxchange.org>\r
- if (($this->_word_wrap > 0) && (strlen($this->_item["description"]) > $this->_word_wrap))\r
- {\r
- // Switch off _use_nl2br\r
- $this->_use_nl2br = false;\r
- // First remove all \n\r
- $this->_item["description"] = str_replace('\n', ' ', $this->_item["description"]);\r
- // Wrap with <br />\n\r
- $this->_item["description"] = wordwrap($this->_item["description"], $this->_word_wrap, "*<br>\n");\r
- }\r
- elseif (($this->_word_wrap == 0) && (!$this->_use_nl2br))\r
- {\r
- // Strip tags out instead when word-wrap is disabled\r
- $this->_item["description"] = strip_tags($this->_item["description"], "<a>, <img>");\r
- }\r
-\r
- // nl2br added by Roland Haeder <webmaster@mxchange.org>\r
- if ($this->_use_nl2br) $this->_item["description"] = nl2br($this->_item["description"]);\r
-\r
- $this->_output .= "<tr><td class=\"fase4_rdf_title\"><div class=\"fase4_rdf_title\"><a class=\"fase4_rdf_title\" href=\"".$this->_item["link"]."\" ";\r
- if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }\r
- $this->_output .= ">".strip_tags($this->_item["title"], "<a>, <img>")."</a> (".$this->_item["pubDate"].")</div></td></tr>\n";\r
- $this->_output .= "<tr><td class=\"fase4_rdf\">".$this->_item["description"]."</td></tr>\n";\r
- // we just display the <hr> if there is a description\r
- $this->_output .= "<tr><td><hr noshade=\"noshade\" size=\"1\" /></td></tr>\n";\r
- } else {\r
- $this->_output .= "<tr><td class=\"fase4_rdf\">\n";\r
- $this->_output .= "<a href=\"".$this->_item["link"]."\" ";\r
- if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }\r
- $this->_output .= ">".$this->_item["title"]."</a></td></tr>\n";\r
- }\r
- $this->_array_item[] = array( "title"=>$this->_item["title"],\r
- "link"=>$this->_item["link"],\r
- "description"=>$this->_item["description"]);\r
- ++$this->_item_count;\r
- }\r
- $this->_clear_Items();\r
- break;\r
- case "image":\r
- if(isset($this->_display_opt["image"]) && ($this->_display_opt["image"] != "hidden") && $this->_item["url"]) {\r
- $this->_output .= "<tr><td class=\"fase4_rdf\">\n";\r
- $this->_output .= "<a href=\"".$this->_item["link"]."\" ";\r
- if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }\r
- $this->_output .= "><img src=\"".$this->_item["url"]."\"";\r
- if(isset($this->_item["width"]) && isset($this->_item["height"])) {\r
- $this->_output .= " width=\"".$this->_item["width"]."\" height=\"".$this->_item["height"]."\"";\r
- }\r
- $this->_output .= " alt=\"".$this->_item["title"]."\" border=\"0\" /></a></td></tr>\n";\r
-\r
- $this->_array_image[] = array( "url"=>$this->_item["url"],\r
- "link"=>$this->_item["link"],\r
- "width"=>$this->_item["width"],\r
- "height"=>$this->_item["height"]);\r
- $this->_clear_Items();\r
- } elseif( isset($this->_display_opt["image"] ) && ($this->_display_opt["image"] == "hidden") ) {\r
- $this->_clear_Items();\r
- }\r
-\r
- break;\r
- case "channel":\r
- if(isset($this->_display_opt["channel"]) AND $this->_display_opt["channel"] != "hidden" AND $this->_item["title"] != "") {\r
- $this->_output .= "<tr><td>\n";\r
- $this->_output .= '<table border="0" width="100%" class="fase4_rdf_meta" cellspacing="5" cellpadding="2">'."\n";\r
- $this->_output .= "<tr><td class=\"fase4_rdf\"><div class=\"fase4_rdf_title\">".htmlspecialchars($this->_item["title"])."</div></td></tr>\n";\r
- $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_item["description"], "<a>, <img>")."</td></tr>\n";\r
- $this->_output .= "<tr><td> </td></tr>\n";\r
- $this->_output .= "<tr><td class=\"fase4_rdf\">\n";\r
- if($this->_display_opt["build"] != "hidden") {\r
- if($this->_item["lastBuildDate"]){$this->_output .= "build: ". $this->_item["lastBuildDate"]."<br />";}\r
- }\r
- if($this->_display_opt["cache_update"] != "hidden" && ( $_update = $this->get_cache_update_time()) ) {\r
- $this->_output .= "cache update: ".$_update."<br />\n";\r
- }\r
- $this->_output .= "<a href=\"".$this->_item["link"]."\" ";\r
- if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }\r
- $this->_output .= ">".$this->_cut_string($this->_item["link"])."</a>\n";\r
- $this->_output .= "</td></tr>\n";\r
- $this->_output .= "</table></td></tr>\n";\r
- }\r
- $this->_array_channel = array( "title"=>$this->_item["title"],\r
- "link"=>$this->_item["link"],\r
- "description"=>$this->_item["description"],\r
- "lastBuildDate"=>$this->_item["lastBuildDate"]);\r
- $this->_clear_Items();\r
- $this->_clear_cItems();\r
- break;\r
- case "textinput":\r
- if(isset($this->_display_opt["textinput"]) && ($this->_display_opt["textinput"] != "hidden") && $this->_item["name"] && $this->_item["link"]) {\r
- $this->_output .= "<tr><td class=\"fase4_rdf\">\n";\r
- $this->_output .= "<form action=\"".$this->_item["link"]."\" ";\r
- if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }\r
- $this->_output .= "method=\"get\">\n";\r
- $this->_output .= "<div class=\"fase4_rdf_title\">".$this->_item["title"]."</div>";\r
- $this->_output .= strip_tags($this->_item["description"], "<a>, <img>")."<br><br>\n";\r
- $this->_output .= "<input class=\"fase4_rdf_input\" type=\"text\" name=\"".$this->_item["name"]."\"> \n";\r
- $this->_output .= "<input class=\"fase4_rdf_input\" type=\"submit\" value=\"go\">";\r
- $this->_output .= "</form>\n";\r
- $this->_output .= "</td></tr>\n";\r
- $this->_array_textinput = array( "title"=>$this->_item["title"],\r
- "name"=>$this->_item["name"],\r
- "link"=>$this->_item["link"],\r
- "description"=>$this->_item["description"]);\r
- $this->_clear_Items();\r
- } elseif( isset($this->_display_opt["textinput"]) && ($this->_display_opt["textinput"] == "hidden") ) {\r
- $this->_clear_Items();\r
- }\r
-\r
- break;\r
- }\r
- }\r
-\r
- /**\r
- * This Method returns the data from the <channel /> paragraph.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @return array\r
- * @see _array_channel\r
- */\r
- function get_array_channel( )\r
- {\r
- return $this->_array_channel;\r
- }\r
-\r
- /**\r
- * This Method returns the data from each <item /> paragraph.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @return array\r
- * @see _array_item\r
- */\r
- function get_array_item( )\r
- {\r
- return $this->_array_item;\r
- }\r
-\r
- /**\r
- * This Method returns the data from <textinput />.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @return array\r
- * @see _array_textinput\r
- */\r
- function get_array_textinput( )\r
- {\r
- return $this->_array_textinput;\r
- }\r
-\r
- /**\r
- * This Method returns the data from <image />.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @return array\r
- * @see _array_image\r
- */\r
- function get_array_image( )\r
- {\r
- return $this->_array_image;\r
- }\r
-\r
- /**\r
- * XML Parser Data Handler\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param mixed $parser a reference to the XML parser calling the handler.\r
- * @param string $text contains the character data as a string.\r
- * @see _parse_mode, _item, _tags, _depth, _citem, _ctags, _cdepth\r
- */\r
- function _parseData($parser, $text)\r
- {\r
- // Deocing mode added by Roland Haeder <webmaster@mxchange.org>\r
- switch ($this->_decoding_mode)\r
- {\r
- case "utf8_decode":\r
- $text = utf8_decode($text);\r
- break;\r
-\r
- case "htmlentities":\r
- $text = htmlentities($text);\r
- break;\r
- }\r
-\r
- $clean = preg_replace("/\s/", "", $text);\r
- if ($clean) {\r
- $text = preg_replace("/^\s+/", "", $text)."\n";\r
- if($this->_parse_mode == "all") {\r
- if ( isset($this->_item[$this->_tags[$this->_depth[$parser]]]) &&\r
- $this->_item[$this->_tags[$this->_depth[$parser]]] ) {\r
- $this->_item[$this->_tags[$this->_depth[$parser]]] .= $text;\r
- } else {\r
- $this->_item[$this->_tags[$this->_depth[$parser]]] = $text;\r
- }\r
- } elseif (isset($this->_parse_mode) && $this->_parse_mode == "channel") {\r
- if ( isset($this->_citem[$this->_ctags[$this->_cdepth[$parser]]]) ) {\r
- $this->_citem[$this->_ctags[$this->_cdepth[$parser]]] .= $text;\r
- } else {\r
- $this->_citem[$this->_ctags[$this->_cdepth[$parser]]] = $text;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * This Method allows you to choose if specific Parameters are displayed or not. These are:\r
- * image, channel, textinput, build and cache_update. If set to "hidden" those elements won't be displayed.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param array $options\r
- * @see _display_opt\r
- */\r
- function set_Options( $options = "" )\r
- {\r
- if(is_array( $options )) {\r
- $this->_display_opt = $options;\r
- return true;\r
- } else {\r
- unset($this->_display_opt);\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * This Method allows you to define the width of the table that holds the representation of the rdf/rss file.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param int $width attribute width in tag <table>\r
- * @see _table_width\r
- */\r
- function set_table_width( $width = 400 )\r
- {\r
- $this->_table_width = $width;\r
- return true;\r
- }\r
-\r
- /**\r
- * This Method returns an assocative Array with available Options.\r
- *\r
- * The Keys are the Name of the Options to be set.\r
- * The Values are short Description of available Options.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @return array $options\r
- * @see _display_opt\r
- */\r
- function get_Options()\r
- {\r
- $options = array( "image"=>"If 'image' is set to \"hidden\" no image provided by the RDF Publisher will be displayed.",\r
- "channel"=>"If 'channel' is set to \"hidden\" the Channel Meta Data (i.e the Title and the short description regarding the RDF Publisher will not be displayed",\r
- "textinput"=>"If set to \"hidden\" no Input Form will be displayed",\r
- "build"=>"If set to \"hidden\" the Build Date (if provided) of the RDF File will not be displayed",\r
- "cache_update"=>"If set to \"hidden\" the Update Date/Time of the cached Rdf File will not be displayed");\r
- return $options;\r
- }\r
-\r
- /**\r
- * This Method returns the Content of the RDF File in one string. The String actually holds the whole XML Document.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $rdf RDF File (Location)\r
- * @return string XML Presentation of parsed RDF File\r
- * @see _cached_file, _remote_file, _cache_dir, _refresh, _update_cache()\r
- */\r
- function cache()\r
- {\r
- // checks if the cache directory already exists\r
- // if not, the cache directory will be created\r
- if(!$this->_cache_dir_ok) {\r
- $this->_create_cache_dir();\r
- }\r
- if($this->_use_dynamic_display == true) {\r
- $this->_cached_file = md5("dynamic".$this->salt.$this->_remote_file);\r
- $this->_cache_type = "normal";\r
- } else {\r
- $this->_cached_file = md5($this->salt.$this->_remote_file);\r
- $this->_cache_type = "fast";\r
- }\r
-\r
- $_cache_f = $this->_cache_dir.$this->_cached_file;\r
-\r
- if ( (!file_exists($_cache_f)) || (filemtime($_cache_f) < $this->_refresh) || (filesize($_cache_f) == 0)) {\r
- // We have to parse the remote file\r
- $this->_use_cached_file = false;\r
- // --> we want to provide proper Information for Use in\r
- // get_cache_update_time()\r
- clearstatcache();\r
- if($this->_use_dynamic_display == true) {\r
- $_rdf = @implode(" ", $this->_rdf_data()); // -> proxy\r
- if(!$_rdf) {\r
- $this->_throw_exception( $this->_remote_file." is not available" );\r
- }\r
- $this->_parse_xRDF( $_rdf );\r
- $this->_update_cache( $_rdf );\r
- $data = $this->_output;\r
- } else {\r
- $_rdf = @implode(" ", $this->_rdf_data()); // -> proxy\r
- if(!$_rdf) {\r
- $this->_throw_exception( $this->_remote_file." is not available" );\r
- }\r
- $this->_parse_xRDF( $_rdf );\r
- $this->_update_cache( $this->_output );\r
- $data = $this->_output;\r
- }\r
- } else {\r
- // we can use the cached file\r
- $this->_use_cached_file = true;\r
- if($this->_use_dynamic_display == true) {\r
- $this->_parse_xRDF( implode(" ", file($_cache_f)) );\r
- $data = $this->_output;\r
- } else {\r
- $data = @implode(" ", file($_cache_f));\r
- }\r
- }\r
- return trim($data);\r
- } // END cache()\r
-\r
- /**\r
- * This Methods creates the Cache Directory if the specified Directory does not exist.\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $dir Path to Directory.\r
- * @return boolean\r
- * @see _cache_dir, _cache_dir_ok\r
- */\r
- function _create_cache_dir()\r
- {\r
- $path = "";\r
- if(!@is_dir($this->_cache_dir)) {\r
- $arr = explode("/", $this->_cache_dir);\r
- $c = count($arr);\r
- if($arr[0]=="") {\r
- $path = "/";\r
- }\r
- for($i = 0;$i<$c;$i++)\r
- {\r
- if($arr[$i]!="") {\r
- $path .= $arr[$i]."/";\r
- if(!@is_dir($path)) {\r
- if(!@mkdir($path, 0777)) {\r
- $this->_throw_exception("failed to create directory:<b>".$this->_cache_dir."</b>.<br /><br />Exception on Line: ".__LINE__);\r
- return false;\r
- }\r
- }\r
- }\r
- }\r
- $this->_cache_dir_ok = true;\r
- return true;\r
- } else {\r
- $this->_cache_dir_ok = true;\r
- return true;\r
- }\r
- } // END _create_cache_dir()\r
-\r
- /**\r
- * This Method updates the cached RDF Files and synchronises them with their remote Counterparts.\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $rdf RDF File (Location)\r
- * @see _cache_dir, _cached_file, _throw_exception()\r
- */\r
- function _update_cache( $content = "" )\r
- {\r
- $_local = @fopen( $this->_cache_dir.$this->_cached_file, 'w' );\r
- if(!$_local) {\r
- $this->_throw_exception( "Cannot open ".$this->_cached_file."<br /><br />Exception at Line: ".__LINE__ );\r
- return false;\r
- }\r
- if (fwrite( $_local, $content) === false) {\r
- $this->_throw_exception( "Cannot write to ".$this->_cached_file."<br /<br />Exeception at Line: ".__LINE__);\r
- return false;\r
- }\r
- fclose( $_local );\r
- @chmod( $this->_cache_dir.$this->_cached_file, 0666);\r
- return true;\r
- } // END _update_cache()\r
-\r
- /**\r
- * This Method returns the Date/Time of last Cache Update of the actually parsed RDF File.\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @return string Date/Time of last Update\r
- * @see _cache_dir, _cached_file\r
- */\r
- function get_cache_update_time()\r
- {\r
- return (file_exists($this->_cache_dir.$this->_cached_file))?date("d.m.Y H:i:s", filemtime($this->_cache_dir.$this->_cached_file)):"Cachemiss";\r
- } // END get_cache_update_time()\r
-\r
- /**\r
- * This Method returns the Type of Cache that was used ('normal' or 'fast')\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @param string $rdf RDF File (Location)\r
- * @return string Displays RDF Content ( using _display() )\r
- * @see _remote_file, cache()\r
- */\r
- function get_CacheType()\r
- {\r
- return $this->_cache_type;\r
- }\r
-\r
- /**\r
- * Returns true if cached file was used, otherwise false\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @return array $options\r
- * @see _use_cached_file\r
- */\r
- function is_cachedFile()\r
- {\r
- return $this->_use_cached_file;\r
- }\r
-\r
- /**\r
- * This Method deletes all the cached Files.\r
- *\r
- * Please keep in mind to use this method just as a 'manual garbage collection'\r
- * You should cache the rss/rdf files locally to avoid unnecessary traffic.\r
- * (Both for your visitors and the Publisher)\r
- *\r
- * @access public\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @see _cache_dir\r
- */\r
- function clear_cache()\r
- {\r
- $dir = dir($this->_cache_dir);\r
- while($file=$dir->read()) {\r
- if($file!="." && $file!="..") {\r
- if(!@unlink($dir->path.$file)) {\r
- $this->_throw_exception(\r
- "Unable to unlink ".$dir->path.$file\r
- ."<br /><br />Exception at Line: ".__LINE__ );\r
- return false;\r
- }\r
- }\r
- }\r
- $dir->close();\r
- return true;\r
- } // END clear_cache()\r
-\r
- /**\r
- * Cuts the String $string after $str_len and adds "... "\r
- *\r
- * @access private\r
- * @param string $string String to be shortened\r
- * @param int $str_len length of the returned String (overall length including "... ")\r
- * @return string Cut String\r
- */\r
- function _cut_string( $string, $str_len = "30" )\r
- {\r
- if(strlen(trim($string))>$str_len) {\r
- $string = substr( trim($string) , 0, $str_len - 4);\r
- $string .= " ...";\r
- }\r
- return $string;\r
- } // END _cut_string()\r
-\r
- /**\r
- * this Method implements simple Garbage Collection\r
- *\r
- * @access private\r
- * @author Stefan Saasen <s@fase4.com>\r
- * @see _cache_dir, gc_probability, gc_maxlifetime\r
- */\r
- function _garbage_collection()\r
- {\r
- srand((double) microtime() * 1000000);\r
- if (rand(1, 100) <= $this->gc_probability) {\r
- $dir = dir($this->_cache_dir);\r
- while($file=$dir->read()) {\r
- if($file!="." AND $file!=".." AND filemtime($dir->path.$file) <= time() - $this->_refresh ) {\r
- @unlink($dir->path.$file);\r
- }\r
- }\r
- $dir->close();\r
- } // END if\r
- }\r
-\r
- /* ==== Proxy/Auth methods ==== */\r
-\r
- /**\r
- * this method sets a proxy server\r
- *\r
- * @access public\r
- * @param string $phost Proxy Host\r
- * @param string $pport Prox Port\r
- * @author Marco Kraus <marco.kraus@siemens.com>\r
- */\r
- function set_proxy($phost, $pport)\r
- {\r
- $this->_use_proxy = true;\r
-\r
- if ($phost != "")\r
- $this->_phost = $phost;\r
-\r
- if ($pport != "")\r
- $this->_pport = $pport;\r
- }\r
-\r
- /**\r
- * this method sets a proxy server authentification\r
- *\r
- * @access public\r
- * @param string $pname Username\r
- * @param string $ppaswd Password\r
- * @author Marco Kraus <marco.kraus@siemens.com>\r
- */\r
- function set_proxy_auth( $pname, $ppasswd )\r
- {\r
- $this->_use_proxy_auth = true;\r
-\r
- if ($pname != "")\r
- $this->_pname = $pname;\r
-\r
- if ($ppasswd != "")\r
- $this->_ppasswd = $ppasswd;\r
- }\r
-\r
-\r
- /**\r
- * gets _remote_file into an array\r
- *\r
- * needed, cause if you use a proxy, you have to open\r
- * a raw-tcp-socket to get the data\r
- *\r
- * @access private\r
- * @author Marco Kraus <Marco.Kraus@siemens.com>\r
- * @return array\r
- * @see _use_proxy, cache()\r
- */\r
- function _rdf_data()\r
- {\r
- if ( $this->_use_proxy == true )\r
- {\r
- // we need a raw socket here to connect to proxy\r
- $fp = fsockopen($this->_phost,$this->_pport);\r
-\r
- if (!$fp) {\r
- $this->_throw_exception( $this->_remote_file." is not available with proxy" );\r
- } else {\r
- if ( $this->_use_proxy_auth == true ) {\r
- fputs($fp, "GET ".$this->_remote_file." HTTP/1.0\r\nUser-Agent: Fase4 RDF-Reader/1.40 modified by Quix0r\r\n\r\n");\r
- } else {\r
- fputs($fp, "GET ".$this->_remote_file." HTTP/1.0\r\nUser-Agent: Fase4 RDF-Reader/1.40 modified by Quix0r\r\nProxy-Authorization: Basic ".base64_encode("$this->_pname:$this->_ppasswd") ."\r\n\r\n");\r
- }\r
- }\r
-\r
-\r
- for ( $i = 0; !feof ($fp) ; $i++)\r
- {\r
- $usable_data[$i] = "";\r
- $usable_data[$i] = fgets($fp,4096);\r
-\r
- // PARSE HEADER ---- first line has to be <?xml, second rdf or rss, and third is blank\r
-\r
- // strstr did not fit (ask Rasmus why), so we compare each character\r
- if ( ($usable_data[$i][0] == "<" ) &&\r
- ($usable_data[$i][1] == "?" ) &&\r
- ($usable_data[$i][2] == "x" ) &&\r
- ($usable_data[$i][3] == "m" ) &&\r
- ($usable_data[$i][4] == "l" ) ) {\r
- $usable_data[0] = $usable_data[$i]; // save current field\r
- $i = 1; // just reset array to start\r
- }\r
-\r
- // there seems to be proxystuff after the <?xml....we delete this\r
- if ( (\r
- ($usable_data[$i][0] == "<" ) &&\r
- ($usable_data[$i][1] == "r" ) &&\r
- ($usable_data[$i][2] == "d" ) &&\r
- ($usable_data[$i][3] == "f" ) &&\r
- ($usable_data[$i][4] == ":" )\r
- )\r
- ||\r
- (\r
- ($usable_data[$i][0] == "<" ) &&\r
- ($usable_data[$i][1] == "r" ) &&\r
- ($usable_data[$i][2] == "s" ) &&\r
- ($usable_data[$i][3] == "s" )\r
- )\r
- ) {\r
-\r
- $usable_data[1] = $usable_data[$i]; // save current field\r
- $usable_data[2] = "\n";\r
- $i = 2; // just reset array to start\r
- }\r
- }\r
-\r
- fclose($fp);\r
- return $usable_data;\r
- } else {\r
- if (substr($this->_remote_file, 0, 7) != "http://") {\r
- $this->_throw_exception( "Cannot find http:// in ".$this->_remote_file."!" );\r
- return "";\r
- } else {\r
- // Extract host information\r
- $host = substr($this->_remote_file, 7);\r
- // Extract the GET part\r
- $get = "/";\r
- if (strpos($host, "/") > 0) {\r
- $get = substr($host, strpos($host, "/"));\r
- $host = substr($host, 0, strpos($host, "/"));\r
- }\r
- // Extract port\r
- $port = "80";\r
- if (strpos($host, ":") > 0) {\r
- $port = substr($host, (strpos($host, ":") + 1));\r
- $host = substr($host, 0, (strpos($host, ":") - 1));\r
- }\r
-\r
- // Start connection to server\r
- $fp = fsockopen($host, $port);\r
- if (!$fp) {\r
- $this->_throw_exception( $this->_remote_file." is maybe not available." );\r
- return "";\r
- }\r
- // Repare request line\r
- $request = sprintf("GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Fase4 RDF-Reader/1.40 modified by Quix0r\r\n\r\n", $get, $host);\r
- // Send request out\r
- fputs($fp, $request);\r
- $reply = ""; $isContent = false; $dummy = "";\r
- // Read reply\r
- while ( !feof($fp) ) {\r
- $read = trim(fgets($fp, 4096));\r
- if (substr($read, 0, 5) == "<?xml" || $isContent) {\r
- // Add content\r
- $reply[] = $read;\r
- $isContent = true;\r
- } else {\r
- // Put in dummy\r
- $dummy[] = $read;\r
- }\r
- $i++;\r
- }\r
- if ((count($dummy) > 0) && (count($reply) == 0) && (!$isContent)) {\r
- // Transfer content from dummy\r
- $reply = $content;\r
- }\r
- fclose($fp);\r
- //die(htmlentities($reply));\r
- return $reply;\r
- }\r
- }\r
- } // END _rdf_data()\r
-} // END class\r
-?>\r
+<?php
+/* $Id: rdf.class.php,v 1.40 2003/07/06 20:33:58 sts Exp $ */
+
+//
+// +----------------------------------------------------------------------+
+// | rss Parser |
+// | Copyright (c) 2001 Stefan Saasen |
+// +----------------------------------------------------------------------+
+// | The contents of this file are subject to the Mozilla Public License |
+// | Version 1.1 (the "License"); you may not use this file except in |
+// | compliance with the License. You may obtain a copy of the License at |
+// | http://www.mozilla.org/MPL/ |
+// | |
+// | Software distributed under the License is distributed on an "AS IS" |
+// | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
+// | the License for the specific language governing rights and |
+// | limitations under the License. |
+// +----------------------------------------------------------------------+
+// | |
+// | Maintainer and initial developer: |
+// | Stefan Saasen <s@fase4.com> |
+// | |
+// | Proxy and authentication methods added by: |
+// | Marco Kraus <marco.kraus@siemens.com> |
+// | |
+// | Decoding of data by htmlentities or utf8_decode added by: |
+// | Roland Haeder <webmaster@mxchange.org> |
+// | |
+// +----------------------------------------------------------------------+
+// | Ref: |
+// | @link http://www.fase4.com/rdf/ Latest release |
+// +----------------------------------------------------------------------+
+
+/**
+* Class RSS Parser
+*
+* This class offers methods to parse RSS Files
+*
+* @link http://www.fase4.com/rdf/ Latest release of this class
+* @package rss
+* @copyright Copyright (c) 2001 fase4.com. All rights reserved.
+* @author Stefan Saasen <s@fase4.com>
+* @version 1.7 ($Date: 2003/07/06 20:33:58 $) $Revision: 1.40 $
+* @access public
+*/
+
+class fase4_rdf {
+
+ /**
+ * Word-wrapping mode for description, set it to 0 do disable this feature! Ommits _use_nl2br!
+ *
+ * @access private
+ * @var integer
+ */
+ var $_word_wrap = 0;
+
+ /**
+ * Wether to recode \n -> <BR> or not in description
+ *
+ * @access private
+ * @var boolean
+ */
+ var $_use_nl2br = true;
+
+ /**
+ * Sets the decoding mode of the read data (UTF8 scrambles some german umlauts here!)
+ *
+ * "htmlentities" - Use the function htmlentities()
+ * "utf8_decode" - Use the function ut8_decode() when you have UTF8 encoded text
+ *
+ * @access private
+ * @var string
+ */
+ var $_decoding_mode = "utf8_decode";
+
+ /**
+ * If $_link_target is set a target='xxx' attribute in each <a /> and <form /> html tag will be added
+ *
+ * Possible values are "_blank", "_content", "_parent", "_self", "_top"
+ *
+ * @access private
+ * @var string
+ */
+ var $_link_target = "_blank";
+
+ /**
+ * vars for proxy settings - Prox Host
+ *
+ * @access private
+ * @var string
+ */
+ var $_phost = "";
+
+ /**
+ * vars for proxy settings - Prox Port
+ *
+ * @access private
+ * @var string
+ */
+ var $_pport = "";
+
+ /**
+ * vars for proxy settings - Prox Username
+ *
+ * @access private
+ * @var string
+ */
+ var $_pname = "";
+
+ /**
+ * vars for proxy settings - Prox Password
+ *
+ * @access private
+ * @var string
+ */
+ var $_ppasswd = "";
+
+ /**
+ * just a flag for checking if proxy-support should be enabled
+ * set default to false (will be enabled if set_proxy is called)
+ *
+ * @access private
+ * @see set_proxy()
+ * @var bool
+ */
+ var $_use_proxy = false;
+
+ /**
+ * just a flag for checking if proxy-support with authentication
+ * should be enabled
+ * set default to false (will be enabled if set_proxy is called)
+ *
+ * @access private
+ * @see set_proxy()
+ * @var boolean
+ */
+ var $_use_proxy_auth = false;
+
+ /**
+ * The time the Files will be cached (in seconds).
+ *
+ * @access private
+ * @var int
+ */
+ var $_refresh = 60; // int
+
+ /**
+ * The Name of the cached File.
+ *
+ * @access private
+ * @var string
+ */
+ var $_cached_file = ""; // String
+
+ /**
+ * Indicates whether the cached or the remote file was used.
+ *
+ * @access private
+ * @var boolean
+ */
+ var $_use_cached_file = true;
+
+ /**
+ * (fast|normal) depends on _use_dynamic_display(). _use_dynamic_display( TRUE ) -> 'normal', otherwise 'fast'
+ *
+ * @access private
+ * @var string
+ */
+ var $_cache_type = "fast";
+
+ /**
+ * The Name of the Remote File.
+ *
+ * @access private
+ * @var string
+ */
+ var $_remote_file = "";
+
+ /**
+ * Path to the Cache Directory.
+ *
+ * @access private
+ * @var string
+ */
+ var $_cache_dir = "cache/"; // String
+
+ /**
+ * Indicates whether the Creating of the Cache Directory needs to be done or not.
+ *
+ * @access private
+ * @var boolean
+ */
+ var $_cache_dir_ok = false;
+
+ /**
+ * Type of the file to be parsed (RSS or RDF).
+ *
+ * The Type depends on the root node
+ *
+ * @access private
+ * @var string
+ */
+ var $_type = "rss"; // string (rss or rdf)
+
+ /**
+ * Array of Display Settings.
+ *
+ * Specific Parameters can be set to hidden. These are:
+ * image, channel and textinput. If set to "hidden" those elements won't be displayed.
+ *
+ * @access private
+ * @var array
+ */
+ var $_display_opt = array(
+ 'build' => '',
+ 'image' => '',
+ 'channel' => '',
+ 'textinput' => '',
+ 'cache_update' => '',
+ 'sitelink' => '',
+ 'refid' => '',
+ 'reflink' => '',
+ );
+
+ /**
+ * Defines the width attribute in the table that holds the rdf/rss representation
+ *
+ * @access private
+ * @var int
+ * @see see_table_width()
+ */
+ var $_table_width = "100%";
+
+ /**
+ * Indicates whether or not to use dynamic Display Settings
+ *
+ * @access private
+ * @var array
+ */
+ var $_use_dynamic_display = false;
+
+ /**
+ * <item> count
+ *
+ * @access private
+ * @var int
+ */
+ var $_item_count = 0;
+
+ /**
+ * No of max <item>s
+ *
+ * @access private
+ * @var boolean
+ */
+ var $_max_count = false;
+
+ /**
+ * Array containing the content of <channel />
+ *
+ * @access private
+ * @var array
+ */
+ var $_array_channel = array();
+
+ /**
+ * Array containing the content of each <item />
+ *
+ * @access private
+ * @var array
+ */
+ var $_array_item = array();
+
+ /**
+ * Array containing the content of <textinput />
+ *
+ * @access private
+ * @var array
+ */
+ var $_array_textinput = array();
+
+ /**
+ * Array containing the content of <image />
+ *
+ * @access private
+ * @var array
+ */
+ var $_array_image = array();
+
+ /**
+ * Array containing the Channel content. Just For internal XML Parser Purposes.
+ *
+ * @access private
+ * @var array
+ */
+ var $_citem = array();
+
+ /**
+ * Array containing the Channel Parser Depth. Just For internal XML Parser Purposes.
+ *
+ * @access private
+ * @var array
+ */
+ var $_cdepth = array();
+
+ /**
+ * Array containing the Channel tags. Just For internal XML Parser Purposes.
+ *
+ * @access private
+ * @var array
+ */
+ var $_ctags = array( "x" );
+
+ /**
+ * Array containing the Channel content. Just For internal XML Parser Purposes.
+ *
+ * @access private
+ * @var array
+ */
+ var $_item = array(); // Array
+
+ /**
+ * Array containing the Channel Parser Depth. Just For internal XML Parser Purposes.
+ *
+ * @access private
+ * @var array
+ */
+ var $_depth = array(); // Array
+
+ /**
+ * Array containing the tags. Just For internal XML Parser Purposes.
+ *
+ * @access private
+ * @var array
+ */
+ var $_tags = array( "x" ); // Array
+
+ /**
+ * Garbage collection: probability in percent
+ *
+ * @var integer 0 => never
+ * @access public
+ */
+ var $gc_probability = 1;
+
+ /**
+ * HTML Output
+ *
+ * @var string
+ * @access private
+ */
+ var $_output = "";
+
+ /**
+ * @var string
+ */
+ var $_parse_mode = "";
+
+ // Output variable
+ var $out = "";
+
+ // Salt for hashing
+ var $salt = "";
+
+ /**
+ * Constructor of our Class
+ *
+ * This Method checks if the Cache Directory can be found. Otherwise it tries to creat the Cache Directory at the specified Path.
+ * Additionally the Refresh Time is set to a default Value of 1200s (20 min).
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @see _refresh
+ */
+ function fase4_rdf()
+ {
+ // default Value, to be overwritten in set_refresh()
+ $this->_refresh = (time() - 1200);
+ $this->_clear_cItems();
+ $this->_clear_Items();
+ }
+
+ /**
+ * This Method starts the parsing of the specified RDF File. The File can be a local or a remote File.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $rdf RDF File (Location)
+ * @return string Displays RDF Content ( using _display() )
+ * @see _remote_file, cache()
+ */
+ function parse_RDF( $rdf )
+ {
+ unset($this->_array_item);
+ $this->_remote_file = $rdf;
+ $this->out .= "<!-- http://www.fase4.com/rdf/ -->";
+ $this->out .= "<table width=\"".$this->_table_width."\">";
+ $this->out .= $this->cache();
+ $this->out .= "</table>";
+ $this->_output = "";
+ $this->_item_count = 0;
+ return true;
+ }
+
+ /**
+ * This Method is called when all parsing is finished to use the garbage collection
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $rdf RDF File (Location)
+ * @return string Displays RDF Content ( using _display() )
+ * @see _remote_file, cache()
+ */
+ function finish($return = false)
+ {
+ if (!$return) {
+ echo $this->out;
+ } else {
+ return $this->out;
+ }
+ flush();
+ $this->_garbage_collection();
+ }
+
+ /**
+ * With this method you can decide whether to use the normal cache and dynamic display Options or to use a static cache.
+ *
+ * In the first case the rdf/rss File will be stored locally, in the second case the html output of the specified source will be stored.
+ * In this case you can not modify the display settings.
+ * processing time: ( 1.4792) --> remote file
+ * processing time: ( 0.0313) --> using 'normal cache' with display Modification turned on.
+ * processing time: ( 0.0019) --> using 'fast cache'
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $rdf RDF File (Location)
+ * @return string Displays RDF Content ( using _display() )
+ * @see _remote_file, cache()
+ */
+ function use_dynamic_display( $bool )
+ {
+ $this->_use_dynamic_display = $bool;
+ return true;
+ }
+
+ /**
+ * This Method avtually parses the XML data.
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $data RDF File XML Data
+ * @see _clear_Items()
+ */
+ function _parse_xRDF( $data )
+ {
+ $this->_clear_Items();
+ $xml_parser = xml_parser_create();
+ xml_set_object($xml_parser,$this);
+ xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);
+ xml_set_element_handler($xml_parser, "_startElement", "_endElement");
+ xml_set_character_data_handler($xml_parser, "_parseData");
+ if (!xml_parse($xml_parser, trim($data))) {
+ $this->_throw_exception(sprintf("XML error: %s at line %d",
+ xml_error_string(xml_get_error_code($xml_parser)),
+ xml_get_current_line_number($xml_parser))."<br /><br />Exception in function parse_RDF().");
+ }
+ xml_parser_free($xml_parser);
+ }
+
+
+ /**
+ * This Methods allows you to set the Refresh Time
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param int $seconds time files will be cached (in seconds).
+ * @return boolean
+ * @see _refresh
+ */
+ function set_refresh( $seconds )
+ {
+ $this->_refresh = (time() - $seconds);
+ return true;
+ }
+
+ function set_salt( $saltPara )
+ {
+ $this->salt = $saltPara;
+ return true;
+ }
+
+ /**
+ * This Methods allows you to set the No. of <item>s to display
+ *
+ * @access public
+ * @param int $int No of max <item>s
+ * @author Stefan Saasen <s@fase4.com>
+ * @return boolean
+ * @see _max_count, _endElement()
+ */
+ function set_max_item( $int )
+ {
+ $this->_max_count = $int;
+ return true;
+ }
+
+ /**
+ * This Methods allows you to set the Cache Directory
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $dir Path to Directory.
+ * @return boolean
+ * @see _cache_dir
+ */
+ function set_CacheDir( $dir )
+ {
+ if(substr($dir, -1) != "/") {
+ $dir = $dir."/";
+ }
+ $this->_cache_dir = $dir;
+ }
+
+ /**
+ * This Method displays Error Messages and terminates the Execution of the Script
+ *
+ * @access private
+ * @param string $msg Message to display on failure
+ * @author Stefan Saasen <s@fase4.com>
+ */
+ function _throw_exception( $msg )
+ {
+ $this->out .= "<div style=\"font-family: verdana, helvetica, arial, sans-serif;font-size:11px; color: #6699cc;margin-top:10px;margin-bottom:10px;\" align=\"center\">fase4 RDF Error: ".$msg."</div>";
+ return true;
+ }
+
+ /**
+ * This Method clears the Array containig the Items.
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @see _item
+ */
+ function _clear_Items( ) {
+ $this->_item = array(
+ 'title'=>"",
+ 'link'=>"",
+ 'description'=>"",
+ 'url'=>"",
+ 'language'=>"",
+ 'pubDate'=>"",
+ 'lastBuildDate'=>"",
+ 'width'=>'',
+ 'height'=>''
+ );
+ }
+ /**
+ * This Method clears the Array containig the Channel Items.
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @see _item
+ */
+ function _clear_cItems( ) {
+ $this->_citem = array(
+ 'title'=>"",
+ 'link'=>"",
+ 'description'=>"",
+ 'url'=>"",
+ 'language'=>"",
+ 'copyright'=>"",
+ 'managingEditor'=>"",
+ 'webMaster'=>"",
+ 'pubDate'=>"",
+ 'lastBuildDate'=>"",
+ 'category'=>"",
+ 'generator'=>"",
+ 'docs'=>"",
+ 'cloud'=>"",
+ 'ttl'=>"",
+ 'image'=>"",
+ 'textinput'=>"",
+ 'skipHours'=>"",
+ 'skipDays' =>"",
+ 'sitelink'=>"",
+ 'refid'=>"",
+ 'reflink'=>"",
+ );
+ }
+
+ /**
+ * XML Parser Start Element Handler
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @param mixed $parser a reference to the XML parser calling the handler.
+ * @param string $name contains the name of the element for which this handler is called.
+ * @param string $attrs contains an associative array with the element's attributes (if any).
+ * @see _get_ChannelData(), _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags
+ */
+ function _startElement($parser, $name, $attrs) {
+ // We have to determine, which type of xml data we have to parse
+ if($name == "rss") {
+ $this->_type = "rss";
+ } elseif($name == "rdf:RDF" OR $name == "rdf") {
+ $this->_type = "rdf";
+ }
+
+
+ if ( $name == "channel" AND $this->_type != "rdf" ) {
+ $this->_parse_mode = "channel";
+ } elseif ( ($name=="item")
+ ||($name=="image")
+ ||($name=="textinput")
+ ||(($name=="channel") && ($this->_type != "rss")) ) {
+ if($this->_parse_mode=="channel") {
+ $this->_get_ChannelData( $parser );
+ }
+ $this->_parse_mode = "all";
+ }
+
+ if( !isset( $this->_depth[$parser] ) ) {
+ $this->_depth[$parser] = 0;
+ }
+ $this->_depth[$parser]++;
+ array_push($this->_tags, $name);
+
+ if( !isset( $this->_cdepth[$parser] ) ) {
+ $this->_cdepth[$parser] = 0;
+ }
+ $this->_cdepth[$parser]++;
+ array_push($this->_ctags, $name);
+ } // END _startElement()
+
+ /**
+ * Retrives the Channel Data in <rss> File
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @param mixed $parser a reference to the XML parser calling the handler.
+ * @see _output, _display_opt, _citem
+ */
+ function _get_ChannelData( $parser )
+ {
+ $this->_citem["link"] = trim($this->_citem["link"]);
+ if (($this->_display_opt["sitelink"] == $this->_citem["link"]) && (!empty($this->_display_opt["reflink"])) && (!empty($this->_display_opt["refid"])))
+ {
+ $this->_citem["link"] .= $this->_display_opt["reflink"].$this->_display_opt["refid"];
+ }
+
+ if( empty($this->_display_opt["channel"]) OR
+ $this->_display_opt["channel"] != "hidden") {
+ $this->_output .= "<tr><td>\n";
+ $this->_output .= "<table border=\"0\" width=\"100%\" class=\"fase4_rdf_meta\" cellspacing=\"5\" cellpadding=\"2\">\n";
+ $this->_output .= "<tr><td class=\"fase4_rdf_main_title\"><div class=\"fase4_rdf_main_title\">".htmlspecialchars($this->_citem["title"])."</div></td></tr>\n";
+ $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_citem["description"], "<a>, <img>")."</td></tr>\n";
+ $this->_output .= "<tr><td> </td></tr>\n";
+ $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
+ if(isset($this->_display_opt["build"]) && $this->_display_opt["build"] != "hidden") {
+ if($this->_citem["lastBuildDate"]){$this->_output .= "build: ". $this->_citem["lastBuildDate"]."<br />";}
+ }
+ if(isset($this->_display_opt["cache_update"]) && $this->_display_opt["cache_update"] != "hidden" && ( $_update = $this->get_cache_update_time()) ) {
+ $this->_output .= "cache update: ".$_update."<br />\n";
+ }
+ $this->_output .= "<a href=\"".$this->_citem["link"]."\" ";
+ if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
+ $this->_output .= ">".$this->_cut_string($this->_citem["link"])."</a>";
+ $this->_output .= "</td></tr>\n";
+ $this->_output .= "<tr><td><hr noshade width=\"100%\" size=\"1\"></td></tr>\n";
+ $this->_output .= "</table></td></tr>";
+ }
+ $this->_array_channel = array( "title"=>$this->_citem["title"],
+ "link"=>$this->_citem["link"],
+ "description"=>$this->_citem["description"],
+ "lastBuildDate"=>$this->_citem["lastBuildDate"]);
+ }
+
+ /**
+ * XML Parser End Element Handler
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @param mixed $parser a reference to the XML parser calling the handler.
+ * @param string $name contains the name of the element for which this handler is called.
+ * @see _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags, _item, _output, _display_opt
+ */
+ function _endElement($parser, $name) {
+ array_pop($this->_tags);
+ $this->_depth[$parser]--;
+ array_pop($this->_ctags);
+ $this->_cdepth[$parser]--;
+ $this->_item["link"] = trim($this->_item["link"]);
+ if ((!empty($this->_display_opt["refid"])) && (!empty($this->_item["link"])))
+ {
+ if (!ereg("refid=", $this->_item["link"])) $this->_item["link"] .= "?refid=" . $this->_display_opt["refid"];
+ }
+ switch ($name) {
+ case "item":
+ if(empty($this->_max_count) OR $this->_item_count < $this->_max_count) {
+ if($this->_item["title"] != $this->_item["description"]
+ AND $this->_item["description"]) {
+
+ // word-wrapping added by Roland Haeder <webmaster@mxchange.org>
+ if (($this->_word_wrap > 0) && (strlen($this->_item["description"]) > $this->_word_wrap))
+ {
+ // Switch off _use_nl2br
+ $this->_use_nl2br = false;
+ // First remove all \n
+ $this->_item["description"] = str_replace('\n', ' ', $this->_item["description"]);
+ // Wrap with <br />\n
+ $this->_item["description"] = wordwrap($this->_item["description"], $this->_word_wrap, "*<br>\n");
+ }
+ elseif (($this->_word_wrap == 0) && (!$this->_use_nl2br))
+ {
+ // Strip tags out instead when word-wrap is disabled
+ $this->_item["description"] = strip_tags($this->_item["description"], "<a>, <img>");
+ }
+
+ // nl2br added by Roland Haeder <webmaster@mxchange.org>
+ if ($this->_use_nl2br) $this->_item["description"] = nl2br($this->_item["description"]);
+
+ $this->_output .= "<tr><td class=\"fase4_rdf_title\"><div class=\"fase4_rdf_title\"><a class=\"fase4_rdf_title\" href=\"".$this->_item["link"]."\" ";
+ if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
+ $this->_output .= ">".strip_tags($this->_item["title"], "<a>, <img>")."</a> (".$this->_item["pubDate"].")</div></td></tr>\n";
+ $this->_output .= "<tr><td class=\"fase4_rdf\">".$this->_item["description"]."</td></tr>\n";
+ // we just display the <hr> if there is a description
+ $this->_output .= "<tr><td><hr noshade=\"noshade\" size=\"1\" /></td></tr>\n";
+ } else {
+ $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
+ $this->_output .= "<a href=\"".$this->_item["link"]."\" ";
+ if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
+ $this->_output .= ">".$this->_item["title"]."</a></td></tr>\n";
+ }
+ $this->_array_item[] = array( "title"=>$this->_item["title"],
+ "link"=>$this->_item["link"],
+ "description"=>$this->_item["description"]);
+ ++$this->_item_count;
+ }
+ $this->_clear_Items();
+ break;
+ case "image":
+ if(isset($this->_display_opt["image"]) && ($this->_display_opt["image"] != "hidden") && $this->_item["url"]) {
+ $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
+ $this->_output .= "<a href=\"".$this->_item["link"]."\" ";
+ if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
+ $this->_output .= "><img src=\"".$this->_item["url"]."\"";
+ if(isset($this->_item["width"]) && isset($this->_item["height"])) {
+ $this->_output .= " width=\"".$this->_item["width"]."\" height=\"".$this->_item["height"]."\"";
+ }
+ $this->_output .= " alt=\"".$this->_item["title"]."\" border=\"0\" /></a></td></tr>\n";
+
+ $this->_array_image[] = array( "url"=>$this->_item["url"],
+ "link"=>$this->_item["link"],
+ "width"=>$this->_item["width"],
+ "height"=>$this->_item["height"]);
+ $this->_clear_Items();
+ } elseif( isset($this->_display_opt["image"] ) && ($this->_display_opt["image"] == "hidden") ) {
+ $this->_clear_Items();
+ }
+
+ break;
+ case "channel":
+ if(isset($this->_display_opt["channel"]) AND $this->_display_opt["channel"] != "hidden" AND $this->_item["title"] != "") {
+ $this->_output .= "<tr><td>\n";
+ $this->_output .= '<table border="0" width="100%" class="fase4_rdf_meta" cellspacing="5" cellpadding="2">'."\n";
+ $this->_output .= "<tr><td class=\"fase4_rdf\"><div class=\"fase4_rdf_title\">".htmlspecialchars($this->_item["title"])."</div></td></tr>\n";
+ $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_item["description"], "<a>, <img>")."</td></tr>\n";
+ $this->_output .= "<tr><td> </td></tr>\n";
+ $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
+ if($this->_display_opt["build"] != "hidden") {
+ if($this->_item["lastBuildDate"]){$this->_output .= "build: ". $this->_item["lastBuildDate"]."<br />";}
+ }
+ if($this->_display_opt["cache_update"] != "hidden" && ( $_update = $this->get_cache_update_time()) ) {
+ $this->_output .= "cache update: ".$_update."<br />\n";
+ }
+ $this->_output .= "<a href=\"".$this->_item["link"]."\" ";
+ if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
+ $this->_output .= ">".$this->_cut_string($this->_item["link"])."</a>\n";
+ $this->_output .= "</td></tr>\n";
+ $this->_output .= "</table></td></tr>\n";
+ }
+ $this->_array_channel = array( "title"=>$this->_item["title"],
+ "link"=>$this->_item["link"],
+ "description"=>$this->_item["description"],
+ "lastBuildDate"=>$this->_item["lastBuildDate"]);
+ $this->_clear_Items();
+ $this->_clear_cItems();
+ break;
+ case "textinput":
+ if(isset($this->_display_opt["textinput"]) && ($this->_display_opt["textinput"] != "hidden") && $this->_item["name"] && $this->_item["link"]) {
+ $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
+ $this->_output .= "<form action=\"".$this->_item["link"]."\" ";
+ if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
+ $this->_output .= "method=\"get\">\n";
+ $this->_output .= "<div class=\"fase4_rdf_title\">".$this->_item["title"]."</div>";
+ $this->_output .= strip_tags($this->_item["description"], "<a>, <img>")."<br><br>\n";
+ $this->_output .= "<input class=\"fase4_rdf_input\" type=\"text\" name=\"".$this->_item["name"]."\"> \n";
+ $this->_output .= "<input class=\"fase4_rdf_input\" type=\"submit\" value=\"go\">";
+ $this->_output .= "</form>\n";
+ $this->_output .= "</td></tr>\n";
+ $this->_array_textinput = array( "title"=>$this->_item["title"],
+ "name"=>$this->_item["name"],
+ "link"=>$this->_item["link"],
+ "description"=>$this->_item["description"]);
+ $this->_clear_Items();
+ } elseif( isset($this->_display_opt["textinput"]) && ($this->_display_opt["textinput"] == "hidden") ) {
+ $this->_clear_Items();
+ }
+
+ break;
+ }
+ }
+
+ /**
+ * This Method returns the data from the <channel /> paragraph.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @return array
+ * @see _array_channel
+ */
+ function get_array_channel( )
+ {
+ return $this->_array_channel;
+ }
+
+ /**
+ * This Method returns the data from each <item /> paragraph.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @return array
+ * @see _array_item
+ */
+ function get_array_item( )
+ {
+ return $this->_array_item;
+ }
+
+ /**
+ * This Method returns the data from <textinput />.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @return array
+ * @see _array_textinput
+ */
+ function get_array_textinput( )
+ {
+ return $this->_array_textinput;
+ }
+
+ /**
+ * This Method returns the data from <image />.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @return array
+ * @see _array_image
+ */
+ function get_array_image( )
+ {
+ return $this->_array_image;
+ }
+
+ /**
+ * XML Parser Data Handler
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @param mixed $parser a reference to the XML parser calling the handler.
+ * @param string $text contains the character data as a string.
+ * @see _parse_mode, _item, _tags, _depth, _citem, _ctags, _cdepth
+ */
+ function _parseData($parser, $text)
+ {
+ // Deocing mode added by Roland Haeder <webmaster@mxchange.org>
+ switch ($this->_decoding_mode)
+ {
+ case "utf8_decode":
+ $text = utf8_decode($text);
+ break;
+
+ case "htmlentities":
+ $text = htmlentities($text);
+ break;
+ }
+
+ $clean = preg_replace("/\s/", "", $text);
+ if ($clean) {
+ $text = preg_replace("/^\s+/", "", $text)."\n";
+ if($this->_parse_mode == "all") {
+ if ( isset($this->_item[$this->_tags[$this->_depth[$parser]]]) &&
+ $this->_item[$this->_tags[$this->_depth[$parser]]] ) {
+ $this->_item[$this->_tags[$this->_depth[$parser]]] .= $text;
+ } else {
+ $this->_item[$this->_tags[$this->_depth[$parser]]] = $text;
+ }
+ } elseif (isset($this->_parse_mode) && $this->_parse_mode == "channel") {
+ if ( isset($this->_citem[$this->_ctags[$this->_cdepth[$parser]]]) ) {
+ $this->_citem[$this->_ctags[$this->_cdepth[$parser]]] .= $text;
+ } else {
+ $this->_citem[$this->_ctags[$this->_cdepth[$parser]]] = $text;
+ }
+ }
+ }
+ }
+
+ /**
+ * This Method allows you to choose if specific Parameters are displayed or not. These are:
+ * image, channel, textinput, build and cache_update. If set to "hidden" those elements won't be displayed.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param array $options
+ * @see _display_opt
+ */
+ function set_Options( $options = "" )
+ {
+ if(is_array( $options )) {
+ $this->_display_opt = $options;
+ return true;
+ } else {
+ unset($this->_display_opt);
+ return false;
+ }
+ }
+
+ /**
+ * This Method allows you to define the width of the table that holds the representation of the rdf/rss file.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param int $width attribute width in tag <table>
+ * @see _table_width
+ */
+ function set_table_width( $width = 400 )
+ {
+ $this->_table_width = $width;
+ return true;
+ }
+
+ /**
+ * This Method returns an assocative Array with available Options.
+ *
+ * The Keys are the Name of the Options to be set.
+ * The Values are short Description of available Options.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @return array $options
+ * @see _display_opt
+ */
+ function get_Options()
+ {
+ $options = array( "image"=>"If 'image' is set to \"hidden\" no image provided by the RDF Publisher will be displayed.",
+ "channel"=>"If 'channel' is set to \"hidden\" the Channel Meta Data (i.e the Title and the short description regarding the RDF Publisher will not be displayed",
+ "textinput"=>"If set to \"hidden\" no Input Form will be displayed",
+ "build"=>"If set to \"hidden\" the Build Date (if provided) of the RDF File will not be displayed",
+ "cache_update"=>"If set to \"hidden\" the Update Date/Time of the cached Rdf File will not be displayed");
+ return $options;
+ }
+
+ /**
+ * This Method returns the Content of the RDF File in one string. The String actually holds the whole XML Document.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $rdf RDF File (Location)
+ * @return string XML Presentation of parsed RDF File
+ * @see _cached_file, _remote_file, _cache_dir, _refresh, _update_cache()
+ */
+ function cache()
+ {
+ // checks if the cache directory already exists
+ // if not, the cache directory will be created
+ if(!$this->_cache_dir_ok) {
+ $this->_create_cache_dir();
+ }
+ if($this->_use_dynamic_display == true) {
+ $this->_cached_file = md5("dynamic".$this->salt.$this->_remote_file);
+ $this->_cache_type = "normal";
+ } else {
+ $this->_cached_file = md5($this->salt.$this->_remote_file);
+ $this->_cache_type = "fast";
+ }
+
+ $_cache_f = $this->_cache_dir.$this->_cached_file;
+
+ if ( (!file_exists($_cache_f)) || (filemtime($_cache_f) < $this->_refresh) || (filesize($_cache_f) == 0)) {
+ // We have to parse the remote file
+ $this->_use_cached_file = false;
+ // --> we want to provide proper Information for Use in
+ // get_cache_update_time()
+ clearstatcache();
+ if($this->_use_dynamic_display == true) {
+ $_rdf = @implode(" ", $this->_rdf_data()); // -> proxy
+ if(!$_rdf) {
+ $this->_throw_exception( $this->_remote_file." is not available" );
+ }
+ $this->_parse_xRDF( $_rdf );
+ $this->_update_cache( $_rdf );
+ $data = $this->_output;
+ } else {
+ $_rdf = @implode(" ", $this->_rdf_data()); // -> proxy
+ if(!$_rdf) {
+ $this->_throw_exception( $this->_remote_file." is not available" );
+ }
+ $this->_parse_xRDF( $_rdf );
+ $this->_update_cache( $this->_output );
+ $data = $this->_output;
+ }
+ } else {
+ // we can use the cached file
+ $this->_use_cached_file = true;
+ if($this->_use_dynamic_display == true) {
+ $this->_parse_xRDF( implode(" ", file($_cache_f)) );
+ $data = $this->_output;
+ } else {
+ $data = @implode(" ", file($_cache_f));
+ }
+ }
+ return trim($data);
+ } // END cache()
+
+ /**
+ * This Methods creates the Cache Directory if the specified Directory does not exist.
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $dir Path to Directory.
+ * @return boolean
+ * @see _cache_dir, _cache_dir_ok
+ */
+ function _create_cache_dir()
+ {
+ $path = "";
+ if(!@is_dir($this->_cache_dir)) {
+ $arr = explode("/", $this->_cache_dir);
+ $c = count($arr);
+ if($arr[0]=="") {
+ $path = "/";
+ }
+ for($i = 0;$i<$c;$i++)
+ {
+ if($arr[$i]!="") {
+ $path .= $arr[$i]."/";
+ if(!@is_dir($path)) {
+ if(!@mkdir($path, 0777)) {
+ $this->_throw_exception("failed to create directory:<b>".$this->_cache_dir."</b>.<br /><br />Exception on Line: ".__LINE__);
+ return false;
+ }
+ }
+ }
+ }
+ $this->_cache_dir_ok = true;
+ return true;
+ } else {
+ $this->_cache_dir_ok = true;
+ return true;
+ }
+ } // END _create_cache_dir()
+
+ /**
+ * This Method updates the cached RDF Files and synchronises them with their remote Counterparts.
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $rdf RDF File (Location)
+ * @see _cache_dir, _cached_file, _throw_exception()
+ */
+ function _update_cache( $content = "" )
+ {
+ $_local = @fopen( $this->_cache_dir.$this->_cached_file, 'w' );
+ if(!$_local) {
+ $this->_throw_exception( "Cannot open ".$this->_cached_file."<br /><br />Exception at Line: ".__LINE__ );
+ return false;
+ }
+ if (fwrite( $_local, $content) === false) {
+ $this->_throw_exception( "Cannot write to ".$this->_cached_file."<br /<br />Exeception at Line: ".__LINE__);
+ return false;
+ }
+ fclose( $_local );
+ @chmod( $this->_cache_dir.$this->_cached_file, 0666);
+ return true;
+ } // END _update_cache()
+
+ /**
+ * This Method returns the Date/Time of last Cache Update of the actually parsed RDF File.
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @return string Date/Time of last Update
+ * @see _cache_dir, _cached_file
+ */
+ function get_cache_update_time()
+ {
+ return (file_exists($this->_cache_dir.$this->_cached_file))?date("d.m.Y H:i:s", filemtime($this->_cache_dir.$this->_cached_file)):"Cachemiss";
+ } // END get_cache_update_time()
+
+ /**
+ * This Method returns the Type of Cache that was used ('normal' or 'fast')
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @param string $rdf RDF File (Location)
+ * @return string Displays RDF Content ( using _display() )
+ * @see _remote_file, cache()
+ */
+ function get_CacheType()
+ {
+ return $this->_cache_type;
+ }
+
+ /**
+ * Returns true if cached file was used, otherwise false
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @return array $options
+ * @see _use_cached_file
+ */
+ function is_cachedFile()
+ {
+ return $this->_use_cached_file;
+ }
+
+ /**
+ * This Method deletes all the cached Files.
+ *
+ * Please keep in mind to use this method just as a 'manual garbage collection'
+ * You should cache the rss/rdf files locally to avoid unnecessary traffic.
+ * (Both for your visitors and the Publisher)
+ *
+ * @access public
+ * @author Stefan Saasen <s@fase4.com>
+ * @see _cache_dir
+ */
+ function clear_cache()
+ {
+ $dir = dir($this->_cache_dir);
+ while($file=$dir->read()) {
+ if($file!="." && $file!="..") {
+ if(!@unlink($dir->path.$file)) {
+ $this->_throw_exception(
+ "Unable to unlink ".$dir->path.$file
+ ."<br /><br />Exception at Line: ".__LINE__ );
+ return false;
+ }
+ }
+ }
+ $dir->close();
+ return true;
+ } // END clear_cache()
+
+ /**
+ * Cuts the String $string after $str_len and adds "... "
+ *
+ * @access private
+ * @param string $string String to be shortened
+ * @param int $str_len length of the returned String (overall length including "... ")
+ * @return string Cut String
+ */
+ function _cut_string( $string, $str_len = "30" )
+ {
+ if(strlen(trim($string))>$str_len) {
+ $string = substr( trim($string) , 0, $str_len - 4);
+ $string .= " ...";
+ }
+ return $string;
+ } // END _cut_string()
+
+ /**
+ * this Method implements simple Garbage Collection
+ *
+ * @access private
+ * @author Stefan Saasen <s@fase4.com>
+ * @see _cache_dir, gc_probability, gc_maxlifetime
+ */
+ function _garbage_collection()
+ {
+ srand((double) microtime() * 1000000);
+ if (rand(1, 100) <= $this->gc_probability) {
+ $dir = dir($this->_cache_dir);
+ while($file=$dir->read()) {
+ if($file!="." AND $file!=".." AND filemtime($dir->path.$file) <= time() - $this->_refresh ) {
+ @unlink($dir->path.$file);
+ }
+ }
+ $dir->close();
+ } // END if
+ }
+
+ /* ==== Proxy/Auth methods ==== */
+
+ /**
+ * this method sets a proxy server
+ *
+ * @access public
+ * @param string $phost Proxy Host
+ * @param string $pport Prox Port
+ * @author Marco Kraus <marco.kraus@siemens.com>
+ */
+ function set_proxy($phost, $pport)
+ {
+ $this->_use_proxy = true;
+
+ if ($phost != "")
+ $this->_phost = $phost;
+
+ if ($pport != "")
+ $this->_pport = $pport;
+ }
+
+ /**
+ * this method sets a proxy server authentification
+ *
+ * @access public
+ * @param string $pname Username
+ * @param string $ppaswd Password
+ * @author Marco Kraus <marco.kraus@siemens.com>
+ */
+ function set_proxy_auth( $pname, $ppasswd )
+ {
+ $this->_use_proxy_auth = true;
+
+ if ($pname != "")
+ $this->_pname = $pname;
+
+ if ($ppasswd != "")
+ $this->_ppasswd = $ppasswd;
+ }
+
+
+ /**
+ * gets _remote_file into an array
+ *
+ * needed, cause if you use a proxy, you have to open
+ * a raw-tcp-socket to get the data
+ *
+ * @access private
+ * @author Marco Kraus <Marco.Kraus@siemens.com>
+ * @return array
+ * @see _use_proxy, cache()
+ */
+ function _rdf_data()
+ {
+ if ( $this->_use_proxy == true )
+ {
+ // we need a raw socket here to connect to proxy
+ $fp = fsockopen($this->_phost,$this->_pport);
+
+ if (!$fp) {
+ $this->_throw_exception( $this->_remote_file." is not available with proxy" );
+ } else {
+ if ( $this->_use_proxy_auth == true ) {
+ fputs($fp, "GET ".$this->_remote_file." HTTP/1.0\r\nUser-Agent: Fase4 RDF-Reader/1.40 modified by Quix0r\r\n\r\n");
+ } else {
+ fputs($fp, "GET ".$this->_remote_file." HTTP/1.0\r\nUser-Agent: Fase4 RDF-Reader/1.40 modified by Quix0r\r\nProxy-Authorization: Basic ".base64_encode("$this->_pname:$this->_ppasswd") ."\r\n\r\n");
+ }
+ }
+
+
+ for ( $i = 0; !feof ($fp) ; $i++)
+ {
+ $usable_data[$i] = "";
+ $usable_data[$i] = fgets($fp,4096);
+
+ // PARSE HEADER ---- first line has to be <?xml, second rdf or rss, and third is blank
+
+ // strstr did not fit (ask Rasmus why), so we compare each character
+ if ( ($usable_data[$i][0] == "<" ) &&
+ ($usable_data[$i][1] == "?" ) &&
+ ($usable_data[$i][2] == "x" ) &&
+ ($usable_data[$i][3] == "m" ) &&
+ ($usable_data[$i][4] == "l" ) ) {
+ $usable_data[0] = $usable_data[$i]; // save current field
+ $i = 1; // just reset array to start
+ }
+
+ // there seems to be proxystuff after the <?xml....we delete this
+ if ( (
+ ($usable_data[$i][0] == "<" ) &&
+ ($usable_data[$i][1] == "r" ) &&
+ ($usable_data[$i][2] == "d" ) &&
+ ($usable_data[$i][3] == "f" ) &&
+ ($usable_data[$i][4] == ":" )
+ )
+ ||
+ (
+ ($usable_data[$i][0] == "<" ) &&
+ ($usable_data[$i][1] == "r" ) &&
+ ($usable_data[$i][2] == "s" ) &&
+ ($usable_data[$i][3] == "s" )
+ )
+ ) {
+
+ $usable_data[1] = $usable_data[$i]; // save current field
+ $usable_data[2] = "\n";
+ $i = 2; // just reset array to start
+ }
+ }
+
+ fclose($fp);
+ return $usable_data;
+ } else {
+ if (substr($this->_remote_file, 0, 7) != "http://") {
+ $this->_throw_exception( "Cannot find http:// in ".$this->_remote_file."!" );
+ return "";
+ } else {
+ // Extract host information
+ $host = substr($this->_remote_file, 7);
+ // Extract the GET part
+ $get = "/";
+ if (strpos($host, "/") > 0) {
+ $get = substr($host, strpos($host, "/"));
+ $host = substr($host, 0, strpos($host, "/"));
+ }
+ // Extract port
+ $port = "80";
+ if (strpos($host, ":") > 0) {
+ $port = substr($host, (strpos($host, ":") + 1));
+ $host = substr($host, 0, (strpos($host, ":") - 1));
+ }
+
+ // Start connection to server
+ $fp = fsockopen($host, $port);
+ if (!$fp) {
+ $this->_throw_exception( $this->_remote_file." is maybe not available." );
+ return "";
+ }
+ // Repare request line
+ $request = sprintf("GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Fase4 RDF-Reader/1.40 modified by Quix0r\r\n\r\n", $get, $host);
+ // Send request out
+ fputs($fp, $request);
+ $reply = ""; $isContent = false; $dummy = "";
+ // Read reply
+ while ( !feof($fp) ) {
+ $read = trim(fgets($fp, 4096));
+ if (substr($read, 0, 5) == "<?xml" || $isContent) {
+ // Add content
+ $reply[] = $read;
+ $isContent = true;
+ } else {
+ // Put in dummy
+ $dummy[] = $read;
+ }
+ $i++;
+ }
+ if ((count($dummy) > 0) && (count($reply) == 0) && (!$isContent)) {
+ // Transfer content from dummy
+ $reply = $content;
+ }
+ fclose($fp);
+ //die(htmlentities($reply));
+ return $reply;
+ }
+ }
+ } // END _rdf_data()
+} // END class
+?>