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