1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-27 17:00:52 +01:00
Conflicts:
	install.php
	templates/index.html
	templates/thread.html
This commit is contained in:
czaks 2013-07-16 13:02:13 -04:00
commit 7bdb96a16b
15 changed files with 110 additions and 39 deletions

View File

@ -384,6 +384,9 @@
// When true, a blank password will be used for files (not usable for deletion). // When true, a blank password will be used for files (not usable for deletion).
$config['field_disable_password'] = false; $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 * Markup settings
@ -557,6 +560,9 @@
// Number of characters in the poster ID (maximum is 40) // Number of characters in the poster ID (maximum is 40)
$config['poster_id_length'] = 5; $config['poster_id_length'] = 5;
// Show thread subject in page title?
$config['thread_subject_in_title'] = false;
// Page footer // Page footer
$config['footer'][] = 'All trademarks, copyrights, comments, and images on this page are owned by and are the responsibility of their respective parties.'; $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 // Edit raw HTML in posts by default
$config['mod']['raw_html_default'] = false; $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: // Probably best not to change these:
if (!defined('JANITOR')) { if (!defined('JANITOR')) {
define('JANITOR', 0, true); define('JANITOR', 0, true);

View File

@ -214,7 +214,7 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) {
} }
function bidi_cleanup($str){ 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. # it can be used inside another without controlling its direction.
# More info: http://www.iamcal.com/understanding-bidirectional-text/ # 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'; $explicits = '\xE2\x80\xAA|\xE2\x80\xAB|\xE2\x80\xAD|\xE2\x80\xAE';
$pdf = '\xE2\x80\xAC'; $pdf = '\xE2\x80\xAC';
$stack = 0; $str = preg_replace("!(?<explicits>$explicits)|(?<pdf>$pdf)!", '', $str);
$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";
}
return $str; return $str;
} }

View File

