extract create_pm_header

This commit is contained in:
Zankaria 2024-09-20 02:03:42 +02:00
parent 25b2b6bc6e
commit 23f3d15a52
4 changed files with 65 additions and 15 deletions

View File

@ -401,7 +401,18 @@ class Post {
public function build($index=false) {
global $board, $config;
return Element($config['file_post_reply'], array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'mod' => $this->mod));
$options = [
'config' => $config,
'board' => $board,
'post' => &$this,
'index' => $index,
'mod' => $this->mod
];
if ($this->mod) {
$options['pm'] = create_pm_header();
}
return Element($config['file_post_reply'], $options);
}
};
@ -465,8 +476,21 @@ class Thread {
event('show-thread', $this);
$options = [
'config' => $config,
'board' => $board,
'post' => &$this,
'index' => $index,
'hasnoko50' => $hasnoko50,
'isnoko50' => $isnoko50,
'mod' => $this->mod
];
if ($this->mod) {
$options['pm'] = create_pm_header();
}
$file = ($index && $config['file_board']) ? $config['file_post_thread_fileboard'] : $config['file_post_thread'];
$built = Element($file, array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'hasnoko50' => $hasnoko50, 'isnoko50' => $isnoko50, 'mod' => $this->mod));
$built = Element($file, $options);
return $built;
}

View File

@ -1301,7 +1301,14 @@ function index($page, $mod=false, $brief = false) {
}
if ($config['file_board']) {
$body = Element($config['file_fileboard'], array('body' => $body, 'mod' => $mod));
$options = [
'body' => $body,
'mod' => $mod
];
if ($mod) {
$options['pm'] = create_pm_header();
}
$body = Element($config['file_fileboard'], $options);
}
return array(
@ -1620,7 +1627,7 @@ function incrementSpamHash($hash) {
}
function buildIndex($global_api = "yes") {
global $board, $config, $build_pages;
global $board, $config, $build_pages, $mod;
$catalog_api_action = generation_strategy('sb_api', array($board['uri']));
@ -1692,6 +1699,9 @@ function buildIndex($global_api = "yes") {
$content['pages'][$page-1]['selected'] = true;
$content['btn'] = getPageButtons($content['pages']);
$content['antibot'] = $antibot;
if ($mod) {
$content['pm'] = create_pm_header();
}
file_write($filename, Element($config['file_board_index'], $content));
}
@ -2274,7 +2284,7 @@ function buildThread($id, $return = false, $mod = false) {
$hasnoko50 = $thread->postCount() >= $config['noko50_min'];
$antibot = $mod || $return ? false : create_antibot($board['uri'], $id);
$body = Element($config['file_thread'], array(
$options = [
'board' => $board,
'thread' => $thread,
'body' => $thread->build(),
@ -2286,7 +2296,12 @@ function buildThread($id, $return = false, $mod = false) {
'antibot' => $antibot,
'boardlist' => createBoardlist($mod),
'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index'])
));
];
if ($mod) {
$options['pm'] = create_pm_header();
}
$body = Element($config['file_thread'], $options);
// json api
if ($config['api']['enabled'] && !$mod) {
@ -2323,7 +2338,7 @@ function buildThread($id, $return = false, $mod = false) {
}
function buildThread50($id, $return = false, $mod = false, $thread = null, $antibot = false) {
global $board, $config, $build_pages;
global $board, $config;
$id = round($id);
if ($antibot)
@ -2381,7 +2396,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
$hasnoko50 = $thread->postCount() >= $config['noko50_min'];
$body = Element($config['file_thread'], array(
$options = [
'board' => $board,
'thread' => $thread,
'body' => $thread->build(false, true),
@ -2393,7 +2408,12 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
'antibot' => $mod ? false : ($antibot ? $antibot : create_antibot($board['uri'], $id)),
'boardlist' => createBoardlist($mod),
'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index'])
));
];
if ($mod) {
$options['pm'] = create_pm_header();
}
$body = Element($config['file_thread'], $options);
if ($return) {
return $body;

View File

@ -28,6 +28,7 @@ function mod_page($title, $template, $args, $subtitle = false) {
'title' => $title,
'subtitle' => $subtitle,
'boardlist' => createBoardlist($mod),
'pm' => create_pm_header(),
'body' => Element($template,
array_merge(
array('config' => $config, 'mod' => $mod),
@ -511,7 +512,7 @@ function mod_new_board(Context $ctx) {
if (!openBoard($_POST['uri']))
error(_("Couldn't open board after creation."));
$query = Element('posts.sql', array('board' => $board['uri']));
$query = Element('posts.sql', [ 'board' => $board['uri'] ]);
if (mysql_version() < 50503)
$query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query);
@ -785,6 +786,7 @@ function mod_view_board(Context $ctx, $boardName, $page_no = 1) {
$page['btn'] = getPageButtons($page['pages'], true);
$page['mod'] = true;
$page['config'] = $config;
$page['pm'] = create_pm_header();
echo Element($config['file_board_index'], $page);
}
@ -2358,6 +2360,7 @@ function mod_reports(Context $ctx) {
'report' => $report,
'config' => $config,
'mod' => $mod,
'pm' => create_pm_header(),
'token' => make_secure_link_token('reports/' . $report['id'] . '/dismiss'),
'token_all' => make_secure_link_token('reports/' . $report['id'] . '/dismiss&all'),
'token_post' => make_secure_link_token('reports/'. $report['id'] . '/dismiss&post'),
@ -2609,6 +2612,7 @@ function mod_config(Context $ctx, $board_config = false) {
<p style="text-align:center">You may proceed with these changes manually by copying and pasting the following code to the end of <strong>' . $config_file . '</strong>:</p>
<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" readonly>' . $config_append . '</textarea>
';
$page['pm'] = create_pm_header();
echo Element($config['file_page_template'], $page);
exit;
}
@ -2869,7 +2873,13 @@ function mod_edit_page(Context $ctx, $id) {
$fn = (isset($board['uri']) ? ($board['uri'] . '/') : '') . $page['name'] . '.html';
$body = "<div class='ban'>$write</div>";
$html = Element($config['file_page_template'], array('config' => $config, 'boardlist' => createBoardlist(), 'body' => $body, 'title' => utf8tohtml($page['title'])));
$html = Element($config['file_page_template'], [
'config' => $config,
'boardlist' => createBoardlist(),
'body' => $body,
'title' => utf8tohtml($page['title']),
'pm' => create_pm_header()
]);
file_write($fn, $html);
}

View File

@ -34,10 +34,6 @@ function Element($templateFile, array $options) {
if (!$twig)
load_twig();
if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) {
$options['pm'] = create_pm_header();
}
if (isset($options['body']) && $config['debug']) {
$_debug = $debug;