[go: up one dir, main page]

Menu

[r63]: / trunk / code.php  Maximize  Restore  History

Download this file

243 lines (223 with data), 7.4 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
session_start();
include_once('inc/config.php');
mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_database);
include_once('inc/util.inc');
include_once('inc/svn/phpsvnclient.php');
include_once('inc/geshi.php');
// Setup Theme
$modules = getModules();
$pageTitle = 'Source Code';
$curPage = 'code';
$theme = getTheme();
$js = '<link rel="stylesheet" type="text/css" href="'.$theme.'dawn.css"/>';
include_once($theme.'header.php');
$repoUrl = getRepoUrl();
if (empty($repoUrl)) {
echo '
<p>'._('SVN Repository not configured yet.').'</p>';
include($theme.'footer.php');
return;
}
$svn = new phpsvnclient($repoUrl);
$show_dirs = true;
//-----------------------------------------------
// Directory
//-----------------------------------------------
if (isset($_GET['directory'])) {
$files = $svn->getDirectoryFiles($_GET['directory']);
//-----------------------------------------------
// File
//-----------------------------------------------
} elseif (isset($_GET['file'])) {
$show_dirs = false;
$logs = $svn->getFileLogs($_GET['file']);
if (isset($_GET['revision'])) {
$file = $svn->getFile($_GET['file'], $_GET['revision']);
// get the id of the current revision
for ($i=0; $i<count($logs); $i++) {
$found = array_search($_GET['revision'], $logs[$i]);
if ($found !== false) {
$id = $i;
break;
}
}
} else {
$file = $svn->getFile($_GET['file']);
$id = count($logs) - 1;
}
$prevRev = isset($logs[$id-1]) ? $logs[$id-1]['version'] : false;
$nextRev = isset($logs[$id+1]) ? $logs[$id+1]['version'] : false;
$date = daysAgo($logs[$id]['date']);
$language = getSourceCodeLanguage($_GET['file']);
$geshi = new GeSHi($file, $language);
$geshi->set_overall_id('source-code');
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->enable_keyword_links(false);
$geshi->enable_classes();
// Show the previous revision, if applicable
echo '
<div id="revision-nav">';
if ($prevRev) {
echo '
<a href="code.php?file='.$_GET['file'].'&amp;revision='.$prevRev.'">'._('Previous Change').'</a> ';
}
if ($nextRev) {
echo '
| <a href="code.php?file='.$_GET['file'].'&amp;revision='.$nextRev.'">'._('Next Change').'</a>';
}
echo '
</div>';
// Show the breadcrumbs
echo '
<p class="breadcrumbs">
'.getBreadcrumbs($_GET['file']).'
</p>';
// Show file details
echo '
<div id="revision-info">
<p>'.sprintf(_('Revision %d'), $logs[$id]['version']).' '.sprintf(_('(checked in by %s, %s)'), $logs[$id]['author'], $date).'</p>
<p>'.$logs[$id]['comment'].'</p>
</div>
<div id="source-code-header">
<b>'._('Line').'</b>
</div>';
echo $geshi->parse_code();
//-----------------------------------------------
// Default Directory
//-----------------------------------------------
} else {
$files = $svn->getDirectoryFiles();
}
//-----------------------------------------------
// Show the Directory Listing
//-----------------------------------------------
if ($show_dirs) {
$h2 = _('Source Code');
if (isset($_GET['directory'])) {
$h2 = $_GET['directory'];
}
// Sort by directories first, then files
$files = msort($files, 'path', true);
$files = dirSort($files);
echo '
<h2>'.$h2.'</h2><br/>
<table id="code" class="data">
<thead>
<tr>
<th class="file_link">'._('Directory').'</th>
<th>'._('Last Updated').'</th>
<th>'._('Last Change').'</th>
</tr>
</thead>
<tbody>';
if (isset($_GET['directory'])) {
$pos = strrpos($_GET['directory'], '/');
if ($pos === false) {
$up = 'code.php';
} else {
$up = '?directory='.substr($_GET['directory'], 0, $pos);
}
echo '
<tr>
<td><a class="up" href="'.$up.'">'._('up a level').'</a></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>';
}
$first = true;
foreach ($files as $file) {
if ($file['status'] == 'HTTP/1.1 200 OK' && !$first) {
$link = strrchr($file['path'], "/");
if ($link) {
$link = substr($link, 1);
} else {
$link = $file['path'];
}
$comment = '';
$size = '';
if ($file['type'] == 'file') {
$logs = $svn->getFileLogs($file['path']);
$id = count($logs) - 1;
if ($id > 0) {
$comment = $logs[$id]['comment'];
}
if (strlen($comment) > 100) {
$comment = substr($comment, 0, 100).'...';
}
}
echo '
<tr>
<td><a class="'.$file['type'].'" href="?'.$file['type'].'='.$file['path'].'">'.$link.'</a></td>
<td>'.date('Y-m-d', strtotime($file['last-mod'])).'</td>
<td class="last_change">'.$comment.'</td>
</tr>';
}
$first = false;
}
echo '
</tbody>
</table>';
}
include($theme.'footer.php');
// TODO
// Move these to the inc/util file
function dirSort($arr)
{
$top = array();
$count = count($arr);
for ($i = 0; $i < $count; $i++) {
if ($arr[$i]['type'] == 'directory') {
$top[$i+$count] = $arr[$i];
unset($arr[$i]);
}
}
return array_merge($top, $arr);
}
function getBreadcrumbs ($path)
{
global $mainUrl;
$crumbs = explode("/",$path);
if (!isset($url)) {
$url = 'code.php';
}
$out = '<a href="'.$url.'">'._('root').'</a> / ';
$url = $mainUrl."?directory=";
for ($i=0; $i < count($crumbs)-1; $i++) {
$link = $crumbs[$i];
if ($i > 0) {
$url .= '/';
}
$url .= $crumbs[$i];
$out .= '<a href="'.$url.'">'.$link.'</a> / ';
}
$out .= '<span>'.$crumbs[$i].'</span>';
return $out;
}
function msort($array, $id="id", $sort_ascending=true)
{
$temp_array = array();
while (count($array) > 0) {
$lowest_id = 0;
$index=0;
foreach ($array as $item) {
if (isset($item[$id])) {
if ($array[$lowest_id][$id]) {
if (strtolower($item[$id]) < strtolower($array[$lowest_id][$id])) {
$lowest_id = $index;
}
}
}
$index++;
}
$temp_array[] = $array[$lowest_id];
$array = array_merge(array_slice($array, 0,$lowest_id), array_slice($array, $lowest_id+1));
}
if ($sort_ascending) {
return $temp_array;
} else {
return array_reverse($temp_array);
}
}