diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-26 11:24:50 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-26 11:24:50 -0800 |
commit | 3060a6f662da66008d57a461bf1c9b5b4aa2b002 (patch) | |
tree | 442fd290505817efc0324f2af6e01805cb7396aa /system/helpers/format.php | |
parent | 1cd6a615bb47a33794e4a4f690c87a348ab752d7 (diff) | |
parent | 32d25dafd5b033338b6a9bb8c7c53edab462543a (diff) |
Merge branch 'master' into talmdal_dev
Conflicts:
modules/gallery/controllers/albums.php
modules/gallery/controllers/movies.php
modules/gallery/controllers/photos.php
Diffstat (limited to 'system/helpers/format.php')
-rw-r--r-- | system/helpers/format.php | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/system/helpers/format.php b/system/helpers/format.php index fb8a0294..9351afda 100644 --- a/system/helpers/format.php +++ b/system/helpers/format.php @@ -2,16 +2,33 @@ /** * Format helper class. * - * $Id: format.php 4070 2009-03-11 20:37:38Z Geert $ + * $Id: format.php 4679 2009-11-10 01:45:52Z isaiah $ * * @package Core * @author Kohana Team - * @copyright (c) 2007-2008 Kohana Team - * @license http://kohanaphp.com/license.html + * @copyright (c) 2007-2009 Kohana Team + * @license http://kohanaphp.com/license */ class format_Core { /** + * Formats a number according to the current locale. + * + * @param float + * @param int|boolean number of fractional digits or TRUE to use the locale default + * @return string + */ + public static function number($number, $decimals = 0) + { + $locale = localeconv(); + + if ($decimals === TRUE) + return number_format($number, $locale['frac_digits'], $locale['decimal_point'], $locale['thousands_sep']); + + return number_format($number, $decimals, $locale['decimal_point'], $locale['thousands_sep']); + } + + /** * Formats a phone number according to the specified format. * * @param string phone number @@ -63,4 +80,35 @@ class format_Core { return $str; } + /** + * Normalizes a hexadecimal HTML color value. All values will be converted + * to lowercase, have a "#" prepended and contain six characters. + * + * @param string hexadecimal HTML color value + * @return string + */ + public static function color($str = '') + { + // Reject invalid values + if ( ! valid::color($str)) + return ''; + + // Convert to lowercase + $str = strtolower($str); + + // Prepend "#" + if ($str[0] !== '#') + { + $str = '#'.$str; + } + + // Expand short notation + if (strlen($str) === 4) + { + $str = '#'.$str[1].$str[1].$str[2].$str[2].$str[3].$str[3]; + } + + return $str; + } + } // End format
\ No newline at end of file |