]> git.mxchange.org Git - mailer.git/blob - inc/classes/rdf.class.php
Huge rewrite of default parameters, ext-network continued:
[mailer.git] / inc / classes / rdf.class.php
1 <?php
2 /* $Id$ */
3
4 //
5 // +----------------------------------------------------------------------+
6 // | rss Parser                                                           |
7 // | Copyright (c) 2001 Stefan Saasen                                     |
8 // +----------------------------------------------------------------------+
9 // | The contents of this file are subject to the Mozilla Public License  |
10 // | Version 1.1 (the "License"); you may not use this file except in     |
11 // | compliance with the License. You may obtain a copy of the License at |
12 // | http://www.mozilla.org/MPL/                                          |
13 // |                                                                      |
14 // | Software distributed under the License is distributed on an "AS IS"  |
15 // | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  |
16 // | the License for the specific language governing rights and           |
17 // | limitations under the License.                                       |
18 // +----------------------------------------------------------------------+
19 // |                                                                      |
20 // | Maintainer and initial developer:                                    |
21 // | Stefan Saasen <s@fase4.com>                                          |
22 // |                                                                      |
23 // | Proxy and authentication methods added by:                           |
24 // | Marco Kraus <marco.kraus@siemens.com>                                |
25 // |                                                                      |
26 // | Decoding of data by htmlentities or utf8_decode added by:            |
27 // | Roland Haeder <webmaster@mxchange.org>                               |
28 // |                                                                      |
29 // +----------------------------------------------------------------------+
30 // | Ref:                                                                 |
31 // |   @link http://www.fase4.com/rdf/                   Latest release   |
32 // +----------------------------------------------------------------------+
33
34 /**
35  * Class RSS Parser
36  *
37  * This class offers methods to parse RSS Files
38  *
39  * @link      http://www.fase4.com/rdf/ Latest release of this class
40  * @package   rss
41  * @copyright Copyright (c) 2001 fase4.com. All rights reserved.
42  * @author    Stefan Saasen <s@fase4.com>
43  * @author    Roland Haeder <webmaster@mxchange.org>
44  * @version   1.7 ($Date$Revision: 856 $
45  * @access    public
46  */
47
48 class fase4_rdf {
49
50         /**
51          * Word-wrapping mode for description, set it to 0 do disable this feature! Ommits _use_nl2br!
52          *
53          * @access private
54          * @var    integer
55          */
56         var $_word_wrap = '0';
57
58         /**
59          * Wether to recode \n -> <br /> or not in description
60          *
61          * @access private
62          * @var    boolean
63          */
64         var $_use_nl2br = true;
65
66         /**
67          * Sets the decoding mode of the read data (UTF8 scrambles some german umlauts here!)
68          *
69          * "htmlentities" - Use the function htmlentities()
70          * "utf8_decode"  - Use the function ut8_decode() when you have UTF8 encoded text
71          *
72          * @access private
73          * @var    string
74          */
75         var $_decoding_mode = 'utf8_decode';
76
77         /**
78          * If $_link_target is set a target='xxx' attribute in each <a /> and <form accept-charset="utf-8" /> html tag will be added
79          *
80          * Possible values are "_blank", "_content", "_parent", "_self", "_top"
81          *
82          * @access private
83          * @var    string
84          */
85         var $_link_target = '_blank';
86
87         /**
88          * vars for proxy settings - Prox Host
89          *
90          * @access private
91          * @var      string
92          */
93         var $_phost = '';
94
95         /**
96          * vars for proxy settings - Prox Port
97          *
98          * @access private
99          * @var      string
100          */
101         var $_pport = '';
102
103         /**
104          * vars for proxy settings - Prox Username
105          *
106          * @access private
107          * @var      string
108          */
109         var $_pname = '';
110
111         /**
112          * vars for proxy settings - Prox Password
113          *
114          * @access private
115          * @var      string
116          */
117         var $_ppasswd = '';
118
119         /**
120          * just a flag for checking if proxy-support should be enabled
121          * set default to false (will be enabled if set_proxy is called)
122          *
123          * @access   private
124          * @see      set_proxy()
125          * @var      bool
126          */
127         var $_use_proxy = false;
128
129         /**
130          * just a flag for checking if proxy-support with authentication
131          * should be enabled
132          * set default to false (will be enabled if set_proxy is called)
133          *
134          * @access   private
135          * @see      set_proxy()
136          * @var      boolean
137          */
138         var $_use_proxy_auth = false;
139
140         /**
141          * The time the Files will be cached (in seconds).
142          *
143          * @access private
144          * @var    int
145          */
146         var $_refresh = 60;   // int
147
148         /**
149          * The Name of the cached File.
150          *
151          * @access private
152          * @var    string
153          */
154         var $_cached_file = '';   // String
155
156         /**
157          * Indicates whether the cached or the remote file was used.
158          *
159          * @access private
160          * @var    boolean
161          */
162         var $_use_cached_file = true;
163
164         /**
165          * (fast|normal) depends on _use_dynamic_display(). _use_dynamic_display( TRUE ) -> 'normal', otherwise 'fast'
166          *
167          * @access private
168          * @var    string
169          */
170         var $_cache_type = 'fast';
171
172         /**
173          * The Name of the Remote File.
174          *
175          * @access private
176          * @var    string
177          */
178         var $_remote_file = '';
179
180         /**
181          * Path to the Cache Directory.
182          *
183          * @access private
184          * @var    string
185          */
186         var $_cache_dir = 'cache/';  // String
187
188         /**
189          * Indicates whether the Creating of the Cache Directory needs to be done or not.
190          *
191          * @access private
192          * @var    boolean
193          */
194         var $_cache_dir_ok = false;
195
196         /**
197          * Type of the file to be parsed (RSS or RDF).
198          *
199          * The Type depends on the root node
200          *
201          * @access private
202          * @var    string
203          */
204         var $_type = 'rss'; // string (rss or rdf)
205
206         /**
207          * Array of Display Settings.
208          *
209          * Specific Parameters can be set to hidden. These are:
210          * image, channel and textinput. If set to "hidden" those elements won't be displayed.
211          *
212          * @access private
213          * @var    array
214          */
215         var $_display_opt = array(
216                 'build'        => '',
217                 'image'        => '',
218                 'channel'      => '',
219                 'textinput'    => '',
220                 'cache_update' => '',
221                 'sitelink'     => '',
222                 'refid'        => '',
223                 'reflink'      => '',
224         );
225
226         /**
227          * Defines the width attribute in the table that holds the rdf/rss representation
228          *
229          * @access private
230          * @var    int
231          * @see    see_table_width()
232          */
233         var $_table_width = '100%';
234
235         /**
236          * Indicates whether or not to use dynamic Display Settings
237          *
238          * @access private
239          * @var    array
240          */
241         var $_use_dynamic_display = false;
242
243         /**
244          * <item> count
245          *
246          * @access private
247          * @var    int
248          */
249         var $_item_count = '0';
250
251         /**
252          * No of max <item>s
253          *
254          * @access private
255          * @var    boolean
256          */
257         var $_max_count = false;
258
259         /**
260          * Array containing the content of <channel />
261          *
262          * @access private
263          * @var    array
264          */
265         var $_array_channel = array();
266
267         /**
268          * Array containing the content of each <item />
269          *
270          * @access private
271          * @var    array
272          */
273         var $_array_item = array();
274
275         /**
276          * Array containing the content of <textinput />
277          *
278          * @access private
279          * @var    array
280          */
281         var $_array_textinput = array();
282
283         /**
284          * Array containing the content of <image />
285          *
286          * @access private
287          * @var    array
288          */
289         var $_array_image = array();
290
291         /**
292          * Array containing the Channel content. Just For internal XML Parser Purposes.
293          *
294          * @access private
295          * @var    array
296          */
297         var $_citem = array();
298
299         /**
300          * Array containing the Channel Parser Depth. Just For internal XML Parser Purposes.
301          *
302          * @access private
303          * @var    array
304          */
305         var $_cdepth = array();
306
307         /**
308          * Array containing the Channel tags. Just For internal XML Parser Purposes.
309          *
310          * @access private
311          * @var    array
312          */
313         var $_ctags = array( 'x' );
314
315         /**
316          * Array containing the Channel content. Just For internal XML Parser Purposes.
317          *
318          * @access private
319          * @var    array
320          */
321         var $_item = array();   // Array
322
323         /**
324          * Array containing the Channel Parser Depth. Just For internal XML Parser Purposes.
325          *
326          * @access private
327          * @var    array
328          */
329         var $_depth = array();  // Array
330
331         /**
332          * Array containing the tags. Just For internal XML Parser Purposes.
333          *
334          * @access private
335          * @var    array
336          */
337         var $_tags = array( 'x' );  // Array
338
339         /**
340          * Garbage collection: probability in percent
341          *
342          * @var      integer     0 => never
343          * @access   public
344          */
345         var $gc_probability = 1;
346
347         /**
348          * HTML Output
349          *
350          * @var      string
351          * @access   private
352          */
353         var $_output = '';
354
355         /**
356          * @var  string
357          */
358         var $_parse_mode = '';
359
360         // Output variable
361         var $out = '';
362
363         // Salt for hashing
364         var $salt = '';
365
366         /**
367          * Constructor of our Class
368          *
369          * This Method checks if the Cache Directory can be found. Otherwise it tries to creat the Cache Directory at the specified Path.
370          * Additionally the Refresh Time is set to a default Value of 1200s (20 min).
371          *
372          * @access    public
373          * @author    Stefan Saasen <s@fase4.com>
374          * @see          _refresh
375          */
376         function fase4_rdf()
377         {
378                 // default Value, to be overwritten in set_refresh()
379                 $this->_refresh = (time() - 1200);
380                 $this->_clear_cItems();
381                 $this->_clear_Items();
382         }
383
384         /**
385          * This Method starts the parsing of the specified RDF File. The File can be a local or a remote File.
386          *
387          * @access    public
388          * @author    Stefan Saasen <s@fase4.com>
389          * @param     string $rdf    RDF File (Location)
390          * @return    string Displays RDF Content ( using _display() )
391          * @see          _remote_file, cache()
392          */
393         function parse_RDF( $rdf )
394         {
395                 unset($this->_array_item);
396                 $this->_remote_file = $rdf;
397                 $this->out .= "<!-- http://www.fase4.com/rdf/ -->";
398                 $this->out .= "<table width=\"".$this->_table_width."\">";
399                 $this->out .= $this->cache();
400                 $this->out .= "</table>";
401                 $this->_output = '';
402                 $this->_item_count = '0';
403                 return true;
404         }
405
406         /**
407          * This Method is called when all parsing is finished to use the garbage collection
408          *
409          * @access    public
410          * @author    Stefan Saasen <s@fase4.com>
411          * @param     string $rdf    RDF File (Location)
412          * @return    string Displays RDF Content ( using _display() )
413          * @see          _remote_file, cache()
414          */
415         function finish($return = false)
416         {
417                 if (!$return) {
418                         echo $this->out;
419                 } else {
420                         return $this->out;
421                 }
422                 flush();
423                 $this->_garbage_collection();
424         }
425
426         /**
427          * With this method you can decide whether to use the normal cache and dynamic display Options or to use a static cache.
428          *
429          * 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.
430          * In this case you can not modify the display settings.
431          * processing time: ( 1.4792) --> remote file
432          * processing time: ( 0.0313) --> using 'normal cache' with display Modification turned on.
433          * processing time: ( 0.0019) --> using 'fast cache'
434          *
435          * @access    public
436          * @author    Stefan Saasen <s@fase4.com>
437          * @param     string $rdf    RDF File (Location)
438          * @return    string Displays RDF Content ( using _display() )
439          * @see          _remote_file, cache()
440          */
441         function use_dynamic_display( $bool )
442         {
443                 $this->_use_dynamic_display = $bool;
444                 return true;
445         }
446
447         /**
448          * This Method avtually parses the XML data.
449          *
450          * @access    private
451          * @author    Stefan Saasen <s@fase4.com>
452          * @param     string $data    RDF File XML Data
453          * @see       _clear_Items()
454          */
455         function _parse_xRDF( $data )
456         {
457                 $this->_clear_Items();
458                 $xml_parser = xml_parser_create();
459                 xml_set_object($xml_parser,$this);
460                 xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);
461                 xml_set_element_handler($xml_parser, '_startElement', '_endElement');
462                 xml_set_character_data_handler($xml_parser, '_parseData');
463                 if (!xml_parse($xml_parser, trim($data))) {
464                         $this->_throw_exception(sprintf("XML error: %s at line %d",
465                         xml_error_string(xml_get_error_code($xml_parser)),
466                         xml_get_current_line_number($xml_parser)).'<br /><br />Exception in function parse_RDF().');
467                 }
468                 xml_parser_free($xml_parser);
469         }
470
471
472         /**
473          * This Methods allows you to set the Refresh Time
474          *
475          * @access    public
476          * @author    Stefan Saasen <s@fase4.com>
477          * @param     int $seconds time files will be cached (in seconds).
478          * @return       boolean
479          * @see          _refresh
480          */
481         function set_refresh( $seconds )
482         {
483                 $this->_refresh = (time() - $seconds);
484                 return true;
485         }
486
487         function set_salt( $saltPara )
488         {
489                 $this->salt = $saltPara;
490                 return true;
491         }
492
493         /**
494          * This Methods allows you to set the No. of <item>s to display
495          *
496          * @access    public
497          * @param     int $int No of max <item>s
498          * @author    Stefan Saasen <s@fase4.com>
499          * @return       boolean
500          * @see          _max_count, _endElement()
501          */
502         function set_max_item( $int )
503         {
504                 $this->_max_count = $int;
505                 return true;
506         }
507
508         /**
509          * This Methods allows you to set the Cache Directory
510          *
511          * @access    public
512          * @author    Stefan Saasen <s@fase4.com>
513          * @param     string $dir Path to Directory.
514          * @return       boolean
515          * @see          _cache_dir
516          */
517         function set_CacheDir( $dir )
518         {
519                 if(substr($dir, -1) != '/') {
520                         $dir = $dir.'/';
521                 }
522                 $this->_cache_dir = $dir;
523         }
524
525         /**
526          * This Method displays Error Messages and terminates the Execution of the Script
527          *
528          * @access    private
529          * @param     string $msg Message to display on failure
530          * @author    Stefan Saasen <s@fase4.com>
531          */
532         function _throw_exception( $msg )
533         {
534                 $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>";
535                 return true;
536         }
537
538         /**
539          * This Method clears the Array containig the Items.
540          *
541          * @access    private
542          * @author    Stefan Saasen <s@fase4.com>
543          * @see       _item
544          */
545         function _clear_Items( ) {
546                 $this->_item = array(
547                         'title'         => '',
548                         'link'          => '',
549                         'description'   => '',
550                         'url'           => '',
551                         'language'      => '',
552                         'pubDate'       => '',
553                         'lastBuildDate' => '',
554                         'width'         => '',
555                         'height'        => ''
556                 );
557         }
558         /**
559          * This Method clears the Array containig the Channel Items.
560          *
561          * @access    private
562          * @author    Stefan Saasen <s@fase4.com>
563          * @see       _item
564          */
565         function _clear_cItems( ) {
566                 $this->_citem = array(
567                         'title'          => '',
568                         'link'           => '',
569                         'description'    => '',
570                         'url'            => '',
571                         'language'       => '',
572                         'copyright'      => '',
573                         'managingEditor' => '',
574                         'webMaster'      => '',
575                         'pubDate'        => '',
576                         'lastBuildDate'  => '',
577                         'category'       => '',
578                         'generator'      => '',
579                         'docs'           => '',
580                         'cloud'          => '',
581                         'ttl'            => '',
582                         'image'          => '',
583                         'textinput'      => '',
584                         'skipHours'      => '',
585                         'skipDays'       => '',
586                         'sitelink'       => '',
587                         'refid'          => '',
588                         'reflink'        => '',
589                 );
590         }
591
592         /**
593          * XML Parser Start Element Handler
594          *
595          * @access    private
596          * @author    Stefan Saasen <s@fase4.com>
597          * @param     mixed  $parser a reference to the XML parser calling the handler.
598          * @param     string $name contains the name of the element for which this handler is called.
599          * @param     string $attrs contains an associative array with the element's attributes (if any).
600          * @see          _get_ChannelData(), _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags
601          */
602         function _startElement($parser, $name, $attrs) {
603                 // We have to determine, which type of xml data we have to parse
604                 if($name == 'rss') {
605                         $this->_type = 'rss';
606                 } elseif($name == 'rdf:RDF' OR $name == 'rdf') {
607                         $this->_type = 'rdf';
608                 }
609
610
611                 if ( $name == 'channel' AND $this->_type != 'rdf' ) {
612                         $this->_parse_mode = 'channel';
613                 } elseif ( ($name=='item')
614                 ||($name=='image')
615                 ||($name=='textinput')
616                 ||(($name=='channel') && ($this->_type != 'rss')) ) {
617                         if($this->_parse_mode=='channel') {
618                                 $this->_get_ChannelData( $parser );
619                         }
620                         $this->_parse_mode = 'all';
621                 }
622
623                 if( !isset( $this->_depth[$this->get_parser_id($parser)] ) ) {
624                         $this->_depth[$this->get_parser_id($parser)] = '0';
625                 }
626                 $this->_depth[$this->get_parser_id($parser)]++;
627                 array_push($this->_tags, $name);
628
629                 if( !isset( $this->_cdepth[$this->get_parser_id($parser)] ) ) {
630                         $this->_cdepth[$this->get_parser_id($parser)] = '0';
631                 }
632                 $this->_cdepth[$this->get_parser_id($parser)]++;
633                 array_push($this->_ctags, $name);
634         }   // END _startElement()
635
636         /**
637          * Retrives the Channel Data in <rss> File
638          *
639          * @access    private
640          * @author    Stefan Saasen <s@fase4.com>
641          * @param     mixed  $parser a reference to the XML parser calling the handler.
642          * @see          _output, _display_opt, _citem
643          */
644         function _get_ChannelData( $parser )
645         {
646                 $this->_citem['link'] = trim($this->_citem['link']);
647                 if (($this->_display_opt['sitelink'] == $this->_citem['link']) && (!empty($this->_display_opt['reflink'])) && (!empty($this->_display_opt['refid'])))
648                 {
649                         $this->_citem['link'] .= $this->_display_opt['reflink'].$this->_display_opt['refid'];
650                 }
651
652                 if( empty($this->_display_opt['channel']) OR
653                 $this->_display_opt['channel'] != 'hidden') {
654                         $this->_output .= "<tr><td>\n";
655                         $this->_output .= "<table border=\"0\" width=\"100%\" class=\"fase4_rdf_meta\" cellspacing=\"5\" cellpadding=\"2\">\n";
656                         $this->_output .= "<tr><td class=\"fase4_rdf_main_title\"><div class=\"fase4_rdf_main_title\">".htmlspecialchars($this->_citem['title'])."</div></td></tr>\n";
657                         $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_citem['description'], '<a>, <img>')."</td></tr>\n";
658                         $this->_output .= "<tr><td>&nbsp;</td></tr>\n";
659                         $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
660                         if(isset($this->_display_opt['build']) && $this->_display_opt['build'] != 'hidden') {
661                                 if($this->_citem['lastBuildDate']){$this->_output .= 'build: '. $this->_citem['lastBuildDate'].'<br />';}
662                         }
663                         if(isset($this->_display_opt['cache_update']) && $this->_display_opt['cache_update'] != 'hidden' && ( $_update = $this->get_cache_update_time()) ) {
664                                 $this->_output .= 'cache update: '.$_update."<br />\n";
665                         }
666                         $this->_output .= "<a href=\"".$this->_citem['link']."\" ";
667                         if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
668                         $this->_output .= ">".$this->_cut_string($this->_citem['link'])."</a>";
669                         $this->_output .= "</td></tr>\n";
670                         $this->_output .= "<tr><td><hr noshade width=\"100%\" size=\"1\"></td></tr>\n";
671                         $this->_output .= "</table></td></tr>";
672                 }
673                 $this->_array_channel = array(
674                         'title'         => $this->_citem['title'],
675                         'link'          => $this->_citem['link'],
676                         'description'   => $this->_citem['description'],
677                         'lastBuildDate' => $this->_citem['lastBuildDate']);
678         }
679
680         /**
681          * XML Parser End Element Handler
682          *
683          * @access    private
684          * @author    Stefan Saasen <s@fase4.com>
685          * @param     mixed  $parser a reference to the XML parser calling the handler.
686          * @param     string $name contains the name of the element for which this handler is called.
687          * @see          _clear_Items(), _type, _parse_mode, _depth, _tags, _cdepth, _ctags, _item, _output, _display_opt
688          */
689         function _endElement($parser, $name) {
690                 array_pop($this->_tags);
691                 $this->_depth[$this->get_parser_id($parser)]--;
692                 array_pop($this->_ctags);
693                 $this->_cdepth[$this->get_parser_id($parser)]--;
694                 $this->_item['link'] = trim($this->_item['link']);
695                 if ((!empty($this->_display_opt['refid'])) && (!empty($this->_item['link'])))
696                 {
697                         if (!ereg('refid=', $this->_item['link'])) $this->_item['link'] .= '?refid=' . $this->_display_opt['refid'];
698                 }
699                 switch ($name) {
700                         case 'item':
701                                 if(empty($this->_max_count) OR $this->_item_count < $this->_max_count) {
702                                         if($this->_item['title'] != $this->_item['description']
703                                         AND $this->_item['description']) {
704
705                                                 // word-wrapping added by Roland Haeder <webmaster@mxchange.org>
706                                                 if (($this->_word_wrap > 0) && (strlen($this->_item['description']) > $this->_word_wrap))
707                                                 {
708                                                         // Switch off _use_nl2br
709                                                         $this->_use_nl2br = false;
710                                                         // First remove all \n
711                                                         $this->_item['description'] = str_replace('\n', ' ', $this->_item['description']);
712                                                         // Wrap with <br />\n
713                                                         $this->_item['description'] = wordwrap($this->_item['description'], $this->_word_wrap, "*<br>\n");
714                                                 }
715                                                 elseif (($this->_word_wrap == '0') && (!$this->_use_nl2br))
716                                                 {
717                                                         // Strip tags out instead when word-wrap is disabled
718                                                         $this->_item['description'] = strip_tags($this->_item['description'], '<a>, <img>');
719                                                 }
720
721                                                 // nl2br added by Roland Haeder <webmaster@mxchange.org>
722                                                 if ($this->_use_nl2br) $this->_item['description'] = nl2br($this->_item['description']);
723
724                                                 $this->_output .= "<tr><td class=\"fase4_rdf_title\"><div class=\"fase4_rdf_title\"><a class=\"fase4_rdf_title\" href=\"".$this->_item['link']."\" ";
725                                                 if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
726                                                 $this->_output .= ">".strip_tags($this->_item['title'], '<a>, <img>').'</a> ('.$this->_item['pubDate'].")</div></td></tr>\n";
727                                                 $this->_output .= "<tr><td class=\"fase4_rdf\">".$this->_item['description']."</td></tr>\n";
728                                                 // we just display the <hr> if there is a description
729                                                 $this->_output .= "<tr><td><hr noshade=\"noshade\" size=\"1\" /></td></tr>\n";
730                                         } else {
731                                                 $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
732                                                 $this->_output .= "<a href=\"".$this->_item["link"]."\" ";
733                                                 if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
734                                                 $this->_output .= ">".$this->_item["title"]."</a></td></tr>\n";
735                                         }
736
737                                         $this->_array_item[] = array(
738                                                 'title'       => $this->_item['title'],
739                                                 'link'        => $this->_item['link'],
740                                                 'description' => $this->_item['description']
741                                         );
742
743                                         ++$this->_item_count;
744                                 }
745                                 $this->_clear_Items();
746                                 break;
747
748                         case 'image':
749                                 if(isset($this->_display_opt['image']) && ($this->_display_opt['image'] != 'hidden') && $this->_item['url']) {
750                                         $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
751                                         $this->_output .= "<a href=\"".$this->_item['link']."\" ";
752                                         if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
753                                         $this->_output .= "><img src=\"".$this->_item['url']."\"";
754                                         if(isset($this->_item['width']) && isset($this->_item['height'])) {
755                                                 $this->_output .= " width=\"".$this->_item['width']."\" height=\"".$this->_item['height']."\"";
756                                         }
757                                         $this->_output .= " alt=\"".$this->_item['title']."\" border=\"0\" /></a></td></tr>\n";
758
759                                         $this->_array_image[] = array(
760                                                 'url'    => $this->_item['url'],
761                                                 'link'   => $this->_item['link'],
762                                                 'width'  => $this->_item['width'],
763                                                 'height' => $this->_item['height']
764                                         );
765                                         $this->_clear_Items();
766                                 } elseif( isset($this->_display_opt['image'] ) && ($this->_display_opt['image'] == 'hidden') ) {
767                                         $this->_clear_Items();
768                                 }
769
770                                 break;
771
772                         case 'channel':
773                                 if(isset($this->_display_opt['channel']) AND $this->_display_opt['channel'] != 'hidden' AND $this->_item['title'] != '') {
774                                         $this->_output .= "<tr><td>\n";
775                                         $this->_output .= "<table border=\"0\" width=\"100%\" class=\"fase4_rdf_meta\" cellspacing=\"5\" cellpadding=\"2\">\n";
776                                         $this->_output .= "<tr><td class=\"fase4_rdf\"><div class=\"fase4_rdf_title\">".htmlspecialchars($this->_item['title'])."</div></td></tr>\n";
777                                         $this->_output .= "<tr><td class=\"fase4_rdf\">".strip_tags($this->_item['description'], '<a>, <img>')."</td></tr>\n";
778                                         $this->_output .= "<tr><td>&nbsp;</td></tr>\n";
779                                         $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
780                                         if($this->_display_opt['build'] != 'hidden') {
781                                                 if($this->_item['lastBuildDate']){$this->_output .= 'build: '. $this->_item['lastBuildDate'].'<br />';}
782                                         }
783                                         if($this->_display_opt['cache_update'] != 'hidden' && ( $_update = $this->get_cache_update_time()) ) {
784                                                 $this->_output .= 'cache update: '.$_update."<br />\n";
785                                         }
786                                         $this->_output .= "<a href=\"".$this->_item['link']."\" ";
787                                         if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
788                                         $this->_output .= ">".$this->_cut_string($this->_item['link'])."</a>\n";
789                                         $this->_output .= "</td></tr>\n";
790                                         $this->_output .= "</table></td></tr>\n";
791                                 }
792                                 $this->_array_channel = array(
793                                         'title'         => $this->_item['title'],
794                                         'link'          => $this->_item['link'],
795                                         'description'   => $this->_item['description'],
796                                         'lastBuildDate' => $this->_item['lastBuildDate']
797                                 );
798                                 $this->_clear_Items();
799                                 $this->_clear_cItems();
800                                 break;
801
802                         case 'textinput':
803                                 if(isset($this->_display_opt['textinput']) && ($this->_display_opt['textinput'] != 'hidden') && $this->_item['name'] && $this->_item['link']) {
804                                         $this->_output .= "<tr><td class=\"fase4_rdf\">\n";
805                                         $this->_output .= "<form accept-charset=\"utf-8\" action=\"".$this->_item['link']."\" ";
806                                         if(isset($this->_link_target)) { $this->_output .= "target=\"".$this->_link_target."\" "; }
807                                         $this->_output .= "method=\"get\">\n";
808                                         $this->_output .= "<div class=\"fase4_rdf_title\">".$this->_item['title']."</div>";
809                                         $this->_output .= strip_tags($this->_item['description'], '<a>, <img>')."<br><br>\n";
810                                         $this->_output .= "<input class=\"fase4_rdf_input\" type=\"text\" name=\"".$this->_item['name']."\">&nbsp;\n";
811                                         $this->_output .= "<input class=\"fase4_rdf_input\" type=\"submit\" value=\"go\">";
812                                         $this->_output .= "</form>\n";
813                                         $this->_output .= "</td></tr>\n";
814                                         $this->_array_textinput = array(
815                                                 'title'       => $this->_item['title'],
816                                                 'name'        => $this->_item['name'],
817                                                 'link'        => $this->_item['link'],
818                                                 'description' => $this->_item['description']
819                                         );
820                                         $this->_clear_Items();
821                                 } elseif( isset($this->_display_opt['textinput']) && ($this->_display_opt['textinput'] == 'hidden') ) {
822                                         $this->_clear_Items();
823                                 }
824
825                                 break;
826                 }
827         }
828
829         /**
830          * This Method returns the data from the <channel /> paragraph.
831          *
832          * @access    public
833          * @author    Stefan Saasen <s@fase4.com>
834          * @return    array
835          * @see       _array_channel
836          */
837         function get_array_channel( )
838         {
839                 return $this->_array_channel;
840         }
841
842         /**
843          * This Method returns the data from each <item /> paragraph.
844          *
845          * @access    public
846          * @author    Stefan Saasen <s@fase4.com>
847          * @return    array
848          * @see       _array_item
849          */
850         function get_array_item( )
851         {
852                 return $this->_array_item;
853         }
854
855         /**
856          * This Method returns the data from <textinput />.
857          *
858          * @access    public
859          * @author    Stefan Saasen <s@fase4.com>
860          * @return    array
861          * @see       _array_textinput
862          */
863         function get_array_textinput( )
864         {
865                 return $this->_array_textinput;
866         }
867
868         /**
869          * Getter for parser id from resource
870          *
871          * @access   private
872          * @author   Roland Haeder <webmaster@mxchange.org>
873          * @return   int
874          */
875         function get_parser_id ($parser) {
876                 // Default is zero
877                 $id = '0';
878
879                 // Is it a resource?
880                 if (is_resource($parser)) {
881                         // Cast the resource into id
882                         $id = (int) $parser;
883                 } // END - if
884
885                 // Return the id
886                 return $id;
887         }
888
889         /**
890          * This Method returns the data from <image />.
891          *
892          * @access    public
893          * @author    Stefan Saasen <s@fase4.com>
894          * @return    array
895          * @see       _array_image
896          */
897         function get_array_image( )
898         {
899                 return $this->_array_image;
900         }
901
902         /**
903          * XML Parser Data Handler
904          *
905          * @access    private
906          * @author    Stefan Saasen <s@fase4.com>
907          * @param     mixed  $parser a reference to the XML parser calling the handler.
908          * @param     string $text contains the character data as a string.
909          * @see          _parse_mode, _item, _tags, _depth, _citem, _ctags, _cdepth
910          */
911         function _parseData($parser, $text)
912         {
913                 // Deocing mode added by Roland Haeder <webmaster@mxchange.org>
914                 switch ($this->_decoding_mode)
915                 {
916                         case 'utf8_decode':
917                                 $text = utf8_decode($text);
918                                 break;
919
920                         case 'htmlentities':
921                                 $text = htmlentities($text);
922                                 break;
923                 }
924
925                 $clean = preg_replace("/\s/", "", $text);
926                 if ($clean) {
927                         $text = preg_replace("/^\s+/", "", $text)."\n";
928                         if($this->_parse_mode == 'all') {
929                                 if ( isset($this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]]) &&
930                                 $this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]] ) {
931                                         $this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]] .= $text;
932                                 } else {
933                                         $this->_item[$this->_tags[$this->_depth[$this->get_parser_id($parser)]]] = $text;
934                                 }
935                         } elseif (isset($this->_parse_mode) && $this->_parse_mode == 'channel') {
936                                 if ( isset($this->_citem[$this->_ctags[$this->_cdepth[$this->get_parser_id($parser)]]]) ) {
937                                         $this->_citem[$this->_ctags[$this->_cdepth[$this->get_parser_id($parser)]]] .= $text;
938                                 } else {
939                                         $this->_citem[$this->_ctags[$this->_cdepth[$this->get_parser_id($parser)]]] = $text;
940                                 }
941                         }
942                 }
943         }
944
945         /**
946          * This Method allows you to choose if specific Parameters are displayed or not. These are:
947          * image, channel, textinput, build and cache_update. If set to "hidden" those elements won't be displayed.
948          *
949          * @access    public
950          * @author    Stefan Saasen <s@fase4.com>
951          * @param     array  $options
952          * @see          _display_opt
953          */
954         function set_Options( $options = '' )
955         {
956                 if(is_array( $options )) {
957                         $this->_display_opt = $options;
958                         return true;
959                 } else {
960                         unset($this->_display_opt);
961                         return false;
962                 }
963         }
964
965         /**
966          * This Method allows you to define the width of the table that holds the representation of the rdf/rss file.
967          *
968          * @access    public
969          * @author    Stefan Saasen <s@fase4.com>
970          * @param     int  $width  attribute width in tag <table>
971          * @see          _table_width
972          */
973         function set_table_width( $width = 400 )
974         {
975                 $this->_table_width = $width;
976                 return true;
977         }
978
979         /**
980          * This Method returns an assocative Array with available Options.
981          *
982          * The Keys are the Name of the Options to be set.
983          * The Values are  short Description of available Options.
984          *
985          * @access    public
986          * @author    Stefan Saasen <s@fase4.com>
987          * @return    array  $options
988          * @see          _display_opt
989          */
990         function get_Options() {
991                 $options = array(
992                         'image'        => "If 'image' is set to \"hidden\" no image provided by the RDF Publisher will be displayed.",
993                         '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",
994                         'textinput'    => "If set to \"hidden\" no Input Form will be displayed",
995                         'build'        => "If set to \"hidden\" the Build Date (if provided) of the RDF File will not be displayed",
996                         'cache_update' => "If set to \"hidden\" the Update Date/Time of the cached Rdf File will not be displayed"
997                 );
998                 return $options;
999         }
1000
1001         /**
1002          * This Method returns the Content of the RDF File in one string. The String actually holds the whole XML Document.
1003          *
1004          * @access    public
1005          * @author    Stefan Saasen <s@fase4.com>
1006          * @param     string $rdf    RDF File (Location)
1007          * @return    string XML Presentation of parsed RDF File
1008          * @see          _cached_file, _remote_file, _cache_dir, _refresh, _update_cache()
1009          */
1010         function cache()
1011         {
1012                 // checks if the cache directory already exists
1013                 // if not, the cache directory will be created
1014                 if(!$this->_cache_dir_ok) {
1015                         $this->_create_cache_dir();
1016                 }
1017                 if($this->_use_dynamic_display == true) {
1018                         $this->_cached_file = md5('dynamic'.$this->salt.$this->_remote_file) . '.cache';
1019                         $this->_cache_type = 'normal';
1020                 } else {
1021                         $this->_cached_file = md5($this->salt.$this->_remote_file) . '.cache';
1022                         $this->_cache_type = 'fast';
1023                 }
1024
1025                 $_cache_f = $this->_cache_dir.$this->_cached_file;
1026
1027                 if ( (!file_exists($_cache_f)) || (filemtime($_cache_f) < $this->_refresh) || (filesize($_cache_f) == '0')) {
1028                         // We have to parse the remote file
1029                         $this->_use_cached_file = false;
1030                         // --> we want to provide proper Information for Use in
1031                         // get_cache_update_time()
1032                         clearstatcache();
1033                         if($this->_use_dynamic_display == true) {
1034                                 $_rdf = @implode(' ', $this->_rdf_data()); // -> proxy
1035                                 if(!$_rdf) {
1036                                         $this->_throw_exception( $this->_remote_file.' is not available' );
1037                                 }
1038                                 $this->_parse_xRDF( $_rdf );
1039                                 $this->_update_cache( $_rdf );
1040                                 $data = $this->_output;
1041                         } else {
1042                                 $_rdf = @implode(' ', $this->_rdf_data()); // -> proxy
1043                                 if(!$_rdf) {
1044                                         $this->_throw_exception( $this->_remote_file.' is not available' );
1045                                 }
1046                                 $this->_parse_xRDF( $_rdf );
1047                                 $this->_update_cache( $this->_output );
1048                                 $data = $this->_output;
1049                         }
1050                 } else {
1051                         // we can use the cached file
1052                         $this->_use_cached_file = true;
1053                         if($this->_use_dynamic_display == true) {
1054                                 $this->_parse_xRDF( implode(' ', file($_cache_f)) );
1055                                 $data = $this->_output;
1056                         } else {
1057                                 $data = @implode(' ', file($_cache_f));
1058                         }
1059                 }
1060                 return trim($data);
1061         }   // END cache()
1062
1063         /**
1064          * This Methods creates the Cache Directory if the specified Directory does not exist.
1065          *
1066          * @access    private
1067          * @author    Stefan Saasen <s@fase4.com>
1068          * @param     string $dir Path to Directory.
1069          * @return       boolean
1070          * @see          _cache_dir, _cache_dir_ok
1071          */
1072         function _create_cache_dir()
1073         {
1074                 $path = '';
1075                 if(!@is_dir($this->_cache_dir)) {
1076                         $arr = explode('/', $this->_cache_dir);
1077                         $c = count($arr);
1078                         if($arr[0]=='') {
1079                                 $path = '/';
1080                         }
1081                         for($i = '0';$i<$c;$i++)
1082                         {
1083                                 if($arr[$i]!='') {
1084                                         $path .= $arr[$i].'/';
1085                                         if(!@is_dir($path)) {
1086                                                 if(!@mkdir($path, 0777)) {
1087                                                         $this->_throw_exception("failed to create directory:<b>".$this->_cache_dir."</b>.<br /><br />Exception on Line: ".__LINE__);
1088                                                         return false;
1089                                                 }
1090                                         }
1091                                 }
1092                         }
1093                         $this->_cache_dir_ok = true;
1094                         return true;
1095                 } else {
1096                         $this->_cache_dir_ok = true;
1097                         return true;
1098                 }
1099         }   // END _create_cache_dir()
1100
1101         /**
1102          * This Method updates the cached RDF Files and synchronises them with their remote Counterparts.
1103          *
1104          * @access    private
1105          * @author    Stefan Saasen <s@fase4.com>
1106          * @param     string $rdf    RDF File (Location)
1107          * @see          _cache_dir, _cached_file, _throw_exception()
1108          */
1109         function _update_cache( $content = '' )
1110         {
1111                 $_local = @fopen( $this->_cache_dir.$this->_cached_file, 'w' );
1112                 if(!$_local) {
1113                         $this->_throw_exception( 'Cannot open '.$this->_cached_file.'<br /><br />Exception at Line: '.__LINE__ );
1114                         return false;
1115                 }
1116                 if (fwrite( $_local, $content) === false) {
1117                         $this->_throw_exception( 'Cannot write to '.$this->_cached_file.'<br /<br />Exeception at Line: '.__LINE__);
1118                         return false;
1119                 }
1120                 fclose( $_local );
1121                 @chmod( $this->_cache_dir.$this->_cached_file, 0666);
1122                 return true;
1123         }   // END _update_cache()
1124
1125         /**
1126          * This Method returns the Date/Time of last Cache Update of the actually parsed RDF File.
1127          *
1128          * @access    public
1129          * @author    Stefan Saasen <s@fase4.com>
1130          * @return       string Date/Time of last Update
1131          * @see          _cache_dir, _cached_file
1132          */
1133         function get_cache_update_time()
1134         {
1135                 return (file_exists($this->_cache_dir.$this->_cached_file))?date('d.m.Y H:i:s', filemtime($this->_cache_dir.$this->_cached_file)):'Cachemiss';
1136         }   // END get_cache_update_time()
1137
1138         /**
1139          * This Method returns the Type of Cache that was used ('normal' or 'fast')
1140          *
1141          * @access    public
1142          * @author    Stefan Saasen <s@fase4.com>
1143          * @param     string $rdf    RDF File (Location)
1144          * @return    string Displays RDF Content ( using _display() )
1145          * @see          _remote_file, cache()
1146          */
1147         function get_CacheType()
1148         {
1149                 return $this->_cache_type;
1150         }
1151
1152         /**
1153          * Returns true if cached file was used, otherwise false
1154          *
1155          * @access    public
1156          * @author    Stefan Saasen <s@fase4.com>
1157          * @return    array  $options
1158          * @see          _use_cached_file
1159          */
1160         function is_cachedFile()
1161         {
1162                 return $this->_use_cached_file;
1163         }
1164
1165         /**
1166          * This Method deletes all the cached Files.
1167          *
1168          * Please keep in mind to use this method just as a 'manual garbage collection'
1169          * You should cache the rss/rdf files locally to avoid unnecessary traffic.
1170          * (Both for your visitors and the Publisher)
1171          *
1172          * @access    public
1173          * @author    Stefan Saasen <s@fase4.com>
1174          * @see          _cache_dir
1175          */
1176         function clear_cache()
1177         {
1178                 $dir = dir($this->_cache_dir);
1179                 while($file=$dir->read()) {
1180                         // Exclude directories
1181                         if (is_file($dir->path.$file) && substr($file, -6, 6) != '.cache' && substr($file, -4, 4) != '.log')  {
1182                                 if(!@unlink($dir->path.$file)) {
1183                                         $this->_throw_exception("Unable to unlink ".$dir->path.$file."<br />\n<br />\nException at Line: ".__LINE__ );
1184                                         return false;
1185                                 } // END - if
1186                         } // END - if
1187                 } // END - while
1188                 $dir->close();
1189                 return true;
1190         }   // END clear_cache()
1191
1192         /**
1193          * Cuts the String $string after $str_len and adds '... '
1194          *
1195          * @access   private
1196          * @param    string  $string String to be shortened
1197          * @param    int     $str_len length of the returned String (overall length including '... ')
1198          * @return   string  Cut String
1199          */
1200         function _cut_string( $string, $str_len = '30' )
1201         {
1202                 if(strlen(trim($string))>$str_len) {
1203                         $string = substr( trim($string) , 0, $str_len - 4);
1204                         $string .= ' ...';
1205                 }
1206                 return $string;
1207         }   // END _cut_string()
1208
1209         /**
1210          * this Method implements simple Garbage Collection
1211          *
1212          * @access    private
1213          * @author    Stefan Saasen <s@fase4.com>
1214          * @see          _cache_dir, gc_probability, gc_maxlifetime
1215          */
1216         function _garbage_collection()
1217         {
1218                 srand((double) microtime() * 1000000);
1219                 if (mt_rand(1, 100) <= $this->gc_probability) {
1220                         $dir = dir($this->_cache_dir);
1221                         while($file=$dir->read()) {
1222                                 if (is_file($dir->path.$file) && substr($file, -6, 6) != '.cache' && substr($file, -4, 4) != '.log' && filemtime($dir->path.$file) <= time() - $this->_refresh )  {
1223                                         @unlink($dir->path.$file);
1224                                 } // END - if
1225                         }
1226                         $dir->close();
1227                 }   // END if
1228         }
1229
1230         /* ==== Proxy/Auth methods ==== */
1231
1232         /**
1233          * this method sets a proxy server
1234          *
1235          * @access    public
1236          * @param     string $phost Proxy Host
1237          * @param     string $pport Prox Port
1238          * @author    Marco Kraus <marco.kraus@siemens.com>
1239          */
1240         function set_proxy($phost, $pport)
1241         {
1242                 $this->_use_proxy = true;
1243
1244                 if ($phost != '')
1245                 $this->_phost = $phost;
1246
1247                 if ($pport != '')
1248                 $this->_pport = $pport;
1249         }
1250
1251         /**
1252          * this method sets a proxy server authentification
1253          *
1254          * @access    public
1255          * @param     string $pname Username
1256          * @param     string $ppaswd Password
1257          * @author    Marco Kraus <marco.kraus@siemens.com>
1258          */
1259         function set_proxy_auth( $pname, $ppasswd )
1260         {
1261                 $this->_use_proxy_auth = true;
1262
1263                 if ($pname != '')
1264                 $this->_pname = $pname;
1265
1266                 if ($ppasswd != '')
1267                 $this->_ppasswd = $ppasswd;
1268         }
1269
1270
1271         /**
1272          * gets _remote_file into an array
1273          *
1274          * needed, cause if you use a proxy, you have to open
1275          * a raw-tcp-socket to get the data
1276          *
1277          * @access    private
1278          * @author    Marco Kraus <Marco.Kraus@siemens.com>
1279          * @return array
1280          * @see _use_proxy, cache()
1281          */
1282         function _rdf_data()
1283         {
1284                 if ( $this->_use_proxy == true )
1285                 {
1286                         // we need a raw socket here to connect to proxy
1287                         $fp = fsockopen($this->_phost,$this->_pport);
1288
1289                         if (!$fp) {
1290                                 $this->_throw_exception( $this->_remote_file.' is not available with proxy' );
1291                         } else {
1292                                 if ( $this->_use_proxy_auth == true ) {
1293                                         fputs($fp, "GET ".$this->_remote_file." HTTP/1.0\r\nUser-Agent: Fase4 RDF-Reader/1.40 modified by Quix0r\r\n\r\n");
1294                                 } else {
1295                                         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");
1296                                 }
1297                         }
1298
1299
1300                         for ( $i = '0'; !feof ($fp) ; $i++)
1301                         {
1302                                 $usable_data[$i] = "";
1303                                 $usable_data[$i] = fgets($fp,4096);
1304
1305                                 // PARSE HEADER ---- first line has to be <?xml, second rdf or rss, and third is blank
1306
1307                                 // strstr did not fit (ask Rasmus why), so we compare each character
1308                                 if ( ($usable_data[$i][0] == '<' ) &&
1309                                 ($usable_data[$i][1] == '?' ) &&
1310                                 ($usable_data[$i][2] == 'x' ) &&
1311                                 ($usable_data[$i][3] == 'm' ) &&
1312                                 ($usable_data[$i][4] == 'l' ) ) {
1313                                         $usable_data[0] = $usable_data[$i]; // save current field
1314                                         $i = 1; // just reset array to start
1315                                 }
1316
1317                                 // there seems to be proxystuff after the <?xml....we delete this
1318                                 if ( (
1319                                 ($usable_data[$i][0] == '<' ) &&
1320                                 ($usable_data[$i][1] == 'r' ) &&
1321                                 ($usable_data[$i][2] == 'd' ) &&
1322                                 ($usable_data[$i][3] == 'f' ) &&
1323                                 ($usable_data[$i][4] == ':' )
1324                                 )
1325                                 ||
1326                                 (
1327                                 ($usable_data[$i][0] == '<' ) &&
1328                                 ($usable_data[$i][1] == 'r' ) &&
1329                                 ($usable_data[$i][2] == 's' ) &&
1330                                 ($usable_data[$i][3] == 's' )
1331                                 )
1332                                 ) {
1333
1334                                         $usable_data[1] = $usable_data[$i]; // save current field
1335                                         $usable_data[2] = "\n";
1336                                         $i = 2; // just reset array to start
1337                                 }
1338                         }
1339
1340                         fclose($fp);
1341                         return $usable_data;
1342                 } else {
1343                         if (substr($this->_remote_file, 0, 7) != 'http://') {
1344                                 $this->_throw_exception( 'Cannot find http:// in '.$this->_remote_file.'!' );
1345                                 return '';
1346                         } else {
1347                                 // Extract host information
1348                                 $host = substr($this->_remote_file, 7);
1349                                 // Extract the GET part
1350                                 $get = '/';
1351                                 if (strpos($host, '/') > 0) {
1352                                         $get = substr($host, strpos($host, '/'));
1353                                         $host = substr($host, 0, strpos($host, '/'));
1354                                 }
1355                                 // Extract port
1356                                 $port = '80';
1357                                 if (strpos($host, ':') > 0) {
1358                                         $port = substr($host, (strpos($host, ':') + 1));
1359                                         $host = substr($host, 0, (strpos($host, ':') - 1));
1360                                 }
1361
1362                                 // Start connection to server
1363                                 $fp = fsockopen($host, $port);
1364                                 if (!$fp) {
1365                                         $this->_throw_exception( $this->_remote_file.' is maybe not available.' );
1366                           return '';
1367                                 }
1368                                 // Repare request line
1369                                 $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);
1370                                 // Send request out
1371                                 fputs($fp, $request);
1372                                 $reply = ''; $isContent = false; $dummy = '';
1373                                 // Read reply
1374                                 $i=0;
1375                                 while ( !feof($fp) ) {
1376                                         $read = trim(fgets($fp, 4096));
1377                                         if (substr($read, 0, 5) == '<?xml' || $isContent) {
1378                                                 // Add content
1379                                                 $reply[] = $read;
1380                                                 $isContent = true;
1381                                         } else {
1382                                                 // Put in dummy
1383                                                 $dummy[] = $read;
1384                                         }
1385                                         $i++;
1386                                 }
1387                                 if ((count($dummy) > 0) && (count($reply) == '0') && (!$isContent)) {
1388                                         // Transfer content from dummy
1389                                         $reply = $content;
1390                                 }
1391                                 fclose($fp);
1392                                 //die(htmlentities($reply));
1393                                 return $reply;
1394                         }
1395                 }
1396         }    // END _rdf_data()
1397 }   // END class
1398 ?>