$max_length) {
return substr($value, 0, strpos($value, ' ', $max_length)).' '.$end;
}
else if ($length < $min_length) {
return '';
}
return $value;
}
function in_list($id, array $listing)
{
if (isset($listing[$id])) {
return escape($listing[$id]);
}
return '?';
}
function relative_time($timestamp, $fallback_date_format = '%e %B %Y %k:%M')
{
$diff = time() - $timestamp;
if ($diff < 60) return \t('%d second'.($diff > 1 ? 's' : '').' ago', $diff);
$diff = floor($diff / 60);
if ($diff < 60) return \t('%d minute'.($diff > 1 ? 's' : '').' ago', $diff);
$diff = floor($diff / 60);
if ($diff < 24) return \t('%d hour'.($diff > 1 ? 's' : '').' ago', $diff);
$diff = floor($diff / 24);
if ($diff < 7) return \t('%d day'.($diff > 1 ? 's' : '').' ago', $diff);
$diff = floor($diff / 7);
if ($diff < 4) return \t('%d week'.($diff > 1 ? 's' : '').' ago', $diff);
$diff = floor($diff / 4);
if ($diff < 12) return \t('%d month'.($diff > 1 ? 's' : '').' ago', $diff);
return \dt($fallback_date_format, $timestamp);
}
function error_class(array $errors, $name)
{
return ! isset($errors[$name]) ? '' : ' form-error';
}
function error_list(array $errors, $name)
{
$html = '';
if (isset($errors[$name])) {
$html .= '
';
}
return $html;
}
function form_value($values, $name)
{
if (isset($values->$name)) {
return 'value="'.escape($values->$name).'"';
}
return isset($values[$name]) ? 'value="'.escape($values[$name]).'"' : '';
}
function form_hidden($name, $values = array())
{
return '';
}
function form_default_select($name, array $options, $values = array(), array $errors = array(), $class = '')
{
$options = array('' => '?') + $options;
return form_select($name, $options, $values, $errors, $class);
}
function form_select($name, array $options, $values = array(), array $errors = array(), $class = '')
{
$html = '';
$html .= error_list($errors, $name);
return $html;
}
function form_radios($name, array $options, array $values = array())
{
$html = '';
foreach ($options as $value => $label) {
$html .= form_radio($name, $label, $value, isset($values[$name]) && $values[$name] == $value);
}
return $html;
}
function form_radio($name, $label, $value, $selected = false, $class = '')
{
return '';
}
function form_checkbox($name, $label, $value, $checked = false, $class = '')
{
return '';
}
function form_label($label, $name, $class = '')
{
return '';
}
function form_textarea($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '')
{
$class .= error_class($errors, $name);
$html = '';
$html .= error_list($errors, $name);
return $html;
}
function form_input($type, $name, $values = array(), array $errors = array(), array $attributes = array(), $class = '')
{
$class .= error_class($errors, $name);
$html = '';
$html .= error_list($errors, $name);
return $html;
}
function form_text($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '')
{
return form_input('text', $name, $values, $errors, $attributes, $class);
}
function form_password($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '')
{
return form_input('password', $name, $values, $errors, $attributes, $class);
}
function form_email($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '')
{
return form_input('email', $name, $values, $errors, $attributes, $class);
}
function form_date($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '')
{
return form_input('date', $name, $values, $errors, $attributes, $class);
}
function form_number($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '')
{
return form_input('number', $name, $values, $errors, $attributes, $class);
}