Rev Author Line No. Line
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 // index.php
22 //
4988 kaklik 23 // Main page which lists all configured repositories (optionally by groups).
185 miho 24  
4988 kaklik 25 require_once 'include/setup.php';
26 require_once 'include/svnlook.php';
27 require_once 'include/template.php';
185 miho 28  
4988 kaklik 29 $vars['action'] = $lang['PROJECTS'];
30 $vars['repname'] = '';
31 $vars['rev'] = 0;
32 $vars['path'] = '';
33 $vars['safepath'] = escape('');
34 $vars['showlastmod'] = $config->showLastModInIndex();
185 miho 35  
36 // Sort the repositories by group
37 $config->sortByGroup();
4988 kaklik 38 $projects = $config->getRepositories();
185 miho 39  
4988 kaklik 40 if (count($projects) == 1 && $projects[0]->hasReadAccess('/')) {
41 header('Location: '.str_replace('&amp;', '', $config->getURL($projects[0], '', 'dir')));
42 exit;
185 miho 43 }
44  
4988 kaklik 45 $i = 0;
46 $parity = 0; // Alternates between every entry, whether it is a group or project
47 $groupparity = 0; // The first project (and first of any group) resets this to 0
48 $curgroup = null;
49 $groupcount = 0;
185 miho 50  
4988 kaklik 51 // Create listing of all configured projects (includes groups if they are used).
52 foreach ($projects as $project) {
53 if (!$project->hasReadAccess('/'))
54 continue;
185 miho 55  
4988 kaklik 56 $listvar = &$listing[$i];
57 // If this is the first project in a group, add an entry for the group.
58 if ($curgroup != $project->group) {
59 $groupcount++;
60 $groupparity = 0;
61 $listvar['notfirstgroup'] = !empty($curgroup);
62 $curgroup = $project->group;
63 $listvar['groupname'] = $curgroup; // Applies until next group is set.
64 $listvar['groupid'] = strtr(base64_encode('grp'.$curgroup), array('+' => '-', '/' => '_', '=' => ''));
185 miho 65  
4988 kaklik 66 // setting to null because template.php won't unset them
67 $listvar['projectlink'] = null;
68 $listvar['projectname'] = null;
69 $listvar['projecturl'] = null;
70 $i++; // Causes the subsequent lines to store data in the next array slot.
71 $listvar = &$listing[$i];
72 $listvar['groupid'] = null;
73 }
74 $listvar['clientrooturl'] = $project->clientRootURL;
75  
76 // Populate variables for latest modification to the current repository
77 if ($config->showLastModInIndex()) {
78 $svnrep = new SVNRepository($project);
79 $log = $svnrep->getLog('/', '', '', true, 1);
80  
81 if (isset($log->entries[0])) {
82 $head = $log->entries[0];
83 $listvar['revision'] = $head->rev;
84 $listvar['date'] = $head->date;
85 $listvar['age'] = datetimeFormatDuration(time() - strtotime($head->date));
86 $listvar['author'] = $head->author;
87 } else {
88 $listvar['revision'] = 0;
89 $listvar['date'] = '';
90 $listvar['age'] = '';
91 $listvar['author'] = '';
92 }
93 }
94  
95 // Create project (repository) listing
96 $url = str_replace('&amp;', '', $config->getURL($project, '', 'dir'));
97 $name = ($config->flatIndex) ? $project->getDisplayName() : $project->name;
98 $listvar['projectlink'] = '<a href="'.$url.'">'.escape($name).'</a>';
99 $listvar['projectname'] = escape($name);
100 $listvar['projecturl'] = $url;
101 $listvar['rowparity'] = $parity % 2;
102 $parity++;
103 $listvar['groupparity'] = $groupparity % 2;
104 $groupparity++;
105 $listvar['groupname'] = ($curgroup != null) ? $curgroup : '';
106 $i++;
185 miho 107 }
108  
4988 kaklik 109 if (empty($listing) && !empty($projects)) {
110 $vars['error'] = $lang['NOACCESS'];
111 sendHeaderForbidden();
112 }
185 miho 113  
4988 kaklik 114 $vars['flatview'] = $config->flatIndex;
115 $vars['treeview'] = !$config->flatIndex;
116 $vars['opentree'] = $config->openTree;
117 $vars['groupcount'] = $groupcount; // Indicates whether any groups were present.
118  
119 renderTemplate('index');