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()
|
|
|
|
{
|
|
|
|
return Array(
|
2012-04-13 07:43:01 -04:00
|
|
|
'filesize' => new Twig_Filter_Function('format_bytes'),
|
|
|
|
'truncate' => new Twig_Filter_Function('twig_truncate_filter'),
|
|
|
|
'truncate_body' => new Twig_Filter_Function('truncate'),
|
|
|
|
'extension' => new Twig_Filter_Function('twig_extension_filter'),
|
|
|
|
'sprintf' => new Twig_Filter_Function('sprintf'),
|
|
|
|
'capcode' => new Twig_Filter_Function('capcode'),
|
|
|
|
'hasPermission' => new Twig_Filter_Function('twig_hasPermission_filter'),
|
|
|
|
'date' => new Twig_Filter_Function('twig_date_filter'),
|
|
|
|
'poster_id' => new Twig_Filter_Function('poster_id'),
|
|
|
|
'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter'),
|
|
|
|
'count' => new Twig_Filter_Function('count'),
|
|
|
|
'ago' => new Twig_Filter_Function('ago'),
|
|
|
|
'until' => new Twig_Filter_Function('until'),
|
|
|
|
'split' => new Twig_Filter_Function('twig_split_filter'),
|
|
|
|
'push' => new Twig_Filter_Function('twig_push_filter'),
|
2013-04-02 05:28:04 -04:00
|
|
|
'bidi_cleanup' => new Twig_Filter_Function('bidi_cleanup'),
|
2012-04-22 03:50:53 -04:00
|
|
|
'addslashes' => new Twig_Filter_Function('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()
|
|
|
|
{
|
|
|
|
return Array(
|
2012-04-13 07:43:01 -04:00
|
|
|
'time' => new Twig_Filter_Function('time'),
|
2012-04-21 01:15:32 -04:00
|
|
|
'floor' => new Twig_Filter_Function('floor'),
|
2012-04-13 07:43:01 -04:00
|
|
|
'timezone' => new Twig_Filter_Function('twig_timezone_function'),
|
|
|
|
'hiddenInputs' => new Twig_Filter_Function('hiddenInputs'),
|
|
|
|
'hiddenInputsHash' => new Twig_Filter_Function('hiddenInputsHash'),
|
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_split_filter($str, $delim) {
|
|
|
|
return explode($delim, $str);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|