* @package MCMS\System\Component */ class ComUtils extends StrictObject { private static $typeTitles = array( 'boolean' => 'Schalter', 'code' => 'Code', 'color' => 'Farbe', 'date' => 'Datum', 'datetime' => 'Datum+Uhrzeit', 'email' => 'E-Mail', 'file' => 'Datei', 'float' => 'Kommazahl', 'money' => 'Geld', 'html' => 'HTML', 'image' => 'Bild', 'integer' => 'Ganzzahl', 'option' => 'Auswahl', 'password' => 'Passwort', 'set' => 'Set', 'string' => 'Text', 'tel' => 'TelNum', 'text' => 'Textblock', 'time' => 'Zeit', 'url' => 'URL' ); private function __construct() { } public static function getTypes() { // quick hack return array( 'boolean', 'code', 'color', 'date', 'datetime', 'email', 'file', 'float', 'html', 'image', 'integer', 'money', // 'month', 'option', 'password', // 'range', // 'search', 'set', 'string', 'tel', 'text', 'time', 'url' ); } public static function getTypeName($type) { // quick hack if (isset(self::$typeTitles[$type])) return self::$typeTitles[$type]; return $type; } public static function findEditors($type = NULL) { if (is_null($type)) { $types = self::getTypes(); $result = array(); foreach ($types as $t) { $result[$t] = self::findEditors($t); } return $result; } $result = array(); foreach (array(_COMPATH_, _COMPATHX_) as $base) { if (!is_dir($base)) continue; $groupDirs = scandir($base); foreach($groupDirs as $groupDir) { if ($groupDir[0] == '.') // skip hidden stuff and [.|..] continue; $scandir = $base.__DS__.$groupDir.__DS__.'editor'.__DS__.$type; if (!(file_exists($scandir) && is_dir($scandir))) continue; $editors = scandir($scandir); foreach ($editors as $e) { $eDir = $scandir.__DS__.$e; if ($e[0] == '.' || !is_dir($eDir)) // skip hidden stuff and [.|..] continue; if (include_exists($eDir.__DS__.'_info_.php')) { $result[] = self::readEditorInfo(defined('_COMPATHX_') && ($base == _COMPATHX_), $eDir, $groupDir, $e); } } } } return $result; } public static function getEditorInfo($type, $id, $xt = FALSE) { list($group, $name) = explode('.',$id); $base = $xt ? _COMPATHX_ : _COMPATH_; $eDir = $base.__DS__.$group.__DS__.'editor'.__DS__.$type.__DS__.$name; if (include_exists($eDir.__DS__.'_info_.php')) return self::readEditorInfo($xt, $eDir, $group, $name); else return NULL; } private static function readEditorInfo($xt, $eDir, $group, $eName) { $ed = new \stdClass(); $ed->dir = $eDir; $ed->id = $group.'.'.$eName; $ed->xt = $xt; $info = array_from_file($eDir.__DS__.'_info_.php', 'info'); $ed->name = isset($info['name']) ? $info['name'] : $ed->id; $ed->version = isset($info['version']) ? $info['version'] : 'N/A'; $ed->class = isset($info['class']) ? $info['class'] : NULL; return $ed; } public static function getActiveEditors($siteId = NULL) { $types = self::getTypes(); $system = System::getInstance(); $result = array(); foreach ($types as $type) { $editor = $system->getSiteParam(NULL, '', 'editors.'.$type, 'mcms.base'); if (!is_null($siteId)) { $editor = $system->getSiteParam($siteId, '', 'editors.'.$type, $editor); } $result[$type] = $editor; } return $result; } public static function getEditorClass($type, $id) { $info = self::getEditorInfo($type, $id, true); if (empty($info)) $info = self::getEditorInfo($type, $id, false); if (empty($info->class)) throw new \DomainException('$info does not define editor class for editor '.$type.':'.$id); return $info->class; } }