-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshowsource.php
148 lines (130 loc) · 4.65 KB
/
showsource.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
138
139
140
141
142
143
144
145
146
147
148
<?php
# **************************************************************************#
# MolyX2
# ------------------------------------------------------
# @copyright (c) 2009-2010 MolyX Group..
# @official forum http://molyx.com
# @license http://opensource.org/licenses/gpl-2.0.php GNU Public License 2.0
#
# $Id$
# **************************************************************************#
define('THIS_SCRIPT', 'showsource');
require_once('./global.php');
if (!defined('DEVELOPER_MODE') || !DEVELOPER_MODE || !isset($_GET['file']) || strpos(',' . SUPERADMIN . ',', ",{$bbuserinfo['id']},") === false)
{
exit();
}
$file = urldecode($_GET['file']);
$line = isset($_GET['line']) ? intval($_GET['line']) : 0;
$prev = isset($_GET['prev']) ? intval($_GET['prev']) : 10;
$next = isset($_GET['next']) ? intval($_GET['next']) : 10;
hl_source($file, $line, $prev, $next);
/**
* 显示一个文件的部分代码
*
* @param string $file 文件名
* @param int $line 要标注的行
* @param int $prev 在主行前面显示的行数
* @param int $next 在主行后面显示的行数
* @return string
*/
function hl_source($file, $line, $prev = 10, $next = 10)
{
if (!is_file($file))
{
exit();
}
global $forums;
$forums->func->load_lang('debug');
// 读取代码
$data = highlight_file($file, true);
// 分割行
$data = explode('<br />', $data);
$count = count($data) - 1;
// 计算显示行
if ($prev < 0)
{
$prev = 0;
}
if ($next < 0)
{
$next = 0;
}
$start = $line - $prev;
if ($start < 1)
{
$start = 1;
}
$end = $line + $next;
if ($end > $count)
{
$end = $count + 1;
}
$full_prev = $line;
$full_next = $count - $line + 1;
echo '<style type="text/css">
.button {font-size: 12px; text-decoration: none; display: inline-block; padding: 0 3px 0 3px; border: 1px solid;}
</style>';
// 显示
if ($prev != $full_prev)
{
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . ($prev + 1) . '&next=' . $next . '#' . ($line - 15) . '">+</a>';
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . ($prev + 10) . '&next=' . $next . '#' . ($line - 15) . '">+10</a>';
}
if ($prev != 0)
{
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . ($prev - 1) . '&next=' . $next . '#' . ($line - 15) . '">-</a>';
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . ($prev - 10) . '&next=' . $next . '#' . ($line - 15) . '">-10</a>';
}
echo '<br />';
echo '<table cellspacing="0" cellpadding="0" style="font-size: 12px;"><tr>';
echo '<td style="vertical-align: top;"><code style="background-color: #FFFFCC; color: #666666;">';
for ($i = $start; $i <= $end; $i++)
{
echo '<span style="height: 20px;">';
echo '<a name="' . $i . '"></a>';
echo ($line == $i) ? '<span style="background-color: #FF0000; color: #FFFFFF;">' : '';
echo str_repeat(' ', (strlen($end) - strlen($i)) + 1);
echo $i;
echo ' ';
echo ($line == $i) ? '</span>' : '';
echo '</span>';
echo '<br />';
}
echo '</code></td><td style="vertical-align: top;" nowrap="nowrap"><code>';
$t = $start;
while ($start <= $end)
{
echo '<span style="height: 20px;">';
echo ' ' . $data[$start - 1];
echo '</span>';
echo '<br />';
++$start;
}
echo '</code></td>';
echo '</tr></table>';
if ($next != $full_next)
{
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . $prev . '&next=' . ($next + 1) . '#' . ($line - 15) . '">+</a>';
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . $prev . '&next=' . ($next + 10) . '#' . ($line - 15) . '">+10</a>';
}
if ($next != 0)
{
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . $prev . '&next=' . ($next - 1) . '#' . ($line - 15) . '">-</a>';
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . $prev . '&next=' . ($next - 10) . '#' . ($line - 15) . '">-10</a>';
}
if ($prev != $full_prev || $next != $full_next)
{
echo ' ';
echo '<a class="button" href="' . ROOT_PATH . 'showsource.php?file=' . urlencode($file) . '&line=' . $line . '&prev=' . $full_prev . '&next=' . $full_next . '#' . ($line - 15) . '">' . $forums->lang['view_full_source'] . '</a>';
}
}
?>