X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Frdf.class.php;h=a30a4e5b19a67b10cc574653a00f7965cac9d7a3;hb=a524135c24dd0a8fa359c9a92399467d50fd69e0;hp=78c7e95fbbd267e132e9a4d5745f6161b6b44615;hpb=dba0db3d371da5a17ca7da6a8cde2596251660b7;p=mailer.git diff --git a/inc/classes/rdf.class.php b/inc/classes/rdf.class.php index 78c7e95fbb..a30a4e5b19 100644 --- a/inc/classes/rdf.class.php +++ b/inc/classes/rdf.class.php @@ -1,35 +1,36 @@ | -// | | -// | Proxy and authentication methods added by: | -// | Marco Kraus | -// | | -// | Decoding of data by htmlentities or utf8_decode added by: | -// | Roland Haeder | -// | | -// +----------------------------------------------------------------------+ -// | Ref: | -// | @link http://www.fase4.com/rdf/ Latest release | -// +----------------------------------------------------------------------+ +/* + * +----------------------------------------------------------------------+ + * | 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 | + * | | + * | Proxy and authentication methods added by: | + * | Marco Kraus | + * | | + * | Decoding of data by htmlentities or utf8_decode added by: | + * | Roland Haeder | + * | | + * +----------------------------------------------------------------------+ + * | Ref: | + * | @link http://www.fase4.com/rdf/ Latest release | + * +----------------------------------------------------------------------+ + */ /** * Class RSS Parser @@ -41,7 +42,7 @@ * @copyright Copyright (c) 2001 fase4.com. All rights reserved. * @author Stefan Saasen * @author Roland Haeder - * @version 1.7 ($Date$Revision: 856 $ + * @version 1.7 * @access public */ @@ -61,14 +62,14 @@ class fase4_rdf { * @access private * @var boolean */ - var $_use_nl2br = true; + 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 - * - Use non of both + * - Use none of both * * @access private * @var string @@ -125,7 +126,7 @@ class fase4_rdf { * @see set_proxy() * @var bool */ - var $_use_proxy = false; + var $_use_proxy = FALSE; /** * just a flag for checking if proxy-support with authentication @@ -136,7 +137,7 @@ class fase4_rdf { * @see set_proxy() * @var boolean */ - var $_use_proxy_auth = false; + var $_use_proxy_auth = FALSE; /** * The time the Files will be cached (in seconds). @@ -160,10 +161,10 @@ class fase4_rdf { * @access private * @var boolean */ - var $_use_cached_file = true; + var $_use_cached_file = TRUE; /** - * (fast|normal) depends on _use_dynamic_display(). _use_dynamic_display( TRUE ) -> 'normal', otherwise 'fast' + * (fast|normal) depends on _use_dynamic_display(). _use_dynamic_display(TRUE) -> 'normal', otherwise 'fast' * * @access private * @var string @@ -192,7 +193,7 @@ class fase4_rdf { * @access private * @var boolean */ - var $_cache_dir_ok = false; + var $_cache_dir_ok = FALSE; /** * Type of the file to be parsed (RSS or RDF). @@ -239,7 +240,7 @@ class fase4_rdf { * @access private * @var array */ - var $_use_dynamic_display = false; + var $_use_dynamic_display = FALSE; /** * count @@ -255,7 +256,7 @@ class fase4_rdf { * @access private * @var boolean */ - var $_max_count = false; + var $_max_count = FALSE; /** * Array containing the content of @@ -311,7 +312,7 @@ class fase4_rdf { * @access private * @var array */ - var $_ctags = array( 'x' ); + var $_ctags = array('x'); /** * Array containing the Channel content. Just For internal XML Parser Purposes. @@ -335,7 +336,7 @@ class fase4_rdf { * @access private * @var array */ - var $_tags = array( 'x' ); // Array + var $_tags = array('x'); // Array /** * Garbage collection: probability in percent @@ -354,16 +355,25 @@ class fase4_rdf { var $_output = ''; /** - * @var string + * @var string */ var $_parse_mode = ''; - // Output variable + /** + * Output variable + */ var $out = ''; - // Salt for hashing + /** + * Salt for hashing + */ var $salt = ''; + /** + * Callback function for processing content in finish() method. + */ + var $_finishCallback = NULL; + /** * Constructor of our Class * @@ -372,10 +382,9 @@ class fase4_rdf { * * @access public * @author Stefan Saasen - * @see _refresh + * @see _refresh */ - function fase4_rdf() - { + function fase4_rdf () { // default Value, to be overwritten in set_refresh() $this->_refresh = (time() - 1200); $this->_clear_cItems(); @@ -388,11 +397,10 @@ class fase4_rdf { * @access public * @author Stefan Saasen * @param string $rdf RDF File (Location) - * @return string Displays RDF Content ( using _display() ) - * @see _remote_file, cache() + * @return string Displays RDF Content (using _display()) + * @see _remote_file, cache() */ - function parse_RDF( $rdf ) - { + function parse_RDF ($rdf) { unset($this->_array_item); $this->_remote_file = $rdf; $this->out .= ""; @@ -401,7 +409,7 @@ class fase4_rdf { $this->out .= ""; $this->_output = ''; $this->_item_count = '0'; - return true; + return TRUE; } /** @@ -410,18 +418,28 @@ class fase4_rdf { * @access public * @author Stefan Saasen * @param string $rdf RDF File (Location) - * @return string Displays RDF Content ( using _display() ) - * @see _remote_file, cache() + * @return string Displays RDF Content (using _display()) + * @see _remote_file, cache() */ - function finish($return = false) { + function finish ($return = FALSE) { + // Replace dollar chars as they may cause problems $this->out = str_replace('$', '$', $this->out); - if (!$return) { - echo $this->out; + // Is the call-back enabled? + if ((!empty($this->out)) && (!is_null($this->_finishCallback)) && (is_callable($this->_finishCallback))) { + // Then call it + $this->out = call_user_func($this->_finishCallback, $this->out); + } // END - if + + // Do garbage collection + $this->_garbage_collection(); + + // Return or output? + if ($return === FALSE) { + print($this->out); } else { return $this->out; } - $this->_garbage_collection(); } /** @@ -429,19 +447,19 @@ class fase4_rdf { * * 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' + * 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 * @param string $rdf RDF File (Location) - * @return string Displays RDF Content ( using _display() ) - * @see _remote_file, cache() + * @return string Displays RDF Content (using _display()) + * @see _remote_file, cache() */ - function use_dynamic_display( $bool ) { + function use_dynamic_display ($bool) { $this->_use_dynamic_display = $bool; - return true; + return TRUE; } /** @@ -452,7 +470,7 @@ class fase4_rdf { * @param string $data RDF File XML Data * @see _clear_Items() */ - function _parse_xRDF( $data ) { + function _parse_xRDF($data) { $this->_clear_Items(); $xml_parser = xml_parser_create(); xml_set_object($xml_parser,$this); @@ -477,14 +495,14 @@ class fase4_rdf { * @return boolean * @see _refresh */ - function set_refresh( $seconds ) { + function set_refresh($seconds) { $this->_refresh = (time() - $seconds); - return true; + return TRUE; } - function set_salt( $saltPara ) { + function set_salt ($saltPara) { $this->salt = $saltPara; - return true; + return TRUE; } /** @@ -493,13 +511,12 @@ class fase4_rdf { * @access public * @param int $int No of max s * @author Stefan Saasen - * @return boolean - * @see _max_count, _endElement() + * @return boolean + * @see _max_count, _endElement() */ - function set_max_item( $int ) - { + function set_max_item ($int) { $this->_max_count = $int; - return true; + return TRUE; } /** @@ -508,12 +525,11 @@ class fase4_rdf { * @access public * @author Stefan Saasen * @param string $dir Path to Directory. - * @return boolean - * @see _cache_dir + * @return boolean + * @see _cache_dir */ - function set_CacheDir( $dir ) - { - if(substr($dir, -1) != '/') { + function set_CacheDir ($dir) { + if (substr($dir, -1) != '/') { $dir = $dir.'/'; } $this->_cache_dir = $dir; @@ -526,10 +542,9 @@ class fase4_rdf { * @param string $msg Message to display on failure * @author Stefan Saasen */ - function _throw_exception( $msg ) - { + function _throw_exception ($msg) { $this->out .= "
fase4 RDF Error: ".$msg."
"; - return true; + return TRUE; } /** @@ -539,7 +554,7 @@ class fase4_rdf { * @author Stefan Saasen * @see _item */ - function _clear_Items( ) { + function _clear_Items() { $this->_item = array( 'title' => '', 'link' => '', @@ -559,7 +574,7 @@ class fase4_rdf { * @author Stefan Saasen * @see _item */ - function _clear_cItems( ) { + function _clear_cItems() { $this->_citem = array( 'title' => '', 'link' => '', @@ -594,36 +609,36 @@ class fase4_rdf { * @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 + * @see _get_ChannelData(), _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags */ - function _startElement($parser, $name, $attrs) { + function _startElement ($parser, $name, $attrs) { // We have to determine, which type of xml data we have to parse - if($name == 'rss') { + if ($name == 'rss') { $this->_type = 'rss'; - } elseif($name == 'rdf:RDF' OR $name == 'rdf') { + } elseif ($name == 'rdf:RDF' || $name == 'rdf') { $this->_type = 'rdf'; } - if ( $name == 'channel' AND $this->_type != 'rdf' ) { + if ($name == 'channel' && $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 ); + } 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[$this->get_parser_id($parser)] ) ) { + if (!isset($this->_depth[$this->get_parser_id($parser)])) { $this->_depth[$this->get_parser_id($parser)] = '0'; } $this->_depth[$this->get_parser_id($parser)]++; array_push($this->_tags, $name); - if( !isset( $this->_cdepth[$this->get_parser_id($parser)] ) ) { + if (!isset($this->_cdepth[$this->get_parser_id($parser)])) { $this->_cdepth[$this->get_parser_id($parser)] = '0'; } $this->_cdepth[$this->get_parser_id($parser)]++; @@ -636,17 +651,16 @@ class fase4_rdf { * @access private * @author Stefan Saasen * @param mixed $parser a reference to the XML parser calling the handler. - * @see _output, _display_opt, _citem + * @see _output, _display_opt, _citem */ - function _get_ChannelData( $parser ) - { + 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 + if (empty($this->_display_opt['channel']) || $this->_display_opt['channel'] != 'hidden') { $this->_output .= "\n"; $this->_output .= "\n"; @@ -654,14 +668,14 @@ class fase4_rdf { $this->_output .= "\n"; $this->_output .= "\n"; $this->_output .= "\n"; $this->_output .= "\n"; @@ -681,9 +695,9 @@ class fase4_rdf { * @author Stefan Saasen * @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 + * @see _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags, _item, _output, _display_opt */ - function _endElement($parser, $name) { + function _endElement ($parser, $name) { array_pop($this->_tags); $this->_depth[$this->get_parser_id($parser)]--; array_pop($this->_ctags); @@ -695,15 +709,15 @@ class fase4_rdf { } 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']) { + if (empty($this->_max_count) || $this->_item_count < $this->_max_count) { + if ($this->_item['title'] != $this->_item['description'] + && $this->_item['description']) { // word-wrapping added by Roland Haeder if (($this->_word_wrap > 0) && (strlen($this->_item['description']) > $this->_word_wrap)) { // Switch off _use_nl2br - $this->_use_nl2br = false; + $this->_use_nl2br = FALSE; // First remove all \n $this->_item['description'] = str_replace('\n', ' ', $this->_item['description']); // Wrap with
\n @@ -719,7 +733,7 @@ class fase4_rdf { if ($this->_use_nl2br) $this->_item['description'] = nl2br($this->_item['description']); $this->_output .= "
\n"; $this->_output .= "\n"; // we just display the
if there is a description @@ -727,7 +741,7 @@ class fase4_rdf { } else { $this->_output .= "\n"; } @@ -743,12 +757,12 @@ class fase4_rdf { break; case 'image': - if(isset($this->_display_opt['image']) && ($this->_display_opt['image'] != 'hidden') && $this->_item['url']) { + if (isset($this->_display_opt['image']) && ($this->_display_opt['image'] != 'hidden') && $this->_item['url']) { $this->_output .= "\n"; @@ -760,28 +774,28 @@ class fase4_rdf { 'height' => $this->_item['height'] ); $this->_clear_Items(); - } elseif( isset($this->_display_opt['image'] ) && ($this->_display_opt['image'] == 'hidden') ) { + } 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'] != '') { + if (isset($this->_display_opt['channel']) && $this->_display_opt['channel'] != 'hidden' && $this->_item['title'] != '') { $this->_output .= "\n"; @@ -797,10 +811,10 @@ class fase4_rdf { break; case 'textinput': - if(isset($this->_display_opt['textinput']) && ($this->_display_opt['textinput'] != 'hidden') && $this->_item['name'] && $this->_item['link']) { + if (isset($this->_display_opt['textinput']) && ($this->_display_opt['textinput'] != 'hidden') && $this->_item['name'] && $this->_item['link']) { $this->_output .= "
".strip_tags($this->_citem['description'], ', ')."
 
\n"; - if(isset($this->_display_opt['build']) && $this->_display_opt['build'] != 'hidden') { - if($this->_citem['lastBuildDate']){$this->_output .= 'build: '. $this->_citem['lastBuildDate'].'
';} + if (isset($this->_display_opt['build']) && $this->_display_opt['build'] != 'hidden') { + if ($this->_citem['lastBuildDate']) { $this->_output .= 'build: '. $this->_citem['lastBuildDate'].'
';} } - if(isset($this->_display_opt['cache_update']) && $this->_display_opt['cache_update'] != 'hidden' && ( $_update = $this->get_cache_update_time()) ) { + if (isset($this->_display_opt['cache_update']) && $this->_display_opt['cache_update'] != 'hidden' && ($_update = $this->get_cache_update_time())) { $this->_output .= 'cache update: '.$_update."
\n"; } $this->_output .= "_citem['link']."\" "; - if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } + if (isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= ">".$this->_cut_string($this->_citem['link']) . ''; $this->_output .= "

".$this->_item['description']."
\n"; $this->_output .= "_item["link"]."\" "; - if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } + if (isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= ">".$this->_item["title"]."
\n"; $this->_output .= "_item['link']."\" "; - if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } + if (isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= ">_item['url']."\""; - if(isset($this->_item['width']) && isset($this->_item['height'])) { + 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\" />
\n"; $this->_output .= "\n"; $this->_output .= "\n"; $this->_output .= "\n"; $this->_output .= "\n"; $this->_output .= "\n"; $this->_output .= "
".htmlspecialchars($this->_item['title'])."
".strip_tags($this->_item['description'], ', ')."
 
\n"; - if($this->_display_opt['build'] != 'hidden') { - if($this->_item['lastBuildDate']){$this->_output .= 'build: '. $this->_item['lastBuildDate'].'
';} + if ($this->_display_opt['build'] != 'hidden') { + if ($this->_item['lastBuildDate']) { $this->_output .= 'build: '. $this->_item['lastBuildDate'].'
';} } - if($this->_display_opt['cache_update'] != 'hidden' && ( $_update = $this->get_cache_update_time()) ) { + if ($this->_display_opt['cache_update'] != 'hidden' && ($_update = $this->get_cache_update_time())) { $this->_output .= 'cache update: '.$_update."
\n"; } $this->_output .= "_item['link']."\" "; - if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } + if (isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= ">".$this->_cut_string($this->_item['link'])."\n"; $this->_output .= "
\n"; $this->_output .= "
_item['link']."\" "; - if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } + if (isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; } $this->_output .= "method=\"get\">\n"; $this->_output .= "
".$this->_item['title']."
"; $this->_output .= strip_tags($this->_item['description'], ', ')."

\n"; @@ -815,7 +829,7 @@ class fase4_rdf { 'description' => $this->_item['description'] ); $this->_clear_Items(); - } elseif( isset($this->_display_opt['textinput']) && ($this->_display_opt['textinput'] == 'hidden') ) { + } elseif (isset($this->_display_opt['textinput']) && ($this->_display_opt['textinput'] == 'hidden')) { $this->_clear_Items(); } @@ -831,8 +845,7 @@ class fase4_rdf { * @return array * @see _array_channel */ - function get_array_channel( ) - { + function get_array_channel () { return $this->_array_channel; } @@ -844,8 +857,7 @@ class fase4_rdf { * @return array * @see _array_item */ - function get_array_item( ) - { + function get_array_item () { return $this->_array_item; } @@ -857,8 +869,7 @@ class fase4_rdf { * @return array * @see _array_textinput */ - function get_array_textinput( ) - { + function get_array_textinput () { return $this->_array_textinput; } @@ -891,8 +902,7 @@ class fase4_rdf { * @return array * @see _array_image */ - function get_array_image( ) - { + function get_array_image() { return $this->_array_image; } @@ -903,13 +913,11 @@ class fase4_rdf { * @author Stefan Saasen * @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 + * @see _parse_mode, _item, _tags, _depth, _citem, _ctags, _cdepth */ - function _parseData($parser, $text) - { + function _parseData($parser, $text) { // Deocing mode added by Roland Haeder - switch ($this->_decoding_mode) - { + switch ($this->_decoding_mode) { case 'utf8_decode': $text = utf8_decode($text); break; @@ -919,18 +927,18 @@ class fase4_rdf { break; } - $clean = preg_replace("/\s/", "", $text); + $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[$this->get_parser_id($parser)]]]) && - $this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]] ) { + $text = preg_replace("/^\s+/", '', $text)."\n"; + if ($this->_parse_mode == 'all') { + if (isset($this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]]) && + $this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]]) { $this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]] .= $text; } else { $this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]] = $text; } } elseif (isset($this->_parse_mode) && $this->_parse_mode == 'channel') { - if ( isset($this->_citem[$this->_ctags[$this->_cdepth[$this->get_parser_id($parser)]]]) ) { + if (isset($this->_citem[$this->_ctags[$this->_cdepth[$this->get_parser_id($parser)]]])) { $this->_citem[$this->_ctags[$this->_cdepth[$this->get_parser_id($parser)]]] .= $text; } else { $this->_citem[$this->_ctags[$this->_cdepth[$this->get_parser_id($parser)]]] = $text; @@ -946,16 +954,15 @@ class fase4_rdf { * @access public * @author Stefan Saasen * @param array $options - * @see _display_opt + * @see _display_opt */ - function set_Options( $options = '' ) - { - if(is_array( $options )) { + function set_Options ($options = NULL) { + if (is_array($options)) { $this->_display_opt = $options; - return true; + return TRUE; } else { unset($this->_display_opt); - return false; + return FALSE; } } @@ -965,12 +972,11 @@ class fase4_rdf { * @access public * @author Stefan Saasen * @param int $width attribute width in tag - * @see _table_width + * @see _table_width */ - function set_table_width( $width = 400 ) - { + function set_table_width ($width = 400) { $this->_table_width = $width; - return true; + return TRUE; } /** @@ -982,15 +988,15 @@ class fase4_rdf { * @access public * @author Stefan Saasen * @return array $options - * @see _display_opt + * @see _display_opt */ - function get_Options() { + 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" + '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; } @@ -1002,58 +1008,69 @@ class fase4_rdf { * @author Stefan Saasen * @param string $rdf RDF File (Location) * @return string XML Presentation of parsed RDF File - * @see _cached_file, _remote_file, _cache_dir, _refresh, _update_cache() + * @see _cached_file, _remote_file, _cache_dir, _refresh, _update_cache() */ - function cache() - { + function cache () { // checks if the cache directory already exists // if not, the cache directory will be created - if(!$this->_cache_dir_ok) { + 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) . '.cache'; + + if ($this->_use_dynamic_display == TRUE) { + $this->_cached_file = md5('dynamic' . $this->salt.$this->_remote_file) . '.rss'; $this->_cache_type = 'normal'; } else { - $this->_cached_file = md5($this->salt.$this->_remote_file) . '.cache'; + $this->_cached_file = md5($this->salt . $this->_remote_file) . '.rss'; $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)) { + 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; + $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) { + if ($this->_use_dynamic_display == TRUE) { $_rdf = implode(' ', $this->_rdf_data()); // -> proxy - if(!$_rdf) { - $this->_throw_exception( $this->_remote_file.' is not available' ); + if (!$_rdf) { + $this->_throw_exception($this->_remote_file.' is not available'); } - $this->_parse_xRDF( $_rdf ); - $this->_update_cache( $_rdf ); + $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' ); + if (!$_rdf) { + $this->_throw_exception($this->_remote_file.' is not available'); } - $this->_parse_xRDF( $_rdf ); - $this->_update_cache( $this->_output ); + $this->_parse_xRDF($_rdf); + $this->_update_cache($this->_output); + $data = $this->_output; + } + } elseif (defined('__SECURITY') && function_exists('readFromFile')) { + // Use readFromFile() from mailer project + $this->_use_cached_file = TRUE; + if ($this->_use_dynamic_display == TRUE) { + $this->_parse_xRDF(readFromFile($_cache_f)); $data = $this->_output; + } else { + $data = readFromFile($_cache_f); } } 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)) ); + $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 trimmed data return trim($data); } // END cache() @@ -1063,34 +1080,34 @@ class fase4_rdf { * @access private * @author Stefan Saasen * @param string $dir Path to Directory. - * @return boolean - * @see _cache_dir, _cache_dir_ok + * @return boolean + * @see _cache_dir, _cache_dir_ok */ function _create_cache_dir() { $path = ''; - if(!@is_dir($this->_cache_dir)) { + if (!is_dir($this->_cache_dir)) { $arr = explode('/', $this->_cache_dir); $c = count($arr); - if($arr[0]=='') { + if ($arr[0] == '') { $path = '/'; } for($i = '0';$i<$c;$i++) { - if($arr[$i]!='') { + if ($arr[$i]!='') { $path .= $arr[$i].'/'; - if(!@is_dir($path)) { - if(!@mkdir($path, 0777)) { + if (!is_dir($path)) { + if (!mkdir($path, 0777)) { $this->_throw_exception("failed to create directory:".$this->_cache_dir.".

Exception on Line: ".__LINE__); - return false; + return FALSE; } } } } - $this->_cache_dir_ok = true; - return true; + $this->_cache_dir_ok = TRUE; + return TRUE; } else { - $this->_cache_dir_ok = true; - return true; + $this->_cache_dir_ok = TRUE; + return TRUE; } } // END _create_cache_dir() @@ -1100,22 +1117,28 @@ class fase4_rdf { * @access private * @author Stefan Saasen * @param string $rdf RDF File (Location) - * @see _cache_dir, _cached_file, _throw_exception() + * @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.'

Exception at Line: '.__LINE__ ); - return false; + function _update_cache ($content = '') { + if (defined('__SECURITY') && function_exists('writeToFile')) { + // Use mailer-project function + return writeToFile($this->_cache_dir.$this->_cached_file, $content); } - if (fwrite( $_local, $content) === false) { - $this->_throw_exception( 'Cannot write to '.$this->_cached_file.'
Exeception at Line: '.__LINE__); - return false; + + $_local = @fopen($this->_cache_dir.$this->_cached_file, 'w'); + if (!$_local) { + $this->_throw_exception('Cannot open '.$this->_cached_file.'

Exception at Line: '.__LINE__); + return FALSE; } - fclose( $_local ); - @chmod( $this->_cache_dir.$this->_cached_file, 0666); - return true; + + if (fwrite($_local, $content) === FALSE) { + $this->_throw_exception('Cannot write to '.$this->_cached_file.'
Exeception at Line: '.__LINE__); + return FALSE; + } + + fclose($_local); + @chmod($this->_cache_dir.$this->_cached_file, 0666); + return TRUE; } // END _update_cache() /** @@ -1123,11 +1146,10 @@ class fase4_rdf { * * @access public * @author Stefan Saasen - * @return string Date/Time of last Update - * @see _cache_dir, _cached_file + * @return string Date/Time of last Update + * @see _cache_dir, _cached_file */ - function get_cache_update_time() - { + 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() @@ -1137,11 +1159,10 @@ class fase4_rdf { * @access public * @author Stefan Saasen * @param string $rdf RDF File (Location) - * @return string Displays RDF Content ( using _display() ) - * @see _remote_file, cache() + * @return string Displays RDF Content (using _display()) + * @see _remote_file, cache() */ - function get_CacheType() - { + function get_CacheType() { return $this->_cache_type; } @@ -1151,10 +1172,9 @@ class fase4_rdf { * @access public * @author Stefan Saasen * @return array $options - * @see _use_cached_file + * @see _use_cached_file */ - function is_cachedFile() - { + function is_cachedFile () { return $this->_use_cached_file; } @@ -1167,22 +1187,24 @@ class fase4_rdf { * * @access public * @author Stefan Saasen - * @see _cache_dir + * @see _cache_dir */ - function clear_cache() - { + function clear_cache () { $dir = dir($this->_cache_dir); - while($file=$dir->read()) { + while($file = $dir->read()) { // Exclude directories - if (is_file($dir->path.$file) && substr($file, -6, 6) != '.cache' && substr($file, -4, 4) != '.log') { - if(!@unlink($dir->path.$file)) { - $this->_throw_exception("Unable to unlink ".$dir->path.$file."
\n
\nException at Line: ".__LINE__ ); - return false; + if (is_file($dir->path . $file) && substr($file, -4, 4) == '.rss') { + if ((defined('__SECURITY') && function_exists('removeFile')) && (!removeFile($dir->path . $file))) { + $this->_throw_exception("removeFile() was unable to unlink ".$dir->path . $file."
\n
\nException at Line: ".__LINE__); + return FALSE; + } elseif (!unlink($dir->path . $file)) { + $this->_throw_exception("Unable to unlink ".$dir->path . $file."
\n
\nException at Line: ".__LINE__); + return FALSE; } // END - if } // END - if } // END - while $dir->close(); - return true; + return TRUE; } // END clear_cache() /** @@ -1193,10 +1215,10 @@ class fase4_rdf { * @param int $str_len length of the returned String (overall length including '... ') * @return string Cut String */ - function _cut_string( $string, $str_len = '30' ) + function _cut_string($string, $str_len = '30') { - if(strlen(trim($string))>$str_len) { - $string = substr( trim($string) , 0, $str_len - 4); + if (strlen(trim($string))>$str_len) { + $string = substr(trim($string) , 0, $str_len - 4); $string .= ' ...'; } return $string; @@ -1207,16 +1229,22 @@ class fase4_rdf { * * @access private * @author Stefan Saasen - * @see _cache_dir, gc_probability, gc_maxlifetime + * @see _cache_dir, gc_probability, gc_maxlifetime */ function _garbage_collection() { srand((double) microtime() * 1000000); if (mt_rand(1, 100) <= $this->gc_probability) { $dir = dir($this->_cache_dir); - while($file=$dir->read()) { - if (is_file($dir->path.$file) && substr($file, -6, 6) != '.cache' && substr($file, -4, 4) != '.log' && filemtime($dir->path.$file) <= time() - $this->_refresh ) { - @unlink($dir->path.$file); + while($file = $dir->read()) { + if ((is_file($dir->path . $file)) && (substr($file, -4, 4) == '.rss') && (filemtime($dir->path . $file) <= time() - $this->_refresh)) { + if (defined('__SECURITY') && function_exists('removeFile')) { + // Use mailer-project's function + removeFile($dir->path . $file); + } else { + // Use PHP's function + unlink($dir->path . $file); + } } // END - if } $dir->close(); @@ -1235,7 +1263,7 @@ class fase4_rdf { */ function set_proxy($phost, $pport) { - $this->_use_proxy = true; + $this->_use_proxy = TRUE; if ($phost != '') $this->_phost = $phost; @@ -1252,9 +1280,9 @@ class fase4_rdf { * @param string $ppaswd Password * @author Marco Kraus */ - function set_proxy_auth( $pname, $ppasswd ) + function set_proxy_auth($pname, $ppasswd) { - $this->_use_proxy_auth = true; + $this->_use_proxy_auth = TRUE; if ($pname != '') $this->_pname = $pname; @@ -1272,20 +1300,25 @@ class fase4_rdf { * * @access private * @author Marco Kraus - * @return array - * @see _use_proxy, cache() - */ - function _rdf_data() - { - if ( $this->_use_proxy == true ) - { + * @return array + * @see _use_proxy, cache() + */ + function _rdf_data () { + // Init output + $output = array(); + + // Use mailer-project's function or own code? + if (defined('__SECURITY') && function_exists('sendHttpGetRequest')) { + // Use mailer-project instead (see http://mxchange.org) + $output = sendHttpGetRequest($this->_remote_file, array(), TRUE); + } elseif ($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' ); + $this->_throw_exception($this->_remote_file.' is not available with proxy'); } else { - if ( $this->_use_proxy_auth == true ) { + 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"); @@ -1293,37 +1326,37 @@ class fase4_rdf { } - for ( $i = '0'; !feof ($fp) ; $i++) + for ($i = '0'; !feof ($fp) ; $i++) { - $usable_data[$i] = ""; + $usable_data[$i] = ''; $usable_data[$i] = fgets($fp,4096); // PARSE HEADER ---- first line has to be _remote_file, 0, 7) != 'http://') { - $this->_throw_exception( 'Cannot find http:// in '.$this->_remote_file.'!' ); - return ''; + $this->_throw_exception('Cannot find http:// in '.$this->_remote_file.'!'); + return array(); } 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, '/')); - } + } // END - if + // Extract port $port = '80'; if (strpos($host, ':') > 0) { $port = substr($host, (strpos($host, ':') + 1)); $host = substr($host, 0, (strpos($host, ':') - 1)); - } + } // END - if // Start connection to server $fp = fsockopen($host, $port); if (!$fp) { - $this->_throw_exception( $this->_remote_file.' is maybe not available.' ); - return ''; - } + $this->_throw_exception($this->_remote_file.' is maybe not available.'); + return array(); + } // END - if + // 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 = ''; + $reply = ''; $isContent = FALSE; $dummy = ''; + // Read reply $i=0; - while ( !feof($fp) ) { + while (!feof($fp)) { $read = trim(fgets($fp, 4096)); if (substr($read, 0, 5) == ' 0) && (count($reply) == 0) && (!$isContent)) { // Transfer content from dummy $reply = $content; - } + } // END - if + fclose($fp); //die(htmlentities($reply)); - return $reply; + $output = $reply; } } - } // END _rdf_data() -} // END class + + // Exit here + return $output; + } // END _rdf_data() +} // END class + +// [EOF] ?>