Index: branches/RC/core/kernel/utility/formatters/formatter.php =================================================================== diff -u -r10832 -r11760 --- branches/RC/core/kernel/utility/formatters/formatter.php (.../formatter.php) (revision 10832) +++ branches/RC/core/kernel/utility/formatters/formatter.php (.../formatter.php) (revision 11760) @@ -2,8 +2,39 @@ class kFormatter extends kBase { + /** + * Reference to category helper + * + * @var CategoryHelper + */ + var $_categoryHelper = null; + function kFormatter() + { + parent::kBase(); + + $this->_categoryHelper =& $this->Application->recallObject('CategoryHelper'); + } + /** + * Replace FCK links like "@@ID@@" to real page urls, when "using_fck" option is set. + * + * @param string $text + * @param Array $options + * @param string $format + * @return string + */ + function _replaceFCKLinks(&$value, $options, $format = null) + { + if ((isset($format) && strpos($format, 'fck_ready') !== false) || (!array_key_exists('using_fck', $options) || !$options['using_fck'])) { + // in textarea, where fck will be used OR not using fck + return $value; + } + + return $this->_categoryHelper->replacePageIds($value); + } + + /** * Convert's value to match type from config * * @param mixed $value @@ -70,25 +101,42 @@ } //function Format($value, $options, &$errors) - function Format($value, $field_name, &$object, $format=null) + function Format($value, $field_name, &$object, $format = null) { - if ( is_null($value) ) return ''; + if ( is_null($value) ) { + return ''; + } $options = $object->GetFieldOptions($field_name); - if ( isset($format) ) $options['format'] = $format; - $tc_value = $value; // $this->TypeCast($value,$options); - if( ($tc_value === false) || ("$tc_value" != "$value") ) return $value; // for leaving badly formatted date on the form + if (!isset($format) && array_key_exists('format', $options)) { + $format = $options['format']; + } - if (isset($options['format'])) { - $tc_value = sprintf($options['format'], $tc_value); + if ($value === false) { + // used ? + return $value; // for leaving badly formatted date on the form } + $original_format = $format; + if (isset($format)) { + if (strpos($format, 'fck_ready') !== false) { + $format = trim(str_replace('fck_ready', '', $format), ';'); + } + } + + if (isset($format) && $format) { + $value = sprintf($format, $value); + } + if (preg_match('#int|integer|double|float|real|numeric#', $options['type'])) { $lang =& $this->Application->recallObject('lang.current'); - return $lang->formatNumber($tc_value); + return $lang->formatNumber($value); } + elseif ($options['type'] == 'string') { + $value = $this->_replaceFCKLinks($value, $options, $original_format); + } - return $tc_value; + return $value; } /** @@ -101,11 +149,15 @@ */ function Parse($value, $field_name, &$object) { - if ($value == '') return NULL; + if ($value == '') { + return NULL; + } $options = $object->GetFieldOptions($field_name); $tc_value = $this->TypeCast($value,$options); - if($tc_value === false) return $value; // for leaving badly formatted date on the form + if ($tc_value === false) { + return $value; // for leaving badly formatted date on the form + } if(isset($options['type'])) { if (preg_match('#double|float|real|numeric#', $options['type'])) {