230 lines
6.4 KiB
PHP
230 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace skin\main;
|
|
|
|
// index page
|
|
// ----------
|
|
|
|
function index($ctx) {
|
|
return <<<HTML
|
|
<div class="page"><div class="blog-post-text">
|
|
<div class="clearfix index-book">
|
|
<a class="index-book-image" id="index-book-image" href="https://files.4in1.ws/Images/4in1-cover-en.png" target="_blank" data-link-template="https://files.4in1.ws/Images/4in1-cover-{lang}.png"></a>
|
|
|
|
<a class="index-dl-line" href="https://files.4in1.ws/4in1-en.pdf?4" onmouseenter="IndexPage.setCoverLang('en')">
|
|
<b>Download in English</b><br>
|
|
<div class="index-dl-line-info">PDF <span class="bullet">•</span> 379 pp.</div>
|
|
</a>
|
|
<a class="index-dl-line" href="https://files.4in1.ws/4in1-ru.pdf?4" onmouseenter="IndexPage.setCoverLang('ru')">
|
|
<b>Скачать на русском</b>
|
|
<div class="index-dl-line-info">PDF <span class="bullet">•</span> 453 стр.</div>
|
|
</a>
|
|
|
|
<div class="index-book-updates">
|
|
Released by <a href="https://kiwibyrd.org" target="_blank">kiwi arXiv</a> & <a href="https://kniganews.org" target="_blank">kniganews</a> in 2023<br>
|
|
English translation by Eline Cat<br>
|
|
<div class="index-book-updates-link-wrap">
|
|
<a href="/updates/">The book update log</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div></div>
|
|
HTML;
|
|
|
|
}
|
|
|
|
//function articles($ctx): string {
|
|
//return <<<HTML
|
|
//<div class="empty">
|
|
// {$ctx->lang('blog_no')}
|
|
// {$ctx->if_admin('<a href="/write/">'.$ctx->lang('write').'</a>')}
|
|
//</div>
|
|
//HTML;
|
|
//}
|
|
|
|
function articles($ctx, array $posts): string {
|
|
return <<<HTML
|
|
<div class="blog-list">
|
|
<div class="blog-list-title">
|
|
<!--all posts-->
|
|
{$ctx->if_admin(
|
|
'<span>
|
|
<a href="/articles/write/">new</a>
|
|
</span>'
|
|
)}
|
|
</div>
|
|
{$ctx->indexPostsTable($posts)}
|
|
</div>
|
|
HTML;
|
|
}
|
|
|
|
function indexPostsTable($ctx, array $posts): string {
|
|
$ctx->year = 3000;
|
|
return <<<HTML
|
|
<div class="blog-list-table-wrap">
|
|
<table class="blog-list-table" width="100%" cellspacing="0" cellpadding="0">
|
|
{$ctx->for_each($posts, fn($post) => $ctx->indexPostRow(
|
|
$post->getYear(),
|
|
$post->visible,
|
|
$post->getDate(),
|
|
$post->getUrl(),
|
|
$post->title
|
|
))}
|
|
</table>
|
|
</div>
|
|
HTML;
|
|
}
|
|
|
|
function indexPostRow($ctx, $year, $is_visible, $date, $url, $title): string {
|
|
return <<<HTML
|
|
{$ctx->if_true($ctx->year > $year, $ctx->indexYearLine, $year)}
|
|
<tr class="blog-item-row{$ctx->if_not($is_visible, ' ishidden')}">
|
|
<td class="blog-item-date-cell">
|
|
<span class="blog-item-date">{$date}</span>
|
|
</td>
|
|
<td class="blog-item-title-cell">
|
|
<a class="blog-item-title" href="{$url}">{$title}</a>
|
|
</td>
|
|
</tr>
|
|
HTML;
|
|
}
|
|
|
|
function indexYearLine($ctx, $year): string {
|
|
$ctx->year = $year;
|
|
return <<<HTML
|
|
<tr class="blog-item-row-year">
|
|
<td class="blog-item-date-cell"><span>{$year}</span></td>
|
|
<td></td>
|
|
</tr>
|
|
HTML;
|
|
}
|
|
|
|
|
|
|
|
// any page
|
|
// --------
|
|
|
|
function page($ctx, $page_url, $short_name, $unsafe_html) {
|
|
$html = <<<HTML
|
|
<div class="page">
|
|
{$ctx->if_admin($ctx->pageAdminLinks, $page_url, $short_name)}
|
|
<div class="blog-post-text">{$unsafe_html}</div>
|
|
</div>
|
|
HTML;
|
|
|
|
return [$html, markdownThemeChangeListener()];
|
|
}
|
|
|
|
function pageAdminLinks($ctx, $url, $short_name) {
|
|
return <<<HTML
|
|
<div class="page-edit-links">
|
|
<a href="{$url}edit/">{$ctx->lang('edit')}</a>
|
|
<a href="{$url}delete/?token={$ctx->csrf('delpage'.$short_name)}" onclick="return confirm('{$ctx->lang('pages_page_delete_confirmation')}')">{$ctx->lang('delete')}</a>
|
|
</div>
|
|
HTML;
|
|
|
|
}
|
|
|
|
|
|
// post page
|
|
// ---------
|
|
|
|
function post($ctx, $id, $title, $unsafe_html, $unsafe_toc_html, $date, $visible, $url, $tags, $email, $urlencoded_reply_subject) {
|
|
$html = <<<HTML
|
|
<div class="blog-post-wrap2">
|
|
<div class="blog-post-wrap1">
|
|
<div class="blog-post">
|
|
<div class="blog-post-title">
|
|
<h1>{$title}</h1>
|
|
<div class="blog-post-date">
|
|
{$ctx->if_not($visible, '<b>'.$ctx->lang('blog_post_hidden').'</b> |')}
|
|
{$date}
|
|
{$ctx->if_admin($ctx->postAdminLinks, $url, $id)}
|
|
</div>
|
|
<div class="blog-post-tags clearfix">
|
|
{$ctx->for_each($tags, fn($tag) => $ctx->postTag($tag->getUrl(), $tag->tag))}
|
|
</div>
|
|
</div>
|
|
<div class="blog-post-text">{$unsafe_html}</div>
|
|
</div>
|
|
{$ctx->if_true($unsafe_toc_html, $ctx->postToc, $unsafe_toc_html)}
|
|
</div>
|
|
</div>
|
|
HTML;
|
|
|
|
return [$html, markdownThemeChangeListener()];
|
|
}
|
|
|
|
function postToc($ctx, $unsafe_toc_html) {
|
|
return <<<HTML
|
|
<div class="blog-post-toc">
|
|
<div class="blog-post-toc-wrap">
|
|
<div class="blog-post-toc-inner-wrap">
|
|
<div class="blog-post-toc-title">{$ctx->lang('toc')}</div>
|
|
{$unsafe_toc_html}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
HTML;
|
|
|
|
}
|
|
|
|
function postAdminLinks($ctx, $url, $id) {
|
|
return <<<HTML
|
|
<a href="{$url}edit/">{$ctx->lang('edit')}</a>
|
|
<a href="{$url}delete/?token={$ctx->csrf('delpost'.$id)}" onclick="return confirm('{$ctx->lang('blog_post_delete_confirmation')}')">{$ctx->lang('delete')}</a>
|
|
HTML;
|
|
}
|
|
|
|
function postTag($ctx, $url, $name) {
|
|
return <<<HTML
|
|
<a href="{$url}"><span>#</span>{$name}</a>
|
|
HTML;
|
|
}
|
|
|
|
function markdownThemeChangeListener() {
|
|
return <<<JS
|
|
ThemeSwitcher.addOnChangeListener(function(isDark) {
|
|
var nodes = document.querySelectorAll('.md-image-wrap');
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
var node = nodes[i];
|
|
var alpha = parseInt(node.getAttribute('data-alpha'), 10);
|
|
if (!alpha)
|
|
continue;
|
|
var div = node.querySelector('a > div');
|
|
if (!div) {
|
|
console.warn('could not found a>div on this node:', node);
|
|
continue;
|
|
}
|
|
var style = div.getAttribute('style');
|
|
if (isDark) {
|
|
style = style.replace(/(a[\d]+x[\d]+)\.jpg/, '$1_dark.jpg');
|
|
} else {
|
|
style = style.replace(/(a[\d]+x[\d]+)_dark\.jpg/, '$1.jpg');
|
|
}
|
|
div.setAttribute('style', style);
|
|
}
|
|
});
|
|
JS;
|
|
}
|
|
|
|
|
|
// tag page
|
|
// --------
|
|
|
|
function tag($ctx, $count, $posts, $tag) {
|
|
if (!$count)
|
|
return <<<HTML
|
|
<div class="empty">
|
|
{$ctx->lang('blog_tag_not_found')}
|
|
</div>
|
|
HTML;
|
|
|
|
return <<<HTML
|
|
<div class="blog-list">
|
|
<div class="blog-list-title">#{$tag}</div>
|
|
{$ctx->indexPostsTable($posts)}
|
|
</div>
|
|
HTML;
|
|
}
|