forked from leftypol/leftypol
support for slugified links; may introduce a few bugs
This commit is contained in:
parent
eb245c2970
commit
bdb6001f3f
18 changed files with 145 additions and 43 deletions
|
@ -146,6 +146,7 @@ function changeStyle(styleName, link) {
|
|||
{% endraw %}
|
||||
{% if config.stylesheets_board %}
|
||||
{# 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+', '.': '\\.'}) }})/);
|
||||
{% raw %}
|
||||
if (matches) {
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
{% else %}
|
||||
{% set thread = post.id %}
|
||||
{% 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 }}
|
||||
</a>
|
||||
</td>
|
||||
|
|
|
@ -195,7 +195,7 @@
|
|||
{% else %}
|
||||
{% set thread = post.id %}
|
||||
{% 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 }}
|
||||
</a>
|
||||
</td>
|
||||
|
@ -265,4 +265,4 @@
|
|||
<a href="?/search/{{ search_type }}/{{ search_query_escaped }}/{{ i + 1 }}">[{{ i + 1 }}]</a>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
{% include 'post/time.html' %}
|
||||
</label>
|
||||
{% include 'post/poster_id.html' %}
|
||||
<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" 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" 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', '50') }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
|
||||
</p>
|
||||
{% include 'post/fileinfo.html' %}
|
||||
{% include 'post/post_controls.html' %}
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
{% include 'post/time.html' %}
|
||||
</label>
|
||||
{% include 'post/poster_id.html' %}
|
||||
<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" 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" 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', '50') }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
|
||||
{% if post.sticky %}
|
||||
{% if config.font_awesome %}
|
||||
<i class="fa fa-thumb-tack"></i>
|
||||
|
@ -39,14 +39,14 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
{% if hasnoko50 and not isnoko50 %}
|
||||
{% 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 %}
|
||||
{% include 'post/post_controls.html' %}
|
||||
</p>
|
||||
|
|
|
@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS ``posts_{{ board }}`` (
|
|||
`locked` int(1) NOT NULL,
|
||||
`sage` int(1) NOT NULL,
|
||||
`embed` text,
|
||||
`slug` varchar(256) DEFAULT NULL,
|
||||
UNIQUE KEY `id` (`id`),
|
||||
KEY `thread_id` (`thread`,`id`),
|
||||
KEY `filehash` (`filehash`(40)),
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
$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['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post));
|
||||
$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)) {
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
|
||||
// board settings won't be available in the template file, so generate links now
|
||||
$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[0]->thumb == 'spoiler') {
|
||||
|
@ -92,7 +92,7 @@
|
|||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
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'] != "")
|
||||
$post['snippet'] = pm_snippet($post['body'], 30);
|
||||
else
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
{% for board, thread_list in threads %}
|
||||
{% for thread in thread_list %}
|
||||
<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>
|
||||
<changefreq>{{ settings.changefreq }}</changefreq>
|
||||
</url>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</urlset>
|
||||
{% endfilter %}
|
||||
{% endfilter %}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
$threads = array();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue