$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($date, $postfix = ' ago', $fallback = '%e %B %Y %k:%M')
{
$diff = time() - strtotime($date);
if($diff < 60)
return $diff . ' second'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/60);
if($diff < 60)
return $diff . ' minute'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/60);
if($diff < 24)
return $diff . ' hour'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/24);
if($diff < 7)
return $diff . ' day'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/7);
if($diff < 4)
return $diff . ' week'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/4);
if($diff < 12)
return $diff . ' month'. ($diff != 1 ? 's' : '') . $postfix;
return date($fallback, strtotime($date));
}
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);
}