tiki-wiki_rss.php 3.24 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
6
// $Id$
7

8
require_once ('tiki-setup.php');
9
require_once ('lib/tikilib.php');
10
require_once ('lib/wiki/histlib.php');
11
require_once('lib/wiki/wikilib.php');
12
require_once ('lib/rss/rsslib.php'); 
13

14
$access->check_feature('feature_wiki');
15

16
if ($prefs['feed_wiki'] != 'y') {
17 18
	$errmsg=tra("rss feed disabled");
	require_once ('tiki-rss_error.php');
19
}
20

21
$res=$access->authorize_rss(array('tiki_p_view', 'tiki_p_wiki_view_ref'));
m_stef's avatar
m_stef committed
22 23 24 25 26 27 28
if($res) {
   if($res['header'] == 'y') {
      header('WWW-Authenticate: Basic realm="'.$tikidomain.'"');
      header('HTTP/1.0 401 Unauthorized');
   }
   $errmsg=$res['msg'];
   require_once ('tiki-rss_error.php');
29
}
30

ohertel's avatar
ohertel committed
31
$feed = "wiki";
mose's avatar
mose committed
32
$uniqueid = $feed;
33
$output = $rsslib->get_from_cache($uniqueid);
ohertel's avatar
ohertel committed
34

35
if ($output["data"]=="EMPTY") {
36 37
	$title = $prefs['feed_wiki_title'];
	$desc = $prefs['feed_wiki_desc'];
38 39 40 41 42
	$id = "pageName";
	$titleId = "pageName";
	$descId = "data";
	$dateId = "lastModif";
	$authorId = "user";
43
	// if param &diff=1 exists, link to diff, not to page itself
ohertel's avatar
ohertel committed
44
	if (isset($_REQUEST["diff"])) {
45 46 47 48
		$readrepl = "tiki-pagehistory.php?page=%s&compare=1&oldver=%s&newver=0&diff_style=minsidediff";
	} else {
		$readrepl = "tiki-index.php?page=%s";
	}
49
	$param = "previous";
50
	
51
	$changes = $tikilib -> list_pages(0, $prefs['feed_wiki_max'], 'lastModif_desc', '', '', true, false, false, false, '', false, 'y');
52 53
	$tmp = array();
	foreach ($changes["data"] as $data) {
54
		$result = '';
55 56 57 58 59 60
		if ($tiki_p_view != 'y') {
			$data['sefurl'] = $wikilib->sefurl($data['pageName']);
			unset($data['data']);
			$tmp[] = $data;
			continue;
		}
61 62 63 64 65 66 67 68
		// get last 2 versions of the page and parse them
		$curr_page = $tikilib->get_page_info($data["pageName"]);
		$pageversion = (int)$histlib->get_page_latest_version($data["pageName"]);
		if ($pageversion==FALSE) {
			$prev_page = $curr_page;
			$prev_page["data"]="";
		} else {
			$prev_page = $histlib->get_page_from_history($data["pageName"], $pageversion, true);
69
		}
70
		$_REQUEST['redirectpage'] = 'y';//block the redirect interpretation 
71
		$_REQUEST['page'] = $data["pageName"];
72 73
		$curr_page_p = $tikilib->parse_data($curr_page[$descId], array('print'=>true));
		$prev_page_p = $tikilib->parse_data($prev_page[$descId], array('print'=>true));
74 75 76 77 78 79 80 81 82
	
		// do a diff between both pages
		require_once('lib/diff/difflib.php');
		$diff = diff2($prev_page_p , $curr_page_p, "unidiff");
	
		
		foreach ($diff as $part) {
			if ($part["type"]=="diffdeleted") {
				foreach ($part["data"] as $chunk) {
83
					$result.="<blockquote>- $chunk</blockquote>";
84 85 86 87
				}
			}
			if ($part["type"]=="diffadded") {
				foreach ($part["data"] as $chunk) {
88
					$result.="<blockquote>+ $chunk</blockquote>";
89
				}
90 91
			}
		}
92 93 94 95 96 97
		
		$data["$descId"] = $result;
	
		// hand over the version of the second page
		$data["$param"] = $prev_page["version"];
		$tmp[] = $data;
98
	}
99
	$changes["data"] = $tmp;
100
	
101 102
	$tmp = null;
	$output = $rsslib->generate_feed($feed, $uniqueid, '', $changes, $readrepl, $param, $id, $title, $titleId, $desc, $descId, $dateId, $authorId);
ohertel's avatar
ohertel committed
103
}
104 105
header("Content-type: ".$output["content-type"]);
print $output["data"];