You are here

function _strongarm_readable in Strongarm 7.2

Same name and namespace in other branches
  1. 6.2 strongarm.admin.inc \_strongarm_readable()
  2. 6 strongarm.admin.inc \_strongarm_readable()

Display variables in a nicer way.

1 call to _strongarm_readable()
strongarm_admin_form in ./strongarm.admin.inc
Variable management strongarm form.

File

./strongarm.admin.inc, line 85

Code

function _strongarm_readable($var) {
  if (is_string($var) || is_numeric($var)) {
    return truncate_utf8($var, 30, TRUE, TRUE);
  }
  else {
    if (is_bool($var)) {
      return $var ? 'TRUE' : 'FALSE';
    }
    else {
      if (is_array($var)) {
        $test = $detected = array();
        $test['keys'] = array_keys($var);
        $test['values'] = array_values($var);
        foreach ($test as $type => $values) {
          $numeric = TRUE;
          $sequential = 0;
          $boolean = TRUE;
          foreach ($values as $v) {
            $numeric = is_numeric($v) && $numeric;
            $sequential = is_numeric($v) && $sequential == $v && $sequential !== FALSE ? $sequential + 1 : FALSE;
            $boolean = $boolean && ($v === 0 || $v === 1 || $v === '1' || $v === '0' || $v === TRUE || $v === FALSE);
          }
          $detected[$type]['numeric'] = $numeric;
          $detected[$type]['sequential'] = $sequential !== FALSE;
          $detected[$type]['boolean'] = $boolean;
        }

        // List of things
        if (!empty($var) && $detected['keys']['numeric'] && $detected['keys']['sequential']) {
          return truncate_utf8(implode(', ', $var), 30, TRUE, TRUE);
        }
        return '-';
      }
    }
  }
}