'd.m.Y', self::FMT_TIME => 'H:i:s', self::FMT_DATETIME => 'd.m.Y H:i:s' ]; protected $addOns = array(); public function __construct() { // TODO: find a way to make this optional $this->addOns[] = new \MCMS\_\Plugin\Misc\MCMS\CSRFProtect\CSRFProtect(); } /** * Replaces a generated editor info with another one * * @param string $name * the name of the field * @param string $newInfo * the new info string of the field */ public abstract function replaceEditorInfo($name, $newInfo); public function setEditorParams($editor, array $param, $merge = false) { if ($merge && isset($this->editorParams[$editor])) $param = array_merge($this->editorParams[$editor], $param); $this->editorParams[$editor] = $param; } public function getEditorParams($editor) { if (isset($this->editorParams[$editor])) return $this->editorParams[$editor]; return NULL; } public function getFormat($key) { return $this->format[$key]; } public function setFormat($key, $value) { if(is_empty($value)) throw new \InvalidArgumentException("empty format is not allowed"); $this->format[$key] = $value; } protected function generateEditorFor($fieldInfo) { $type = (string) $fieldInfo; $size = -1; $maxsize = -1; $extra = NULL; $editor = NULL; $parts = explode(',', $fieldInfo); $nullok = in_array('null', $parts); $unsigned = in_array('unsigned', $parts); $required = in_array('required', $parts); if($nullok && $required) throw new \InvalidArgumentException('required and null cannot be defined on the same column'); if(preg_match('#^([a-zA-Z]+)\(([0-9,]+)\)(,unsigned){0,1}#', $fieldInfo, $match)) { $type = $match[1]; $ccount = substr_count($match[2], ','); if($ccount == 0) $maxsize = (int) $match[2]; elseif($ccount == 1) list($size, $maxsize) = explode(',', $match[2], 2); else throw new \InvalidArgumentException("illegal count of ','"); $unsigned = empty($match[3]); } elseif(preg_match('#^([a-zA-Z]+)\[([a-zA-Z0-9|]+)\](,unsigned){0,1}#', $fieldInfo, $match)) { $type = $match[1]; $extra = $match[2]; } elseif(preg_match('#^([a-zA-Z]+)(,unsigned){0,1}#', $fieldInfo, $match)) { $type = $match[1]; } switch($type) { case 'bool': $type = 'boolean'; break; case 'double': $type = 'float'; break; case 'char': case 'varchar': $type = 'string'; break; case 'int': case 'integer': case 'serial': $type = 'integer'; break; } if(isset($this->editorClasses[$type])) { $className = $this->editorClasses[$type]; if(substr_count($className, '.') != 0) $className = substr($className, strpos($className, '.') + 1); if(class_exists($className)) $editor = new $className(); else throw new \InvalidArgumentException('editor class ' . $className . ' not found'); } else throw new \InvalidArgumentException('editor type for ' . $type . ' undefined'); $editor->setParam('size', $size); $editor->setParam('maxsize', $maxsize); $editor->setParam('extra', $extra); $editor->setParam('null', $nullok); $editor->setParam('required', $required); return $editor; } public function addExtraEditor($name, $info, $value = NULL) { $this->extraEd[$name] = $this->generateEditorFor($info); $this->extraEd[$name]->setName($name); $this->extraEd[$name]->setValue($value); } public function removeExtraEditor($name) { unset($this->extraEd[$name]); } }