From f87068e453ae134b273cb6a02be36065db40f01a Mon Sep 17 00:00:00 2001 From: avl Date: Wed, 24 Dec 2008 11:39:11 +0200 Subject: [PATCH] floatformat filter --- ipf/template.php | 23 +++++++++++++---------- ipf/template/compiler.php | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ipf/template.php b/ipf/template.php index f15f505..6379ba4 100644 --- a/ipf/template.php +++ b/ipf/template.php @@ -22,7 +22,7 @@ class IPF_Template } else { $this->cache = $cache; } - + } function render($c=null) @@ -56,15 +56,15 @@ class IPF_Template return $this->cache.'/IPF_Template-'.md5($_tmp.$this->tpl).'.phps'; } - function write() + function write() { - $fp = @fopen($this->compiled_template, 'a'); + $fp = @fopen($this->compiled_template, 'a'); if ($fp !== false) { - flock($fp, LOCK_EX); - ftruncate($fp, 0); - rewind($fp); + flock($fp, LOCK_EX); + ftruncate($fp, 0); + rewind($fp); fwrite($fp, $this->template_content, strlen($this->template_content)); - flock($fp, LOCK_UN); + flock($fp, LOCK_UN); fclose($fp); @chmod($this->compiled_template, 0777); return true; @@ -86,7 +86,7 @@ function IPF_Template_htmlspecialchars($string) return htmlspecialchars((string)$string, ENT_COMPAT, 'UTF-8'); } -function IPF_Template_dateFormat($date, $format='%b %e, %Y') +function IPF_Template_dateFormat($date, $format='%b %e, %Y') { if (substr(PHP_OS,0,3) == 'WIN') { $_win_from = array ('%e', '%T', '%D'); @@ -97,11 +97,14 @@ function IPF_Template_dateFormat($date, $format='%b %e, %Y') return strftime($format, strtotime($date)); } -function IPF_Template_timeFormat($time, $format='Y-m-d H:i:s') -{ +function IPF_Template_timeFormat($time, $format='Y-m-d H:i:s'){ return date($format, $time); } +function IPF_Template_floatFormat($number, $decimals=2, $dec_point='.', $thousands_sep=' '){ + return number_format($number, $decimals, $dec_point, $thousands_sep); +} + function IPF_Template_safeEcho($mixed, $echo=true) { if (!is_object($mixed) or 'IPF_Template_SafeString' !== get_class($mixed)) { diff --git a/ipf/template/compiler.php b/ipf/template/compiler.php index 3b33d7c..00bbda1 100644 --- a/ipf/template/compiler.php +++ b/ipf/template/compiler.php @@ -42,6 +42,7 @@ class IPF_Template_Compiler 'safe' => 'IPF_Template_unsafe', 'date' => 'IPF_Template_dateFormat', 'time' => 'IPF_Template_timeFormat', + 'floatformat' => 'IPF_Template_floatFormat', ); public $_usedModifiers = array(); -- 2.49.0