Add catalog page

Resolves #107.
This commit is contained in:
Trevor Slocum 2020-08-11 06:01:00 -07:00
parent 3b4e486160
commit d705edda91
5 changed files with 67 additions and 4 deletions

View file

@ -115,6 +115,17 @@ hr {
clear: both;
}
.catalogpost {
display: inline-block;
vertical-align: top;
overflow: hidden;
white-space: nowrap;
text-align: center;
text-overflow: ellipsis;
min-width: 100px;
padding: 0px 3px 3px;
}
.login {
text-align: center;
}

View file

@ -43,6 +43,9 @@ if (!defined('TINYIB_WORDBREAK')) {
if (!defined('TINYIB_TIMEZONE')) {
define('TINYIB_TIMEZONE', '');
}
if (!defined('TINYIB_CATALOG')) {
define('TINYIB_CATALOG', true);
}
if (!defined('TINYIB_DBMIGRATE')) {
define('TINYIB_DBMIGRATE', false);
}

View file

@ -240,8 +240,8 @@ function writePage($filename, $contents) {
}
function fixLinksInRes($html) {
$search = array(' href="css/', ' src="js/', ' href="src/', ' href="thumb/', ' href="res/', ' href="imgboard.php', ' href="favicon.ico', 'src="thumb/', 'src="inc/', 'src="sticky.png', 'src="lock.png', ' action="imgboard.php');
$replace = array(' href="../css/', ' src="../js/', ' href="../src/', ' href="../thumb/', ' href="../res/', ' href="../imgboard.php', ' href="../favicon.ico', 'src="../thumb/', 'src="../inc/', 'src="../sticky.png', 'src="../lock.png', ' action="../imgboard.php');
$search = array(' href="css/', ' src="js/', ' href="src/', ' href="thumb/', ' href="res/', ' href="imgboard.php', ' href="catalog.html', ' href="favicon.ico', 'src="thumb/', 'src="inc/', 'src="sticky.png', 'src="lock.png', ' action="imgboard.php', ' action="catalog.html');
$replace = array(' href="../css/', ' src="../js/', ' href="../src/', ' href="../thumb/', ' href="../res/', ' href="../imgboard.php', ' href="../catalog.html', ' href="../favicon.ico', 'src="../thumb/', 'src="../inc/', 'src="../sticky.png', 'src="../lock.png', ' action="../imgboard.php', ' action="../catalog.html');
return str_replace($search, $replace, $html);
}

View file

@ -503,7 +503,7 @@ function buildPage($htmlposts, $parent, $pages = 0, $thispage = 0) {
$pagelinks .= ($pages <= $thispage) ? "<td>Next</td>" : '<td><form method="get" action="' . $next . '.html"><input value="Next" type="submit"></form></td>';
$pagenavigator = <<<EOF
<table border="1">
<table border="1" style="display: inline-block;">
<tbody>
<tr>
$pagelinks
@ -511,15 +511,32 @@ function buildPage($htmlposts, $parent, $pages = 0, $thispage = 0) {
</tbody>
</table>
EOF;
if (TINYIB_CATALOG) {
$pagenavigator .= <<<EOF
<table border="1" style="display: inline-block;margin-left: 21px;">
<tbody>
<tr>
<td><form method="get" action="catalog.html"><input value="Catalog" type="submit"></form></td>
</tr>
</tbody>
</table>
EOF;
}
} else if ($parent == -1) {
$postingmode = '&#91;<a href="index.html">Return</a>&#93;<div class="replymode">Catalog</div> ';
} else {
$postingmode = '&#91;<a href="../">Return</a>&#93;<div class="replymode">Posting mode: Reply</div> ';
}
$postform = buildPostForm($parent);
$postform = '';
if ($parent >= TINYIB_NEWTHREAD) {
$postform = buildPostForm($parent);
}
$body = <<<EOF
<body>
<div class="adminbar">
[<a href="catalog.html" style="text-decoration: underline;">Catalog</a>]
[<a href="$managelink" style="text-decoration: underline;">Manage</a>]
</div>
<div class="logo">
@ -551,6 +568,33 @@ EOF;
return pageHeader() . $body . pageFooter();
}
function buildCatalogPost($post) {
$maxwidth = max(100, $post['thumb_width']);
$replies = numRepliesToThreadByID($post['id']);
$subject = trim($post['subject']) != '' ? $post['subject'] : substr(trim(str_ireplace("\n", '', strip_tags($post['message']))), 0, 75);
return <<<EOF
<div class="catalogpost" style="max-width: {$maxwidth}px;">
<a href="res/{$post['id']}.html">
<img src="thumb/{$post["thumb"]}" alt="{$post["id"]}" width="{$post['thumb_width']}" height="{$post['thumb_height']}" border="0">
</a><br>
<b>$replies</b><br>
$subject
</div>
EOF;
}
function rebuildCatalog() {
$threads = allThreads();
$htmlposts = '';
foreach ($threads as $post) {
$htmlposts .= buildCatalogPost($post);
}
$htmlposts .= '<hr size="1">';
writePage('catalog.html', buildPage($htmlposts, -1));
}
function rebuildIndexes() {
$page = 0;
$i = 0;
@ -584,6 +628,10 @@ function rebuildIndexes() {
$file = ($page == 0) ? TINYIB_INDEX : ($page . '.html');
writePage($file, buildPage($htmlposts, 0, $pages, $page));
}
if (TINYIB_CATALOG) {
rebuildCatalog();
}
}
function rebuildThread($id) {

View file

@ -27,6 +27,7 @@ define('TINYIB_PREVIEWREPLIES', 3); // Amount of replies previewed on index pa
define('TINYIB_TRUNCATE', 15); // Messages are truncated to this many lines on board index pages [0 to disable]
define('TINYIB_WORDBREAK', 80); // Words longer than this many characters will be broken apart [0 to disable]
define('TINYIB_TIMEZONE', 'UTC'); // See https://secure.php.net/manual/en/timezones.php - e.g. America/Los_Angeles
define('TINYIB_CATALOG', true); // Generate catalog page
$tinyib_hidefieldsop = array(); // Fields to hide when creating a new thread - e.g. array('name', 'email', 'subject', 'message', 'file', 'embed', 'password')
$tinyib_hidefields = array(); // Fields to hide when replying