Fix Tinyboard Twig extension date filter
This commit is contained in:
parent
823115ef9d
commit
4cfbec0504
|
@ -4,6 +4,7 @@
|
|||
"guzzlehttp/guzzle": "^7.0",
|
||||
"lifo/ip": "^1.1",
|
||||
"twig/twig": "^3.0",
|
||||
"phpmyadmin/twig-i18n-extension": "^4.0"
|
||||
"phpmyadmin/twig-i18n-extension": "^4.0",
|
||||
"php81_bc/strftime": "^0.5.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3c18ea3d0277087541385610b2db992b",
|
||||
"content-hash": "fd9d40f38b577e52a0475b62da8bd994",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
|
@ -604,6 +604,50 @@
|
|||
},
|
||||
"time": "2022-02-21T01:04:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "php81_bc/strftime",
|
||||
"version": "0.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alphp/strftime.git",
|
||||
"reference": "4c1b56eaae4bb3f02f994ba47c2e5a225378e62f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/alphp/strftime/zipball/4c1b56eaae4bb3f02f994ba47c2e5a225378e62f",
|
||||
"reference": "4c1b56eaae4bb3f02f994ba47c2e5a225378e62f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-intl": "*",
|
||||
"php": ">=7.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "@stable"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/php-8.1-strftime.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fernando Herrero",
|
||||
"homepage": "https://github.com/alphp/strftime/graphs/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible)",
|
||||
"support": {
|
||||
"issues": "https://github.com/alphp/strftime/issues",
|
||||
"source": "https://github.com/alphp/strftime"
|
||||
},
|
||||
"time": "2022-04-10T22:31:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpmyadmin/twig-i18n-extension",
|
||||
"version": "v4.0.1",
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
|
||||
require_once 'inc/anti-bot.php';
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use function PHP81_BC\strftime;
|
||||
|
||||
class TinyboardExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
* @return array An array of filters
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
new TwigFilter('filesize', 'format_bytes'),
|
||||
new TwigFilter('truncate', 'twig_truncate_filter'),
|
||||
new TwigFilter('truncate_body', 'truncate'),
|
||||
new TwigFilter('truncate_filename', 'twig_filename_truncate_filter'),
|
||||
new TwigFilter('extension', 'twig_extension_filter'),
|
||||
new TwigFilter('sprintf', 'sprintf'),
|
||||
new TwigFilter('capcode', 'capcode'),
|
||||
new TwigFilter('remove_modifiers', 'remove_modifiers'),
|
||||
new TwigFilter('hasPermission', 'twig_hasPermission_filter'),
|
||||
new TwigFilter('date', 'twig_date_filter'),
|
||||
new TwigFilter('poster_id', 'poster_id'),
|
||||
new TwigFilter('remove_whitespace', 'twig_remove_whitespace_filter'),
|
||||
new TwigFilter('count', 'count'),
|
||||
new TwigFilter('ago', 'ago'),
|
||||
new TwigFilter('until', 'until'),
|
||||
new TwigFilter('push', 'twig_push_filter'),
|
||||
new TwigFilter('bidi_cleanup', 'bidi_cleanup'),
|
||||
new TwigFilter('addslashes', 'addslashes'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return array An array of filters
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new TwigFunction('time', 'time'),
|
||||
new TwigFunction('floor', 'floor'),
|
||||
new TwigFunction('timezone', 'twig_timezone_function'),
|
||||
new TwigFunction('hiddenInputs', 'hiddenInputs'),
|
||||
new TwigFunction('hiddenInputsHash', 'hiddenInputsHash'),
|
||||
new TwigFunction('ratio', 'twig_ratio_function'),
|
||||
new TwigFunction('secure_link_confirm', 'twig_secure_link_confirm'),
|
||||
new TwigFunction('secure_link', 'twig_secure_link'),
|
||||
new TwigFunction('link_for', 'link_for')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'tinyboard';
|
||||
}
|
||||
}
|
||||
|
||||
function twig_timezone_function() {
|
||||
return 'Z';
|
||||
}
|
||||
|
||||
function twig_push_filter($array, $value) {
|
||||
array_push($array, $value);
|
||||
return $array;
|
||||
}
|
||||
|
||||
function twig_remove_whitespace_filter($data) {
|
||||
return preg_replace('/[\t\r\n]/', '', $data);
|
||||
}
|
||||
|
||||
function twig_date_filter($date, $format) {
|
||||
return strftime($format, $date, 'en_US');
|
||||
}
|
||||
|
||||
function twig_hasPermission_filter($mod, $permission, $board = null) {
|
||||
return hasPermission($permission, $board, $mod);
|
||||
}
|
||||
|
||||
function twig_extension_filter($value, $case_insensitive = true) {
|
||||
$ext = mb_substr($value, mb_strrpos($value, '.') + 1);
|
||||
if($case_insensitive)
|
||||
$ext = mb_strtolower($ext);
|
||||
return $ext;
|
||||
}
|
||||
|
||||
function twig_sprintf_filter( $value, $var) {
|
||||
return sprintf($value, $var);
|
||||
}
|
||||
|
||||
function twig_truncate_filter($value, $length = 30, $preserve = false, $separator = '…') {
|
||||
if (mb_strlen($value) > $length) {
|
||||
if ($preserve) {
|
||||
if (false !== ($breakpoint = mb_strpos($value, ' ', $length))) {
|
||||
$length = $breakpoint;
|
||||
}
|
||||
}
|
||||
return mb_substr($value, 0, $length) . $separator;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function twig_filename_truncate_filter($value, $length = 30, $separator = '…') {
|
||||
if (mb_strlen($value) > $length) {
|
||||
$value = strrev($value);
|
||||
$array = array_reverse(explode(".", $value, 2));
|
||||
$array = array_map("strrev", $array);
|
||||
|
||||
$filename = &$array[0];
|
||||
$extension = isset($array[1]) ? $array[1] : false;
|
||||
|
||||
$filename = mb_substr($filename, 0, $length - ($extension ? mb_strlen($extension) + 1 : 0)) . $separator;
|
||||
|
||||
return implode(".", $array);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function twig_ratio_function($w, $h) {
|
||||
return fraction($w, $h, ':');
|
||||
}
|
||||
function twig_secure_link_confirm($text, $title, $confirm_message, $href) {
|
||||
global $config;
|
||||
|
||||
return '<a onclick="if (event.which==2) return true;if (confirm(\'' . htmlentities(addslashes($confirm_message)) . '\')) document.location=\'?/' . htmlspecialchars(addslashes($href . '/' . make_secure_link_token($href))) . '\';return false;" title="' . htmlentities($title) . '" href="?/' . $href . '">' . $text . '</a>';
|
||||
}
|
||||
function twig_secure_link($href) {
|
||||
return $href . '/' . make_secure_link_token($href);
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
defined('TINYBOARD') or exit;
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once 'inc/lib/twig/Extensions/Tinyboard.php';
|
||||
|
||||
use PhpMyAdmin\Twig\Extensions\I18nExtension;
|
||||
|
||||
|
@ -15,7 +16,6 @@ $twig = false;
|
|||
function load_twig() {
|
||||
global $twig, $config;
|
||||
|
||||
|
||||
$loader = new Twig\Loader\FilesystemLoader($config['dir']['template']);
|
||||
$twig = new Twig\Environment($loader, array(
|
||||
'autoescape' => false,
|
||||
|
@ -25,6 +25,7 @@ function load_twig() {
|
|||
));
|
||||
|
||||
$twig->addExtension(new I18nExtension());
|
||||
$twig->addExtension(new TinyboardExtension());
|
||||
}
|
||||
|
||||
function Element($templateFile, array $options) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% filter remove_whitespace %}
|
||||
{% apply remove_whitespace %}
|
||||
{# tabs and new lines will be ignored #}
|
||||
|
||||
<div class="thread" id="thread_{{ post.id }}" data-board="{{ board.uri }}">
|
||||
|
@ -58,7 +58,7 @@
|
|||
{% include 'post/post_controls.html' %}
|
||||
</p>
|
||||
<div class="body">
|
||||
{% endfilter %}{% if index %}{{ post.body|truncate_body(post.link) }}{% else %}{{ post.body }}{% endif %}{% filter remove_whitespace %}
|
||||
{% endapply %}{% if index %}{{ post.body|truncate_body(post.link) }}{% else %}{{ post.body }}{% endif %}{% apply remove_whitespace %}
|
||||
{% if post.modifiers['ban message'] %}
|
||||
{{ config.mod.ban_message|sprintf(post.modifiers['ban message']) }}
|
||||
{% endif %}
|
||||
|
@ -89,7 +89,7 @@
|
|||
{% endif %}
|
||||
{% if not index %}
|
||||
{% endif %}
|
||||
</div>{% endfilter %}
|
||||
</div>{% endapply %}
|
||||
{% set iparray = [post.ip] %}
|
||||
{% set hr = post.hr %}
|
||||
{% for post in post.posts %}
|
||||
|
|
Loading…
Reference in New Issue