-//
-// +----------------------------------------------------------------------+
-// | 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 |
-// +----------------------------------------------------------------------+
+/*
+ * +----------------------------------------------------------------------+
+ * | 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 |
+ * +----------------------------------------------------------------------+
+ */
/**
* 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
/**
* 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
- 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);
- * 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'
$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().');
$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().');
* @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).
* @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
- } 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->_depth[$this->get_parser_id($parser)] = '0';
}
$this->_depth[$this->get_parser_id($parser)]++;
array_push($this->_tags, $name);
$this->_depth[$this->get_parser_id($parser)] = '0';
}
$this->_depth[$this->get_parser_id($parser)]++;
array_push($this->_tags, $name);
$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'];
}
$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'];
}
$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->_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\">".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";
$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";
$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 .= ">".$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";
* @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.
* @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
+ * @see _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags, _item, _output, _display_opt
- 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']) {
$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 .= ">".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>\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";
$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";
$this->_output .= ">".$this->_cut_string($this->_item['link'])."</a>\n";
$this->_output .= "</td></tr>\n";
$this->_output .= "</table></td></tr>\n";
$this->_output .= ">".$this->_cut_string($this->_item['link'])."</a>\n";
$this->_output .= "</td></tr>\n";
$this->_output .= "</table></td></tr>\n";
$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 .= "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";
* @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.
* @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
+ * @see _parse_mode, _item, _tags, _depth, _citem, _ctags, _cdepth
- $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') {
$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') {
- '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"
- if($this->_use_dynamic_display == true) {
- $_rdf = @implode(' ', $this->_rdf_data()); // -> proxy
- if(!$_rdf) {
- $this->_throw_exception( $this->_remote_file.' is not available' );
+ if ($this->_use_dynamic_display == TRUE) {
+ $_rdf = implode(' ', $this->_rdf_data()); // -> proxy
+ if (!$_rdf) {
+ $this->_throw_exception($this->_remote_file.' is not available');
+ } 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);
+ }
- $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)));
- 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;
+ 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.'<br /<br />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.'<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;
- 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."<br />\n<br />\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."<br />\n<br />\nException at Line: ".__LINE__);
+ return FALSE;
+ } elseif (!unlink($dir->path . $file)) {
+ $this->_throw_exception("Unable to unlink ".$dir->path . $file."<br />\n<br />\nException at Line: ".__LINE__);
+ return FALSE;
*/
function _garbage_collection()
{
srand((double) microtime() * 1000000);
if (mt_rand(1, 100) <= $this->gc_probability) {
$dir = dir($this->_cache_dir);
*/
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);
+ }
- * @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) {
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");
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");
$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
$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' ) ) {
+ 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
$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] == ':' )
+ 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[$i][0] == '<') &&
+ ($usable_data[$i][1] == 'r') &&
+ ($usable_data[$i][2] == 's') &&
+ ($usable_data[$i][3] == 's')
// Extract the GET part
$get = '/';
if (strpos($host, '/') > 0) {
$get = substr($host, strpos($host, '/'));
$host = substr($host, 0, strpos($host, '/'));
// 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));
// Extract port
$port = '80';
if (strpos($host, ':') > 0) {
$port = substr($host, (strpos($host, ':') + 1));
$host = substr($host, 0, (strpos($host, ':') - 1));
$read = trim(fgets($fp, 4096));
if (substr($read, 0, 5) == '<?xml' || $isContent) {
// Add content
$reply[] = $read;
$read = trim(fgets($fp, 4096));
if (substr($read, 0, 5) == '<?xml' || $isContent) {
// Add content
$reply[] = $read;