Browse Source

support for slugified links; may introduce a few bugs

pull/40/head
czaks 9 years ago
parent
commit
bdb6001f3f
  1. 7
      inc/config.php
  2. 4
      inc/display.php
  3. 92
      inc/functions.php
  4. 3
      inc/lib/Twig/Extensions/Extension/Tinyboard.php
  5. 18
      inc/mod/pages.php
  6. 6
      install.php
  7. 5
      mod.php
  8. 19
      post.php
  9. 1
      templates/main.js
  10. 2
      templates/mod/debug/recent_posts.html
  11. 4
      templates/mod/search_results.html
  12. 4
      templates/post_reply.html
  13. 10
      templates/post_thread.html
  14. 1
      templates/posts.sql
  15. 2
      templates/themes/catalog/theme.php
  16. 4
      templates/themes/recent/theme.php
  17. 4
      templates/themes/sitemap/sitemap.xml
  18. 2
      templates/themes/sitemap/theme.php

7
inc/config.php

@ -566,6 +566,9 @@
// Allow dice rolling: an email field of the form "dice XdY+/-Z" will result in X Y-sided dice rolled and summed, // Allow dice rolling: an email field of the form "dice XdY+/-Z" will result in X Y-sided dice rolled and summed,
// with the modifier Z added, with the result displayed at the top of the post body. // with the modifier Z added, with the result displayed at the top of the post body.
$config['allow_roll'] = false; $config['allow_roll'] = false;
// Use semantic URLs for threads, like /b/res/12345/daily-programming-thread.html
$config['slugify'] = false;
/* /*
* ==================== * ====================
@ -1118,8 +1121,10 @@
// Location of files. // Location of files.
$config['file_index'] = 'index.html'; $config['file_index'] = 'index.html';
$config['file_page'] = '%d.html'; $config['file_page'] = '%d.html'; // NB: page is both an index page and a thread
$config['file_page50'] = '%d+50.html'; $config['file_page50'] = '%d+50.html';
$config['file_page_slug'] = '%d-%s.html';
$config['file_page50_slug'] = '%d-%s+50.html';
$config['file_mod'] = 'mod.php'; $config['file_mod'] = 'mod.php';
$config['file_post'] = 'post.php'; $config['file_post'] = 'post.php';
$config['file_script'] = 'main.js'; $config['file_script'] = 'main.js';

4
inc/display.php

@ -383,7 +383,7 @@ class Post {
public function link($pre = '', $page = false) { public function link($pre = '', $page = false) {
global $config, $board; global $config, $board;
return $this->root . $board['dir'] . $config['dir']['res'] . sprintf(($page ? $page : $config['file_page']), $this->thread) . '#' . $pre . $this->id; return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id;
} }
public function build($index=false) { public function build($index=false) {
@ -438,7 +438,7 @@ class Thread {
public function link($pre = '', $page = false) { public function link($pre = '', $page = false) {
global $config, $board; global $config, $board;
return $this->root . $board['dir'] . $config['dir']['res'] . sprintf(($page ? $page : $config['file_page']), $this->id) . '#' . $pre . $this->id; return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id;
} }
public function add(Post $post) { public function add(Post $post) {
$this->posts[] = $post; $this->posts[] = $post;

92
inc/functions.php

@ -150,7 +150,9 @@ function loadConfig() {
preg_quote($config['dir']['res'], '/') . preg_quote($config['dir']['res'], '/') .
'(' . '(' .
str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' . str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' .
str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . '|' .
str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' .
str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) .
')' . ')' .
'|' . '|' .
preg_quote($config['file_mod'], '/') . '\?\/.+' . preg_quote($config['file_mod'], '/') . '\?\/.+' .
@ -912,7 +914,7 @@ function insertFloodPost(array $post) {
function post(array $post) { function post(array $post) {
global $pdo, $board; global $pdo, $board;
$query = prepare(sprintf("INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, 0, :embed)", $board['uri'])); $query = prepare(sprintf("INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, 0, :embed, :slug)", $board['uri']));
// Basic stuff // Basic stuff
if (!empty($post['subject'])) { if (!empty($post['subject'])) {
@ -981,6 +983,10 @@ function post(array $post) {
$query->bindValue(':filehash', null, PDO::PARAM_NULL); $query->bindValue(':filehash', null, PDO::PARAM_NULL);
} }
if ($post['op']) {
$query->bindValue(':slug', slugify($post));
}
if (!$query->execute()) { if (!$query->execute()) {
undoImage($post); undoImage($post);
error(db_error($query)); error(db_error($query));
@ -1094,8 +1100,8 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
if (!$post['thread']) { if (!$post['thread']) {
// Delete thread HTML page // Delete thread HTML page
file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['id'])); file_unlink($board['dir'] . $config['dir']['res'] . link_for($post) );
file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $post['id'])); file_unlink($board['dir'] . $config['dir']['res'] . link_for($post, true) ); // noko50
file_unlink($board['dir'] . $config['dir']['res'] . sprintf('%d.json', $post['id'])); file_unlink($board['dir'] . $config['dir']['res'] . sprintf('%d.json', $post['id']));
$antispam_query = prepare('DELETE FROM ``antispam`` WHERE `board` = :board AND `thread` = :thread'); $antispam_query = prepare('DELETE FROM ``antispam`` WHERE `board` = :board AND `thread` = :thread');
@ -2067,12 +2073,12 @@ function buildThread($id, $return = false, $mod = false) {
if ($return) { if ($return) {
return $body; return $body;
} else { } else {
$noko50fn = $board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id); $noko50fn = $board['dir'] . $config['dir']['res'] . link_for($thread, true);
if ($hasnoko50 || file_exists($noko50fn)) { if ($hasnoko50 || file_exists($noko50fn)) {
buildThread50($id, $return, $mod, $thread, $antibot); buildThread50($id, $return, $mod, $thread, $antibot);
} }
file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); file_write($board['dir'] . $config['dir']['res'] . link_for($thread), $body);
} }
} }
@ -2152,7 +2158,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
if ($return) { if ($return) {
return $body; return $body;
} else { } else {
file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id), $body); file_write($board['dir'] . $config['dir']['res'] . link_for($thread, true), $body);
} }
} }
@ -2421,3 +2427,75 @@ function diceRoller($post) {
} }
} }
} }
function slugify($post) {
$slug = "";
if (isset($post['thread']) && $post['thread'])
$slug = $post['thread'];
elseif (isset ($post['body_nomarkup']) && $post['body_nomarkup'])
$slug = $post['body_nomarkup'];
elseif (isset ($post['body']) && $post['body'])
$slug = strip_html($post['body']);
// Fix UTF-8 first
$slug = mb_convert_encoding($slug, "UTF-8", "UTF-8");
// Transliterate local characters like ü, I wonder how would it work for weird alphabets :^)
$slug = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $slug);
// Downcase everything
$slug = strtolower($slug);
// Strip bad characters, alphanumerics should suffice
$slug = preg_replace('/[^a-zA-Z0-9]/', '-', $slug);
// Replace multiple dashes with single ones
$slug = preg_replace('/-+/', '-', $slug);
// Strip dashes at the beginning and at the end
$slug = preg_replace('/^-|-$/', '', $slug);
// Slug should be 200 characters long, at max
$slug = substr($slug, 0, 200);
// Slug is now ready
return $slug;
}
function link_for($post, $page50 = false, $foreignlink = false, $thread = false) {
global $config, $board;
$post = (array)$post;
// Where do we need to look for OP?
$b = $foreignlink ? $foreignlink : $board;
$id = (isset($post['thread']) && $post['thread']) ? $post['thread'] : $post['id'];
$slug = false;
if ($config['slugify'] && isset($post['thread']) && $post['thread']) {
if (!$thread) {
// Oh fuck, we'd better optimize it ASAP
$query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
$query->bindValue(':id', $id, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$thread = $query->fetch(PDO::FETCH_ASSOC);
}
$slug = $thread['slug'];
}
elseif ($config['slugify']) {
$slug = $post['slug'];
}
if ( $page50 && $slug) $tpl = $config['file_page50_slug'];
else if (!$page50 && $slug) $tpl = $config['file_page_slug'];
else if ( $page50 && !$slug) $tpl = $config['file_page50'];
else if (!$page50 && !$slug) $tpl = $config['file_page'];
return sprintf($tpl, $id, $slug);
}

3
inc/lib/Twig/Extensions/Extension/Tinyboard.php

@ -45,7 +45,8 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
new Twig_SimpleFunction('hiddenInputsHash', 'hiddenInputsHash'), new Twig_SimpleFunction('hiddenInputsHash', 'hiddenInputsHash'),
new Twig_SimpleFunction('ratio', 'twig_ratio_function'), new Twig_SimpleFunction('ratio', 'twig_ratio_function'),
new Twig_SimpleFunction('secure_link_confirm', 'twig_secure_link_confirm'), new Twig_SimpleFunction('secure_link_confirm', 'twig_secure_link_confirm'),
new Twig_SimpleFunction('secure_link', 'twig_secure_link') new Twig_SimpleFunction('secure_link', 'twig_secure_link'),
new Twig_SimpleFunction('link_for', 'link_for')
); );
} }

18
inc/mod/pages.php

@ -1161,7 +1161,7 @@ function mod_move_reply($originBoard, $postID) {
$post = $query->fetch(PDO::FETCH_ASSOC); $post = $query->fetch(PDO::FETCH_ASSOC);
// redirect // redirect
header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $newID) . '#' . $newID, true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post) . '#' . $newID, true, $config['redirect_http']);
} }
else { else {
@ -1322,6 +1322,8 @@ function mod_move($originBoard, $postID) {
// trigger themes // trigger themes
rebuildThemes('post', $targetBoard); rebuildThemes('post', $targetBoard);
$newboard = $board;
// return to original board // return to original board
openBoard($originBoard); openBoard($originBoard);
@ -1332,7 +1334,7 @@ function mod_move($originBoard, $postID) {
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
// leave a reply, linking to the new thread // leave a reply, linking to the new thread
$post = array( $spost = array(
'mod' => true, 'mod' => true,
'subject' => '', 'subject' => '',
'email' => '', 'email' => '',
@ -1346,23 +1348,23 @@ function mod_move($originBoard, $postID) {
'op' => false 'op' => false
); );
$post['body'] = $post['body_nomarkup'] = sprintf($config['mod']['shadow_mesage'], '>>>/' . $targetBoard . '/' . $newID); $spost['body'] = $spost['body_nomarkup'] = sprintf($config['mod']['shadow_mesage'], '>>>/' . $targetBoard . '/' . $newID);
markup($post['body']); markup($spost['body']);
$botID = post($post); $botID = post($spost);
buildThread($postID); buildThread($postID);
buildIndex(); buildIndex();
header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] .sprintf($config['file_page'], $postID) . header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($post, false, $newboard) .
'#' . $botID, true, $config['redirect_http']); '#' . $botID, true, $config['redirect_http']);
} else { } else {
deletePost($postID); deletePost($postID);
buildIndex(); buildIndex();
openBoard($targetBoard); openBoard($targetBoard);
header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . sprintf($config['file_page'], $newID), true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post, false, $newboard), true, $config['redirect_http']);
} }
} }
@ -1494,7 +1496,7 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
rebuildThemes('post', $board); rebuildThemes('post', $board);
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . link_for($post) . '#' . $postID, true, $config['redirect_http']);
} else { } else {
if ($config['minify_html']) { if ($config['minify_html']) {
$post['body_nomarkup'] = str_replace("\n", '
', utf8tohtml($post['body_nomarkup'])); $post['body_nomarkup'] = str_replace("\n", '
', utf8tohtml($post['body_nomarkup']));

6
install.php

@ -1,7 +1,7 @@
<?php <?php
// Installation/upgrade file // Installation/upgrade file
define('VERSION', '4.9.92'); define('VERSION', '4.9.93');
require 'inc/functions.php'; require 'inc/functions.php';
@ -547,6 +547,10 @@ if (file_exists($config['has_installed'])) {
} }
case '4.9.90': case '4.9.90':
case '4.9.91': case '4.9.91':
case '4.9.92':
foreach ($boards as &$board) {
query(sprintf('ALTER TABLE ``posts_%s`` ADD `slug` VARCHAR(255) DEFAULT NULL AFTER `embed`;', $board['uri'])) or error(db_error());
}
case false: case false:
// TODO: enhance Tinyboard -> vichan upgrade path. // TODO: enhance Tinyboard -> vichan upgrade path.
query("CREATE TABLE IF NOT EXISTS ``search_queries`` ( `ip` varchar(39) NOT NULL, `time` int(11) NOT NULL, `query` text NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error()); query("CREATE TABLE IF NOT EXISTS ``search_queries`` ( `ip` varchar(39) NOT NULL, `time` int(11) NOT NULL, `query` text NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error());

5
mod.php

@ -105,6 +105,11 @@ $pages = array(
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'], '!') . '/(\%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',
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '!')) => 'view_thread50',
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '!')) => 'view_thread',
); );

19
post.php

@ -85,7 +85,7 @@ if (isset($_POST['delete'])) {
} }
_syslog(LOG_INFO, 'Deleted post: ' . _syslog(LOG_INFO, 'Deleted post: ' .
'/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $id) . ($post['thread'] ? '#' . $id : '') '/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '')
); );
} }
} }
@ -142,7 +142,7 @@ if (isset($_POST['delete'])) {
if ($config['syslog']) if ($config['syslog'])
_syslog(LOG_INFO, 'Reported post: ' . _syslog(LOG_INFO, 'Reported post: ' .
'/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $thread ? $thread : $id) . ($thread ? '#' . $id : '') . '/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($thread ? '#' . $id : '') .
' for "' . $reason . '"' ' for "' . $reason . '"'
); );
$query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)"); $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)");
@ -250,7 +250,7 @@ if (isset($_POST['delete'])) {
//Check if thread exists //Check if thread exists
if (!$post['op']) { if (!$post['op']) {
$query = prepare(sprintf("SELECT `sticky`,`locked`,`sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri'])); $query = prepare(sprintf("SELECT `sticky`,`locked`,`sage`,`slug` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
$query->bindValue(':id', $post['thread'], PDO::PARAM_INT); $query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
$query->execute() or error(db_error()); $query->execute() or error(db_error());
@ -259,6 +259,9 @@ if (isset($_POST['delete'])) {
error($config['error']['nonexistant']); error($config['error']['nonexistant']);
} }
} }
else {
$thread = false;
}
// Check for an embed field // Check for an embed field
@ -782,6 +785,7 @@ if (isset($_POST['delete'])) {
$post = (object)$post; $post = (object)$post;
$post->files = array_map(function($a) { return (object)$a; }, $post->files); $post->files = array_map(function($a) { return (object)$a; }, $post->files);
$error = event('post', $post); $error = event('post', $post);
$post->files = array_map(function($a) { return (array)$a; }, $post->files); $post->files = array_map(function($a) { return (array)$a; }, $post->files);
@ -845,19 +849,20 @@ if (isset($_POST['delete'])) {
if ($noko) { if ($noko) {
$redirect = $root . $board['dir'] . $config['dir']['res'] . $redirect = $root . $board['dir'] . $config['dir']['res'] .
sprintf($config['file_page'], $post['op'] ? $id:$post['thread']) . (!$post['op'] ? '#' . $id : ''); link_for($post, false, false, $thread) . (!$post['op'] ? '#' . $id : '');
if (!$post['op'] && isset($_SERVER['HTTP_REFERER'])) { if (!$post['op'] && isset($_SERVER['HTTP_REFERER'])) {
$regex = array( $regex = array(
'board' => str_replace('%s', '(\w{1,8})', preg_quote($config['board_path'], '/')), 'board' => str_replace('%s', '(\w{1,8})', preg_quote($config['board_path'], '/')),
'page' => str_replace('%d', '(\d+)', preg_quote($config['file_page'], '/')), 'page' => str_replace('%d', '(\d+)', preg_quote($config['file_page'], '/')),
'page50' => str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '/')), 'page50' => '(' . str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '/')) . '|' .
str_replace(array('%d', '%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . ')',
'res' => preg_quote($config['dir']['res'], '/'), 'res' => preg_quote($config['dir']['res'], '/'),
); );
if (preg_match('/\/' . $regex['board'] . $regex['res'] . $regex['page50'] . '([?&].*)?$/', $_SERVER['HTTP_REFERER'])) { if (preg_match('/\/' . $regex['board'] . $regex['res'] . $regex['page50'] . '([?&].*)?$/', $_SERVER['HTTP_REFERER'])) {
$redirect = $root . $board['dir'] . $config['dir']['res'] . $redirect = $root . $board['dir'] . $config['dir']['res'] .
sprintf($config['file_page50'], $post['op'] ? $id:$post['thread']) . (!$post['op'] ? '#' . $id : ''); link_for($post, true, false, $thread) . (!$post['op'] ? '#' . $id : '');
} }
} }
} else { } else {
@ -867,7 +872,7 @@ if (isset($_POST['delete'])) {
if ($config['syslog']) if ($config['syslog'])
_syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . _syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] .
sprintf($config['file_page'], $post['op'] ? $id : $post['thread']) . (!$post['op'] ? '#' . $id : '')); link_for($post) . (!$post['op'] ? '#' . $id : ''));
if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"'); if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"');

1
templates/main.js

@ -146,6 +146,7 @@ function changeStyle(styleName, link) {
{% endraw %} {% endraw %}
{% if config.stylesheets_board %} {% if config.stylesheets_board %}
{# This is such an unacceptable mess. There needs to be an easier way. #} {# This is such an unacceptable mess. There needs to be an easier way. #}
{# Needs fix for slugify #}
var matches = document.URL.match(/\/(\w+)\/($|{{ config.dir.res|replace({'/': '\\/'}) }}{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }}|{{ config.file_index|replace({'.': '\\.'}) }}|{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }})/); var matches = document.URL.match(/\/(\w+)\/($|{{ config.dir.res|replace({'/': '\\/'}) }}{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }}|{{ config.file_index|replace({'.': '\\.'}) }}|{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }})/);
{% raw %} {% raw %}
if (matches) { if (matches) {

2
templates/mod/debug/recent_posts.html

@ -63,7 +63,7 @@
{% else %} {% else %}
{% set thread = post.id %} {% set thread = post.id %}
{% endif %} {% endif %}
<a href="?/{{ post.board ~ '/' ~ config.dir.res}}{{ config.file_page|sprintf(thread) }}#{{ post.id }}"> <a href="?/{{ post.board ~ '/' ~ config.dir.res}}{{ link_for(post) }}#{{ post.id }}">
{{ post.id }} {{ post.id }}
</a> </a>
</td> </td>

4
templates/mod/search_results.html

@ -195,7 +195,7 @@
{% else %} {% else %}
{% set thread = post.id %} {% set thread = post.id %}
{% endif %} {% endif %}
<a href="?/{{ post.board ~ '/' ~ config.dir.res}}{{ config.file_page|sprintf(thread) }}#{{ post.id }}"> <a href="?/{{ post.board ~ '/' ~ config.dir.res}}{{ link_for(post) }}#{{ post.id }}">
{{ post.id }} {{ post.id }}
</a> </a>
</td> </td>
@ -265,4 +265,4 @@
<a href="?/search/{{ search_type }}/{{ search_query_escaped }}/{{ i + 1 }}">[{{ i + 1 }}]</a> <a href="?/search/{{ search_type }}/{{ search_query_escaped }}/{{ i + 1 }}">[{{ i + 1 }}]</a>
{% endfor %} {% endfor %}
</p> </p>
{% endif %} {% endif %}

4
templates/post_reply.html

@ -12,8 +12,8 @@
{% include 'post/time.html' %} {% include 'post/time.html' %}
</label> </label>
{% include 'post/poster_id.html' %}&nbsp; {% include 'post/poster_id.html' %}&nbsp;
<a class="post_no" id="post_no_{{ post.id }}" onclick="highlightReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('', config.file_page50) }}{% else %}{{ post.link }}{% endif %}">No.</a> <a class="post_no" id="post_no_{{ post.id }}" onclick="highlightReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('', '50') }}{% else %}{{ post.link }}{% endif %}">No.</a>
<a class="post_no" onclick="citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', config.file_page50) }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a> <a class="post_no" onclick="citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', '50') }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
</p> </p>
{% include 'post/fileinfo.html' %} {% include 'post/fileinfo.html' %}
{% include 'post/post_controls.html' %} {% include 'post/post_controls.html' %}

10
templates/post_thread.html

@ -15,8 +15,8 @@
{% include 'post/time.html' %} {% include 'post/time.html' %}
</label> </label>
{% include 'post/poster_id.html' %}&nbsp; {% include 'post/poster_id.html' %}&nbsp;
<a class="post_no" id="post_no_{{ post.id }}" onclick="highlightReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('', config.file_page50) }}{% else %}{{ post.link }}{% endif %}">No.</a> <a class="post_no" id="post_no_{{ post.id }}" onclick="highlightReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('', '50') }}{% else %}{{ post.link }}{% endif %}">No.</a>
<a class="post_no" onclick="citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', config.file_page50) }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a> <a class="post_no" onclick="citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', '50') }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
{% if post.sticky %} {% if post.sticky %}
{% if config.font_awesome %} {% if config.font_awesome %}
<i class="fa fa-thumb-tack"></i> <i class="fa fa-thumb-tack"></i>
@ -39,14 +39,14 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if index %} {% if index %}
<a href="{{ post.root }}{{ board.dir }}{{ config.dir.res }}{{ config.file_page|sprintf(post.id) }}">[{% trans %}Reply{% endtrans %}]</a> <a href="{{ post.root }}{{ board.dir }}{{ config.dir.res }}{{ link_for(post) }}">[{% trans %}Reply{% endtrans %}]</a>
{% endif %} {% endif %}
{% if isnoko50 %} {% if isnoko50 %}
<a href="{{ post.root }}{{ board.dir }}{{ config.dir.res }}{{ config.file_page|sprintf(post.id) }}">[{% trans %}View All{% endtrans %}]</a> <a href="{{ post.root }}{{ board.dir }}{{ config.dir.res }}{{ link_for(post) }}">[{% trans %}View All{% endtrans %}]</a>
{% endif %} {% endif %}
{% if hasnoko50 and not isnoko50 %} {% if hasnoko50 and not isnoko50 %}
{% set lastcount = config.noko50_count %} {% set lastcount = config.noko50_count %}
<a href="{{ post.root }}{{ board.dir }}{{ config.dir.res }}{{ config.file_page50|sprintf(post.id) }}">[{% trans %}Last 1 Post{% plural lastcount %}Last {{ count }} Posts{% endtrans %}]</a> <a href="{{ post.root }}{{ board.dir }}{{ config.dir.res }}{{ link_for(post, true) }}">[{% trans %}Last 1 Post{% plural lastcount %}Last {{ count }} Posts{% endtrans %}]</a>
{% endif %} {% endif %}
{% include 'post/post_controls.html' %} {% include 'post/post_controls.html' %}
</p> </p>

1
templates/posts.sql

@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS ``posts_{{ board }}`` (
`locked` int(1) NOT NULL, `locked` int(1) NOT NULL,
`sage` int(1) NOT NULL, `sage` int(1) NOT NULL,
`embed` text, `embed` text,
`slug` varchar(256) DEFAULT NULL,
UNIQUE KEY `id` (`id`), UNIQUE KEY `id` (`id`),
KEY `thread_id` (`thread`,`id`), KEY `thread_id` (`thread`,`id`),
KEY `filehash` (`filehash`(40)), KEY `filehash` (`filehash`(40)),

2
templates/themes/catalog/theme.php

@ -42,7 +42,7 @@
$board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error()); $board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error());
while ($post = $query->fetch(PDO::FETCH_ASSOC)) { 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['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post));
$post['board_name'] = $board['name']; $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)) { if ($post['embed'] && preg_match('/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) {

4
templates/themes/recent/theme.php

@ -62,7 +62,7 @@
// board settings won't be available in the template file, so generate links now // board settings won't be available in the template file, so generate links now
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res']
. sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; . link_for($post) . '#' . $post['id'];
if ($files) { if ($files) {
if ($files[0]->thumb == 'spoiler') { if ($files[0]->thumb == 'spoiler') {
@ -92,7 +92,7 @@
while ($post = $query->fetch(PDO::FETCH_ASSOC)) { while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
openBoard($post['board']); openBoard($post['board']);
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id'];
if ($post['body'] != "") if ($post['body'] != "")
$post['snippet'] = pm_snippet($post['body'], 30); $post['snippet'] = pm_snippet($post['body'], 30);
else else

4
templates/themes/sitemap/sitemap.xml

@ -9,11 +9,11 @@
{% for board, thread_list in threads %} {% for board, thread_list in threads %}
{% for thread in thread_list %} {% for thread in thread_list %}
<url> <url>
<loc>{{ settings.url ~ (config.board_path | format(board)) ~ config.dir.res ~ (config.file_page | format(thread.thread_id)) }}</loc> <loc>{{ settings.url ~ (config.board_path | format(board)) ~ config.dir.res ~ link_for(thread) }}</loc>
<lastmod>{{ thread.lastmod | date('%Y-%m-%dT%H:%M:%S') }}{{ timezone() }}</lastmod> <lastmod>{{ thread.lastmod | date('%Y-%m-%dT%H:%M:%S') }}{{ timezone() }}</lastmod>
<changefreq>{{ settings.changefreq }}</changefreq> <changefreq>{{ settings.changefreq }}</changefreq>
</url> </url>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
</urlset> </urlset>
{% endfilter %} {% endfilter %}

2
templates/themes/sitemap/theme.php

@ -26,7 +26,7 @@
$threads = array(); $threads = array();
foreach ($boards as $board) { foreach ($boards as $board) {
$query = query(sprintf("SELECT `id` AS `thread_id`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM ``posts_%s`` WHERE `thread` IS NULL", $board, $board)) or error(db_error()); $query = query(sprintf("SELECT `id`, `slug`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM ``posts_%s`` WHERE `thread` IS NULL", $board, $board)) or error(db_error());
$threads[$board] = $query->fetchAll(PDO::FETCH_ASSOC); $threads[$board] = $query->fetchAll(PDO::FETCH_ASSOC);
} }

Loading…
Cancel
Save