| 1 | 1 | simandl | <?php |
| 2 | | | // WebSVN - Subversion repository viewing via the web using PHP |
| 3 | | | // Copyright (C) 2004-2006 Tim Armes |
| 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 |
| 12 | | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 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 |
| 17 | | | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | | | // |
| 19 | | | // -- |
| 20 | | | // |
| 21 | | | // listing.php |
| 22 | | | // |
| 23 | | | // Show the listing for the given repository/path/revision |
| 24 | | | |
| 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"); |
| 30 | | | |
| 31 | | | function removeURLSeparator($url) { |
| 32 | | | return preg_replace('#(\?|&(amp;)?)$#', '', $url); |
| 33 | | | } |
| 34 | | | |
| 35 | | | function fileLink($path, $file, $returnjoin = false) { |
| 36 | | | global $rep, $passrev, $config; |
| 37 | | | |
| 38 | | | if ($path == "" || $path{0} != "/") { |
| 39 | | | $ppath = "/".$path; |
| 40 | | | } else { |
| 41 | | | $ppath = $path; |
| 42 | | | } |
| 43 | | | |
| 44 | | | if ($ppath{strlen($ppath)-1} != "/") { |
| 45 | | | $ppath .= "/"; |
| 46 | | | } |
| 47 | | | |
| 48 | | | if ($file{0} == "/") { |
| 49 | | | $pfile = substr($file, 1); |
| 50 | | | } else { |
| 51 | | | $pfile = $file; |
| 52 | | | } |
| 53 | | | |
| 54 | | | if ($returnjoin) { |
| 55 | | | return $ppath.$pfile; |
| 56 | | | } |
| 57 | | | |
| 58 | | | $isDir = $pfile{strlen($pfile) - 1} == "/"; |
| 59 | | | |
| 60 | | | if ($passrev) $passrevstr = "rev=$passrev&"; else $passrevstr = ""; |
| 61 | | | |
| 62 | | | if ($isDir) { |
| 63 | | | $url = $config->getURL($rep, $ppath.$pfile, "dir"); |
| 64 | | | |
| 65 | | | // XHTML doesn't allow slashes in IDs and must begin with a letter |
| 66 | | | $id = str_replace('/', '_', 'path'.$ppath.$pfile); |
| 67 | | | $url = "<a id='$id' href=\"${url}$passrevstr"; |
| 68 | | | |
| 69 | | | $url = removeURLSeparator($url); |
| 70 | | | if ($config->treeView) $url .= "#$id"; |
| 71 | | | $url .= "\">$pfile</a>"; |
| 72 | | | |
| 73 | | | } else { |
| 74 | | | $url = $config->getURL($rep, $ppath.$pfile, "file"); |
| 75 | | | $url .= $passrevstr; |
| 76 | | | $url = removeURLSeparator($url); |
| 77 | | | $url = "<a href=\"${url}\">$pfile</a>"; |
| 78 | | | } |
| 79 | | | |
| 80 | | | return $url; |
| 81 | | | } |
| 82 | | | |
| 83 | | | function showDirFiles($svnrep, $subs, $level, $limit, $rev, $listing, $index, $treeview = true) { |
| 84 | | | global $rep, $passrev, $config, $lang; |
| 85 | | | |
| 86 | | | $path = ""; |
| 87 | | | |
| 88 | | | if (!$treeview) { |
| 89 | | | $level = $limit; |
| 90 | | | } |
| 91 | | | |
| 92 | | | for ($n = 0; $n <= $level; $n++) { |
| 93 | | | $path .= $subs[$n]."/"; |
| 94 | | | } |
| 95 | | | |
| 96 | | | $logList = $svnrep->getList($path, $rev); |
| 97 | | | |
| 98 | | | // List each file in the current directory |
| 99 | | | $loop = 0; |
| 100 | | | $last_index = 0; |
| 101 | | | $openDir = false; |
| 102 | | | $fullaccess = $rep->hasReadAccess($path, false); |
| 103 | | | |
| 104 | | | foreach ($logList->entries as $entry) { |
| 105 | | | $file = $entry->file; |
| 106 | | | $isDir = $entry->isdir; |
| 107 | | | $access = false; |
| 108 | | | |
| 109 | | | if ($isDir) { |
| 110 | | | if ($rep->hasReadAccess($path.$file, true)) { |
| 111 | | | $access = true; |
| 112 | | | $openDir = isset($subs[$level+1]) && (!strcmp($subs[$level+1]."/", $file) || !strcmp($subs[$level+1], $file)); |
| 113 | | | |
| 114 | | | if ($openDir) { |
| 115 | | | $listing[$index]["filetype"] = "diropen"; |
| 116 | | | } else { |
| 117 | | | $listing[$index]["filetype"] = "dir"; |
| 118 | | | } |
| 119 | | | |
| 120 | | | if ($rep->isDownloadAllowed($path.$file)) { |
| 121 | | | $dlurl = $config->getURL($rep, $path.$file, "dl"); |
| 122 | | | $listing[$index]["fileviewdllink"] = "<a href=\"${dlurl}rev=$passrev&isdir=1\">${lang["TARBALL"]}</a>"; |
| 123 | | | $listing[$index]['downloadurl'] = $dlurl.'rev='.$passrev.'&isdir=1'; |
| 124 | | | } else { |
| 125 | | | $listing[$index]['downloadurl'] = ''; |
| 126 | | | } |
| 127 | | | } |
| 128 | | | |
| 129 | | | } else { |
| 130 | | | if ($fullaccess) { |
| 131 | | | $access = true; |
| 132 | | | if ($level != $limit) { |
| 133 | | | // List directories only, skip all files |
| 134 | | | continue; |
| 135 | | | } |
| 136 | | | |
| 137 | | | $listing[$index]['downloadurl'] = ''; |
| 138 | | | $listing[$index]["filetype"] = strtolower(strrchr($file, ".")); |
| 139 | | | } |
| 140 | | | } |
| 141 | | | |
| 142 | | | if ($access) { |
| 143 | | | $listing[$index]["rowparity"] = ($index % 2)?"1":"0"; |
| 144 | | | |
| 145 | | | if ($treeview) { |
| 146 | | | $listing[$index]["compare_box"] = "<input type=\"checkbox\" name=\"compare[]\" value=\"".fileLink($path, $file, true)."@$passrev\" onclick=\"checkCB(this)\" />"; |
| 147 | | | } else { |
| 148 | | | $listing[$index]["compare_box"] = ""; |
| 149 | | | } |
| 150 | | | |
| 151 | | | if ($openDir) { |
| 152 | | | $listing[$index]["filelink"] = "<b>".fileLink($path, $file)."</b>"; |
| 153 | | | } else { |
| 154 | | | $listing[$index]["filelink"] = fileLink($path, $file); |
| 155 | | | } |
| 156 | | | |
| 157 | | | // The history command doesn't return with a trailing slash. We need to remember here if the |
| 158 | | | // file is a directory or not! |
| 159 | | | |
| 160 | | | $listing[$index]["isDir"] = $isDir; |
| 161 | | | |
| 162 | | | if ($treeview) { |
| 163 | | | $listing[$index]["level"] = $level; |
| 164 | | | } else { |
| 165 | | | $listing[$index]["level"] = 0; |
| 166 | | | } |
| 167 | | | |
| 168 | | | $listing[$index]["node"] = 0; // t-node |
| 169 | | | |
| 170 | | | $fileurl = $config->getURL($rep, $path.$file, "log"); |
| 171 | | | $listing[$index]["fileviewloglink"] = "<a href=\"${fileurl}rev=$passrev&isdir=$isDir\">${lang["VIEWLOG"]}</a>"; |
| 172 | | | $listing[$index]['logurl'] = $fileurl.'rev='.$passrev.'&isdir='.$isDir; |
| 173 | | | |
| 174 | | | if ($rep->getHideRss()) { |
| 175 | | | $rssurl = $config->getURL($rep, $path.$file, 'rss'); |
| 176 | | | $listing[$index]['rssurl'] = $rssurl.'rev='.$passrev.'&isdir='.$isDir; |
| 177 | | | } |
| 178 | | | |
| 179 | | | if ($config->showLastMod) { |
| 180 | | | $listing[$index]['revision'] = $entry->rev; |
| 181 | | | $listing[$index]['author'] = $entry->author; |
| 182 | | | $listing[$index]['date'] = $entry->date; |
| 183 | | | $listing[$index]['committime'] = $entry->committime; |
| 184 | | | $listing[$index]['age'] = $entry->age; |
| 185 | | | $listing[$index]['revurl'] = $config->getURL($rep, '', 'revision').'rev='.$entry->rev.'&'; |
| 186 | | | } |
| 187 | | | |
| 188 | | | $index++; |
| 189 | | | $loop++; |
| 190 | | | $last_index = $index; |
| 191 | | | |
| 192 | | | if (($level != $limit) && ($isDir)) { |
| 193 | | | if (isset($subs[$level + 1]) && !strcmp(htmlentities($subs[$level + 1],ENT_QUOTES).'/', htmlentities($file))) { |
| 194 | | | $listing = showDirFiles($svnrep, $subs, $level + 1, $limit, $rev, $listing, $index); |
| 195 | | | $index = count($listing); |
| 196 | | | } |
| 197 | | | } |
| 198 | | | } |
| 199 | | | } |
| 200 | | | |
| 201 | | | if ($last_index != 0 && $treeview) { |
| 202 | | | $listing[$last_index - 1]["node"] = 1; // l-node |
| 203 | | | } |
| 204 | | | |
| 205 | | | return $listing; |
| 206 | | | } |
| 207 | | | |
| 208 | | | function showTreeDir($svnrep, $path, $rev, $listing) { |
| 209 | | | global $vars, $config; |
| 210 | | | |
| 211 | | | $subs = explode("/", $path); |
| 212 | | | |
| 213 | | | // For directory, the last element in the subs is empty. |
| 214 | | | // For file, the last element in the subs is the file name. |
| 215 | | | // Therefore, it is always count($subs) - 2 |
| 216 | | | $limit = count($subs) - 2; |
| 217 | | | |
| 218 | | | for ($n = 0; $n < $limit; $n++) { |
| 219 | | | $vars["last_i_node"][$n] = FALSE; |
| 220 | | | } |
| 221 | | | |
| 222 | | | return showDirFiles($svnrep, $subs, 0, $limit, $rev, $listing, 0, $config->treeView); |
| 223 | | | } |
| 224 | | | |
| 225 | | | // Make sure that we have a repository |
| 226 | | | if (!isset($rep)) { |
| 227 | | | echo $lang["NOREP"]; |
| 228 | | | exit; |
| 229 | | | } |
| 230 | | | |
| 231 | | | $svnrep = new SVNRepository($rep); |
| 232 | | | |
| 233 | | | // Revision info to pass along chain |
| 234 | | | $passrev = $rev; |
| 235 | | | |
| 236 | | | // If there's no revision info, go to the lastest revision for this path |
| 237 | | | $history = $svnrep->getLog($path, "", "", false); |
| 238 | | | |
| 239 | | | if (!empty($history->entries[0])) { |
| 240 | | | $youngest = $history->entries[0]->rev; |
| 241 | | | } else { |
| 242 | | | $youngest = -1; |
| 243 | | | } |
| 244 | | | |
| 245 | | | // Unless otherwise specified, we get the log details of the latest change |
| 246 | | | if (empty($rev)) { |
| 247 | | | $logrev = $youngest; |
| 248 | | | } else { |
| 249 | | | $logrev = $rev; |
| 250 | | | } |
| 251 | | | |
| 252 | | | if ($logrev != $youngest) { |
| 253 | | | $logEntry = $svnrep->getLog($path, $logrev, $logrev, false); |
| 254 | | | $logEntry = isset($logEntry->entries[0]) ? $logEntry->entries[0] : false; |
| 255 | | | } else { |
| 256 | | | $logEntry = isset($history->entries[0]) ? $history->entries[0] : false; |
| 257 | | | } |
| 258 | | | |
| 259 | | | $headlog = $svnrep->getLog("/", "", "", true, 1); |
| 260 | | | $headrev = isset($headlog->entries[0]) ? $headlog->entries[0]->rev : 0; |
| 261 | | | |
| 262 | | | // If we're not looking at a specific revision, get the HEAD revision number |
| 263 | | | // (the revision of the rest of the tree display) |
| 264 | | | |
| 265 | | | if (empty($rev)) { |
| 266 | | | $rev = $headrev; |
| 267 | | | } |
| 268 | | | |
| 269 | | | if ($path == "" || $path{0} != "/") { |
| 270 | | | $ppath = "/".$path; |
| 271 | | | } else { |
| 272 | | | $ppath = $path; |
| 273 | | | } |
| 274 | | | |
| 275 | | | $vars["repname"] = $rep->getDisplayName(); |
| 276 | | | |
| 277 | | | $compurl = $config->getURL($rep, "/", "comp"); |
| 278 | | | $revisionurl = $config->getURL($rep, $path, 'revision'); |
| 279 | | | |
| 280 | | | if ($passrev != 0 && $passrev != $headrev && $youngest != -1) { |
| 281 | | | $vars['goyoungesturl'] = $config->getURL($rep, $path, 'dir').'opt=dir'; |
| 282 | | | } else { |
| 283 | | | $vars['goyoungesturl'] = ''; |
| 284 | | | } |
| 285 | | | |
| 286 | | | $bugtraq = new Bugtraq($rep, $svnrep, $ppath); |
| 287 | | | |
| 288 | | | $vars["action"] = ""; |
| 289 | | | $vars["rev"] = $rev; |
| 290 | | | $vars["path"] = htmlentities($ppath, ENT_QUOTES, 'UTF-8'); |
| 291 | | | $vars["lastchangedrev"] = $logrev; |
| 292 | | | $vars["date"] = $logEntry ? $logEntry->date : ''; |
| 293 | | | $vars["author"] = $logEntry ? $logEntry->author : ''; |
| 294 | | | $vars["log"] = $logEntry ? nl2br($bugtraq->replaceIDs(create_anchors($logEntry->msg))) : ''; |
| 295 | | | $vars["changesurl"] = $revisionurl.'rev='.$passrev; |
| 296 | | | |
| 297 | | | createDirLinks($rep, $ppath, $passrev); |
| 298 | | | |
| 299 | | | $logurl = $config->getURL($rep, $path, "log"); |
| 300 | | | $vars['logurl'] = $logurl.'rev='.$passrev.'&isdir=1'; |
| 301 | | | |
| 302 | | | $vars['indexurl'] = $config->getURL($rep, '', 'index'); |
| 303 | | | $vars['repurl'] = $config->getURL($rep, '', 'dir'); |
| 304 | | | |
| 305 | | | if ($rev != $headrev) { |
| 306 | | | $history = $svnrep->getLog($path, $rev, "", false); |
| 307 | | | } |
| 308 | | | |
| 309 | | | if ($rep->getHideRss()) { |
| 310 | | | $rssurl = $config->getURL($rep, $path, "rss"); |
| 311 | | | // $vars["curdirrsslink"] = "<a href=\"${rssurl}isdir=1\">${lang["RSSFEED"]}</a>"; |
| 312 | | | $vars['rssurl'] = $rssurl.'isdir=1'; |
| 313 | | | // $vars["curdirrssanchor"] = "<a href=\"${rssurl}isdir=1\">"; |
| 314 | | | } |
| 315 | | | |
| 316 | | | // Set up the tarball link |
| 317 | | | |
| 318 | | | $subs = explode("/", $path); |
| 319 | | | $level = count($subs) - 2; |
| 320 | | | if ($rep->isDownloadAllowed($path)) { |
| 321 | | | $dlurl = $config->getURL($rep, $path, "dl"); |
| 322 | | | $vars["curdirdllink"] = "<a href=\"${dlurl}rev=$passrev&isdir=1\">${lang["TARBALL"]}</a>"; |
| 323 | | | $vars['downloadurl'] = $dlurl.'rev='.$passrev.'&isdir=1'; |
| 324 | | | } else { |
| 325 | | | $vars["curdirdllink"] = ''; |
| 326 | | | $vars['downloadurl'] = ''; |
| 327 | | | } |
| 328 | | | |
| 329 | | | $url = $config->getURL($rep, "/", "comp"); |
| 330 | | | |
| 331 | | | $vars["compare_form"] = "<form action=\"$url\" method=\"post\">"; |
| 332 | | | $vars["compare_submit"] = "<input name=\"comparesubmit\" type=\"submit\" value=\"${lang["COMPAREPATHS"]}\" />"; |
| 333 | | | $vars["compare_hidden"] = "<input type=\"hidden\" name=\"op\" value=\"comp\" />"; |
| 334 | | | $vars["compare_endform"] = "</form>"; |
| 335 | | | |
| 336 | | | $vars['showlastmod'] = $config->showLastMod; |
| 337 | | | |
| 338 | | | $listing = array(); |
| 339 | | | $listing = showTreeDir($svnrep, $path, $rev, $listing); |
| 340 | | | |
| 341 | | | $vars["version"] = $version; |
| 342 | | | |
| 343 | | | if (!$rep->hasReadAccess($path, true)) { |
| 344 | | | $vars["noaccess"] = true; |
| 345 | | | } |
| 346 | | | if (!$rep->hasReadAccess($path, false)) { |
| 347 | | | $vars["restricted"] = true; |
| 348 | | | } |
| 349 | | | |
| 350 | | | parseTemplate($rep->getTemplatePath()."header.tmpl", $vars, $listing); |
| 351 | | | parseTemplate($rep->getTemplatePath()."directory.tmpl", $vars, $listing); |
| 352 | | | parseTemplate($rep->getTemplatePath()."footer.tmpl", $vars, $listing); |