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

Added support for anchor threads. #296

Open
wants to merge 1 commit 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/8chan-mod-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function purify($s){
$config['mod']['unban'] = BOARDVOLUNTEER;
$config['mod']['deletebyip'] = BOARDVOLUNTEER;
$config['mod']['sticky'] = BOARDVOLUNTEER;
$config['mod']['anchor'] = BOARDVOLUNTEER;
$config['mod']['lock'] = BOARDVOLUNTEER;
$config['mod']['postinlocked'] = BOARDVOLUNTEER;
$config['mod']['bumplock'] = BOARDVOLUNTEER;
Expand Down
2 changes: 2 additions & 0 deletions inc/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function __construct(){
'replies' => 'replies',
'images' => 'images',
'sticky' => 'sticky',
'anchor' => 'anchor',
'locked' => 'locked',
'bump' => 'last_modified',
);
Expand Down Expand Up @@ -67,6 +68,7 @@ function __construct(){
'replies' => 1,
'images' => 1,
'sticky' => 1,
'anchor' => 1,
'locked' => 1,
'last_modified' => 1
);
Expand Down
6 changes: 6 additions & 0 deletions inc/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
'body',
'password',
'sticky',
'anchor',
'lock',
'raw',
'embed',
Expand Down Expand Up @@ -1193,6 +1194,7 @@
// Static images. These can be URLs OR base64 (data URI scheme). These are only used if
// $config['font_awesome'] is false (default).
// $config['image_sticky'] = 'static/sticky.png';
// $config['image_anchor'] = 'static/anchor.png';
// $config['image_locked'] = 'static/locked.gif';
// $config['image_bumplocked'] = 'static/sage.png'.

Expand Down Expand Up @@ -1238,6 +1240,8 @@
$config['mod']['link_deletebyip_global'] = '[D++]';
$config['mod']['link_sticky'] = '[Sticky]';
$config['mod']['link_desticky'] = '[-Sticky]';
$config['mod']['link_anchor'] = '[Anchor]';
$config['mod']['link_deanchor'] = '[-Anchor]';
$config['mod']['link_lock'] = '[Lock]';
$config['mod']['link_unlock'] = '[-Lock]';
$config['mod']['link_bumplock'] = '[Sage]';
Expand Down Expand Up @@ -1387,6 +1391,8 @@
$config['mod']['deletebyip_global'] = ADMIN;
// Sticky a thread
$config['mod']['sticky'] = MOD;
// Anchor a thread
$config['mod']['anchor'] = MOD;
// Lock a thread
$config['mod']['lock'] = MOD;
// Post in a locked thread
Expand Down
11 changes: 9 additions & 2 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ function loadConfig() {

if (!isset($config['image_sticky']))
$config['image_sticky'] = $config['dir']['static'] . 'sticky.gif';
if (!isset($config['image_anchor']))
$config['image_anchor'] = $config['dir']['static'] . 'anchor.gif';
if (!isset($config['image_locked']))
$config['image_locked'] = $config['dir']['static'] . 'locked.gif';
if (!isset($config['image_bumplocked']))
Expand Down Expand Up @@ -911,7 +913,7 @@ function insertFloodPost(array $post) {

function post(array $post) {
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, NULL)", $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, :anchor, :locked, 0, :embed, NULL)", $board['uri']));

// Basic stuff
if (!empty($post['subject'])) {
Expand Down Expand Up @@ -944,6 +946,11 @@ function post(array $post) {
} else {
$query->bindValue(':sticky', false, PDO::PARAM_INT);
}
if ($post['op'] && $post['mod'] && isset($post['anchor']) && $post['anchor']) {
$query->bindValue(':anchor', true, PDO::PARAM_INT);
} else {
$query->bindValue(':anchor', false, PDO::PARAM_INT);
}

if ($post['op'] && $post['mod'] && isset($post['locked']) && $post['locked']) {
$query->bindValue(':locked', true, PDO::PARAM_INT);
Expand Down Expand Up @@ -1155,7 +1162,7 @@ function clean() {
$offset = round($config['max_pages']*$config['threads_per_page']);

// I too wish there was an easier way of doing this...
$query = prepare(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri']));
$query = prepare(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `anchor` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri']));
$query->bindValue(':offset', $offset, PDO::PARAM_INT);

$query->execute() or error(db_error($query));
Expand Down
23 changes: 23 additions & 0 deletions inc/mod/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,29 @@ function mod_sticky($board, $unsticky, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}

function mod_anchor($board, $unanchor, $post) {
global $config;

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

// If mod can sticky, they should be able to anchor.
if (!hasPermission($config['mod']['sticky'], $board))
error($config['error']['noaccess']);

$query = prepare(sprintf('UPDATE ``posts_%s`` SET `anchor` = :anchor WHERE `id` = :id AND `thread` IS NULL', $board));
$query->bindValue(':id', $post);
$query->bindValue(':anchor', $unanchor ? 0 : 1);
$query->execute() or error(db_error($query));
if ($query->rowCount()) {
modLog(($unanchor ? 'Unanchored' : 'Anchored') . " thread #{$post}");
buildThread($post);
buildIndex();
}

header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}

function mod_bumplock($board, $unbumplock, $post) {
global $config;

Expand Down
1 change: 1 addition & 0 deletions mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function strip_array($var) {
'/(\%b)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address
'/(\%b)/(un)?lock/(\d+)' => 'secure lock', // lock thread
'/(\%b)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
'/(\%b)/(un)?anchor/(\d+)' => 'secure anchor', // anchor thread
'/(\%b)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread

'/themes' => 'themes_list', // manage themes
Expand Down
5 changes: 3 additions & 2 deletions post.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,11 @@ function strip_array($var) {
}

$post['sticky'] = $post['op'] && isset($_POST['sticky']);
$post['anchor'] = $post['op'] && isset($_POST['anchor']);
$post['locked'] = $post['op'] && isset($_POST['lock']);
$post['raw'] = isset($_POST['raw']);

if ($post['sticky'] && !hasPermission($config['mod']['sticky'], $board['uri']))
if (($post['sticky'] || $post['anchor']) && !hasPermission($config['mod']['sticky'], $board['uri']))
error($config['error']['noaccess']);
if ($post['locked'] && !hasPermission($config['mod']['lock'], $board['uri']))
error($config['error']['noaccess']);
Expand All @@ -293,7 +294,7 @@ function strip_array($var) {

//Check if thread exists
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`,`anchor`,`locked`,`sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
$query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
$query->execute() or error(db_error());

Expand Down
7 changes: 7 additions & 0 deletions templates/post/post_controls.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
<a title="{% trans %}Make thread sticky{% endtrans %}" href="?/{{ secure_link(board.dir ~ 'sticky/' ~ post.id) }}">{{ config.mod.link_sticky }}</a>&nbsp;
{% endif %}
{% endif %}
{% if mod|hasPermission(config.mod.anchor, board.uri) %}
{% if post.anchor %}
<a title="{% trans %}Make thread unanchored{% endtrans %}" href="?/{{ secure_link(board.dir ~ 'unanchor/' ~ post.id) }}">{{ config.mod.link_deanchor }}</a>&nbsp;
{% else %}
<a title="{% trans %}Make thread anchored{% endtrans %}" href="?/{{ secure_link(board.dir ~ 'anchor/' ~ post.id) }}">{{ config.mod.link_anchor }}</a>&nbsp;
{% endif %}
{% endif %}
{% if mod|hasPermission(config.mod.bumplock, board.uri) %}
{% if post.sage %}
<a title="{% trans %}Allow thread to be bumped{% endtrans %}" href="?/{{ secure_link(board.dir ~ 'bumpunlock/' ~ post.id) }}">{{ config.mod.link_bumpunlock }}</a>&nbsp;
Expand Down
4 changes: 4 additions & 0 deletions templates/post_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
<label for="sticky">{% trans %}Sticky{% endtrans %}</label>
<input title="{% trans %}Sticky{% endtrans %}" type="checkbox" name="sticky" id="sticky"><br>
</div>{% endif %}
{% if not id and post.mod|hasPermission(config.mod.anchor, board.uri) %}<div class="center">
<label for="anchor">{% trans %}Anchor{% endtrans %}</label>
<input title="{% trans %}Anchor{% endtrans %}" type="checkbox" name="anchor" id="anchor"><br>
</div>{% endif %}
{% if not id and post.mod|hasPermission(config.mod.lock, board.uri) %}<div class="center">
<label for="lock">{% trans %}Lock{% endtrans %}</label><br>
<input title="{% trans %}Lock{% endtrans %}" type="checkbox" name="lock" id="lock">
Expand Down
8 changes: 7 additions & 1 deletion templates/post_thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
{% else %}
<img class="icon" title="Sticky" src="{{ config.image_sticky }}" alt="Sticky" />
{% endif %}
{% endif %}
{% else %}{% if post.anchor %}
{% if config.font_awesome %}
<i class="fa fa-anchor"></i>
{% else %}
<img class="icon" title="anchor" src="{{ config.image_anchor }}" alt="Anchor" />
{% endif %}
{% endif %}{% endif %}
{% if post.locked %}
{% if config.font_awesome %}
<i class="fa fa-lock"></i>
Expand Down
1 change: 1 addition & 0 deletions templates/posts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS ``posts_{{ board }}`` (
`password` varchar(20) DEFAULT NULL,
`ip` varchar(39) CHARACTER SET ascii NOT NULL,
`sticky` int(1) NOT NULL,
`anchor` int(1) NOT NULL,
`locked` int(1) NOT NULL,
`sage` int(1) NOT NULL,
`embed` text,
Expand Down