public function content($content = null) { if (DevValue::isNotNull($content)) { $content = DevArray::toArray($content); $this->_content = $content; } return $this->_content; }
public function __construct($value = null) { parent::__construct($value); if (empty($value)) { $this->_value = new ArrayObject(); } else { $this->_value = new ArrayObject(DevArray::toArray($this->_value)); } }
public function instance() { if (isset($this->instance) && $this->instance instanceof $this->type) { $service = $this->instance; } else { $reflection_class = new ReflectionClass($this->type); $args = DevArray::toArray($this->arguments); $this->instance = $reflection_class->getConstructor() ? $reflection_class->newInstanceArgs($args) : $reflection_class->newInstanceWithoutConstructor(); foreach ($this->_registrations as $name => $registrations) { usort($registrations, function ($a, $b) { if ($a['priority'] == $b['priority']) { return 0; } return $a['priority'] < $b['priority'] ? -1 : 1; }); foreach ($registrations as $registration) { $this->apply($registration); } } } return $this->instance; }
public function month($events = null) { $date = $this->info(); $event_r = DevArray::toArray($events); $month = array(); $notes = array(); for ($i = 0, $j = 1 - $date['firstweekday']; $i < 5 || $j <= $date['daysinmonth']; $i++) { for ($k = 0; $k < 7; $k++, $j++) { if (in_array($j, $event_r) && DevArray::isAssoc($event_r)) { $note_r = array_keys($event_r, $j); $notes = implode(', ', $note_r); } $month[$i][$k] = $i == 0 && $k < $date['firstweekday'] || $j > $date['daysinmonth'] ? ' ' : (in_array($j, $event_r) ? "<b>{$j}</b> " . ($notes ? " - {$notes}" : '') : $j); } } return $month; }
public function params($params) { $this->_parameters = DevArray::toArray($params); return $this; }
static function field($type = '', $name = '', $label = '', $value = '', $required = false, $id = '', $readonly = false, $properties = '') { $output = ''; $label_text = ''; $varname = $name; $properties = DevArray::toArray($properties); if (!isset($properties['class'])) { $properties['class'] = $type ? $type : 'formdata'; } foreach ($properties as $a => $b) { $attribs[] = "{$a}=\"{$b}\""; } $attrib = implode(' ', $attribs); $id = 'id="' . ($id != '' ? $id : $name) . '"'; $disabled = $readonly === false ? '' : 'readonly'; if ($readonly == 3) { $type = 'static'; } if ($label != '' && $type != 'static') { $label_text = '<label for="' . $name . '">' . ($required ? '*' : '') . $label . ': </label>'; } if ($type != 'date' && $type != 'select') { $name .= is_array($value) ? '[]' : ''; } $value = DevArray::toArray($value, true); switch ($type) { default: case 'text': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'prompt': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' onFocus="this.value=\'\'" /><br />'; } break; case 'password': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="password" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'textarea': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<textarea ' . $disabled . ' name="' . $name . '" ' . $id . ' ' . $attrib . '>' . $a . '</textarea><br />'; } break; case 'select': $output .= $label_text . ' <br />' . "\n"; $output .= '<select name="' . $name . '" ' . $disabled . ' ' . $id . ' ' . $attrib . '>' . "\n"; $value = DevArray::toArray($value); global ${$varname}; foreach ($value as $a => $b) { if (is_array($b)) { $output .= "\t" . '<optgroup label="' . $a . '">' . "\n"; foreach ($b as $c => $d) { $output .= "\t\t" . '<option value="' . $d . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (${$varname} == $d) { $output .= ' selected="selected"'; } $output .= '>' . $c . '</option>' . "\n"; } $output .= "\t" . '</optgroup>' . "\n"; } else { $output .= "\t" . '<option value="' . $b . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (${$varname} == $b) { $output .= ' selected="selected"'; } $output .= '>' . $a . '</option>' . "\n"; } } $output .= '</select><br />'; break; case 'multiple': $output .= $label_text . ' <br />' . "\n"; $output .= '<select name="' . $name . '" ' . $disabled . ' ' . $id . ' ' . $attrib . ' size="6" multiple="multiple">' . "\n"; $value = DevArray::toArray($value); global ${$varname}; foreach ($value as $a => $b) { if (is_array($b)) { $output .= "\t" . '<optgroup label="' . $a . '">' . "\n"; foreach ($b as $c => $d) { $output .= "\t\t" . '<option value="' . $d . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (is_array(${$varname})) { if (in_array($d, ${$varname})) { $output .= ' selected="selected"'; } elseif (${$varname} == $d) { $output .= ' selected="selected"'; } } $output .= '>' . $c . '</option>' . "\n"; } $output .= "\t" . '</optgroup>' . "\n"; } else { $output .= "\t" . '<option value="' . $b . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (is_array(${$varname})) { if (in_array($b, ${$varname})) { $output .= ' selected="selected"'; } elseif (${$varname} == $b) { $output .= ' selected="selected"'; } } $output .= '>' . $a . '</option>' . "\n"; } } $output .= '</select><br />'; break; case 'hidden': foreach ($value as $a) { $output .= '<input type="hidden" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" />'; } break; case 'checkbox': if (DevArray::isAssoc($value)) { $output .= ($required ? '*' : '') . $label . '<br />'; $i = 1; foreach ($value as $a => $b) { $output .= '<input ' . $attrib . ' type="checkbox" ' . $disabled . ' name="' . $name . '" ' . substr_replace($id, $i . '"', -1, strlen($id)); global ${$varname}; if (${$varname} == $b) { $output .= ' checked="checked"'; } $output .= ' value="' . $b . '" />'; $output .= '<label for="' . $varname . $i . '">' . substr($a, 0, strlen($a)) . " </label><br /> \n"; $i++; } } else { foreach ($value as $a) { $output .= '<input type="checkbox" ' . $disabled . ' name="' . $name . '" ' . $id; global ${$varname}; if (${$varname} == $a) { $output .= ' checked="checked"'; } $output .= ' value="' . $a . '" /> '; $output .= '<label for="' . $varname . '">' . substr($label, 0, strlen($label)) . " </label><br /> \n"; } } break; case 'radio': if (DevArray::isAssoc($value)) { $output .= ($required ? '*' : '') . $label . '<br />'; $i = 1; foreach ($value as $a => $b) { $output .= '<input ' . $attrib . ' type="radio" ' . $disabled . ' name="' . $name . '" ' . substr_replace($id, $i . '"', -1, strlen($id)); global ${$varname}; if (${$varname} == $b) { $output .= ' checked="checked"'; } $output .= ' value="' . $b . '" />'; $output .= '<label for="' . $varname . $i . '">' . substr($a, 0, strlen($a)) . " </label><br /> \n"; $i++; } } else { foreach ($value as $a) { $output .= '<input type="radio" ' . $disabled . ' name="' . $name . '" ' . $id; global ${$varname}; if (${$varname} == $a) { $output .= ' checked="checked"'; } $output .= ' value="' . $a . '" /> '; $output .= '<label for="' . $varname . '">' . substr($label, 0, strlen($label)) . " </label><br /> \n"; } } break; case 'date': $output .= Form::date($name, $label, $value[0], $readonly); break; case 'calendar': $output .= $label_text . "\n\t" . '<SCRIPT LANGUAGE="JavaScript" ID="js' . $name . '"> var cal' . $name . ' = new CalendarPopup("datediv1"); cal' . $name . '.setCssPrefix("DATE"); </SCRIPT> <SCRIPT LANGUAGE="JavaScript">writeSource("js' . $name . '");</SCRIPT> <input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $value[0] . '" ' . $attrib . ' /> <A HREF="#" onclick="cal' . $name . '.select(document.getElementById(\'' . $name . '\'),\'anchor' . $name . '\',\'yyyy-MM-dd\'); return false;" TITLE="cal' . $name . '.select(document.getElementById(\'' . $id . '\'),\'anchor1x\',\'yyyy-MM-dd\'); return false;" NAME="anchor' . $name . '" ID="anchor' . $name . '"><img src="' . $image_path . 'calendar.gif" alt="select" title="select" border="0" /></A><br />'; break; case 'time': $output .= Form::date($name, $label); break; case 'file': foreach ($value as $a) { if (!$readonly && $a == '') { $output .= $label_text . ' - ' . $a . ' <br />' . "\n\t" . '<input type="file" ' . $disabled . ' name="' . $name . '" ' . $id . ' /><br />'; } else { $output = Form::field('checkbox', $name, $label . ' (' . $a . ')', $a, $required, $name, $readonly, $properties); } } break; case 'richtext': foreach ($value as $a) { //Code provided by Kevin Roth at www.kevinroth.com/rte/demo.htm //Requires following form header: /* <script language="JavaScript" type="text/javascript"> <!-- function submitForm() { //make sure hidden and iframe values are in sync before submitting form //to sync only 1 rte, use updateRTE(rte) //to sync all rtes, use updateRTEs //updateRTE(\'rte1\'); updateRTEs(); //change the following line to true to submit form return true; } //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML) initRTE("images/", "", "", true); //--> </script> */ //and included JS file and 'onsubmit="return submitForm();"' in form. $output .= ' <noscript>'; $output .= Form::field('textarea', $name, $label, $a, '', $id, $readonly); $output .= ' </noscript> <script language="JavaScript" type="text/javascript"> <!-- var ' . $name . '_val = ""; '; //$output .= "\n"; $a = html_entity_decode($a); $val_search = array('"', '</script>', '</textarea>', '</noscript>'); $val_replace = array('\\"', '</script>', '</textarea>', '</noscript>'); $a = str_replace($val_search, $val_replace, $a); $val_array = explode("\n", $a); //foreach ($val_array as $a) $output .= $name . '_val += "' . html_entity_decode(rtrim($a)) . '\n";' . "\n"; foreach ($val_array as $var) { $output .= $name . '_val += "' . rtrim($var) . '\\n";' . "\n"; } $output .= ' //--> </script> '; //$output .= Form::field('hidden', $name . '_hidden', '', $a); if ($id == 'id="big"') { $w = '100%'; $h = 400; } else { $w = 450; $h = 200; } $output .= ' <script language="JavaScript" type="text/javascript"> <!-- ' . $name . '_val = ' . $name . '_val.replace(/<\\/script>/gi, "<" + "/script>"); ' . $name . '_val = ' . $name . '_val.replace(/<\\/textarea>/gi, "<" + "/textarea>"); ' . $name . '_val = ' . $name . '_val.replace(/<\\/noscript>/gi, "<" + "/noscript>"); writeRichText(\'' . $name . '\', ' . $name . '_val, \'' . $w . '\', \'' . $h . '\', true, ' . ($readonly ? 'true' : 'false') . '); //--> </script> '; } break; case 'static': foreach ($value as $a) { $output .= $label . '<br /><span ' . implode(' ', $attribs) . ' name="' . $name . '" ' . $id . '>' . $a . '</span>'; $output .= Form::field('hidden', $name, '', $a); } break; case 'submit': foreach ($value as $a) { $output .= '<input type="submit" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" onclick="this.disabled=false;this.value=' . htmlentities($label != '' ? $label : 'Submitting...') . ';" ' . $attrib . ' /><br />'; } break; case 'reset': foreach ($value as $a) { $output .= '<input type="reset" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'button': foreach ($value as $a) { $output .= '<input type="button" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; } if ($label != '' && $type != 'hidden') { $output .= "<br />\n"; } return $output; }
private function validate($field_name = null, $table = null) { $fields = $this->fields(); // if no table is specified, used the first available entry. $table = $table ? $table : (isset($tables[0]) ? $tables[0] : current(DevArray::toArray($this->config(self::NAME_FIELD)))); $passed = true; if (isset($fields[$field_name])) { $field = $fields[$field_name]; $type = strtolower($field['Type']); //If duplicate entry if ($field['Key'] == 'PRI' || $field['Key'] == 'UNI') { if (self::inDB($field_name, $this->field($field_name), $table)) { // In what case do we really need to know this? $this->status("A row having field '{$field_name}' with value '" . $this->field($field_name) . "' already exists."); } } else { if ($this->field($field_name) !== 0 && $this->field($field_name) == '') { if (!$field['Null'] || $field['Null'] == 'NO') { if (DevString::has($type, 'date')) { //$this->field($field_name, dev_join_date($field_name)); $this->field($field_name, date('Y-m-d')); if (!is_string($this->field($field_name)) || !DateTime::stringIsDate($this->field($field_name))) { $this->status("Field '{$field_name}' contains an inaccurate date format!"); $passed = false; } } else { $this->status("Field '{$field_name}' cannot be empty!"); $passed = false; } } } else { //Correct Datatype/Size if (DevString::has($type, 'int') || DevString::has($type, 'double') || DevString::has($type, 'float')) { if (!is_numeric($this->field($field_name))) { $this->status("Field '{$field_name}' must be numeric!"); $passed = false; } } if (DevString::has($type, 'char') || DevString::has($type, 'text')) { if (!is_string($this->field($field_name))) { $this->status("Field '{$field_name}' is not text!"); $passed = false; } if (isset($field['LENGTH']) && DevValue::isNotNull($field['LENGTH']) && strlen($this->field($field_name)) > $field['LENGTH']) { $this->status("Field '{$field_name}' is greater than maximum allowed string length!"); $passed = false; } } if (DevString::has($type, 'date')) { if (!is_string($this->field($field_name)) || !DateTime::stringIsDate($this->field($field_name))) { $this->field($field_name, dev_join_date($field_name)); if (!is_string($this->field($field_name)) || !DateTime::stringIsDate($this->field($field_name))) { $this->status("Field '{$field_name}' contains an inaccurate date format!"); $passed = false; } } } if (DevString::has($type, 'set')) { if (is_array($this->field($field_name))) { $this->field($field_name, implode(', ', $this->field($field_name))); } elseif (!is_string($this->field($field_name))) { $this->status("Field '{$field_name}' contains invalid input!"); $passed = false; } } } } } return $passed; }