diff --git a/src/Pluf/Template.php b/src/Pluf/Template.php index b9e6c41..25562e5 100644 --- a/src/Pluf/Template.php +++ b/src/Pluf/Template.php @@ -301,4 +301,38 @@ function Pluf_Template_safeEmail($email) $email = chunk_split(bin2hex($email), 2, '%'); $email = '%'.substr($email, 0, strlen($email) - 1); return Pluf_Template::markSafe($email); -} \ No newline at end of file +} + +/** + * Returns the first item in the given array. + * + * @param array $array + * @return mixed An empty string if $array is not an array. + */ +function Pluf_Template_first($array) +{ + $array = (array) $array; + $result = array_shift($array); + if (null === $result) { + return ''; + } + + return $result; +} + +/** + * Returns the last item in the given array. + * + * @param array $array + * @return mixed An empty string if $array is not an array. + */ +function Pluf_Template_last($array) +{ + $array = (array) $array; + $result = array_pop($array); + if (null === $result) { + return ''; + } + + return $result; +} diff --git a/src/Pluf/Template/Compiler.php b/src/Pluf/Template/Compiler.php index e790e1a..14ecd31 100644 --- a/src/Pluf/Template/Compiler.php +++ b/src/Pluf/Template/Compiler.php @@ -89,6 +89,7 @@ class Pluf_Template_Compiler 'lower' => 'strtolower', 'count' => 'count', 'md5' => 'md5', + 'sha1' => 'sha1', 'escxml' => 'htmlspecialchars', 'escape' => 'Pluf_Template_htmlspecialchars', 'strip_tags' => 'strip_tags', @@ -98,9 +99,10 @@ class Pluf_Template_Compiler 'debug' => 'print_r', 'dump' => 'Pluf_Template_varExport', 'fulldebug' => 'var_export', - 'count' => 'count', 'nl2br' => 'Pluf_Template_nl2br', 'trim' => 'trim', + 'ltrim' => 'ltrim', + 'rtrim' => 'rtrim', 'unsafe' => 'Pluf_Template_unsafe', 'safe' => 'Pluf_Template_unsafe', 'date' => 'Pluf_Template_dateFormat', @@ -108,6 +110,8 @@ class Pluf_Template_Compiler 'dateago' => 'Pluf_Template_dateAgo', 'timeago' => 'Pluf_Template_timeAgo', 'email' => 'Pluf_Template_safeEmail', + 'first' => 'Pluf_Template_first', + 'last' => 'Pluf_Template_last', ); /** @@ -673,4 +677,3 @@ class Pluf_Template_Compiler } } } -