/** * Get the formatted value of a field * * This is used for HTML and non-HTML output so HTML should not be added * - see printFieldValue below for that. */ public function getFormattedValue($name, $value = null) { if (!isset($this->fields[$name])) { trigger_error('Cannot get value for field ' . ents($name) . ' - field does not exist', E_USER_WARNING); return NULL; } if (is_null($value)) { $value = array_get($this->values, $name, NULL); } $field = $this->fields[$name]; if (!empty($field['references'])) { $obj =& $GLOBALS['system']->getDBObject($field['references'], $value); if (!is_null($obj)) { if (!array_get($field, 'show_id', true)) { return $obj->toString(); } else { return $obj->toString() . ' (#' . $value . ')'; } } else { if ($value != 0) { return $value; } } return ''; } switch ($field['type']) { case 'select': return array_get($field['options'], $value, '(Invalid Value)'); break; case 'datetime': if (empty($value) && array_get($field, 'allow_empty')) { return ''; } return format_datetime($value); break; case 'date': if (empty($value) && array_get($field, 'allow_empty')) { return ''; } return format_date($value); break; case 'bibleref': require_once 'bible_ref.class.php'; $br = new bible_ref($value); return $br->toShortString(); break; case 'phone': return format_phone_number($value, $field['formats']); break; default: if (is_array($value)) { return '<pre>' . print_r($value, 1) . '</pre>'; } else { return $value; } } }
function process_widget($name, $params) { $value = null; switch ($params['type']) { case 'phone': if (array_get($params, 'allow_empty', TRUE) && empty($_REQUEST[$name])) { $value = ''; } else { if (!is_valid_phone_number($_REQUEST[$name], $params['formats'])) { trigger_error('The phone number "' . $_REQUEST[$name] . '" is not valid and has not been set', E_USER_NOTICE); $value = NULL; } else { $value = clean_phone_number($_REQUEST[$name]); } } break; case 'date': if (isset($_REQUEST[$name])) { // might have an ISO8601 date if (preg_match('/^(\\d\\d\\d\\d-\\d\\d-\\d\\d)$/', $_REQUEST[$name])) { return $_REQUEST[$name]; } } if (FALSE === strpos($name, '[')) { $subindex = NULL; } else { $subindex = substr($name, strpos($name, '[') + 1, strpos($name, ']') - strpos($name, '[') - 1); $name = substr($name, 0, strpos($name, '[')); } if (!isset($_REQUEST[$name . '_d'])) { return NULL; } if (!is_null($subindex) && !isset($_REQUEST[$name . '_d'][$subindex])) { return NULL; } foreach (array('y', 'm', 'd') as $comp) { $comp_vals[$comp] = array_get($_REQUEST, $name . '_' . $comp, 0); if (!is_null($subindex)) { $comp_vals[$comp] = $comp_vals[$comp][$subindex]; } } $value = sprintf('%04d-%02d-%02d', $comp_vals['y'], $comp_vals['m'], $comp_vals['d']); if ($value == '0000-00-00') { return NULL; } if ($value == '0000-01-00') { return NULL; } if (array_get($params, 'allow_blank_year') && !(int) $comp_vals['y']) { $value = substr($value, 4); if (date('-m-d', strtotime('2000' . $value)) != $value) { trigger_error('The date "' . $value . '" is not valid and has not been set', E_USER_NOTICE); $value = NULL; } } else { if (date('Y-m-d', strtotime($value)) != $value) { trigger_error('The date "' . $value . '" is not valid and has not been set', E_USER_NOTICE); $value = NULL; } } break; case 'bibleref': if (!empty($_REQUEST[$name])) { require_once 'bible_ref.class.php'; $br = new bible_ref($_REQUEST[$name]); if ($br->book) { $value = $br->toCode(); } } break; case 'bitmask': // value is the bitwise-or of all submitted values $value = 0; if (isset($_REQUEST[$name])) { if (isset($_REQUEST[$name])) { foreach ($_REQUEST[$name] as $i) { $value = $value | (int) $i; } } } break; case 'html': if (isset($_REQUEST[$name])) { require_once 'htmLawed.php'; $value = htmLawed($_REQUEST[$name], array('deny_attribute' => '* -href', 'safe' => 1)); } break; default: $value = array_get($_REQUEST, $name); if (!empty($params['regex']) && !empty($value) && !preg_match($params['regex'] . 'i', $value)) { trigger_error($value . ' is not a valid value for ' . array_get($params, 'label', ucfirst($name))); $value = NULL; } break; } return $value; }
function format_value($value, $params) { if (!empty($params['references'])) { $obj =& $GLOBALS['system']->getDBObject($params['references'], $value); if (!is_null($obj)) { if (!array_get($params, 'show_id', true)) { return $obj->toString(); } else { return $obj->toString() . ' (#' . $value . ')'; } } else { if ($value != 0) { return $value; } } return ''; } switch ($params['type']) { case 'select': return array_get($params['options'], $value, '(Invalid Value)'); break; case 'datetime': if (empty($value) && array_get($params, 'allow_empty')) { return ''; } return format_datetime($value); break; case 'date': if (empty($value) && array_get($params, 'allow_empty')) { return ''; } return format_date($value); break; case 'bibleref': require_once 'bible_ref.class.php'; $br = new bible_ref($value); return $br->toShortString(); break; case 'phone': return format_phone_number($value, $params['formats']); break; default: if (is_array($value)) { return '<pre>' . print_r($value, 1) . '</pre>'; } else { return $value; } } }