File inc/format.inc.php changed (mode: 100644) (index 7eb899e..11eff58) |
... |
... |
function rg_format_markdown($a) |
154 |
154 |
return preg_replace($k, $v, $a); |
return preg_replace($k, $v, $a); |
155 |
155 |
} |
} |
156 |
156 |
|
|
|
157 |
|
function rg_format_unk_to_html_string(string $file_name, string $content) |
|
158 |
|
{ |
|
159 |
|
$ret = array('ok' => 0); |
|
160 |
|
do { |
|
161 |
|
if (stristr($file_name, '.txt')) { |
|
162 |
|
$ret['doc'] = nl2br(htmlspecialchars($content)); |
|
163 |
|
$ret['ok'] = 1; |
|
164 |
|
break; |
|
165 |
|
} |
|
166 |
|
|
|
167 |
|
if (stristr($file_name, '.md')) { |
|
168 |
|
$content = htmlspecialchars($content); // For now, we do not support inline HTML |
|
169 |
|
$format = 'markdown'; |
|
170 |
|
} else { |
|
171 |
|
$ret['doc'] = ''; |
|
172 |
|
$ret['ok'] = 1; |
|
173 |
|
break; |
|
174 |
|
} |
|
175 |
|
|
|
176 |
|
$a = array( |
|
177 |
|
'cmds' => array( |
|
178 |
|
'cmd1' => array( |
|
179 |
|
'cmd' => 'pandoc --toc' |
|
180 |
|
. ' --from ' . escapeshellarg($format) |
|
181 |
|
. ' --to html', |
|
182 |
|
'out_buf' => $content |
|
183 |
|
) |
|
184 |
|
) |
|
185 |
|
); |
|
186 |
|
$r = rg_exec2($a); |
|
187 |
|
//rg_debug('exec: ' . print_r($r, TRUE)); |
|
188 |
|
if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) { |
|
189 |
|
$ret['errmsg'] = 'cannot generate: ' |
|
190 |
|
. $r['cmds']['cmd1']['last_errmsg'] |
|
191 |
|
. ' [' . $r['cmds']['cmd1']['err_buf'] . ']'; |
|
192 |
|
break; |
|
193 |
|
} |
|
194 |
|
|
|
195 |
|
$ret['doc'] = $r['cmds']['cmd1']['in_buf']; |
|
196 |
|
$ret['ok'] = 1; |
|
197 |
|
} while (0); |
|
198 |
|
|
|
199 |
|
return $ret; |
|
200 |
|
} |
|
201 |
|
|
|
202 |
|
function rg_format_unk_to_html_file(string $file, string $file_name) |
|
203 |
|
{ |
|
204 |
|
$ret = array('ok' => 0); |
|
205 |
|
do { |
|
206 |
|
$c = @file_get_contents($file); |
|
207 |
|
if ($c === FALSE) { |
|
208 |
|
$ret['errmsg'] = 'cannot load file ' . $file; |
|
209 |
|
break; |
|
210 |
|
} |
|
211 |
|
|
|
212 |
|
$ret = rg_format_unk_to_html_string($file_name, $c); |
|
213 |
|
} while (0); |
|
214 |
|
|
|
215 |
|
return $ret; |
|
216 |
|
} |
File inc/repo.inc.php changed (mode: 100644) (index 72de84d..c6a38a6) |
... |
... |
require_once(__DIR__ . '/prof.inc.php'); |
9 |
9 |
require_once(__DIR__ . '/mail.inc.php'); |
require_once(__DIR__ . '/mail.inc.php'); |
10 |
10 |
require_once(__DIR__ . '/events.inc.php'); |
require_once(__DIR__ . '/events.inc.php'); |
11 |
11 |
require_once(__DIR__ . '/webhooks.inc.php'); |
require_once(__DIR__ . '/webhooks.inc.php'); |
|
12 |
|
require_once(__DIR__ . '/format.inc.php'); |
12 |
13 |
|
|
13 |
14 |
$rg_repo_refs_rights = array( |
$rg_repo_refs_rights = array( |
14 |
15 |
"F" => "Fetch", |
"F" => "Fetch", |
|
... |
... |
function rg_repo_fetch_push_helper($db, $host, $prefix, $repo_user, |
2515 |
2516 |
return $ret; |
return $ret; |
2516 |
2517 |
} |
} |
2517 |
2518 |
|
|
|
2519 |
|
// Renders readme files |
|
2520 |
|
function rg_repo_show_readme(array $rg, string $ref, string $path) |
|
2521 |
|
{ |
|
2522 |
|
rg_prof_start('repo_show_readme'); |
|
2523 |
|
rg_log_enter('repo_show_readme: ref=' . $ref); |
|
2524 |
|
|
|
2525 |
|
$ret = ''; |
|
2526 |
|
do { |
|
2527 |
|
$list = rg_git_ls_tree($rg['repo_path'], $ref, $path); |
|
2528 |
|
if ($list === FALSE) { |
|
2529 |
|
$ret .= rg_template('repo/readme/err.html', $rg, TRUE /*xss*/); |
|
2530 |
|
break; |
|
2531 |
|
} |
|
2532 |
|
|
|
2533 |
|
rg_log_debug('git_ls_tree: ' . print_r($list, TRUE)); |
|
2534 |
|
foreach ($list as $i) { |
|
2535 |
|
if (!stristr($i['file'], 'readme') |
|
2536 |
|
&& !stristr($i['file'], 'read-me') |
|
2537 |
|
&& !stristr($i['file'], 'howto')) |
|
2538 |
|
continue; |
|
2539 |
|
|
|
2540 |
|
$r = rg_git_content($i['ref']); |
|
2541 |
|
rg_log_debug('git_content returned: ' . print_r($r, TRUE)); |
|
2542 |
|
|
|
2543 |
|
$rg['readme_file'] = $i['file']; |
|
2544 |
|
|
|
2545 |
|
$r = rg_format_unk_to_html_string($i['file'], $r); |
|
2546 |
|
if ($r['ok'] != 1) { |
|
2547 |
|
rg_log('error: ' . $r['errmsg']); |
|
2548 |
|
$ret .= rg_template('repo/readme/err_file.html', $rg, TRUE /*xss*/); |
|
2549 |
|
continue; |
|
2550 |
|
} |
|
2551 |
|
|
|
2552 |
|
if (empty($r['doc'])) |
|
2553 |
|
continue; |
|
2554 |
|
|
|
2555 |
|
$rg['HTML:readme_doc'] = $r['doc']; |
|
2556 |
|
$ret .= rg_template('repo/readme/one.html', $rg, TRUE /*xss*/); |
|
2557 |
|
} |
|
2558 |
|
} while (0); |
|
2559 |
|
|
|
2560 |
|
rg_log_exit(); |
|
2561 |
|
rg_prof_end('repo_show_readme'); |
|
2562 |
|
return $ret; |
|
2563 |
|
} |
File inc/user/repo-page.php changed (mode: 100644) (index dc66fe8..a4d2de8) |
... |
... |
if (strcmp($_subop, "history") == 0) { |
367 |
367 |
$_repo_body .= rg_warning("Cannot load history. Try again later."); |
$_repo_body .= rg_warning("Cannot load history. Try again later."); |
368 |
368 |
else |
else |
369 |
369 |
$_repo_body .= rg_template_table("repo/history", $hist, $rg); |
$_repo_body .= rg_template_table("repo/history", $hist, $rg); |
|
370 |
|
|
|
371 |
|
$_repo_body .= rg_repo_show_readme($rg, 'HEAD', '.' /*path*/); |
370 |
372 |
} else if (strcmp($_subop, "admin") == 0) { |
} else if (strcmp($_subop, "admin") == 0) { |
371 |
373 |
$_repo_body .= rg_repo_admin($db, $rg, $paras); |
$_repo_body .= rg_repo_admin($db, $rg, $paras); |
372 |
374 |
} else if (strcmp($_subop, "source") == 0) { |
} else if (strcmp($_subop, "source") == 0) { |
File tests/markdown1.php added (mode: 100644) (index 0000000..0533d9c) |
|
1 |
|
<?php |
|
2 |
|
error_reporting(E_ALL | E_STRICT); |
|
3 |
|
ini_set("track_errors", "On"); |
|
4 |
|
|
|
5 |
|
$test_normal = TRUE; |
|
6 |
|
|
|
7 |
|
$INC = dirname(__FILE__) . "/../inc"; |
|
8 |
|
require_once(dirname(__FILE__) . "/config.php"); |
|
9 |
|
require_once($INC . "/init.inc.php"); |
|
10 |
|
require_once($INC . "/git.inc.php"); |
|
11 |
|
require_once($INC . '/format.inc.php'); |
|
12 |
|
require_once("helpers.inc.php"); |
|
13 |
|
require_once("http.inc.php"); |
|
14 |
|
|
|
15 |
|
rg_log_set_file("markdown1.log"); |
|
16 |
|
|
|
17 |
|
require_once("common.php"); |
|
18 |
|
|
|
19 |
|
$_testns = 'markdown1'; |
|
20 |
|
|
|
21 |
|
|
|
22 |
|
rg_test_create_user($db, $rg_ui); |
|
23 |
|
$info = array('id' => $rg_ui['username']); |
|
24 |
|
prepare_http($info); |
|
25 |
|
|
|
26 |
|
rg_test_create_repo($db, $rg_ui, $repo); |
|
27 |
|
$r = test_login($test_url, $rg_ui); |
|
28 |
|
if ($r === FALSE) { |
|
29 |
|
rg_log("Cannot login!"); |
|
30 |
|
exit(1); |
|
31 |
|
} |
|
32 |
|
|
|
33 |
|
rg_test_upload_ssh_key($db, $rg_ui, 'markdown1', $kn); |
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
rg_log(''); |
|
38 |
|
rg_log_enter('Testing rg_markdown_to_html...'); |
|
39 |
|
$r = rg_format_unk_to_html_file('markdown1-a.md', 'markdown1-a.md'); |
|
40 |
|
if ($r['ok'] != 1) { |
|
41 |
|
rg_log('error: ' . $r['errmsg']); |
|
42 |
|
exit(1); |
|
43 |
|
} |
|
44 |
|
|
|
45 |
|
$e = '<h2 id="test-2">Test 2</h2>' . "\n" |
|
46 |
|
. '<p>some text</p>' . "\n" |
|
47 |
|
. '<h3 id="test-3">Test 3</h3>' . "\n" |
|
48 |
|
. '<p>bla bla</p>' . "\n" |
|
49 |
|
. '<p><xss></p>' . "\n" |
|
50 |
|
. '<p><b>this is bold generated by embedding html inside' . "\n" |
|
51 |
|
. 'markdown</b></p>' . "\n" |
|
52 |
|
. '<p>This is markdown1-a.md file.</p>' . "\n"; |
|
53 |
|
if (strcmp($r['doc'], $e) != 0) { |
|
54 |
|
rg_log_ml('error: mismatch: doc r/e:' . "\n" . $r['doc'] . "\n" . $e); |
|
55 |
|
exit(1); |
|
56 |
|
} |
|
57 |
|
rg_log_exit(); |
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
rg_log(''); |
|
62 |
|
rg_log_enter('Trying to push main...'); |
|
63 |
|
$remote = 'ssh://rocketgit@' . $rg_ssh_host . ':' .$rg_ssh_port |
|
64 |
|
. '/user/' . escapeshellarg($rg_ui['username']) |
|
65 |
|
. '/' . escapeshellarg($repo['name']); |
|
66 |
|
$r = rg_exec('rm -rf temp_repos/markdown1' |
|
67 |
|
. ' && mkdir -p temp_repos/markdown1' |
|
68 |
|
. ' && cp markdown1-a.md temp_repos/markdown1/ReadMe.mD' |
|
69 |
|
. ' && cp markdown1-b.md temp_repos/markdown1/readMe.mD' |
|
70 |
|
. ' && cp markdown1-c.html temp_repos/markdown1/readMe.html' |
|
71 |
|
. ' && cp markdown1-d.txt temp_repos/markdown1/readme.txt' |
|
72 |
|
. ' && cd temp_repos/markdown1' |
|
73 |
|
. ' && git init --initial-branch=main' |
|
74 |
|
. ' && git add .' |
|
75 |
|
. ' && git commit -m "bla"' |
|
76 |
|
. ' && git remote add origin ' . $remote |
|
77 |
|
. ' && git push origin main:main', |
|
78 |
|
'', FALSE, FALSE, FALSE); |
|
79 |
|
if ($r['ok'] != 1) { |
|
80 |
|
rg_log_ml('out: ' . print_r($r, TRUE)); |
|
81 |
|
rg_log('Seems I cannot push main!'); |
|
82 |
|
exit(1); |
|
83 |
|
} |
|
84 |
|
rg_log_exit(); |
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
rg_log(''); |
|
89 |
|
rg_log_enter('Checking on web the readme.md file...'); |
|
90 |
|
$data = array(); |
|
91 |
|
$headers = array(); |
|
92 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
93 |
|
. '/' . rawurlencode($repo['name']), $data, $headers); |
|
94 |
|
if (!strstr($r['body'], 'This is markdown1-a.md file.') |
|
95 |
|
|| !strstr($r['body'], 'This is markdown1-b.md file')) { |
|
96 |
|
rg_log('body: ' . $r['body']); |
|
97 |
|
rg_log_ml('Markdown not rendered correctly!'); |
|
98 |
|
exit(1); |
|
99 |
|
} |
|
100 |
|
rg_log_exit(); |
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
rg_log('OK!'); |