185 |
miho |
1 |
<?php |
|
|
2 |
// WebSVN - Subversion repository viewing via the web using PHP |
4988 |
kaklik |
3 |
// Copyright (C) 2004-2006 Tim Armes |
185 |
miho |
4 |
// |
|
|
5 |
// This program is free software; you can redistribute it and/or modify |
|
|
6 |
// it under the terms of the GNU General Public License as published by |
|
|
7 |
// the Free Software Foundation; either version 2 of the License, or |
|
|
8 |
// (at your option) any later version. |
|
|
9 |
// |
|
|
10 |
// This program is distributed in the hope that it will be useful, |
|
|
11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
4988 |
kaklik |
12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
185 |
miho |
13 |
// GNU General Public License for more details. |
|
|
14 |
// |
|
|
15 |
// You should have received a copy of the GNU General Public License |
|
|
16 |
// along with this program; if not, write to the Free Software |
4988 |
kaklik |
17 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
185 |
miho |
18 |
// |
|
|
19 |
// -- |
|
|
20 |
// |
|
|
21 |
// rss.php |
|
|
22 |
// |
|
|
23 |
// Creates an rss feed for the given repository number |
|
|
24 |
|
4988 |
kaklik |
25 |
require_once 'include/setup.php'; |
|
|
26 |
require_once 'include/svnlook.php'; |
|
|
27 |
require_once 'include/utils.php'; |
|
|
28 |
require_once 'include/template.php'; |
|
|
29 |
require_once 'include/bugtraq.php'; |
185 |
miho |
30 |
|
4988 |
kaklik |
31 |
$max = (int)@$_REQUEST['max']; |
|
|
32 |
if ($max == 0) |
|
|
33 |
$max = $config->getRssMaxEntries(); |
|
|
34 |
$quiet = (isset($_REQUEST['quiet'])); |
185 |
miho |
35 |
|
|
|
36 |
// Find the base URL name |
4988 |
kaklik |
37 |
if ($config->multiViews) { |
|
|
38 |
$baseurl = ''; |
|
|
39 |
} else { |
|
|
40 |
$baseurl = dirname($_SERVER['PHP_SELF']); |
|
|
41 |
if ($baseurl != '' && $baseurl != DIRECTORY_SEPARATOR && $baseurl != '\\' && $baseurl != '/') { |
|
|
42 |
$baseurl .= '/'; |
|
|
43 |
} else { |
|
|
44 |
$baseurl = '/'; |
|
|
45 |
} |
185 |
miho |
46 |
} |
4988 |
kaklik |
47 |
|
|
|
48 |
if ($path == '' || $path[0] != '/') { |
|
|
49 |
$ppath = '/'.$path; |
|
|
50 |
} else { |
|
|
51 |
$ppath = $path; |
185 |
miho |
52 |
} |
|
|
53 |
|
4988 |
kaklik |
54 |
if (!$rep) { |
|
|
55 |
http_response_code(404); |
|
|
56 |
print 'Unable to access resource at path: '.xml_entities($path); |
|
|
57 |
exit; |
|
|
58 |
} |
185 |
miho |
59 |
// Make sure that the user has full access to the specified directory |
4988 |
kaklik |
60 |
if (!$rep->hasReadAccess($path, false)) { |
|
|
61 |
http_response_code(403); |
|
|
62 |
print 'Unable to access resource at path: '.xml_entities($path); |
|
|
63 |
exit; |
|
|
64 |
} |
185 |
miho |
65 |
|
|
|
66 |
// If there's no revision info, go to the lastest revision for this path |
4988 |
kaklik |
67 |
$svnrep = new SVNRepository($rep); |
|
|
68 |
$history = $svnrep->getLog($path, $rev, '', false, $max, $peg, !$quiet); |
|
|
69 |
if (!$history) { |
|
|
70 |
http_response_code(404); |
|
|
71 |
echo $lang['NOPATH']; |
|
|
72 |
exit; |
|
|
73 |
} |
185 |
miho |
74 |
|
4988 |
kaklik |
75 |
header('Content-Type: application/xml; charset=utf-8'); |
185 |
miho |
76 |
|
4988 |
kaklik |
77 |
if ($rep->isRssCachingEnabled()) { |
|
|
78 |
// Filename for storing a cached RSS feed for this particular path/revision |
|
|
79 |
$cache = $locwebsvnreal.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.strtr($rep->getDisplayName().$path, '\\/:*?"<>|.', '__________').($peg ? '@'.$peg : '').($rev ? '_r'.$rev : '').'m'.$max.($quiet ? 'q' : '').'.rss.xml'; |
|
|
80 |
// If a recent-enough cached version exists, use it and avoid the work below |
|
|
81 |
if (file_exists($cache) && filemtime($cache) >= $history->curEntry->committime) { |
|
|
82 |
readfile($cache); |
|
|
83 |
exit(); |
|
|
84 |
} |
|
|
85 |
} |
185 |
miho |
86 |
|
4988 |
kaklik |
87 |
$bugtraq = new Bugtraq($rep, $svnrep, $ppath); |
185 |
miho |
88 |
|
4988 |
kaklik |
89 |
// Generate RSS 2.0 feed |
|
|
90 |
$rss = '<?xml version="1.0" encoding="utf-8"?>'; |
|
|
91 |
$rss .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel>'; |
|
|
92 |
$rss .= '<title>'.escape($rep->getDisplayName()).($path ? ' – '.$path : '').'</title>'; |
|
|
93 |
$rss .= '<description>'.escape($lang['RSSFEEDTITLE']).' – '.escape($repname).'</description>'; |
|
|
94 |
$rss .= '<lastBuildDate>'.date('r').'</lastBuildDate>'; // RFC 2822 date format |
|
|
95 |
$rss .= '<generator>WebSVN '.$vars['version'].'</generator>'; |
|
|
96 |
$rss .= '<language>'.$lang['LANGUAGETAG'].'</language>'; |
|
|
97 |
// URL for matching WebSVN log page |
|
|
98 |
$rss .= '<link>'.getFullURL($baseurl.$config->getURL($rep, $path, 'log').(@$_REQUEST['isdir'] == 1 ? 'isdir=1&' : '').'max='.$max.'&'.createRevAndPegString($passrev, $peg)).'</link>'; |
|
|
99 |
// URL where this original RSS feed can be found |
|
|
100 |
$rss .= '<atom:link href="'.escape(getFullURL($_SERVER['REQUEST_URI'])).'" rel="self" type="application/rss+xml" />'."\n"; |
|
|
101 |
if (is_array($history->entries)) { |
|
|
102 |
$itemURL = $baseurl.$config->getURL($rep, $path, 'revision'); |
|
|
103 |
if (@$_REQUEST['isdir'] == 1 || $path == '' || $path == '/') |
|
|
104 |
$itemURL .= 'isdir=1&'; |
|
|
105 |
foreach ($history->entries as $r) { |
|
|
106 |
$wordLimit = 10; // Display only up to the first 10 words of the log message |
|
|
107 |
$title = trim(explode('\n', $r->msg)[0]); |
|
|
108 |
$title = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $title); |
|
|
109 |
$words = explode(' ', $title, $wordLimit + 1); |
|
|
110 |
if (count($words) > $wordLimit) { |
|
|
111 |
$title = implode(' ', array_slice($words, 0, $wordLimit)).' ...'; |
|
|
112 |
} |
|
|
113 |
$title = $lang['REV'].' '.$r->rev.' '.mb_convert_encoding('–', 'UTF-8', 'HTML-ENTITIES').' '.$title; |
|
|
114 |
$description = '<div><strong>'.$r->author; |
|
|
115 |
if (!$quiet) { |
|
|
116 |
$description .= ' '.mb_convert_encoding('–', 'UTF-8', 'HTML-ENTITIES').' '.count($r->mods).' '.$lang['FILESMODIFIED']; |
|
|
117 |
} |
|
|
118 |
$description .= '</strong><br/>'.nl2br($bugtraq->replaceIDs(create_anchors(str_replace('<', '<', $r->msg)))).'</div>'; |
|
|
119 |
if (!$quiet) { |
|
|
120 |
usort($r->mods, 'SVNLogEntry_compare'); |
|
|
121 |
foreach ($r->mods as $modifiedResource) { |
|
|
122 |
switch ($modifiedResource->action) { |
|
|
123 |
case 'A': $description .= '+ '; break; |
|
|
124 |
case 'M': $description .= '~ '; break; |
|
|
125 |
case 'D': $description .= 'x '; break; |
|
|
126 |
} |
|
|
127 |
$description .= $modifiedResource->path; |
|
|
128 |
if ($modifiedResource->copyfrom != '') { |
|
|
129 |
$description .= ' <i>(copied from '.$modifiedResource->copyfrom.'@'.$modifiedResource->copyrev.')</i>'; |
|
|
130 |
} |
|
|
131 |
$description .= '<br />'; |
|
|
132 |
} |
|
|
133 |
} |
185 |
miho |
134 |
|
4988 |
kaklik |
135 |
// skip items with no access |
|
|
136 |
if ($r->committime) { |
|
|
137 |
$rss .= '<item>'; |
|
|
138 |
$rss .= '<pubDate>'.date('r', $r->committime).'</pubDate>'; |
|
|
139 |
$rss .= '<dc:creator>'.escape($r->author).'</dc:creator>'; |
|
|
140 |
$rss .= '<title>'.escape($title).'</title>'; |
|
|
141 |
$rss .= '<description>'.escape($description).'</description>'; |
|
|
142 |
$itemLink = getFullURL($itemURL.createRevAndPegString($r->rev,$peg)); |
|
|
143 |
$rss .= '<link>'.$itemLink.'</link>'; |
|
|
144 |
$rss .= '<guid>'.$itemLink.'</guid>'; |
|
|
145 |
$rss .= '</item>'."\n"; |
|
|
146 |
} |
|
|
147 |
} |
|
|
148 |
} |
|
|
149 |
$rss .= '</channel></rss>'; |
185 |
miho |
150 |
|
4988 |
kaklik |
151 |
if ($rep->isRssCachingEnabled()) { |
|
|
152 |
$file = fopen($cache, 'w+'); |
|
|
153 |
if ($file) { |
|
|
154 |
fputs($file, $rss); |
|
|
155 |
fclose($file); |
|
|
156 |
touch($cache, $history->curEntry->committime); // set timestamp to commit time |
|
|
157 |
} else { |
|
|
158 |
echo 'Error creating RSS cache file, please check write permissions.'; |
|
|
159 |
} |
185 |
miho |
160 |
} |
4988 |
kaklik |
161 |
echo $rss; |