Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Added catalog navigation inside mod.php #321

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inc/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@

// Location of files.
$config['file_index'] = 'index.html';
$config['file_catalog'] = 'catalog.html';
$config['file_page'] = '%d.html';
$config['file_page50'] = '%d+50.html';
$config['file_mod'] = 'mod.php';
Expand Down
74 changes: 74 additions & 0 deletions inc/mod/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,80 @@ function mod_view_board($boardName, $page_no = 1) {
echo Element('index.html', $page);
}

function mod_view_catalog($board_name) {
global $config, $mod, $board;

if (!openBoard($board_name))
error($config['error']['noboard']);

$recent_images = array();
$recent_posts = array();
$stats = array();

$query = query(sprintf("SELECT *, `id` AS `thread_id`,
(SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`,
(SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `thread` = `thread_id` AND `num_files` IS NOT NULL) AS `image_count`,
'%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC",
$board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error());

while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id']));
$post['board_name'] = $board['name'];

if ($post['embed'] && preg_match('/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) {
$post['youtube'] = $matches[2];
}

if (isset($post['files']) && $post['files']) {
$files = json_decode($post['files']);

if ($files[0]) {
if ($files[0]->file == 'deleted') {
if (count($files) > 1) {
foreach ($files as $file) {
if (($file == $files[0]) || ($file->file == 'deleted')) continue;
$post['file'] = $config['uri_thumb'] . $file->thumb;
}

if (empty($post['file'])) $post['file'] = $config['image_deleted'];
}
else {
$post['file'] = $config['image_deleted'];
}
}
else if($files[0]->thumb == 'spoiler') {
$post['file'] = '/' . $config['spoiler_image'];
}
else {
$post['file'] = $config['uri_thumb'] . $files[0]->thumb;
}
}
}

if (empty($post['image_count'])) $post['image_count'] = 0;
$recent_posts[] = $post;
}

$required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js');

foreach($required_scripts as $i => $s) {
if (!in_array($s, $config['additional_javascript']))
$config['additional_javascript'][] = $s;
}

echo Element('themes/catalog/catalog.html', Array(
'settings' => array('title'=>$board['title'],'subtitle'=>$board['subtitle']),
'config' => $config,
'boardlist' => createBoardlist(),
'recent_images' => $recent_images,
'recent_posts' => $recent_posts,
'stats' => $stats,
'board' => $board['uri'],
'link' => '/'. $board['uri'] .'/',
'mod' => true
));
}

function mod_view_thread($boardName, $thread) {
global $config, $mod;

Expand Down
11 changes: 6 additions & 5 deletions mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ function strip_array($var) {
'/debug/sql' => 'secure_POST debug_sql',

// This should always be at the end:
'/(\%b)/?' => 'view_board',
'/(\%b)/' . preg_quote($config['file_index'], '!') => 'view_board',
'/(\%b)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_board',
'/(\%b)/'. preg_quote($config['file_catalog'], '!') => 'view_catalog',
'/(\%b)/?' => 'view_board',
'/(\%b)/' . preg_quote($config['file_index'], '!') => 'view_board',
'/(\%b)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_board',
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '!')) => 'view_thread50',
str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '!')) => 'view_thread50',
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_thread',
str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_thread',
);


Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1>{{ board.url }} - {{ board.title|e }}</h1>
{% endif %}
{% endif %}
{% if mod %}<p><a href="?/">{% trans %}Return to dashboard{% endtrans %}</a></p>{% endif %}
<p><a href="{{ config.root }}{{ board.dir }}{{ config.catalog_link }}">{% trans %}Catalog{% endtrans %}</a></p>
<p><a href="{{ config.root }}{% if mod %}mod.php?/{% endif %}{{ board.dir }}{{ config.catalog_link }}">{% trans %}Catalog{% endtrans %}</a></p>
</div>
</header>

Expand Down
4 changes: 2 additions & 2 deletions templates/themes/catalog/catalog.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<body class="theme-catalog">
{{ boardlist.top }}
<header>
<h1>{{ settings.title }} (<a href="{{link}}">/{{ board }}/</a>)</h1>
<h1>{{ settings.title }} (<a href="{% if mod %}/mod.php?{% endif %}{{link}}">/{{ board }}/</a>)</h1>
<div class="subtitle">{{ settings.subtitle }}</div>
</header>

Expand All @@ -39,7 +39,7 @@ <h1>{{ settings.title }} (<a href="{{link}}">/{{ board }}/</a>)</h1>
data-time="{{ post.time }}"
>
<div class="thread grid-li grid-size-small">
<a href="{{post.link}}">
<a href="{% if mod %}/mod.php?{% endif %}{{post.link}}">
{% if post.youtube %}
<img src="https://img.youtube.com/vi/{{ post.youtube }}/0.jpg"
{% else %}
Expand Down
3 changes: 2 additions & 1 deletion templates/themes/catalog/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public function build($settings, $board_name) {
'recent_posts' => $recent_posts,
'stats' => $stats,
'board' => $board_name,
'link' => $config['root'] . $board['dir']
'link' => $config['root'] . $board['dir'],
'mod' => false
)));
}
};
2 changes: 1 addition & 1 deletion templates/thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1>{{ board.url }} - {{ board.title|e }}</h1>
{% endif %}
{% endif %}
{% if mod %}<p><a href="?/">{% trans %}Return to dashboard{% endtrans %}</a></p>{% endif %}
<p><a href="{{ config.root }}{{ board.dir }}{{ config.catalog_link }}">Catalog</a></p>
<p><a href="{{ config.root }}{% if mod %}mod.php?/{% endif %}{{ board.dir }}{{ config.catalog_link }}">Catalog</a></p>
</div>
</header>

Expand Down