summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/config.php9
-rw-r--r--inc/display.php18
-rw-r--r--inc/functions.php43
-rw-r--r--inc/mod/ban.php2
-rw-r--r--inc/mod/pages.php24
-rw-r--r--install.php4
-rw-r--r--install.sql1
-rw-r--r--mod.php4
-rw-r--r--post.php4
-rw-r--r--templates/banned.html16
-rw-r--r--templates/index.html2
-rw-r--r--templates/mod/ban_list.html8
-rw-r--r--templates/mod/dashboard.html2
-rw-r--r--templates/mod/view_ip.html10
-rw-r--r--templates/thread.html2
15 files changed, 110 insertions, 39 deletions
diff --git a/inc/config.php b/inc/config.php
index e5715cae..1140b1c9 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -384,6 +384,9 @@
// When true, a blank password will be used for files (not usable for deletion).
$config['field_disable_password'] = false;
+ // Require users to see the ban page at least once for a ban even if it has since expired?
+ $config['require_ban_view'] = false;
+
/*
* ====================
* Markup settings
@@ -557,6 +560,9 @@
// Number of characters in the poster ID (maximum is 40)
$config['poster_id_length'] = 5;
+ // Show thread subject in page title?
+ $config['thread_subject_in_title'] = false;
+
// Page footer
$config['footer'][] = 'All trademarks, copyrights, comments, and images on this page are owned by and are the responsibility of their respective parties.';
@@ -923,6 +929,9 @@
// Edit raw HTML in posts by default
$config['mod']['raw_html_default'] = false;
+ // Automatically dismiss all reports regarding a thread when it is locked
+ $config['mod']['dismiss_reports_on_lock'] = true;
+
// Probably best not to change these:
if (!defined('JANITOR')) {
define('JANITOR', 0, true);
diff --git a/inc/display.php b/inc/display.php
index 30560d3a..ba55903d 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -214,7 +214,7 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) {
}
function bidi_cleanup($str){
- # Closes all embedded RTL and LTR unicode formatting blocks in a string so that
+ # Removes all embedded RTL and LTR unicode formatting blocks in a string so that
# it can be used inside another without controlling its direction.
# More info: http://www.iamcal.com/understanding-bidirectional-text/
#
@@ -228,21 +228,7 @@ function bidi_cleanup($str){
$explicits = '\xE2\x80\xAA|\xE2\x80\xAB|\xE2\x80\xAD|\xE2\x80\xAE';
$pdf = '\xE2\x80\xAC';
- $stack = 0;
- $str = preg_replace_callback("!(?<explicits>$explicits)|(?<pdf>$pdf)!", function($match) use (&$stack) {
- if (isset($match['explicits']) && $match['explicits']) {
- $stack++;
- } else {
- if ($stack)
- $stack--;
- else
- return '';
- }
- return $match[0];
- }, $str);
- for ($i=0; $i<$stack; $i++){
- $str .= "\xE2\x80\xAC";
- }
+ $str = preg_replace("!(?<explicits>$explicits)|(?<pdf>$pdf)!", '', $str);
return $str;
}
diff --git a/inc/functions.php b/inc/functions.php
index 158973e2..d04b7ae9 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -78,7 +78,7 @@ function loadConfig() {
if ($config['debug']) {
if (!isset($debug)) {
- $debug = array('sql' => array(), 'purge' => array(), 'cached' => array());
+ $debug = array('sql' => array(), 'purge' => array(), 'cached' => array(), 'write' => array());
$debug['start'] = microtime(true);
}
}
@@ -392,7 +392,7 @@ function purge($uri) {
}
function file_write($path, $data, $simple = false, $skip_purge = false) {
- global $config;
+ global $config, $debug;
if (preg_match('/^remote:\/\/(.+)\:(.+)$/', $path, $m)) {
if (isset($config['remote'][$m[1]])) {
@@ -419,7 +419,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
error('Unable to truncate file: ' . $path);
// Write data
- if (fwrite($fp, $data) === false)
+ if (($bytes = fwrite($fp, $data)) === false)
error('Unable to write to file: ' . $path);
// Unlock
@@ -445,6 +445,10 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
purge($path);
}
+ if ($config['debug']) {
+ $debug['write'][] = $path . ': ' . $bytes . ' bytes';
+ }
+
event('write', $path);
}
@@ -575,6 +579,12 @@ function ago($timestamp) {
function displayBan($ban) {
global $config;
+ if (!$ban['seen']) {
+ $query = prepare("UPDATE `bans` SET `seen` = 1 WHERE `id` = :id");
+ $query->bindValue(':id', $ban['id'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+ }
+
$ban['ip'] = $_SERVER['REMOTE_ADDR'];
// Show banned page and exit
@@ -601,12 +611,12 @@ function checkBan($board = 0) {
if (event('check-ban', $board))
return true;
- $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1");
+ $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board);
$query->execute() or error(db_error($query));
if ($query->rowCount() < 1 && $config['ban_range']) {
- $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND :ip LIKE REPLACE(REPLACE(`ip`, '%', '!%'), '*', '%') ESCAPE '!' ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
+ $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board) AND :ip LIKE REPLACE(REPLACE(`ip`, '%', '!%'), '*', '%') ESCAPE '!' ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board);
$query->execute() or error(db_error($query));
@@ -614,7 +624,7 @@ function checkBan($board = 0) {
if ($query->rowCount() < 1 && $config['ban_cidr'] && !isIPv6()) {
// my most insane SQL query yet
- $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board)
+ $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, `bans`.`id` FROM `bans` WHERE (`board` IS NULL OR `board` = :board)
AND (
`ip` REGEXP '^(\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+\)\/(\[0-9]+)$'
AND
@@ -631,15 +641,29 @@ function checkBan($board = 0) {
if ($ban = $query->fetch()) {
if ($ban['expires'] && $ban['expires'] < time()) {
// Ban expired
- $query = prepare("DELETE FROM `bans` WHERE `id` = :id LIMIT 1");
+ $query = prepare("DELETE FROM `bans` WHERE `id` = :id");
$query->bindValue(':id', $ban['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
+ if ($config['require_ban_view'] && !$ban['seen']) {
+ displayBan($ban);
+ }
+
return;
}
displayBan($ban);
}
+
+ // I'm not sure where else to put this. It doesn't really matter where; it just needs to be called every now and then to keep the ban list tidy.
+ purge_bans();
+}
+
+// No reason to keep expired bans in the database (except those that haven't been viewed yet)
+function purge_bans() {
+ $query = prepare("DELETE FROM `bans` WHERE `expires` IS NOT NULL AND `expires` < :time AND `seen` = 1");
+ $query->bindValue(':time', time());
+ $query->execute() or error(db_error($query));
}
function threadLocked($id) {
@@ -1539,8 +1563,9 @@ function buildThread($id, $return=false, $mod=false) {
error($config['error']['nonexistant']);
$body = Element('thread.html', array(
- 'board'=>$board,
- 'body'=>$thread->build(),
+ 'board' => $board,
+ 'thread' => $thread,
+ 'body' => $thread->build(),
'config' => $config,
'id' => $id,
'mod' => $mod,
diff --git a/inc/mod/ban.php b/inc/mod/ban.php
index 30234157..cfc2636f 100644
--- a/inc/mod/ban.php
+++ b/inc/mod/ban.php
@@ -56,7 +56,7 @@ function parse_time($str) {
function ban($mask, $reason, $length, $board) {
global $mod, $pdo;
- $query = prepare("INSERT INTO `bans` VALUES (NULL, :ip, :mod, :time, :expires, :reason, :board)");
+ $query = prepare("INSERT INTO `bans` VALUES (NULL, :ip, :mod, :time, :expires, :reason, :board, 0)");
$query->bindValue(':ip', $mask);
$query->bindValue(':mod', $mod['id']);
$query->bindValue(':time', time());
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index f8a730d0..0e261357 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -217,6 +217,19 @@ function mod_edit_board($boardName) {
$query = prepare('DELETE FROM `antispam` WHERE `board` = :board');
$query->bindValue(':board', $board['uri']);
$query->execute() or error(db_error($query));
+
+ // Remove board from users/permissions table
+ $query = query('SELECT `id`,`boards` FROM `mods`') or error(db_error());
+ while ($user = $query->fetch(PDO::FETCH_ASSOC)) {
+ $user_boards = explode(',', $user['boards']);
+ if (in_array($board['uri'], $user_boards)) {
+ unset($user_boards[array_search($board['uri'], $user_boards)]);
+ $_query = prepare('UPDATE `mods` SET `boards` = :boards WHERE `id` = :id');
+ $_query->bindValue(':boards', implode(',', $user_boards));
+ $_query->bindValue(':id', $user['id']);
+ $_query->execute() or error(db_error($_query));
+ }
+ }
} else {
$query = prepare('UPDATE `boards` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri');
$query->bindValue(':uri', $board['uri']);
@@ -725,6 +738,13 @@ function mod_lock($board, $unlock, $post) {
buildIndex();
}
+ if ($config['mod']['dismiss_reports_on_lock']) {
+ $query = prepare('DELETE FROM `reports` WHERE `board` = :board AND `post` = :id');
+ $query->bindValue(':board', $board);
+ $query->bindValue(':id', $post);
+ $query->execute() or error(db_error($query));
+ }
+
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
if ($unlock)
@@ -906,8 +926,10 @@ function mod_move($originBoard, $postID) {
modLog("Moved thread #${postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#${newID})", $originBoard);
- // build new hread
+ // build new thread
buildThread($newID);
+
+ clean();
buildIndex();
// trigger themes
diff --git a/install.php b/install.php
index 0a85602b..42fbb15d 100644
--- a/install.php
+++ b/install.php
@@ -1,7 +1,7 @@
<?php
// Installation/upgrade file
-define('VERSION', 'v0.9.6-dev-7 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0-gold</a>');
+define('VERSION', 'v0.9.6-dev-8 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0.1</a>');
require 'inc/functions.php';
@@ -228,6 +228,8 @@ if (file_exists($config['has_installed'])) {
query(sprintf("ALTER TABLE `posts_%s` DROP INDEX `thread`", $_board['uri'])) or error(db_error());
}
case 'v0.9.6-dev-7':
+ case 'v0.9.6-dev-7 + <a href="https://github.com/vichan-devel/Tinyboard/">vichan-devel-4.0-gold</a>':
+ query("ALTER TABLE `bans` ADD `seen` BOOLEAN NOT NULL") or error(db_error());
case false:
// Update version number
file_write($config['has_installed'], VERSION);
diff --git a/install.sql b/install.sql
index 811811e2..04896681 100644
--- a/install.sql
+++ b/install.sql
@@ -51,6 +51,7 @@ CREATE TABLE IF NOT EXISTS `bans` (
`expires` int(11) DEFAULT NULL,
`reason` text,
`board` varchar(120) DEFAULT NULL,
+ `seen` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
diff --git a/mod.php b/mod.php
index 8d6db402..e76f1f01 100644
--- a/mod.php
+++ b/mod.php
@@ -103,7 +103,7 @@ if (isset($config['mod']['custom_pages'])) {
$new_pages = array();
foreach ($pages as $key => $callback) {
- if (preg_match('/^secure /', $callback))
+ if (is_string($callback) && preg_match('/^secure /', $callback))
$key .= '(/(?P<token>[a-f0-9]{8}))?';
$new_pages[@$key[0] == '!' ? $key : '!^' . $key . '(?:&[^&=]+=[^&]*)*$!'] = $callback;
}
@@ -113,7 +113,7 @@ foreach ($pages as $uri => $handler) {
if (preg_match($uri, $query, $matches)) {
$matches = array_slice($matches, 1);
- if (preg_match('/^secure(_POST)? /', $handler, $m)) {
+ if (is_string($handler) && preg_match('/^secure(_POST)? /', $handler, $m)) {
$secure_post_only = isset($m[1]);
if (!$secure_post_only || $_SERVER['REQUEST_METHOD'] == 'POST') {
$token = isset($matches['token']) ? $matches['token'] : (isset($_POST['token']) ? $_POST['token'] : false);
diff --git a/post.php b/post.php
index 710bb178..aa897340 100644
--- a/post.php
+++ b/post.php
@@ -635,10 +635,6 @@ if (isset($_POST['delete'])) {
incrementSpamHash($post['antispam_hash']);
}
- if (isset($post['antispam_hash'])) {
- incrementSpamHash($post['antispam_hash']);
- }
-
if (isset($post['tracked_cites'])) {
foreach ($post['tracked_cites'] as $cite) {
$query = prepare('INSERT INTO `cites` VALUES (:board, :post, :target_board, :target)');
diff --git a/templates/banned.html b/templates/banned.html
index e912c1a9..e7b626f6 100644
--- a/templates/banned.html
+++ b/templates/banned.html
@@ -1,9 +1,17 @@
{% filter remove_whitespace %}
{# Automatically removes unnecessary whitespace #}
<div class="ban">
- <h2>{% trans %}You are banned! ;_;{% endtrans %}</h2>
+ {% if ban.expires and time() >= ban.expires %}
+ <h2>{% trans %}You were banned! ;_;{% endtrans %}</h2>
+ {% else %}
+ <h2>{% trans %}You are banned! ;_;{% endtrans %}</h2>
+ {% endif %}
<p>
- {% trans %}You have been banned from{% endtrans %}
+ {% if ban.expires and time() >= ban.expires %}
+ {% trans %}You were banned from{% endtrans %}
+ {% else %}
+ {% trans %}You have been banned from{% endtrans %}
+ {% endif %}
{% if ban.board %}
<strong>{{ config.board_abbreviation|sprintf(ban.board) }}</strong>
{% else %}
@@ -23,7 +31,9 @@
<p>
{% trans %}Your ban was filed on{% endtrans %}
<strong>{{ ban.set|date(config.ban_date) }}</strong> {% trans %}and{% endtrans %} <span id="expires">
- {% if ban.expires %}
+ {% if ban.expires and time() >= ban.expires %}
+ {% trans %} has since expired. Refresh the page to continue.{% endtrans %}
+ {% elseif ban.expires %}
{% trans %}expires{% endtrans %} <span id="countdown">{{ ban.expires|until }}</span> {% trans %}from now, which is on{% endtrans %}
<strong>
{{ ban.expires|date(config.ban_date) }}
diff --git a/templates/index.html b/templates/index.html
index 82d3104e..451ca8b1 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -15,7 +15,7 @@
</script>
{% include 'header.html' %}
- <title>{{ board.url }} - {{ board.name }}</title>
+ <title>{{ board.url }} - {{ board.title|e }}</title>
</head>
<body>
{{ boardlist.top }}
diff --git a/templates/mod/ban_list.html b/templates/mod/ban_list.html
index 2edb9cdf..f8826ade 100644
--- a/templates/mod/ban_list.html
+++ b/templates/mod/ban_list.html
@@ -10,6 +10,7 @@
<th>{% trans 'Set' %}</th>
<th>{% trans 'Duration' %}</th>
<th>{% trans 'Expires' %}</th>
+ <th>{% trans 'Seen' %}</th>
<th>{% trans 'Staff' %}</th>
</tr>
{% for ban in bans %}
@@ -59,6 +60,13 @@
{% endif %}
</td>
<td>
+ {% if ban.seen %}
+ {% trans 'Yes' %}
+ {% else %}
+ {% trans 'No' %}
+ {% endif %}
+ </td>
+ <td>
{% if ban.username %}
{% if mod|hasPermission(config.mod.view_banstaff) %}
<a href="?/new_PM/{{ ban.username|e }}">{{ ban.username|e }}</a>
diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html
index 2f0b03ad..e54b3cd3 100644
--- a/templates/mod/dashboard.html
+++ b/templates/mod/dashboard.html
@@ -101,6 +101,7 @@
</ul>
</fieldset>
+{#
<fieldset>
<legend>{% trans 'Search' %}</legend>
@@ -115,6 +116,7 @@
</li>
</ul>
</fieldset>
+#}
{% if config.debug %}
<fieldset>
diff --git a/templates/mod/view_ip.html b/templates/mod/view_ip.html
index 562a0140..e2dad7af 100644
--- a/templates/mod/view_ip.html
+++ b/templates/mod/view_ip.html
@@ -137,6 +137,16 @@
</td>
</tr>
<tr>
+ <th>{% trans 'Seen' %}</th>
+ <td>
+ {% if ban.seen %}
+ {% trans 'Yes' %}
+ {% else %}
+ {% trans 'No' %}
+ {% endif %}
+ </td>
+ </tr>
+ <tr>
<th>{% trans 'Staff' %}</th>
<td>
{% if ban.username %}
diff --git a/templates/thread.html b/templates/thread.html
index b8c54dec..1b217c2f 100644
--- a/templates/thread.html
+++ b/templates/thread.html
@@ -8,7 +8,7 @@
</script>
{% include 'header.html' %}
- <title>{{ board.url }} - {{ board.name }}</title>
+ <title>{{ board.url }} - {% if config.thread_subject_in_title and thread.subject %}{{ thread.subject }}{% else %}{{ board.title|e }}{% endif %}</title>
</head>
<body>
{{ boardlist.top }}