Use https://github.com/AwsumChan/IP for CIDR and prepare for Twig 3

This commit is contained in:
Daniel Saunders 2020-01-16 01:33:14 -05:00
parent 9c966c9e88
commit 7aae710441
6 changed files with 833 additions and 593 deletions

View File

@ -11,7 +11,7 @@ Tinyboard is defunct no longer. Circlepuller and others aim to modernize and opt
Requirements
------------
1. PHP >= 7.2
1. PHP >= 7.2.9
2. MySQL/MariaDB server >= 5.5.3
3. [mbstring](http://www.php.net/manual/en/mbstring.installation.php)
4. [PHP GD](http://www.php.net/manual/en/intro.image.php)

View File

@ -4,7 +4,7 @@
"type": "project",
"config": {
"platform": {
"php": "7.0.27"
"php": "7.2.9"
}
},
"require": {
@ -13,7 +13,7 @@
"twig/extensions": "^1.5",
"maxmind/geoip": "^1.1",
"mrclay/minify": "^3.0",
"lifo/ip": "^1.0",
"awsumchan/ip": "^1.1",
"erusev/parsedown": "^1.7"
},
"license": "MIT",

1332
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
<?php
use Lifo\IP\CIDR;
use AwsumChan\IP\CIDR;
class Bans {
static public function range_to_string($mask) {

View File

@ -13,9 +13,9 @@ $twig = false;
function load_twig() {
global $twig, $config;
$loader = new Twig_Loader_Filesystem($config['dir']['template']);
$loader = new Twig\Loader\FilesystemLoader($config['dir']['template']);
$loader->setPaths($config['dir']['template']);
$twig = new Twig_Environment($loader, array(
$twig = new Twig\Environment($loader, array(
'autoescape' => false,
'cache' => is_writable('templates') || (is_dir('templates/cache') && is_writable('templates/cache')) ?
new Twig_Cache_TinyboardFilesystem("{$config['dir']['template']}/cache") : false,
@ -73,7 +73,7 @@ function Element($templateFile, array $options) {
/**
* {@inheritdoc}
*/
class Twig_Cache_TinyboardFilesystem extends Twig_Cache_Filesystem
class Twig_Cache_TinyboardFilesystem extends Twig\Cache\FilesystemCache
{
private $directory;
private $options;
@ -101,7 +101,7 @@ class Twig_Cache_TinyboardFilesystem extends Twig_Cache_Filesystem
}
}
class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
class Twig_Extensions_Extension_Tinyboard extends Twig\Extension\AbstractExtension
{
/**
* Returns a list of filters to add to the existing list.
@ -110,25 +110,25 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
*/
public function getFilters()
{
return array(
new Twig_SimpleFilter('filesize', 'format_bytes'),
new Twig_SimpleFilter('truncate', 'twig_truncate_filter'),
new Twig_SimpleFilter('truncate_body', 'truncate'),
new Twig_SimpleFilter('truncate_filename', 'twig_filename_truncate_filter'),
new Twig_SimpleFilter('extension', 'twig_extension_filter'),
new Twig_SimpleFilter('sprintf', 'sprintf'),
new Twig_SimpleFilter('capcode', 'capcode'),
new Twig_SimpleFilter('remove_modifiers', 'remove_modifiers'),
new Twig_SimpleFilter('hasPermission', 'twig_hasPermission_filter'),
new Twig_SimpleFilter('date', 'twig_date_filter'),
new Twig_SimpleFilter('poster_id', 'poster_id'),
new Twig_SimpleFilter('remove_whitespace', 'twig_remove_whitespace_filter'),
new Twig_SimpleFilter('ago', 'ago'),
new Twig_SimpleFilter('until', 'until'),
new Twig_SimpleFilter('push', 'twig_push_filter'),
new Twig_SimpleFilter('bidi_cleanup', 'bidi_cleanup'),
new Twig_SimpleFilter('addslashes', 'addslashes'),
);
return [
new Twig\TwigFilter('filesize', 'format_bytes'),
new Twig\TwigFilter('truncate', 'twig_truncate_filter'),
new Twig\TwigFilter('truncate_body', 'truncate'),
new Twig\TwigFilter('truncate_filename', 'twig_filename_truncate_filter'),
new Twig\TwigFilter('extension', 'twig_extension_filter'),
new Twig\TwigFilter('sprintf', 'sprintf'),
new Twig\TwigFilter('capcode', 'capcode'),
new Twig\TwigFilter('remove_modifiers', 'remove_modifiers'),
new Twig\TwigFilter('hasPermission', 'twig_hasPermission_filter'),
new Twig\TwigFilter('date', 'twig_date_filter'),
new Twig\TwigFilter('poster_id', 'poster_id'),
new Twig\TwigFilter('remove_whitespace', 'twig_remove_whitespace_filter'),
new Twig\TwigFilter('ago', 'ago'),
new Twig\TwigFilter('until', 'until'),
new Twig\TwigFilter('push', 'twig_push_filter'),
new Twig\TwigFilter('bidi_cleanup', 'bidi_cleanup'),
new Twig\TwigFilter('addslashes', 'addslashes'),
];
}
/**
@ -138,17 +138,17 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
*/
public function getFunctions()
{
return array(
new Twig_SimpleFunction('time', 'time'),
new Twig_SimpleFunction('floor', 'floor'),
new Twig_SimpleFunction('timezone', 'twig_timezone_function'),
new Twig_SimpleFunction('hiddenInputs', 'hiddenInputs'),
new Twig_SimpleFunction('hiddenInputsHash', 'hiddenInputsHash'),
new Twig_SimpleFunction('ratio', 'twig_ratio_function'),
new Twig_SimpleFunction('secure_link_confirm', 'twig_secure_link_confirm'),
new Twig_SimpleFunction('secure_link', 'twig_secure_link'),
new Twig_SimpleFunction('link_for', 'link_for')
);
return [
new Twig\TwigFunction('time', 'time'),
new Twig\TwigFunction('floor', 'floor'),
new Twig\TwigFunction('timezone', 'twig_timezone_function'),
new Twig\TwigFunction('hiddenInputs', 'hiddenInputs'),
new Twig\TwigFunction('hiddenInputsHash', 'hiddenInputsHash'),
new Twig\TwigFunction('ratio', 'twig_ratio_function'),
new Twig\TwigFunction('secure_link_confirm', 'twig_secure_link_confirm'),
new Twig\TwigFunction('secure_link', 'twig_secure_link'),
new Twig\TwigFunction('link_for', 'link_for')
];
}
/**

View File

@ -1,7 +1,7 @@
<?php
// Installation/upgrade file
define('VERSION', 'v0.10.0');
define('VERSION', 'v0.10.1');
require 'inc/functions.php';
loadConfig();
@ -94,6 +94,7 @@ if (file_exists($config['has_installed'])) {
case 'v0.10.0-dev-3':
// Replaced longtable with tablesorter, updated copyright years, PHP 7.3 fixes implemented
// Next update will feature some nice surprises!
case 'v0.10.0':
// Require PHP 7.2 or newer
case false:
query("CREATE TABLE IF NOT EXISTS ``search_queries`` ( `ip` varchar(39) NOT NULL, `time` int(11) NOT NULL, `query` text NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error());
@ -188,15 +189,15 @@ if ($step == 0) {
$tests = [
[
'category' => 'PHP',
'name' => 'PHP &ge; 7.0',
'result' => PHP_VERSION_ID >= 70200,
'name' => 'PHP &ge; 7.2',
'result' => PHP_VERSION_ID >= 70209,
'required' => true,
'message' => 'Tinyboard requires PHP 7.2 or better.',
'message' => 'Tinyboard requires PHP 7.2.9 or better.',
],
[
'category' => 'PHP',
'name' => 'PHP &ge; 7.2',
'result' => PHP_VERSION_ID >= 70200,
'name' => 'PHP &ge; 7.3',
'result' => PHP_VERSION_ID >= 70300,
'required' => false,
'message' => 'Tinyboard works best on PHP 7.3 or better.',
],
@ -411,10 +412,7 @@ if ($step == 0) {
$instance_config .= "\n";
if (@file_put_contents('inc/instance-config.php', $instance_config)) {
// flushes opcache if php >= 5.5.0 or opcache is installed via PECL
if (function_exists('opcache_invalidate')) {
opcache_invalidate('inc/instance-config.php');
}
opcache_invalidate('inc/instance-config.php');
header('Location: ?step=4', true, $config['redirect_http']);
} else {
$page['title'] = 'Manual installation required';