mirror of
https://github.com/getgrav/grav.git
synced 2026-02-06 06:40:29 +01:00
Added pad filter for strings (uses str_pad)
This commit is contained in:
@@ -70,6 +70,7 @@ class TwigExtension extends \Twig_Extension
|
||||
new \Twig_SimpleFilter('randomize', [$this,'randomizeFilter']),
|
||||
new \Twig_SimpleFilter('modulus', [$this,'modulusFilter']),
|
||||
new \Twig_SimpleFilter('rtrim', [$this, 'rtrimFilter']),
|
||||
new \Twig_SimpleFilter('pad', [$this, 'padFilter']),
|
||||
new \Twig_SimpleFilter('safe_email', [$this,'safeEmailFilter']),
|
||||
new \Twig_SimpleFilter('safe_truncate', ['\Grav\Common\Utils','safeTruncate']),
|
||||
new \Twig_SimpleFilter('safe_truncate_html', ['\Grav\Common\Utils','safeTruncateHTML']),
|
||||
@@ -537,6 +538,22 @@ class TwigExtension extends \Twig_Extension
|
||||
return Utils::generateRandomString($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pad a string to a certain length with another string
|
||||
*
|
||||
* @param $input
|
||||
* @param $pad_length
|
||||
* @param string $pad_string
|
||||
* @param int $pad_type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function padFilter($input, $pad_length, $pad_string = " ", $pad_type = STR_PAD_RIGHT)
|
||||
{
|
||||
return str_pad($input, (int) $pad_length, $pad_string, $pad_type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cast a value to array
|
||||
*
|
||||
|
||||
@@ -100,6 +100,9 @@ abstract class Utils
|
||||
return (object)array_merge((array)$obj1, (array)$obj2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function dateFormats()
|
||||
{
|
||||
$now = new DateTime();
|
||||
@@ -300,11 +303,19 @@ abstract class Utils
|
||||
return $root . implode('/', $ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $function
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFunctionDisabled($function)
|
||||
{
|
||||
return in_array($function, explode(',', ini_get('disable_functions')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function timezones()
|
||||
{
|
||||
$timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL);
|
||||
@@ -332,6 +343,12 @@ abstract class Utils
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $source
|
||||
* @param $fn
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function arrayFilterRecursive(Array $source, $fn)
|
||||
{
|
||||
$result = array();
|
||||
@@ -351,6 +368,11 @@ abstract class Utils
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function pathPrefixedByLangCode($string)
|
||||
{
|
||||
$languages_enabled = self::getGrav()['config']->get('system.languages.supported', []);
|
||||
@@ -362,6 +384,11 @@ abstract class Utils
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function date2timestamp($date)
|
||||
{
|
||||
$config = self::getGrav()['config'];
|
||||
|
||||
Reference in New Issue
Block a user