-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
txp-index.php
62 lines (52 loc) · 1.71 KB
/
txp-index.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
<?php
$gitview = 'https://github.com/textpattern/textpattern/blob';
$outdir = '.github/index';
@mkdir($outdir);
$branch = index_get_branch();
index_code('callback_event');
index_code('callback_event_ref');
exit;
function index_code($search)
{
global $gitview, $branch, $outdir;
$out = array();
$out2 = array();
$txt = shell_exec('grep --exclude-dir=.github --include=\*.php -rn . -e "'.escapeshellcmd($search).'("');
if (preg_match_all('%^\./(.*?):(.*?):(?:\s+)?(.*?'.preg_quote($search).'\((.*))$%ium', $txt, $mm)) {
foreach ($mm[3] as $key=>$d) {
if (! preg_match('%^(\*|function)%', trim($d))) {
$d = trim(preg_replace('%(<\?php|\?\>)%', '', $d));
$k = preg_replace('%[\,\)].*$%', '', $mm[4][$key]);
$out["{$k}_{$key}"] = "<tr><td>{$k}</td><td>{$d}</td><td><a href='{$gitview}/{$branch}/{$mm[1][$key]}#L{$mm[2][$key]}'>{$mm[1][$key]}</a></td></tr>";
}
}
ksort($out);
index_file_save($search, '<table class="idx">'.join("\n", $out)."\n".'</table>');
}
}
function index_get_branch()
{
$txt = @file_get_contents('.git/HEAD');
if (preg_match('%refs/heads/(.*)$%m', $txt, $mm)) {
return $mm[1];
}
return '';
}
function index_file_save($name, $data)
{
global $branch, $outdir;
$head =<<<EOF
<!DOCTYPE html><html lang="en-gb" dir="ltr">
<head>
<meta charset="utf-8">
<title>{$branch} :: {$name}</title>
<style>
body { background-color: #fafafa; }
.idx tr:nth-child(odd) { background-color: #eee; }
.idx tr:hover { background-color: #ccc; }
</style>
</head>
<body>
EOF;
file_put_contents("{$outdir}/{$branch}__{$name}.html", $head.$data.'</body></html>');
}