2011-10-11 06:49:14 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns a list of filters to add to the existing list.
|
|
|
|
*
|
|
|
|
* @return array An array of filters
|
|
|
|
*/
|
|
|
|
public function getFilters()
|
|
|
|
{
|
2013-08-01 15:55:28 -04:00
|
|
|
return array(
|
|
|
|
new Twig_SimpleFilter('filesize', 'format_bytes'),
|
|
|
|
new Twig_SimpleFilter('truncate', 'twig_truncate_filter'),
|
|
|
|
new Twig_SimpleFilter('truncate_body', 'truncate'),
|
2014-05-09 20:42:57 -04:00
|
|
|
new Twig_SimpleFilter('truncate_filename', 'truncate_filename'),
|
2013-08-01 15:55:28 -04:00
|
|
|
new Twig_SimpleFilter('extension', 'twig_extension_filter'),
|
|
|
|
new Twig_SimpleFilter('sprintf', 'sprintf'),
|
|
|
|
new Twig_SimpleFilter('capcode', 'capcode'),
|
|
|
|
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('count', 'count'),
|
|
|
|
new Twig_SimpleFilter('ago', 'ago'),
|
|
|
|
new Twig_SimpleFilter('until', 'until'),
|
|
|
|
new Twig_SimpleFilter('push', 'twig_push_filter'),
|
|
|
|
new Twig_SimpleFilter('bidi_cleanup', 'bidi_cleanup'),
|
2014-04-27 09:48:47 -04:00
|
|
|
new Twig_SimpleFilter('addslashes', 'addslashes'),
|
2011-11-23 00:12:19 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of functions to add to the existing list.
|
|
|
|
*
|
|
|
|
* @return array An array of filters
|
|
|
|
*/
|
|
|
|
public function getFunctions()
|
|
|
|
{
|
2013-08-01 15:55:28 -04:00
|
|
|
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'),
|
2014-04-30 17:18:35 -04:00
|
|
|
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')
|
2011-10-11 06:49:14 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of the extension.
|
|
|
|
*
|
|
|
|
* @return string The extension name
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'tinyboard';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 07:38:55 -05:00
|
|
|
function twig_timezone_function() {
|
2013-03-10 09:09:48 -04:00
|
|
|
return 'Z';
|
2012-02-19 07:38:55 -05:00
|
|
|
}
|
|
|
|
|
2012-04-13 07:43:01 -04:00
|
|
|
function twig_push_filter($array, $value) {
|
|
|
|
array_push($array, $value);
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
2011-10-11 06:49:14 -04:00
|
|
|
function twig_remove_whitespace_filter($data) {
|
|
|
|
return preg_replace('/[\t\r\n]/', '', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function twig_date_filter($date, $format) {
|
2013-03-10 09:09:48 -04:00
|
|
|
return gmstrftime($format, $date);
|
2011-10-11 06:49:14 -04:00
|
|
|
}
|
|
|
|
|
2012-04-16 09:18:07 -04:00
|
|
|
function twig_hasPermission_filter($mod, $permission, $board = null) {
|
2011-10-11 06:49:14 -04:00
|
|
|
return hasPermission($permission, $board, $mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
function twig_extension_filter($value, $case_insensitive = true) {
|
2013-07-31 16:38:09 -04:00
|
|
|
$ext = mb_substr($value, mb_strrpos($value, '.') + 1);
|
2011-10-11 06:49:14 -04:00
|
|
|
if($case_insensitive)
|
2013-07-31 16:38:09 -04:00
|
|
|
$ext = mb_strtolower($ext);
|
2011-10-11 06:49:14 -04:00
|
|
|
return $ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
function twig_sprintf_filter( $value, $var) {
|
|
|
|
return sprintf($value, $var);
|
|
|
|
}
|
|
|
|
|
|
|
|
function twig_truncate_filter($value, $length = 30, $preserve = false, $separator = '…') {
|
2011-12-07 01:47:36 -05:00
|
|
|
if (mb_strlen($value) > $length) {
|
2011-10-11 06:49:14 -04:00
|
|
|
if ($preserve) {
|
2013-07-31 16:38:09 -04:00
|
|
|
if (false !== ($breakpoint = mb_strpos($value, ' ', $length))) {
|
2011-10-11 06:49:14 -04:00
|
|
|
$length = $breakpoint;
|
|
|
|
}
|
|
|
|
}
|
2013-07-31 16:38:09 -04:00
|
|
|
return mb_substr($value, 0, $length) . $separator;
|
2011-10-11 06:49:14 -04:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2014-04-27 09:48:47 -04:00
|
|
|
function twig_ratio_function($w, $h) {
|
|
|
|
return fraction($w, $h, ':');
|
|
|
|
}
|
2014-04-30 17:18:35 -04:00
|
|
|
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);
|
|
|
|
}
|