Rev Author Line No. Line
185 miho 1 <?php
2 # vim:et:ts=3:sts=3:sw=3:fdm=marker:
3  
4 // WebSVN - Subversion repository viewing via the web using PHP
5 // Copyright © 2004-2006 Tim Armes, Matt Sicker
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // --
22 //
23 // rss.php
24 //
25 // Creates an rss feed for the given repository number
26  
27 include("include/feedcreator.class.php");
28  
29 require_once("include/setup.inc");
30 require_once("include/svnlook.inc");
31 require_once("include/utils.inc");
32 require_once("include/template.inc");
33  
34 $isDir = (@$_REQUEST["isdir"] == 1)?1:0;
35  
36 $maxmessages = 20;
37  
38 // Find the base URL name
39 if ($config->multiViews)
40 {
41 $baseurl = "";
42 }
43 else
44 {
45 $baseurl = dirname($_SERVER["PHP_SELF"]);
46 if ($baseurl != "" && $baseurl != DIRECTORY_SEPARATOR && $baseurl != "\\" && $baseurl != "/" )
47 $baseurl .= "/";
48 else
49 $baseurl = "/";
50 }
51  
52 $svnrep = new SVNRepository($rep);
53  
54 if ($path == "" || $path{0} != "/")
55 $ppath = "/".$path;
56 else
57 $ppath = $path;
58  
59 // Make sure that the user has full access to the specified directory
60 if (!$rep->hasReadAccess($path, false))
61 exit;
62  
63 $url = $config->getURL($rep, $path, "log");
64 $listurl = $config->getURL($rep, $path, "dir");
65  
66 // If there's no revision info, go to the lastest revision for this path
67 $history = $svnrep->getLog($path, $rev, "", false, 20);
68 $youngest = $history->entries[0]->rev;
69  
70 // Cachename reflecting full path to and rev for rssfeed. Must end with xml to work
71 $cachename = strtr(getFullURL($listurl), ":/\\?", "____");
72 $cachename = $locwebsvnreal.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR.$cachename.@$_REQUEST["rev"]."_rssfeed.xml";
73  
74 $rss = new UniversalFeedCreator();
75 $rss->useCached("RSS2.0", $cachename);
76 $rss->title = $rep->getDisplayName();
77 $rss->description = "${lang["RSSFEEDTITLE"]} - $repname";
78 $rss->link = html_entity_decode(getFullURL($baseurl.$listurl));
79 $rss->syndicationURL = $rss->link;
80 $rss->xslStyleSheet = ""; //required for UniversalFeedCreator since 1.7
81 $rss->cssStyleSheet = ""; //required for UniversalFeedCreator since 1.7
82  
83 //$divbox = "<div>";
84 //$divfont = "<span>";
85  
86 foreach ($history->entries as $r)
87 {
88 $thisrev = $r->rev;
89 $changes = $r->mods;
90 $files = count($changes);
91  
92 // Add the trailing slash if we need to (svnlook history doesn't return trailing slashes!)
93 $rpath = $r->path;
94 if ($isDir && $rpath{strlen($rpath) - 1} != "/")
95 $rpath .= "/";
96  
97 // Find the parent path (or the whole path if it's already a directory)
98 $pos = strrpos($rpath, "/");
99 $parent = substr($rpath, 0, $pos + 1);
100  
101 $url = $config->getURL($rep, $parent, "dir");
102  
103 $desc = $r->msg;
104 $item = new FeedItem();
105  
106 // For the title, we show the first 10 words of the description
107 $pos = 0;
108 $len = strlen($desc);
109 for ($i = 0; $i < 10; $i++)
110 {
111 if ($pos >= $len) break;
112  
113 $pos = strpos($desc, " ", $pos);
114  
115 if ($pos === FALSE) break;
116 $pos++;
117 }
118  
119 if ($pos !== FALSE)
120 {
121 $sdesc = substr($desc, 0, $pos) . "...";
122 }
123 else
124 {
125 $sdesc = $desc;
126 }
127  
128 if ($desc == "") $sdesc = "${lang["REV"]} $thisrev";
129  
130 $item->title = "$sdesc";
131 $item->link = html_entity_decode(getFullURL($baseurl."${url}rev=$thisrev&amp;sc=$showchanged"));
132 $item->description = "<div><strong>${lang["REV"]} $thisrev - ".$r->author."</strong> ($files ${lang["FILESMODIFIED"]})</div><div>".nl2br(create_anchors($desc))."</div>";
133  
134 if ($showchanged)
135 {
136 foreach ($changes as $file)
137 {
138 switch ($file->action)
139 {
140 case "A":
141 $item->description .= "+ ".$file->path."<br />";
142 break;
143  
144 case "M":
145 $item->description .= "~ ".$file->path."<br />";
146 break;
147  
148  
149 case "D":
150 $item->description .= "-".$file->path."<br />";
151 break;
152  
153 }
154 }
155 }
156  
157 $item->date = $r->committime;
158 $item->author = $r->author;
159  
160 $rss->addItem($item);
161 }
162  
163 // valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1, MBOX, OPML
164  
165 // Save the feed
166 $rss->saveFeed("RSS2.0",$cachename, false);
167 header("Content-Type: application/xml");
168 echo $rss->createFeed("RSS2.0");
169  
170 ?>