/**
  * Format content of various types if $format is set to date, filesize, ...
  *
  * @param	string		$itemValue The value to display
  * @param	array		$format Define format type like: date, datetime, truncate, ...
  * @param	string		$config Additional configuration options for the format type
  * @return	string		Formatted content
  * @see t3lib_tceforms::formatValue()
  */
 function tools_formatValue($itemValue, $format, $config = '')
 {
     switch ($format) {
         case 'date':
             $config = $config ? $config : 'd-m-Y';
             $itemValue = date($config, $itemValue);
             break;
         case 'dateage':
             $config = $config ? $config : 'd-m-Y';
             $itemValue = date($config, $itemValue);
             $itemValue .= ' (' . tx_dam_guifunc::tools_calcAge(time() - $itemValue, $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')) . ')';
             break;
         case 'datetime':
             // compatibility with "eval" (type "input")
             $itemValue = date('H:i d-m-Y', $itemValue);
             break;
         case 'time':
             // compatibility with "eval" (type "input")
             $itemValue = date('H:i', $itemValue);
             break;
         case 'timesec':
             // compatibility with "eval" (type "input")
             $itemValue = date('H:i:s', $itemValue);
             break;
         case 'year':
             // compatibility with "eval" (type "input")
             $itemValue = date('Y', $itemValue);
             break;
         case 'int':
             $baseArr = array('dec' => 'd', 'hex' => 'x', 'HEX' => 'X', 'oct' => 'o', 'bin' => 'b');
             $base = trim($config);
             $format = $baseArr[$base] ? $baseArr[$base] : 'd';
             $itemValue = sprintf('%' . $format, $itemValue);
             break;
         case 'float':
             $precision = t3lib_div::intInRange($config, 1, 10, 2);
             $itemValue = sprintf('%.' . $precision . 'f', $itemValue);
             break;
         case 'number':
             $itemValue = sprintf('%' . $config, $itemValue);
             break;
         case 'md5':
             $itemValue = md5($itemValue);
             break;
         case 'filesize':
             $itemValue = t3lib_div::formatSize(intval($itemValue)) . 'B';
             break;
         case 'filesize+bytes':
             $itemValue = t3lib_div::formatSize(intval($itemValue)) . 'B';
             $itemValue .= ' (' . $itemValue . ')';
             break;
         case 'truncate':
             $config = $config ? $config : 20;
             $itemValue = t3lib_div::fixed_lgd_cs($itemValue, $config);
             break;
         case 'strtoupper':
             $itemValue = strtoupper($itemValue);
             break;
         case 'strtolower':
             $itemValue = strtolower($itemValue);
             break;
         case 'shorten':
             $config = $config ? $config : 20;
             if (strlen($itemValue) > $config) {
                 if (is_object($GLOBALS['LANG'])) {
                     $itemValue = $GLOBALS['LANG']->csConvObj->crop($GLOBALS['LANG']->charSet, $itemValue, $config - 3, '');
                 } else {
                     $itemValue = substr(t3lib_div::fixed_lgd_cs($itemValue, $config - 3), 0, -3);
                 }
                 $pos = strrpos($itemValue, ' ');
                 if ($pos > intval(strlen($itemValue) * 0.7)) {
                     $itemValue = substr($itemValue, 0, $pos);
                     $itemValue = $itemValue . ' ...';
                 } else {
                     $itemValue = $itemValue . '...';
                 }
             }
             break;
         default:
             break;
     }
     return $itemValue;
 }