forked from GithubBackups/vichan
Merge branch 'dev' into improve-auth
This commit is contained in:
commit
12bcc63753
@ -34,6 +34,8 @@
|
|||||||
"inc/queue.php",
|
"inc/queue.php",
|
||||||
"inc/functions.php",
|
"inc/functions.php",
|
||||||
"inc/functions/net.php",
|
"inc/functions/net.php",
|
||||||
|
"inc/functions/num.php",
|
||||||
|
"inc/functions/format.php",
|
||||||
"inc/driver/http-driver.php",
|
"inc/driver/http-driver.php",
|
||||||
"inc/driver/log-driver.php",
|
"inc/driver/log-driver.php",
|
||||||
"inc/service/captcha-queries.php"
|
"inc/service/captcha-queries.php"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Vichan\Functions\Format;
|
||||||
use Lifo\IP\CIDR;
|
use Lifo\IP\CIDR;
|
||||||
|
|
||||||
class Bans {
|
class Bans {
|
||||||
@ -371,7 +372,7 @@ class Bans {
|
|||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
if (isset($mod['id']) && $mod['id'] == $mod_id) {
|
if (isset($mod['id']) && $mod['id'] == $mod_id) {
|
||||||
modLog('Created a new ' .
|
modLog('Created a new ' .
|
||||||
($length > 0 ? preg_replace('/^(\d+) (\w+?)s?$/', '$1-$2', until($length)) : 'permanent') .
|
($length > 0 ? preg_replace('/^(\d+) (\w+?)s?$/', '$1-$2', Format\until($length)) : 'permanent') .
|
||||||
' ban on ' .
|
' ban on ' .
|
||||||
($ban_board ? '/' . $ban_board . '/' : 'all boards') .
|
($ban_board ? '/' . $ban_board . '/' : 'all boards') .
|
||||||
' for ' .
|
' for ' .
|
||||||
|
@ -21,9 +21,7 @@ loadConfig();
|
|||||||
|
|
||||||
function init_locale($locale, $error='error') {
|
function init_locale($locale, $error='error') {
|
||||||
if (extension_loaded('gettext')) {
|
if (extension_loaded('gettext')) {
|
||||||
if (setlocale(LC_ALL, $locale) === false) {
|
setlocale(LC_ALL, $locale);
|
||||||
//$error('The specified locale (' . $locale . ') does not exist on your platform!');
|
|
||||||
}
|
|
||||||
bindtextdomain('tinyboard', './inc/locale');
|
bindtextdomain('tinyboard', './inc/locale');
|
||||||
bind_textdomain_codeset('tinyboard', 'UTF-8');
|
bind_textdomain_codeset('tinyboard', 'UTF-8');
|
||||||
textdomain('tinyboard');
|
textdomain('tinyboard');
|
||||||
@ -56,7 +54,8 @@ function loadConfig() {
|
|||||||
|
|
||||||
if (isset($config['cache_config']) &&
|
if (isset($config['cache_config']) &&
|
||||||
$config['cache_config'] &&
|
$config['cache_config'] &&
|
||||||
$config = Cache::get('config_' . $boardsuffix ) ) {
|
$config = Cache::get('config_' . $boardsuffix))
|
||||||
|
{
|
||||||
$events = Cache::get('events_' . $boardsuffix );
|
$events = Cache::get('events_' . $boardsuffix );
|
||||||
|
|
||||||
define_groups();
|
define_groups();
|
||||||
@ -69,8 +68,7 @@ function loadConfig() {
|
|||||||
$current_locale = $config['locale'];
|
$current_locale = $config['locale'];
|
||||||
init_locale($config['locale'], $error);
|
init_locale($config['locale'], $error);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$config = array();
|
$config = array();
|
||||||
|
|
||||||
reset_events();
|
reset_events();
|
||||||
@ -242,13 +240,14 @@ function loadConfig() {
|
|||||||
$__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false;
|
$__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false;
|
||||||
$config['version'] = $__version;
|
$config['version'] = $__version;
|
||||||
|
|
||||||
if ($config['allow_roll'])
|
if ($config['allow_roll']) {
|
||||||
event_handler('post', 'diceRoller');
|
event_handler('post', 'diceRoller');
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array('webm', $config['allowed_ext_files']) ||
|
if (in_array('webm', $config['allowed_ext_files']) || in_array('mp4', $config['allowed_ext_files'])) {
|
||||||
in_array('mp4', $config['allowed_ext_files']))
|
|
||||||
event_handler('post', 'postHandler');
|
event_handler('post', 'postHandler');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Effectful config processing below:
|
// Effectful config processing below:
|
||||||
|
|
||||||
date_default_timezone_set($config['timezone']);
|
date_default_timezone_set($config['timezone']);
|
||||||
@ -280,8 +279,7 @@ function loadConfig() {
|
|||||||
if ($config['cache']['enabled'])
|
if ($config['cache']['enabled'])
|
||||||
require_once 'inc/cache.php';
|
require_once 'inc/cache.php';
|
||||||
|
|
||||||
if (in_array('webm', $config['allowed_ext_files']) ||
|
if (in_array('webm', $config['allowed_ext_files']) || in_array('mp4', $config['allowed_ext_files']))
|
||||||
in_array('mp4', $config['allowed_ext_files']))
|
|
||||||
require_once 'inc/lib/webm/posthandler.php';
|
require_once 'inc/lib/webm/posthandler.php';
|
||||||
|
|
||||||
event('load-config');
|
event('load-config');
|
||||||
@ -517,12 +515,11 @@ function mb_substr_replace($string, $replacement, $start, $length) {
|
|||||||
function setupBoard($array) {
|
function setupBoard($array) {
|
||||||
global $board, $config;
|
global $board, $config;
|
||||||
|
|
||||||
$board = array(
|
$board = [
|
||||||
'uri' => $array['uri'],
|
'uri' => $array['uri'],
|
||||||
'title' => $array['title'],
|
'title' => $array['title'],
|
||||||
'subtitle' => $array['subtitle'],
|
'subtitle' => $array['subtitle'],
|
||||||
#'indexed' => $array['indexed'],
|
];
|
||||||
);
|
|
||||||
|
|
||||||
// older versions
|
// older versions
|
||||||
$board['name'] = &$board['title'];
|
$board['name'] = &$board['title'];
|
||||||
@ -797,42 +794,6 @@ function listBoards($just_uri = false) {
|
|||||||
return $boards;
|
return $boards;
|
||||||
}
|
}
|
||||||
|
|
||||||
function until($timestamp) {
|
|
||||||
$difference = $timestamp - time();
|
|
||||||
switch(TRUE){
|
|
||||||
case ($difference < 60):
|
|
||||||
return $difference . ' ' . ngettext('second', 'seconds', $difference);
|
|
||||||
case ($difference < 3600): //60*60 = 3600
|
|
||||||
return ($num = round($difference/(60))) . ' ' . ngettext('minute', 'minutes', $num);
|
|
||||||
case ($difference < 86400): //60*60*24 = 86400
|
|
||||||
return ($num = round($difference/(3600))) . ' ' . ngettext('hour', 'hours', $num);
|
|
||||||
case ($difference < 604800): //60*60*24*7 = 604800
|
|
||||||
return ($num = round($difference/(86400))) . ' ' . ngettext('day', 'days', $num);
|
|
||||||
case ($difference < 31536000): //60*60*24*365 = 31536000
|
|
||||||
return ($num = round($difference/(604800))) . ' ' . ngettext('week', 'weeks', $num);
|
|
||||||
default:
|
|
||||||
return ($num = round($difference/(31536000))) . ' ' . ngettext('year', 'years', $num);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function ago($timestamp) {
|
|
||||||
$difference = time() - $timestamp;
|
|
||||||
switch(TRUE){
|
|
||||||
case ($difference < 60) :
|
|
||||||
return $difference . ' ' . ngettext('second', 'seconds', $difference);
|
|
||||||
case ($difference < 3600): //60*60 = 3600
|
|
||||||
return ($num = round($difference/(60))) . ' ' . ngettext('minute', 'minutes', $num);
|
|
||||||
case ($difference < 86400): //60*60*24 = 86400
|
|
||||||
return ($num = round($difference/(3600))) . ' ' . ngettext('hour', 'hours', $num);
|
|
||||||
case ($difference < 604800): //60*60*24*7 = 604800
|
|
||||||
return ($num = round($difference/(86400))) . ' ' . ngettext('day', 'days', $num);
|
|
||||||
case ($difference < 31536000): //60*60*24*365 = 31536000
|
|
||||||
return ($num = round($difference/(604800))) . ' ' . ngettext('week', 'weeks', $num);
|
|
||||||
default:
|
|
||||||
return ($num = round($difference/(31536000))) . ' ' . ngettext('year', 'years', $num);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function displayBan($ban) {
|
function displayBan($ban) {
|
||||||
global $config, $board;
|
global $config, $board;
|
||||||
|
|
||||||
@ -2572,35 +2533,6 @@ function generate_tripcode($name) {
|
|||||||
return array($name, $trip);
|
return array($name, $trip);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highest common factor
|
|
||||||
function hcf($a, $b){
|
|
||||||
$gcd = 1;
|
|
||||||
if ($a>$b) {
|
|
||||||
$a = $a+$b;
|
|
||||||
$b = $a-$b;
|
|
||||||
$a = $a-$b;
|
|
||||||
}
|
|
||||||
if ($b==(round($b/$a))*$a)
|
|
||||||
$gcd=$a;
|
|
||||||
else {
|
|
||||||
for ($i=round($a/2);$i;$i--) {
|
|
||||||
if ($a == round($a/$i)*$i && $b == round($b/$i)*$i) {
|
|
||||||
$gcd = $i;
|
|
||||||
$i = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $gcd;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fraction($numerator, $denominator, $sep) {
|
|
||||||
$gcf = hcf($numerator, $denominator);
|
|
||||||
$numerator = $numerator / $gcf;
|
|
||||||
$denominator = $denominator / $gcf;
|
|
||||||
|
|
||||||
return "{$numerator}{$sep}{$denominator}";
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPostByHash($hash) {
|
function getPostByHash($hash) {
|
||||||
global $board;
|
global $board;
|
||||||
$query = prepare(sprintf("SELECT `id`,`thread` FROM ``posts_%s`` WHERE `filehash` = :hash", $board['uri']));
|
$query = prepare(sprintf("SELECT `id`,`thread` FROM ``posts_%s`` WHERE `filehash` = :hash", $board['uri']));
|
||||||
@ -2866,24 +2798,6 @@ function prettify_textarea($s){
|
|||||||
return str_replace("\t", '	', str_replace("\n", ' ', htmlentities($s)));
|
return str_replace("\t", '	', str_replace("\n", ' ', htmlentities($s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*class HTMLPurifier_URIFilter_NoExternalImages extends HTMLPurifier_URIFilter {
|
|
||||||
public $name = 'NoExternalImages';
|
|
||||||
public function filter(&$uri, $c, $context) {
|
|
||||||
global $config;
|
|
||||||
$ct = $context->get('CurrentToken');
|
|
||||||
|
|
||||||
if (!$ct || $ct->name !== 'img') return true;
|
|
||||||
|
|
||||||
if (!isset($uri->host) && !isset($uri->scheme)) return true;
|
|
||||||
|
|
||||||
if (!in_array($uri->scheme . '://' . $uri->host . '/', $config['allowed_offsite_urls'])) {
|
|
||||||
error('No off-site links in board announcement images.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
function purify_html($s) {
|
function purify_html($s) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
28
inc/functions/format.php
Normal file
28
inc/functions/format.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
namespace Vichan\Functions\Format;
|
||||||
|
|
||||||
|
|
||||||
|
function format_timestamp(int $delta): string {
|
||||||
|
switch (true) {
|
||||||
|
case $delta < 60:
|
||||||
|
return $delta . ' ' . ngettext('second', 'seconds', $delta);
|
||||||
|
case $delta < 3600: //60*60 = 3600
|
||||||
|
return ($num = round($delta/ 60)) . ' ' . ngettext('minute', 'minutes', $num);
|
||||||
|
case $delta < 86400: //60*60*24 = 86400
|
||||||
|
return ($num = round($delta / 3600)) . ' ' . ngettext('hour', 'hours', $num);
|
||||||
|
case $delta < 604800: //60*60*24*7 = 604800
|
||||||
|
return ($num = round($delta / 86400)) . ' ' . ngettext('day', 'days', $num);
|
||||||
|
case $delta < 31536000: //60*60*24*365 = 31536000
|
||||||
|
return ($num = round($delta / 604800)) . ' ' . ngettext('week', 'weeks', $num);
|
||||||
|
default:
|
||||||
|
return ($num = round($delta / 31536000)) . ' ' . ngettext('year', 'years', $num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function until(int $timestamp): string {
|
||||||
|
return format_timestamp($timestamp - time());
|
||||||
|
}
|
||||||
|
|
||||||
|
function ago(int $timestamp): string {
|
||||||
|
return format_timestamp(time() - $timestamp);
|
||||||
|
}
|
33
inc/functions/num.php
Normal file
33
inc/functions/num.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
namespace Vichan\Functions\Num;
|
||||||
|
|
||||||
|
// Highest common factor
|
||||||
|
function hcf($a, $b){
|
||||||
|
$gcd = 1;
|
||||||
|
|
||||||
|
if ($a > $b) {
|
||||||
|
$a = $a+$b;
|
||||||
|
$b = $a-$b;
|
||||||
|
$a = $a-$b;
|
||||||
|
}
|
||||||
|
if ($b == (round($b / $a)) * $a) {
|
||||||
|
$gcd = $a;
|
||||||
|
} else {
|
||||||
|
for ($i = round($a / 2); $i; $i--) {
|
||||||
|
if ($a == round($a / $i) * $i && $b == round($b / $i) * $i) {
|
||||||
|
$gcd = $i;
|
||||||
|
$i = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $gcd;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fraction($numerator, $denominator, $sep) {
|
||||||
|
$gcf = hcf($numerator, $denominator);
|
||||||
|
$numerator = $numerator / $gcf;
|
||||||
|
$denominator = $denominator / $gcf;
|
||||||
|
|
||||||
|
return "{$numerator}{$sep}{$denominator}";
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2013 Tinyboard Development Group
|
* Copyright (c) 2010-2013 Tinyboard Development Group
|
||||||
*/
|
*/
|
||||||
|
use Vichan\Functions\Format;
|
||||||
|
|
||||||
use Vichan\Functions\Net;
|
use Vichan\Functions\Net;
|
||||||
|
|
||||||
@ -1558,7 +1559,7 @@ function mod_ban_post($board, $delete, $post, $token = false) {
|
|||||||
|
|
||||||
if (isset($_POST['public_message'], $_POST['message'])) {
|
if (isset($_POST['public_message'], $_POST['message'])) {
|
||||||
// public ban message
|
// public ban message
|
||||||
$length_english = Bans::parse_time($_POST['length']) ? 'for ' . until(Bans::parse_time($_POST['length'])) : 'permanently';
|
$length_english = Bans::parse_time($_POST['length']) ? 'for ' . Format\until(Bans::parse_time($_POST['length'])) : 'permanently';
|
||||||
$_POST['message'] = preg_replace('/[\r\n]/', '', $_POST['message']);
|
$_POST['message'] = preg_replace('/[\r\n]/', '', $_POST['message']);
|
||||||
$_POST['message'] = str_replace('%length%', $length_english, $_POST['message']);
|
$_POST['message'] = str_replace('%length%', $length_english, $_POST['message']);
|
||||||
$_POST['message'] = str_replace('%LENGTH%', strtoupper($length_english), $_POST['message']);
|
$_POST['message'] = str_replace('%LENGTH%', strtoupper($length_english), $_POST['message']);
|
||||||
|
@ -121,8 +121,8 @@ class Tinyboard extends Twig\Extension\AbstractExtension
|
|||||||
new Twig\TwigFilter('date', 'twig_date_filter'),
|
new Twig\TwigFilter('date', 'twig_date_filter'),
|
||||||
new Twig\TwigFilter('poster_id', 'poster_id'),
|
new Twig\TwigFilter('poster_id', 'poster_id'),
|
||||||
new Twig\TwigFilter('count', 'count'),
|
new Twig\TwigFilter('count', 'count'),
|
||||||
new Twig\TwigFilter('ago', 'ago'),
|
new Twig\TwigFilter('ago', 'Vichan\Functions\Format\ago'),
|
||||||
new Twig\TwigFilter('until', 'until'),
|
new Twig\TwigFilter('until', 'Vichan\Functions\Format\until'),
|
||||||
new Twig\TwigFilter('push', 'twig_push_filter'),
|
new Twig\TwigFilter('push', 'twig_push_filter'),
|
||||||
new Twig\TwigFilter('bidi_cleanup', 'bidi_cleanup'),
|
new Twig\TwigFilter('bidi_cleanup', 'bidi_cleanup'),
|
||||||
new Twig\TwigFilter('addslashes', 'addslashes'),
|
new Twig\TwigFilter('addslashes', 'addslashes'),
|
||||||
|
5
post.php
5
post.php
@ -8,6 +8,7 @@ require_once 'inc/bootstrap.php';
|
|||||||
use Vichan\{Context, WebDependencyFactory};
|
use Vichan\{Context, WebDependencyFactory};
|
||||||
use Vichan\Driver\{HttpDriver, Log};
|
use Vichan\Driver\{HttpDriver, Log};
|
||||||
use Vichan\Service\{RemoteCaptchaQuery, NativeCaptchaQuery};
|
use Vichan\Service\{RemoteCaptchaQuery, NativeCaptchaQuery};
|
||||||
|
use Vichan\Functions\Format;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility functions
|
* Utility functions
|
||||||
@ -394,14 +395,14 @@ if (isset($_POST['delete'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($post['time'] < time() - $config['max_delete_time'] && $config['max_delete_time'] != false) {
|
if ($post['time'] < time() - $config['max_delete_time'] && $config['max_delete_time'] != false) {
|
||||||
error(sprintf($config['error']['delete_too_late'], until($post['time'] + $config['max_delete_time'])));
|
error(sprintf($config['error']['delete_too_late'], Format\until($post['time'] + $config['max_delete_time'])));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($password != '' && $post['password'] != $password && (!$thread || $thread['password'] != $password))
|
if ($password != '' && $post['password'] != $password && (!$thread || $thread['password'] != $password))
|
||||||
error($config['error']['invalidpassword']);
|
error($config['error']['invalidpassword']);
|
||||||
|
|
||||||
if ($post['time'] > time() - $config['delete_time'] && (!$thread || $thread['password'] != $password)) {
|
if ($post['time'] > time() - $config['delete_time'] && (!$thread || $thread['password'] != $password)) {
|
||||||
error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time'])));
|
error(sprintf($config['error']['delete_too_soon'], Format\until($post['time'] + $config['delete_time'])));
|
||||||
}
|
}
|
||||||
|
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user