/** * Returns meta data processed with format functions. * Format content of various types if $format is set to date, filesize, ... * * @param mixed $field Field name to get meta data from. These are database fields. * @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 tx_dam_guifunc::tools_formatValue() */ function getFormatedValue($field, $format, $config = '') { require_once PATH_txdam . 'lib/class.tx_dam_guifunc.php'; $value = tx_dam_guifunc::tools_formatValue($this->getMeta($field), $format, $config); return $value; }
/** * Can be used to generate simple form fields * * @param string $field field name * @param string $value Value for the input field * @param integer $size Can be used to set a specific size for the input field in em's. * @return string Input field with label wrapped in div tag */ function getFormInputField($field, $value, $size = 0) { global $LANG, $TCA; t3lib_div::loadTCA('tx_dam'); $size = $size ? $size : $TCA['tx_dam']['columns'][$field]['config']['size']; $size = $size ? $size : 20; $max = $TCA['tx_dam']['columns'][$field]['config']['max']; $max = $max ? $max : 256; return '<div style="margin-bottom:0.8em"> <strong>' . tx_dam_guifunc::getFieldLabel($field) . '</strong><br /> <input type="text" name="data[' . htmlspecialchars($field) . ']" value="' . htmlspecialchars($value) . '" style="width:' . $size . 'em;" maxlength="' . $max . '" /> </div>'; }
/** * 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; }