-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_view.php
137 lines (120 loc) · 3.69 KB
/
func_view.php
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
<?php
/**
* This source code is distributed under the terms as layed out in the
* GNU General Public License.
*
* Purpose: To provide File View Page.
*
* Based on phpcvsview
* @author Brian A Cheeseman <bcheesem@users.sourceforge.net>
* @copyright 2003-2005 Brian A Cheeseman
*
* Thanks To:
* Nigel McNie - Suggestion of Caching of source code from repository, hence improving efficiency.
*
* Ported to bitweaver framework by Lester Caine 2006-12-29
* @version $Id$
**/
//include_once( UTIL_PKG_PATH . 'geshi/geshi.php' );
function DisplayFileContents($File, $Revision = "")
{
global $gBitSmarty, $config, $env;
// Create our CVS connection object and set the required properties.
$CVSServer = new CVS_PServer($env['CVSSettings']['cvsroot'], $env['CVSSettings']['server'], $env['CVSSettings']['username'], $env['CVSSettings']['passwd']);
// Check and see if this file and version has already been viewed and exists in the cache.
$CachedFileName = $config['Cache']['Location'];
if ($config['Cache']['Enable']) {
if (!file_exists($CachedFileName)) {
mkdir($CachedFileName, 0750);
}
$CachedFileName .= "/".str_replace("/", "_", $File).",$Revision";
}
if (file_exists($CachedFileName) && $config['Cache']['Enable']) {
$fd = fopen($CachedFileName, "r");
if ($fd !== false) {
fpassthru($fd);
fclose($fd);
}
}
else
{
// Connect to the CVS server.
if ($CVSServer->Connect() === true) {
// Authenticate against the server.
$Response = $CVSServer->Authenticate();
if ($Response !== true) {
return;
}
// Get a RLOG of the module path specified in $env['mod_path'].
$CVSServer->RLog($env['mod_path']);
// "Export" the file.
$Response = $CVSServer->ExportFile($File, $Revision);
if ($Response !== true) {
return;
}
/*
if ($config['GeSHi']['Enable']) {
// Create the GeSHi instance and parse the output.
// TODO: setup code to auto identify the highlighting class to use for current file.
$FileExt = substr($File, strrpos($File, '.')+1);
$Language = guess_highlighter($FileExt);
if (is_array($Language)) {
$Language = $Language[0];
}
$geshi = new GeSHi($CVSServer->FILECONTENTS, $Language, $config['GeSHi']['HighlightersPath']);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_line_style('background: #fcfcfc;');
$geshi->set_tab_width(4);
$hlcontent = $geshi->parse_code();
// Store in the current cache.
if ($config['Cache']['Enable']) {
$fd = fopen($CachedFileName, "w");
if ($fd !== false) {
fwrite($fd, '<p class="source">'.$hlcontent.'</p>');
fclose($fd);
}
}
// Display the file contents.
echo '<p class="source">';
echo $hlcontent;
echo '</p>';
}
else
{
$search = array('<', '>', '\n', '\t');
$replace = array('<', '>', '', ' ');
$content = str_replace($search, $replace, $CVSServer->FILECONTENTS);
$source = explode('\n', $content);
$soure_size = sizeof($source);
if ($config['Cache']['Enable']) {
$fd = fopen($CachedFileName, "w");
if ($fd !== false) {
fwrite($fd, "<pre>\n");
}
}
else
{
$fd = false;
}
echo "<pre>\n";
for($i = 1; $i <= $soure_size; $i++) {
$line = '<a name="'.$i.'" class="numberedLine"> '.str_repeat(' ', strlen($soure_size) - strlen($i)). $i.'.</a> ' . $source[$i-1] . "\n";
if ($fd !== false) {
fwrite($fd, $line);
}
echo $line;
}
if ($fd !== false) {
fwrite($fd, "</pre>\n");
}
echo "</pre>\n";
}
*/
// Close the connection.
$CVSServer->Disconnect();
} else {
$gBitSmarty->assign('error', "ERROR: Could not connect to the PServer." );
}
}
}
?>