/WebSVN/rss.php
1,8 → 1,6
<?php
# vim:et:ts=3:sts=3:sw=3:fdm=marker:
 
// WebSVN - Subversion repository viewing via the web using PHP
// Copyright © 2004-2006 Tim Armes, Matt Sicker
// 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
11,12 → 9,12
//
// 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
// 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
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// --
//
24,147 → 22,140
//
// Creates an rss feed for the given repository number
 
include("include/feedcreator.class.php");
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';
 
require_once("include/setup.inc");
require_once("include/svnlook.inc");
require_once("include/utils.inc");
require_once("include/template.inc");
$max = (int)@$_REQUEST['max'];
if ($max == 0)
$max = $config->getRssMaxEntries();
$quiet = (isset($_REQUEST['quiet']));
 
$isDir = (@$_REQUEST["isdir"] == 1)?1:0;
 
$maxmessages = 20;
 
// Find the base URL name
if ($config->multiViews)
{
$baseurl = "";
if ($config->multiViews) {
$baseurl = '';
} else {
$baseurl = dirname($_SERVER['PHP_SELF']);
if ($baseurl != '' && $baseurl != DIRECTORY_SEPARATOR && $baseurl != '\\' && $baseurl != '/') {
$baseurl .= '/';
} else {
$baseurl = '/';
}
}
else
{
$baseurl = dirname($_SERVER["PHP_SELF"]);
if ($baseurl != "" && $baseurl != DIRECTORY_SEPARATOR && $baseurl != "\\" && $baseurl != "/" )
$baseurl .= "/";
else
$baseurl = "/";
 
if ($path == '' || $path[0] != '/') {
$ppath = '/'.$path;
} else {
$ppath = $path;
}
 
$svnrep = new SVNRepository($rep);
 
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))
exit;
if (!$rep->hasReadAccess($path, false)) {
http_response_code(403);
print 'Unable to access resource at path: '.xml_entities($path);
exit;
}
 
$url = $config->getURL($rep, $path, "log");
$listurl = $config->getURL($rep, $path, "dir");
 
// If there's no revision info, go to the lastest revision for this path
$history = $svnrep->getLog($path, $rev, "", false, 20);
$youngest = $history->entries[0]->rev;
$svnrep = new SVNRepository($rep);
$history = $svnrep->getLog($path, $rev, '', false, $max, $peg, !$quiet);
if (!$history) {
http_response_code(404);
echo $lang['NOPATH'];
exit;
}
 
// Cachename reflecting full path to and rev for rssfeed. Must end with xml to work
$cachename = strtr(getFullURL($listurl), ":/\\?", "____");
$cachename = $locwebsvnreal.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR.$cachename.@$_REQUEST["rev"]."_rssfeed.xml";
header('Content-Type: application/xml; charset=utf-8');
 
$rss = new UniversalFeedCreator();
$rss->useCached("RSS2.0", $cachename);
$rss->title = $rep->getDisplayName();
$rss->description = "${lang["RSSFEEDTITLE"]} - $repname";
$rss->link = html_entity_decode(getFullURL($baseurl.$listurl));
$rss->syndicationURL = $rss->link;
$rss->xslStyleSheet = ""; //required for UniversalFeedCreator since 1.7
$rss->cssStyleSheet = ""; //required for UniversalFeedCreator since 1.7
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();
}
}
 
//$divbox = "<div>";
//$divfont = "<span>";
$bugtraq = new Bugtraq($rep, $svnrep, $ppath);
 
foreach ($history->entries as $r)
{
$thisrev = $r->rev;
$changes = $r->mods;
$files = count($changes);
// 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 ? ' &#x2013; '.$path : '').'</title>';
$rss .= '<description>'.escape($lang['RSSFEEDTITLE']).' &#x2013; '.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&amp;' : '').'max='.$max.'&amp;'.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&amp;';
foreach ($history->entries as $r) {
$wordLimit = 10; // Display only up to the first 10 words of the log message
$title = trim(explode('\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('&#x2013;', 'UTF-8', 'HTML-ENTITIES').' '.$title;
$description = '<div><strong>'.$r->author;
if (!$quiet) {
$description .= ' '.mb_convert_encoding('&#x2013;', 'UTF-8', 'HTML-ENTITIES').' '.count($r->mods).' '.$lang['FILESMODIFIED'];
}
$description .= '</strong><br/>'.nl2br($bugtraq->replaceIDs(create_anchors(str_replace('<', '&lt;', $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 .= $modifiedResource->path;
if ($modifiedResource->copyfrom != '') {
$description .= ' <i>(copied from '.$modifiedResource->copyfrom.'@'.$modifiedResource->copyrev.')</i>';
}
$description .= '<br />';
}
}
 
// Add the trailing slash if we need to (svnlook history doesn't return trailing slashes!)
$rpath = $r->path;
if ($isDir && $rpath{strlen($rpath) - 1} != "/")
$rpath .= "/";
// Find the parent path (or the whole path if it's already a directory)
$pos = strrpos($rpath, "/");
$parent = substr($rpath, 0, $pos + 1);
$url = $config->getURL($rep, $parent, "dir");
$desc = $r->msg;
$item = new FeedItem();
// For the title, we show the first 10 words of the description
$pos = 0;
$len = strlen($desc);
for ($i = 0; $i < 10; $i++)
{
if ($pos >= $len) break;
$pos = strpos($desc, " ", $pos);
if ($pos === FALSE) break;
$pos++;
}
if ($pos !== FALSE)
{
$sdesc = substr($desc, 0, $pos) . "...";
}
else
{
$sdesc = $desc;
}
if ($desc == "") $sdesc = "${lang["REV"]} $thisrev";
$item->title = "$sdesc";
$item->link = html_entity_decode(getFullURL($baseurl."${url}rev=$thisrev&amp;sc=$showchanged"));
$item->description = "<div><strong>${lang["REV"]} $thisrev - ".$r->author."</strong> ($files ${lang["FILESMODIFIED"]})</div><div>".nl2br(create_anchors($desc))."</div>";
// 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 ($showchanged)
{
foreach ($changes as $file)
{
switch ($file->action)
{
case "A":
$item->description .= "+ ".$file->path."<br />";
break;
case "M":
$item->description .= "~ ".$file->path."<br />";
break;
case "D":
$item->description .= "-".$file->path."<br />";
break;
}
}
}
 
$item->date = $r->committime;
$item->author = $r->author;
$rss->addItem($item);
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.';
}
}
 
// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1, MBOX, OPML
 
// Save the feed
$rss->saveFeed("RSS2.0",$cachename, false);
header("Content-Type: application/xml");
echo $rss->createFeed("RSS2.0");
 
?>
echo $rss;