@ -78,7 +78,7 @@ function loadConfig() {
if ($config['debug']) { if ($config['debug']) {
if (!isset($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); $debug['start'] = microtime(true);
} }
} }
@ -392,7 +392,7 @@ function purge($uri) {
} }
function file_write($path, $data, $simple = false, $skip_purge = false) { function file_write($path, $data, $simple = false, $skip_purge = false) {
global $config; global $config, $debug;
if (preg_match('/^remote:\/\/(.+)\:(.+)$/', $path, $m)) { if (preg_match('/^remote:\/\/(.+)\:(.+)$/', $path, $m)) {
if (isset($config['remote'][$m[1]])) { 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); error('Unable to truncate file: ' . $path);
// Write data // Write data
if (fwrite($fp, $data) === false) if (($bytes = fwrite($fp, $data)) === false)
error('Unable to write to file: ' . $path); error('Unable to write to file: ' . $path);
// Unlock // Unlock
@ -445,6 +445,10 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
purge($path); purge($path);
} }
if ($config['debug']) {
$debug['write'][] = $path . ': ' . $bytes . ' bytes';
}
event('write', $path); event('write', $path);
} }
@ -575,6 +579,12 @@ function ago($timestamp) {
function displayBan($ban) { function displayBan($ban) {
global $config; 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']; $ban['ip'] = $_SERVER['REMOTE_ADDR'];
// Show banned page and exit // Show banned page and exit
@ -601,12 +611,12 @@ function checkBan($board = 0) {
if (event('check-ban', $board)) if (event('check-ban', $board))
return true; 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(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board); $query->bindValue(':board', $board);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if ($query->rowCount() < 1 && $config['ban_range']) { 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(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board); $query->bindValue(':board', $board);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
@ -614,7 +624,7 @@ function checkBan($board = 0) {
if ($query->rowCount() < 1 && $config['ban_cidr'] && !isIPv6()) { if ($query->rowCount() < 1 && $config['ban_cidr'] && !isIPv6()) {
// my most insane SQL query yet // 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 ( AND (
`ip` REGEXP '^(\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+\)\/(\[0-9]+)$' `ip` REGEXP '^(\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+\)\/(\[0-9]+)$'
AND AND
@ -631,15 +641,29 @@ function checkBan($board = 0) {
if ($ban = $query->fetch()) { if ($ban = $query->fetch()) {
if ($ban['expires'] && $ban['expires'] < time()) { if ($ban['expires'] && $ban['expires'] < time()) {
// Ban expired // 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->bindValue(':id', $ban['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if ($config['require_ban_view'] && !$ban['seen']) {
displayBan($ban);
}
return; return;
} }
displayBan($ban); 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) { function threadLocked($id) {
@ -1539,8 +1563,9 @@ function buildThread($id, $return=false, $mod=false) {
error($config['error']['nonexistant']); error($config['error']['nonexistant']);
$body = Element('thread.html', array( $body = Element('thread.html', array(
'board'=>$board, 'board' => $board,
'body'=>$thread->build(), 'thread' => $thread,
'body' => $thread->build(),
'config' => $config, 'config' => $config,
'id' => $id, 'id' => $id,
'mod' => $mod, 'mod' => $mod,

View File

@ -56,7 +56,7 @@ function parse_time($str) {
function ban($mask, $reason, $length, $board) { function ban($mask, $reason, $length, $board) {
global $mod, $pdo; 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(':ip', $mask);
$query->bindValue(':mod', $mod['id']); $query->bindValue(':mod', $mod['id']);
$query->bindValue(':time', time()); $query->bindValue(':time', time());

View File

@ -217,6 +217,19 @@ function mod_edit_board($boardName) {
$query = prepare('DELETE FROM `antispam` WHERE `board` = :board'); $query = prepare('DELETE FROM `antispam` WHERE `board` = :board');
$query->bindValue(':board', $board['uri']); $query->bindValue(':board', $board['uri']);
$query->execute() or error(db_error($query)); $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 { } else {
$query = prepare('UPDATE `boards` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri'); $query = prepare('UPDATE `boards` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri');
$query->bindValue(':uri', $board['uri']); $query->bindValue(':uri', $board['uri']);
@ -725,6 +738,13 @@ function mod_lock($board, $unlock, $post) {
buildIndex(); 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']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
if ($unlock) if ($unlock)
@ -906,8 +926,10 @@ function mod_move($originBoard, $postID) {
modLog("Moved thread #${postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#${newID})", $originBoard); modLog("Moved thread #${postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#${newID})", $originBoard);
// build new hread // build new thread
buildThread($newID); buildThread($newID);
clean();
buildIndex(); buildIndex();
// trigger themes // trigger themes

View File

@ -1,7 +1,7 @@
<?php <?php
// Installation/upgrade file // 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'; 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()); 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':
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: case false:
// Update version number // Update version number
file_write($config['has_installed'], VERSION); file_write($config['has_installed'], VERSION);

View File

@ -51,6 +51,7 @@ CREATE TABLE IF NOT EXISTS `bans` (
`expires` int(11) DEFAULT NULL, `expires` int(11) DEFAULT NULL,
`reason` text, `reason` text,
`board` varchar(120) DEFAULT NULL, `board` varchar(120) DEFAULT NULL,
`seen` tinyint(1) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
FULLTEXT KEY `ip` (`ip`) FULLTEXT KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

View File

@ -103,7 +103,7 @@ if (isset($config['mod']['custom_pages'])) {
$new_pages = array(); $new_pages = array();
foreach ($pages as $key => $callback) { 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}))?'; $key .= '(/(?P<token>[a-f0-9]{8}))?';
$new_pages[@$key[0] == '!' ? $key : '!^' . $key . '(?:&[^&=]+=[^&]*)*$!'] = $callback; $new_pages[@$key[0] == '!' ? $key : '!^' . $key . '(?:&[^&=]+=[^&]*)*$!'] = $callback;
} }
@ -113,7 +113,7 @@ foreach ($pages as $uri => $handler) {
if (preg_match($uri, $query, $matches)) { if (preg_match($uri, $query, $matches)) {
$matches = array_slice($matches, 1); $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]); $secure_post_only = isset($m[1]);
if (!$secure_post_only || $_SERVER['REQUEST_METHOD'] == 'POST') { if (!$secure_post_only || $_SERVER['REQUEST_METHOD'] == 'POST') {
$token = isset($matches['token']) ? $matches['token'] : (isset($_POST['token']) ? $_POST['token'] : false); $token = isset($matches['token']) ? $matches['token'] : (isset($_POST['token']) ? $_POST['token'] : false);

View File

@ -635,10 +635,6 @@ if (isset($_POST['delete'])) {
incrementSpamHash($post['antispam_hash']); incrementSpamHash($post['antispam_hash']);
} }
if (isset($post['antispam_hash'])) {
incrementSpamHash($post['antispam_hash']);
}
if (isset($post['tracked_cites'])) { if (isset($post['tracked_cites'])) {
foreach ($post['tracked_cites'] as $cite) { foreach ($post['tracked_cites'] as $cite) {
$query = prepare('INSERT INTO `cites` VALUES (:board, :post, :target_board, :target)'); $query = prepare('INSERT INTO `cites` VALUES (:board, :post, :target_board, :target)');

View File

@ -1,9 +1,17 @@
{% filter remove_whitespace %} {% filter remove_whitespace %}
{# Automatically removes unnecessary whitespace #} {# Automatically removes unnecessary whitespace #}
<div class="ban"> <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> <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 %} {% if ban.board %}
<strong>{{ config.board_abbreviation|sprintf(ban.board) }}</strong> <strong>{{ config.board_abbreviation|sprintf(ban.board) }}</strong>
{% else %} {% else %}
@ -23,7 +31,9 @@
<p> <p>
{% trans %}Your ban was filed on{% endtrans %} {% trans %}Your ban was filed on{% endtrans %}
<strong>{{ ban.set|date(config.ban_date) }}</strong> {% trans %}and{% endtrans %} <span id="expires"> <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 %} {% trans %}expires{% endtrans %} <span id="countdown">{{ ban.expires|until }}</span> {% trans %}from now, which is on{% endtrans %}
<strong> <strong>
{{ ban.expires|date(config.ban_date) }} {{ ban.expires|date(config.ban_date) }}

View File

@ -15,7 +15,7 @@
</script> </script>
{% include 'header.html' %} {% include 'header.html' %}
<title>{{ board.url }} - {{ board.name }}</title> <title>{{ board.url }} - {{ board.title|e }}</title>
</head> </head>
<body> <body>
{{ boardlist.top }} {{ boardlist.top }}

View File

@ -10,6 +10,7 @@
<th>{% trans 'Set' %}</th> <th>{% trans 'Set' %}</th>
<th>{% trans 'Duration' %}</th> <th>{% trans 'Duration' %}</th>
<th>{% trans 'Expires' %}</th> <th>{% trans 'Expires' %}</th>
<th>{% trans 'Seen' %}</th>
<th>{% trans 'Staff' %}</th> <th>{% trans 'Staff' %}</th>
</tr> </tr>
{% for ban in bans %} {% for ban in bans %}
@ -58,6 +59,13 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</td> </td>
<td>
{% if ban.seen %}
{% trans 'Yes' %}
{% else %}
{% trans 'No' %}
{% endif %}
</td>
<td> <td>
{% if ban.username %} {% if ban.username %}
{% if mod|hasPermission(config.mod.view_banstaff) %} {% if mod|hasPermission(config.mod.view_banstaff) %}

View File

@ -101,6 +101,7 @@
</ul> </ul>
</fieldset> </fieldset>
{#
<fieldset> <fieldset>
<legend>{% trans 'Search' %}</legend> <legend>{% trans 'Search' %}</legend>
@ -115,6 +116,7 @@
</li> </li>
</ul> </ul>
</fieldset> </fieldset>
#}
{% if config.debug %} {% if config.debug %}
<fieldset> <fieldset>

View File

@ -136,6 +136,16 @@
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
<tr>
<th>{% trans 'Seen' %}</th>
<td>
{% if ban.seen %}
{% trans 'Yes' %}
{% else %}
{% trans 'No' %}
{% endif %}
</td>
</tr>
<tr> <tr>
<th>{% trans 'Staff' %}</th> <th>{% trans 'Staff' %}</th>
<td> <td>

View File

@ -8,7 +8,7 @@
</script> </script>
{% include 'header.html' %} {% 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> </head>
<body> <body>
{{ boardlist.top }} {{ boardlist.top }}