WIP - More archive progress, mostly just mod and template work now

This commit is contained in:
Daniel Saunders 2019-12-03 00:56:38 -05:00
parent ff4cd3d041
commit de6944710b
3 changed files with 116 additions and 3 deletions

View File

@ -103,11 +103,88 @@ function rebuildArchiveIndexes()
buildFeaturedIndex();
}
function buildArchiveIndex()
/**
* Retrieve an array of all archived threads
*
* @return array
*/
function archiveList()
{
global $config, $board;
global $board;
$query = query(sprintf('SELECT * FROM ``posts_%s`` WHERE `thread` IS NULL AND `archived` = true AND `featured` = false ORDER BY `bump` DESC', $board['uri'])) or error(db_error());
return $query->fetchAll(PDO::FETCH_ASSOC);
}
function buildFeaturedIndex()
/**
* Retrieve an array of all featured threads
*
* @return array
*/
function featuredList()
{
global $board;
$query = query(sprintf('SELECT * FROM ``posts_%s`` WHERE `thread` IS NULL AND `archived` = true AND `featured` = true ORDER BY `bump` DESC', $board['uri'])) or error(db_error());
return $query->fetchAll(PDO::FETCH_ASSOC);
}
function buildArchiveIndex($root=null, $mod=false)
{
global $config, $board;
if (!isset($root))
$root = &$config['root'];
file_write($board['dir'] . $config['file_archive'], Element('page.html', [
'config' => $config,
'mod' => $mod,
'boardlist' => createBoardlist(),
'title' => sprintf('%s - %s - %s', $board['url'], $board['title'], _('Archive')),
'subtitle' => $board['subtitle'],
'body' => Element('archive.html', [
'config' => $config,
'mod' => $mod,
'board' => $board,
'archive' => array_map(function (&$thread) use ($root) {
$thread['root'] = $root;
if ($thread['body'] != '')
$thread['snippet'] = pm_snippet($thread['body']);
else
$thread['snippet'] = '<em>' . _('(no comment)') . '</em>';
}, archiveList())
])
]));
}
function buildFeaturedIndex($root=null, $mod=false)
{
global $config, $board;
if (!isset($root))
$root = &$config['root'];
file_write($board['dir'] . $config['file_featured'], Element('page.html', [
'config' => $config,
'mod' => $mod,
'boardlist' => createBoardlist(),
'title' => sprintf('%s - %s - %s', $board['url'], $board['title'], _('Featured')),
'subtitle' => $board['subtitle'],
'body' => Element('archive.html', [
'config' => $config,
'mod' => $mod,
'board' => $board,
'archive' => array_map(function (&$thread) use ($root) {
$thread['root'] = $root;
if ($thread['body'] != '')
$thread['snippet'] = pm_snippet($thread['body']);
else
$thread['snippet'] = '<em>' . _('(no comment)') . '</em>';
}, archiveList())
])
]));
}

View File

@ -1177,6 +1177,8 @@
$config['file_mod'] = 'mod.php';
$config['file_post'] = 'post.php';
$config['file_script'] = 'main.js';
$config['file_archive'] = 'archive.html';
$config['file_featured'] = 'featured.html';
// Board directory, followed by a forward-slash (/).
$config['board_path'] = '%s/';

34
templates/archive.html Normal file
View File

@ -0,0 +1,34 @@
<p class="text-align: center">
<strong>{{ 'Displaying %s expired threads%s'|trans|sprintf(archive|length, (config.archive.max_lifetime ? ' from the past %s'|trans|sprintf(config.archive.max_lifetime : ''))) }}</strong>
</p>
<table class="mod tablesorter">
<thead>
<tr>
<th>{% trans 'No.' %}</th>
<th>{% trans 'Excerpt' %}</th>
<th>{# Reply #}&nbsp;</th>
</tr>
</thead>
<tbody>
{% for thread in archive %}
<tr>
<td data-sort-value="{{ thread.id }}">{{ thread.id }}</td>
<td data-sort-value="{{ thread.bump }}">{% if thread.subject %}<strong>{{ thread.subject }}:</strong> {% endif %}{{ thread.snippet }}</td>
<td><a href="{{ thread.root }}{{ board.dir }}{{ config.dir.res }}{{ link_for(thread) }}">[{% trans 'View' %}]</a></td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
if (typeof $ !== 'undefined' && $.tablesorter)
$('table.tablesorter').tablesorter({
textExtraction: (node) => {
let attr = $(node).data('sort-value');
if (typeof attr !== 'undefined' && attr !== false)
return attr;
return $(node).text();
}
});
</script>