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