forked from leftypol/leftypol
Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
Conflicts: install.php templates/index.html templates/thread.html
This commit is contained in:
commit
7bdb96a16b
15 changed files with 110 additions and 39 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue