cvs: pear /HTML_Template_Flexy/Flexy/Plugin Savant.php
| From: | Alan Knowles | Date: | Sat, 12 Jun 2004 07:22:24 +0000 |
| Subject: | cvs: pear /HTML_Template_Flexy/Flexy/Plugin Savant.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-20550@lists.php.net to get a copy of this message | ||
alan_k Sat Jun 12 03:22:24 2004 EDT
Modified files:
/pear/HTML_Template_Flexy/Flexy/Plugin Savant.php
Log:
number format and date format = options stuff needs checking..
http://cvs.php.net/diff.php/pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php?r1=1.4&r2=1.5&ty=u Index: pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php diff -u pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php:1.4 pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php:1.5 --- pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php:1.4 Wed Jun 2 08:41:28 2004 +++ pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php Sat Jun 12 03:22:24 2004 @@ -24,8 +24,6 @@ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $href The URL for the resulting <a href="">...</a> tag. * * @param string $text The text surrounded by the <a>...</a> tag set. @@ -59,12 +57,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $name The HTML "name=" value for the checkbox. * * @param mixed $value The value of the checkbox if checked. @@ -122,12 +118,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $name The HTML "name=" value of all the checkbox * <input>s. The name will get [] appended to it to make it an array * when returned to the server. @@ -236,12 +230,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param int $iteration The iteration number for the cycle. * * @param array $values The values to cycle through. @@ -273,12 +265,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $datestring Any date-time string suitable for * strtotime(). * @@ -288,15 +278,62 @@ * */ - function dateformat($datestring, $format = '%d %b %Y') + function dateformat($datestring, $format = false) { - if (trim($datestring != '')) { - return strftime($format, strtotime($datestring)); - } else { + if ($format === false) { + $format = isset($this->flexy->options['plugin.dateformat']) ? + $this->flexy->options['plugin.dateformat'] : '%d %b %Y'; + } + if (trim($datestring) == '') { return ''; } + + $date = strtotime($datestring); + if ($date > 1) { + return strftime($format, $date); + } + require_once 'Date.php'; + $date = new Date($date); + return $date->format($format); + } + /** + * + * Output a formatted number using number_format + * + * + * + * @param string $datestring Any date-time string suitable for + * strtotime(). + * + * @param string $format The strftime() formatting string. + * + * @return string + * + */ + function numberformat($number, $dec=false,$point=false,$thousands=false) + { + if (!strlen(trim($datestring))) { + return; + } + // numberformat int decimals, string dec_point, string thousands_sep + $dec = ($dec !== false) ? $dec : ( + isset($this->flexy->options['plugin.numberformat.decimals']) ? + $this->flexy->options['plugin.numberformat.decimals'] : 2 + ); + $point = ($point !== false) ? $point : ( + isset($this->flexy->options['plugin.numberformat.point']) ? + $this->flexy->options['plugin.numberformat.point'] : '.'); + $thousands = ($thousands !== false) ? $thousands : ( + isset($this->flexy->options['plugin.numberformat.thousands']) ? + $this->flexy->options['plugin.numberformat.thousands'] : ','); + + + return number_format($number,$dec,$point,$thousands); + } + + /** * @@ -307,12 +344,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $src The image source as a relative or absolute HREF. * * @param string $link Providing a link will make the image clickable, @@ -405,12 +440,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $type The HTML "type=" value (e.g., 'text', * 'hidden', 'password'). * @@ -443,12 +476,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $href The HREF leading to the JavaScript source * file. * @@ -482,12 +513,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $value The value to be printed. * * @param string $functions A space-separated list of @@ -539,12 +568,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param array $options An associative array of key-value pairs; the * key is the option value, the value is the option lable. * @@ -597,12 +624,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $name The HTML "name=" value of all the radio <input>s. * * @param array $options An array of key-value pairs where the key is the @@ -673,12 +698,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $href The HREF leading to the stylesheet file. * * @return string @@ -704,11 +727,9 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public - * - * @param object &$savant A reference to the calling Savant object. * * @param string $name The HTML "name=" value. *
http://cvs.php.net/diff.php/pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php?r1=1.4&r2=1.5&ty=u Index: pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php diff -u pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php:1.4 pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php:1.5 --- pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php:1.4 Wed Jun 2 08:41:28 2004 +++ pear/HTML_Template_Flexy/Flexy/Plugin/Savant.php Sat Jun 12 03:22:24 2004 @@ -24,8 +24,6 @@ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $href The URL for the resulting <a href="">...</a> tag. * * @param string $text The text surrounded by the <a>...</a> tag set. @@ -59,12 +57,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $name The HTML "name=" value for the checkbox. * * @param mixed $value The value of the checkbox if checked. @@ -122,12 +118,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $name The HTML "name=" value of all the checkbox * <input>s. The name will get [] appended to it to make it an array * when returned to the server. @@ -236,12 +230,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param int $iteration The iteration number for the cycle. * * @param array $values The values to cycle through. @@ -273,12 +265,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $datestring Any date-time string suitable for * strtotime(). * @@ -288,15 +278,62 @@ * */ - function dateformat($datestring, $format = '%d %b %Y') + function dateformat($datestring, $format = false) { - if (trim($datestring != '')) { - return strftime($format, strtotime($datestring)); - } else { + if ($format === false) { + $format = isset($this->flexy->options['plugin.dateformat']) ? + $this->flexy->options['plugin.dateformat'] : '%d %b %Y'; + } + if (trim($datestring) == '') { return ''; } + + $date = strtotime($datestring); + if ($date > 1) { + return strftime($format, $date); + } + require_once 'Date.php'; + $date = new Date($date); + return $date->format($format); + } + /** + * + * Output a formatted number using number_format + * + * + * + * @param string $datestring Any date-time string suitable for + * strtotime(). + * + * @param string $format The strftime() formatting string. + * + * @return string + * + */ + function numberformat($number, $dec=false,$point=false,$thousands=false) + { + if (!strlen(trim($datestring))) { + return; + } + // numberformat int decimals, string dec_point, string thousands_sep + $dec = ($dec !== false) ? $dec : ( + isset($this->flexy->options['plugin.numberformat.decimals']) ? + $this->flexy->options['plugin.numberformat.decimals'] : 2 + ); + $point = ($point !== false) ? $point : ( + isset($this->flexy->options['plugin.numberformat.point']) ? + $this->flexy->options['plugin.numberformat.point'] : '.'); + $thousands = ($thousands !== false) ? $thousands : ( + isset($this->flexy->options['plugin.numberformat.thousands']) ? + $this->flexy->options['plugin.numberformat.thousands'] : ','); + + + return number_format($number,$dec,$point,$thousands); + } + + /** * @@ -307,12 +344,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $src The image source as a relative or absolute HREF. * * @param string $link Providing a link will make the image clickable, @@ -405,12 +440,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $type The HTML "type=" value (e.g., 'text', * 'hidden', 'password'). * @@ -443,12 +476,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $href The HREF leading to the JavaScript source * file. * @@ -482,12 +513,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $value The value to be printed. * * @param string $functions A space-separated list of @@ -539,12 +568,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param array $options An associative array of key-value pairs; the * key is the option value, the value is the option lable. * @@ -597,12 +624,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $name The HTML "name=" value of all the radio <input>s. * * @param array $options An array of key-value pairs where the key is the @@ -673,12 +698,10 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public * - * @param object &$savant A reference to the calling Savant object. - * * @param string $href The HREF leading to the stylesheet file. * * @return string @@ -704,11 +727,9 @@ * * @package Savant * - * @version $Id: Savant.php,v 1.4 2004/06/02 12:41:28 alan_k Exp $ + * @version $Id: Savant.php,v 1.5 2004/06/12 07:22:24 alan_k Exp $ * * @access public - * - * @param object &$savant A reference to the calling Savant object. * * @param string $name The HTML "name=" value. *