1<?php
2/* This file can go into either the top level Dokuwiki Driectory or <dokuwki>/lib/exe */
3
4
5require_once DOKU_INC . "lib/plugins/news/scripts/feedData.php";
6
7class externalNewsFeed extends feedData {
8var $ttl;
9function __construct($outfile=null,$ttl=720, $subfeed = "") {
10    $this->ttl = $ttl;
11    parent::__construct($subfeed);
12	$handle = null;
13
14		if($outfile) {
15			$handle = fopen($outfile,'wb');
16			if(!flock($handle,LOCK_EX)) {
17			   fclose($handle);
18			   return;
19			}
20		}
21
22		if($handle) {
23			fwrite($handle,$this->write_header());
24			while($this->feed_data()) {
25			   fwrite($handle,$this->write_item());
26			}
27			fwrite($handle,$this->footer());
28			flock($handle,LOCK_UN);
29			fclose($handle);
30
31		}
32		else {
33			echo $this->write_header();
34			while($this->feed_data()) {
35				echo $this->write_item();
36			}
37		   echo $this->footer();
38		}
39
40    }
41
42
43	function write_item() {
44
45		$src_url=$this->news_feed_url();
46		$src_title = $this->title();   ;
47		$link = $this->url() . '#' . $this->rss_id() ;
48		$title = $this->title();
49		$date = $this->date();
50		$guid = $link;
51		$desc = $this->description();
52
53return <<<ITEM
54
55<item>
56
57      <title><![CDATA[$title]]></title>
58      <link><![CDATA[$link]]></link>
59      <description><![CDATA[$desc]]></description>
60      <pubDate>$date</pubDate>
61      <guid isPermaLink ="true">$guid</guid>
62      <source url="$src_url"><![CDATA[$src_title]]></source>
63 </item>
64ITEM;
65
66}
67
68
69	function write_header () {
70    global $lib_exe;
71    global $newsFeedURL;
72	$date = $this->news_feed_date();
73	 if($lib_exe) {
74	     $link = $newsFeedURL;
75	 }
76	else {
77	    $link = $this->news_feed_url();
78		}
79    $title = $this->channel_title();
80	$desc = $this->channel_description();
81	$ttl = $this->channel_ttl();
82return <<<HEAD
83<?xml version="1.0" encoding="utf-8"?>
84<rss version="2.0">
85  <channel>
86	<title>$title</title>
87	<link>$link</link>
88	<description>$desc</description>
89	<language>en-us</language>
90	<pubDate>$date</pubDate>
91	<ttl>$ttl</ttl>
92HEAD;
93
94	}
95
96	function footer() {
97	  return "\n</channel>\n</rss>\n";
98	}
99
100}
101
102
103?>