openrat-cms

OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit d220a694caeb2633e91f0ed217d2592a3149777e
parent 627dd8c4271c6c7277c2aa205bca291fb91e8456
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 26 Sep 2020 21:42:51 +0200

Refactoring: The UI Actions are now in their own namespace. No need for a confusing require file.

Diffstat:
index.php | 1-
modules/cms/Dispatcher.class.php | 2+-
modules/cms/action/RequestParams.class.php | 5+++++
modules/cms/action/TreeAction.class.php | 358-------------------------------------------------------------------------------
modules/cms/ui/UI.class.php | 8+++++---
modules/cms/ui/action/IndexAction.class.php | 198++++++++++++-------------------------------------------------------------------
modules/cms/ui/action/TitleAction.class.php | 10++--------
modules/cms/ui/action/TreeAction.class.php | 357+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/cms/ui/require.php | 4----
9 files changed, 398 insertions(+), 545 deletions(-)

diff --git a/index.php b/index.php @@ -1,7 +1,6 @@ <?php // Excecuting the CMS user interface (UI) require('modules/autoload.php'); -require('modules/cms/ui/require.php'); use cms\base\Startup; use cms\ui\UI; diff --git a/modules/cms/Dispatcher.class.php b/modules/cms/Dispatcher.class.php @@ -277,7 +277,7 @@ class Dispatcher private function callActionMethod() { $actionClassName = ucfirst($this->request->action) . 'Action'; - $actionClassNameWithNamespace = 'cms\\action\\' . $actionClassName; + $actionClassNameWithNamespace = 'cms\\'.($this->request->isUIAction?'ui\\':'').'action\\' . $actionClassName; if (!class_exists($actionClassNameWithNamespace)) { diff --git a/modules/cms/action/RequestParams.class.php b/modules/cms/action/RequestParams.class.php @@ -44,6 +44,11 @@ namespace cms\action { public $isAction; /** + * @var bool + */ + public $isUIAction; + + /** * RequestParams constructor. */ public function __construct() diff --git a/modules/cms/action/TreeAction.class.php b/modules/cms/action/TreeAction.class.php @@ -1,357 +0,0 @@ -<?php - -namespace cms\action; - -use cms\model\BaseObject; -use cms\model\Element; -use cms\model\Folder; -use cms\model\Group; -use cms\model\ModelFactory; -use cms\model\Page; -use cms\model\Project; -use cms\model\Template; -use cms\model\User; -use cms\model\Value; -use util\json\JSON; -use util\Tree; -use cms\model\Language; -use cms\model\Model; - -use util\Session; - -// OpenRat Content Management System -// Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -/** - * Action-Klasse zum Laden/Anzeigen des Navigations-Baumes - * @author $Author$ - * @version $Revision$ - * @package openrat.actions - */ - -class TreeAction extends BaseAction -{ - public $security = Action::SECURITY_GUEST; - - public function __construct() - { - parent::__construct(); - } - - /** - * Anzeigen des Baumes fuer asynchrone Anfragen. - */ - public function loadBranchView() - { - - $type = $this->getRequestVar('type'); - - $branch = $this->loadTreeBranch( $type ); - - $this->setTemplateVar( 'branch',$branch ); - } - - - - private function loadTreeBranch( $type ) - { - $tree = new Tree(); - - try - { - $method = new \ReflectionMethod($tree,$type); - if ( $this->hasRequestVar('id')) - $method->invoke($tree, $this->getRequestVar('id') ); - else - $method->invoke($tree); // <== Executing the Action - } - catch (\ReflectionException $re) - { - throw new \LogicException('Treemethod not found: '.$type); - } - - - $branch = array(); - foreach($tree->treeElements as $element ) - { - $branch[] = get_object_vars($element); - } - - return $branch; - } - - - /** - * Initialer Aufbau des Navigationsbaums. - */ - public function treeView() - { - $branch = $this->loadTreeBranch( 'root' ); - - foreach( $branch as $k=>$b ) - { - if ( !empty($b['type']) ) - $branch[$k]['children'] = $this->loadTreeBranch( $b['type'] ); - else - $branch[$k]['children'] = array(); - } - - $this->outputTreeBranch( $branch ); - - //$this->setTemplateVar( 'branch',$branch ); - - exit; // no template available. - - } - - - /** - * The path to an object. - */ - public function pathView() { - - $type = $this->getRequestVar('type'); - $id = $this->getRequestVar('id',OR_FILTER_ALPHANUM); - - $result = $this->calculatePath( $type, $id ); - $this->setTemplateVar('path' ,$result ); - - $name = $this->calculateName($type, $id); - $this->setTemplateVar('actual',$this->pathItem($type,$id,$name) ); - } - - - /** - * The path to an object. - */ - private function calculatePath($type, $id) { - - switch( $type ) { - - case 'projectlist': - return array(); - - case 'configuration': - return array(); - - case 'project': - return array( - $this->pathItem('projectlist',0) - ); - case 'folder': - case 'link' : - case 'url' : - case 'page' : - case 'file' : - case 'image' : - $o = new BaseObject( $id ); - $o->load(); - - $result= array( - $this->pathItem('projectlist' ), - $this->pathItem('project' , $o->projectid), - ); - - $parents = array_keys( $o->parentObjectFileNames(true) ); - foreach( $parents as $pid ) - { - $f = new Folder($pid); - $f->load(); - $result[] = $this->pathItem('folder' ,$pid,$f->filename ); - } - return $result; - - case 'pageelement' : - - $ids = explode('_',$id); - if ( count($ids) > 1 ) - { - list( $pageid, $elementid ) = $ids; - } - - $p = new Page($pageid); - $p->load(); - - $result= array( - $this->pathItem('projectlist' ), - $this->pathItem('project' , $p->projectid), - ); - - $parents = array_keys( $p->parentObjectFileNames(true ) ); - foreach( $parents as $pid ) { - $f = new Folder($pid); - $f->load(); - $result[] = $this->pathItem('folder' ,$pid,$f->filename ); - } - $result[] = $this->pathItem('page' ,$id,$p->filename ); - return $result; - - case 'userlist': - case 'usergroup': - return array( - //$this->pathItem('usergroup' ,0) - ); - case 'user': - return array( - //$this->pathItem('userandgroups',0), - $this->pathItem('userlist',0) - ); - case 'grouplist': - return array( - //array('type'=>'userandgroups','action'=>'userandgroups','id'=>0) - ); - case 'group': - return array( - //$this->pathItem('userandgroups',0), - $this->pathItem('grouplist' ,0) - ); - - case 'templatelist': - case 'languagelist': - case 'modellist': - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$id) - ); - - case 'template': - $t = new Template( $id ); - $t->load(); - - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$t->projectid), - $this->pathItem('templatelist',$t->projectid) - ); - - case 'element': - $e = new Element( $id ); - $e->load(); - $t = new Template( $e->templateid ); - $t->load(); - - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$t->projectid ), - $this->pathItem('templatelist',$t->projectid ), - $this->pathItem('template' ,$t->templateid,$t->name) - ); - - case 'language': - $l = new Language( $id ); - $l->load(); - - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$l->projectid), - $this->pathItem('languagelist',$l->projectid) - ); - - case 'model': - $m = new Model( $id ); - $m->load(); - - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$m->projectid), - $this->pathItem('modellist' ,$m->projectid) - ); - - default: - throw new \InvalidArgumentException('Unknown type: '.$type); - } - } - - - - private function outputTreeBranch($branch ) - { - $json = new JSON(); - echo '<ul class="or-navtree-list">'; - - foreach( $branch as $b ) - { - $hasChildren = isset($b['children']) && !empty($b['children']); - - echo '<li class="or-navtree-node or-navtree-node--'.($hasChildren?'is-open':'is-closed').' or-draggable" data-id="'.$b['internalId'].'" data-type="'.$b['type'].'" data-extra="'.str_replace('"',"'",$json->encode($b['extraId'])).'"><div class="or-navtree-node-control"><i class="tree-icon image-icon image-icon--node-'.($hasChildren?'open':'closed').'"></i></div><div class="clickable"><a href="./#/'.$b['type'].($b['internalId']?'/'.$b['internalId']:'').'" class="entry" data-extra="'.str_replace('"',"'",$json->encode($b['extraId'])).'" data-id="'.$b['internalId'].'" data-action="'.$b['action'].'" data-type="open" title="'.$b['description'].'"><i class="image-icon image-icon--action-'.$b['icon'].'" ></i> '.$b['text'].'</a></div>'; - - if ($hasChildren) - { - $this->outputTreeBranch($b['children']); - } - - echo '</li>'; - } - - echo '</ul>'; - } - - - private function pathItem( $action, $id = 0, $name = '' ) { - return array('type'=>$this->typeToInternal($action),'action'=>$action ,'id'=>$id,'name'=>$name ); - } - - - private function typeToInternal($type) - { - switch( $type) { - - case 'projectlist': - return 'projects'; - - case 'userlist': - return 'users'; - - case 'grouplist': - return 'groups'; - - case 'templatelist': - return 'templates'; - - case 'languagelist': - return 'languages'; - - case 'modellist': - return 'models'; - - default: - return $type; - } - - } - - /** - * @param $type - * @param $id - * @return string - */ - protected function calculateName($type, $id) - { - $name = ''; - $o = ModelFactory::create($type, $id); - - if ($o) { - $o->load(); - $name = $o->getName(); - } - return $name; - } - - -} - -?>- \ No newline at end of file diff --git a/modules/cms/ui/UI.class.php b/modules/cms/ui/UI.class.php @@ -40,11 +40,13 @@ class UI // Sending the Content-Security-Policy. self::setContentSecurityPolicy(); - if (empty($request->action)) + if (empty($request->action)) { $request->action = 'index'; - - if (empty($request->method)) $request->method = 'show'; + } + + if ( in_array( $request->action,['index','tree','title']) ) + $request->isUIAction = true; UI::executeAction($request); diff --git a/modules/cms/ui/action/IndexAction.class.php b/modules/cms/ui/action/IndexAction.class.php @@ -1,7 +1,8 @@ <?php -namespace cms\action; +namespace cms\ui\action; +use cms\action\Action; use cms\auth\Auth; use cms\base\Startup; use cms\model\BaseObject; @@ -38,6 +39,9 @@ class IndexAction extends Action } + /** + * Getting the website manifest file. + */ public function manifestView() { $user = Session::getUser(); @@ -165,12 +169,14 @@ class IndexAction extends Action } - + /** + * Gets all necessary CSS files for displaying the UI. + * @return string[] + */ private function getCSSFiles() { - return array( - Startup::THEMES_DIR . 'default/style/openrat'.(PRODUCTION?'.min':'').'.css' - ); + // Ok, for now there is only 1 CSS file, which contains all UI styles. + return [ Startup::THEMES_DIR . 'default/style/openrat'.(PRODUCTION?'.min':'').'.css' ]; } @@ -185,7 +191,11 @@ class IndexAction extends Action } - + /** + * Gets the theme CSS. + * + * @return string + */ private function getThemeCSS() { // Je Theme die Theme-CSS-Datei ausgeben. @@ -217,6 +227,9 @@ class IndexAction extends Action } catch (Exception $e) { + Logger::warn("LESS Parser failed on file '$lessFile'. Reason: " . $e->__toString() . " */\n\n"); + + // For not confusing the browser we are displaying a CSS with a comment. $css .= "\n\n/* WARNING!\n LESS Parser failed on file '$lessFile'. Reason: " . $e->__toString() . " */\n\n"; } } @@ -229,176 +242,23 @@ class IndexAction extends Action { return $css; } - } - + } + /** + * Gets all JS files for displaying the UI. + * + * @return string[] + */ private function getJSFiles() { - return array( + return [ + // There is only 1 JS file needed for the UI. It contains all script files. Startup::THEMES_DIR . 'default/script/openrat'.(PRODUCTION?'.min':'').'.js' - ); + ]; } - private function getColorHexCode($colorName ) { - - $colorName = strtolower($colorName); - - $colors = array( - 'aliceblue'=>'#f0f8ff', - 'antiquewhite'=>'#faebd7', - 'aqua'=>'#00ffff', - 'aquamarine'=>'#7fffd4', - 'azure'=>'#f0ffff', - 'beige'=>'#f5f5dc', - 'bisque'=>'#ffe4c4', - 'black'=>'#000000', - 'blanchedalmond'=>'#ffebcd', - 'blue'=>'#0000ff', - 'blueviolet'=>'#8a2be2', - 'brown'=>'#a52a2a', - 'burlywood'=>'#deb887', - 'cadetblue'=>'#5f9ea0', - 'chartreuse'=>'#7fff00', - 'chocolate'=>'#d2691e', - 'coral'=>'#ff7f50', - 'cornflowerblue'=>'#6495ed', - 'cornsilk'=>'#fff8dc', - 'crimson'=>'#dc143c', - 'cyan'=>'#00ffff', - 'darkblue'=>'#00008b', - 'darkcyan'=>'#008b8b', - 'darkgoldenrod'=>'#b8860b', - 'darkgray'=>'#a9a9a9', - 'darkgrey'=>'#a9a9a9', - 'darkgreen'=>'#006400', - 'darkkhaki'=>'#bdb76b', - 'darkmagenta'=>'#8b008b', - 'darkolivegreen'=>'#556b2f', - 'darkorange'=>'#ff8c00', - 'darkorchid'=>'#9932cc', - 'darkred'=>'#8b0000', - 'darksalmon'=>'#e9967a', - 'darkseagreen'=>'#8fbc8f', - 'darkslateblue'=>'#483d8b', - 'darkslategray'=>'#2f4f4f', - 'darkslategrey'=>'#2f4f4f', - 'darkturquoise'=>'#00ced1', - 'darkviolet'=>'#9400d3', - 'deeppink'=>'#ff1493', - 'deepskyblue'=>'#00bfff', - 'dimgray'=>'#696969', - 'dimgrey'=>'#696969', - 'dodgerblue'=>'#1e90ff', - 'firebrick'=>'#b22222', - 'floralwhite'=>'#fffaf0', - 'forestgreen'=>'#228b22', - 'fuchsia'=>'#ff00ff', - 'gainsboro'=>'#dcdcdc', - 'ghostwhite'=>'#f8f8ff', - 'gold'=>'#ffd700', - 'goldenrod'=>'#daa520', - 'gray'=>'#808080', - 'grey'=>'#808080', - 'green'=>'#008000', - 'greenyellow'=>'#adff2f', - 'honeydew'=>'#f0fff0', - 'hotpink'=>'#ff69b4', - 'indianred'=>'#cd5c5c', - 'indigo'=>'#4b0082', - 'ivory'=>'#fffff0', - 'khaki'=>'#f0e68c', - 'lavender'=>'#e6e6fa', - 'lavenderblush'=>'#fff0f5', - 'lawngreen'=>'#7cfc00', - 'lemonchiffon'=>'#fffacd', - 'lightblue'=>'#add8e6', - 'lightcoral'=>'#f08080', - 'lightcyan'=>'#e0ffff', - 'lightgoldenrodyellow'=>'#fafad2', - 'lightgray'=>'#d3d3d3', - 'lightgrey'=>'#d3d3d3', - 'lightgreen'=>'#90ee90', - 'lightpink'=>'#ffb6c1', - 'lightsalmon'=>'#ffa07a', - 'lightseagreen'=>'#20b2aa', - 'lightskyblue'=>'#87cefa', - 'lightslategray'=>'#778899', - 'lightslategrey'=>'#778899', - 'lightsteelblue'=>'#b0c4de', - 'lightyellow'=>'#ffffe0', - 'lime'=>'#00ff00', - 'limegreen'=>'#32cd32', - 'linen'=>'#faf0e6', - 'magenta'=>'#ff00ff', - 'maroon'=>'#800000', - 'mediumaquamarine'=>'#66cdaa', - 'mediumblue'=>'#0000cd', - 'mediumorchid'=>'#ba55d3', - 'mediumpurple'=>'#9370d8', - 'mediumseagreen'=>'#3cb371', - 'mediumslateblue'=>'#7b68ee', - 'mediumspringgreen'=>'#00fa9a', - 'mediumturquoise'=>'#48d1cc', - 'mediumvioletred'=>'#c71585', - 'midnightblue'=>'#191970', - 'mintcream'=>'#f5fffa', - 'mistyrose'=>'#ffe4e1', - 'moccasin'=>'#ffe4b5', - 'navajowhite'=>'#ffdead', - 'navy'=>'#000080', - 'oldlace'=>'#fdf5e6', - 'olive'=>'#808000', - 'olivedrab'=>'#6b8e23', - 'orange'=>'#ffa500', - 'orangered'=>'#ff4500', - 'orchid'=>'#da70d6', - 'palegoldenrod'=>'#eee8aa', - 'palegreen'=>'#98fb98', - 'paleturquoise'=>'#afeeee', - 'palevioletred'=>'#d87093', - 'papayawhip'=>'#ffefd5', - 'peachpuff'=>'#ffdab9', - 'peru'=>'#cd853f', - 'pink'=>'#ffc0cb', - 'plum'=>'#dda0dd', - 'powderblue'=>'#b0e0e6', - 'purple'=>'#800080', - 'red'=>'#ff0000', - 'rosybrown'=>'#bc8f8f', - 'royalblue'=>'#4169e1', - 'saddlebrown'=>'#8b4513', - 'salmon'=>'#fa8072', - 'sandybrown'=>'#f4a460', - 'seagreen'=>'#2e8b57', - 'seashell'=>'#fff5ee', - 'sienna'=>'#a0522d', - 'silver'=>'#c0c0c0', - 'skyblue'=>'#87ceeb', - 'slateblue'=>'#6a5acd', - 'slategray'=>'#708090', - 'slategrey'=>'#708090', - 'snow'=>'#fffafa', - 'springgreen'=>'#00ff7f', - 'steelblue'=>'#4682b4', - 'tan'=>'#d2b48c', - 'teal'=>'#008080', - 'thistle'=>'#d8bfd8', - 'tomato'=>'#ff6347', - 'turquoise'=>'#40e0d0', - 'violet'=>'#ee82ee', - 'wheat'=>'#f5deb3', - 'white'=>'#ffffff', - 'whitesmoke'=>'#f5f5f5', - 'yellow'=>'#ffff00', - 'yellowgreen'=>'#9acd32' - ); - - return isset($colors[$colorName])?$colors[$colorName]:$colorName; - } - - /** * Ermittelt die erste zu startende Aktion. * @param $action @@ -534,4 +394,3 @@ class IndexAction extends Action } } -?>- \ No newline at end of file diff --git a/modules/cms/ui/action/TitleAction.class.php b/modules/cms/ui/action/TitleAction.class.php @@ -1,14 +1,11 @@ <?php -namespace cms\action; +namespace cms\ui\action; +use cms\action\Action; use cms\base\DB; use cms\base\Startup; -use cms\base\Version; -use cms\model\Project; use cms\model\BaseObject; -use cms\model\Language; -use cms\model\Model; use util\Session; use util\Html; @@ -106,5 +103,3 @@ class TitleAction extends Action $this->setTemplateVar( 'history',$resultList ); } } - -?>- \ No newline at end of file diff --git a/modules/cms/ui/action/TreeAction.class.php b/modules/cms/ui/action/TreeAction.class.php @@ -0,0 +1,357 @@ +<?php + +namespace cms\ui\action; + +use cms\action\Action; +use cms\action\BaseAction; +use cms\model\BaseObject; +use cms\model\Element; +use cms\model\Folder; +use cms\model\Group; +use cms\model\ModelFactory; +use cms\model\Page; +use cms\model\Project; +use cms\model\Template; +use cms\model\User; +use cms\model\Value; +use util\json\JSON; +use util\Tree; +use cms\model\Language; +use cms\model\Model; + +use util\Session; + +// OpenRat Content Management System +// Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** + * Action-Klasse zum Laden/Anzeigen des Navigations-Baumes + * @author $Author$ + * @version $Revision$ + * @package openrat.actions + */ + +class TreeAction extends BaseAction +{ + public $security = Action::SECURITY_GUEST; + + public function __construct() + { + parent::__construct(); + } + + /** + * Anzeigen des Baumes fuer asynchrone Anfragen. + */ + public function loadBranchView() + { + + $type = $this->getRequestVar('type'); + + $branch = $this->loadTreeBranch( $type ); + + $this->setTemplateVar( 'branch',$branch ); + } + + + + private function loadTreeBranch( $type ) + { + $tree = new Tree(); + + try + { + $method = new \ReflectionMethod($tree,$type); + if ( $this->hasRequestVar('id')) + $method->invoke($tree, $this->getRequestVar('id') ); + else + $method->invoke($tree); // <== Executing the Action + } + catch (\ReflectionException $re) + { + throw new \LogicException('Treemethod not found: '.$type); + } + + + $branch = array(); + foreach($tree->treeElements as $element ) + { + $branch[] = get_object_vars($element); + } + + return $branch; + } + + + /** + * Initialer Aufbau des Navigationsbaums. + */ + public function treeView() + { + $branch = $this->loadTreeBranch( 'root' ); + + foreach( $branch as $k=>$b ) + { + if ( !empty($b['type']) ) + $branch[$k]['children'] = $this->loadTreeBranch( $b['type'] ); + else + $branch[$k]['children'] = array(); + } + + $this->outputTreeBranch( $branch ); + + //$this->setTemplateVar( 'branch',$branch ); + + exit; // no template available. + + } + + + /** + * The path to an object. + */ + public function pathView() { + + $type = $this->getRequestVar('type'); + $id = $this->getRequestVar('id',OR_FILTER_ALPHANUM); + + $result = $this->calculatePath( $type, $id ); + $this->setTemplateVar('path' ,$result ); + + $name = $this->calculateName($type, $id); + $this->setTemplateVar('actual',$this->pathItem($type,$id,$name) ); + } + + + /** + * The path to an object. + */ + private function calculatePath($type, $id) { + + switch( $type ) { + + case 'projectlist': + return array(); + + case 'configuration': + return array(); + + case 'project': + return array( + $this->pathItem('projectlist',0) + ); + case 'folder': + case 'link' : + case 'url' : + case 'page' : + case 'file' : + case 'image' : + $o = new BaseObject( $id ); + $o->load(); + + $result= array( + $this->pathItem('projectlist' ), + $this->pathItem('project' , $o->projectid), + ); + + $parents = array_keys( $o->parentObjectFileNames(true) ); + foreach( $parents as $pid ) + { + $f = new Folder($pid); + $f->load(); + $result[] = $this->pathItem('folder' ,$pid,$f->filename ); + } + return $result; + + case 'pageelement' : + + $ids = explode('_',$id); + if ( count($ids) > 1 ) + { + list( $pageid, $elementid ) = $ids; + } + + $p = new Page($pageid); + $p->load(); + + $result= array( + $this->pathItem('projectlist' ), + $this->pathItem('project' , $p->projectid), + ); + + $parents = array_keys( $p->parentObjectFileNames(true ) ); + foreach( $parents as $pid ) { + $f = new Folder($pid); + $f->load(); + $result[] = $this->pathItem('folder' ,$pid,$f->filename ); + } + $result[] = $this->pathItem('page' ,$id,$p->filename ); + return $result; + + case 'userlist': + case 'usergroup': + return array( + //$this->pathItem('usergroup' ,0) + ); + case 'user': + return array( + //$this->pathItem('userandgroups',0), + $this->pathItem('userlist',0) + ); + case 'grouplist': + return array( + //array('type'=>'userandgroups','action'=>'userandgroups','id'=>0) + ); + case 'group': + return array( + //$this->pathItem('userandgroups',0), + $this->pathItem('grouplist' ,0) + ); + + case 'templatelist': + case 'languagelist': + case 'modellist': + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$id) + ); + + case 'template': + $t = new Template( $id ); + $t->load(); + + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$t->projectid), + $this->pathItem('templatelist',$t->projectid) + ); + + case 'element': + $e = new Element( $id ); + $e->load(); + $t = new Template( $e->templateid ); + $t->load(); + + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$t->projectid ), + $this->pathItem('templatelist',$t->projectid ), + $this->pathItem('template' ,$t->templateid,$t->name) + ); + + case 'language': + $l = new Language( $id ); + $l->load(); + + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$l->projectid), + $this->pathItem('languagelist',$l->projectid) + ); + + case 'model': + $m = new Model( $id ); + $m->load(); + + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$m->projectid), + $this->pathItem('modellist' ,$m->projectid) + ); + + default: + throw new \InvalidArgumentException('Unknown type: '.$type); + } + } + + + + private function outputTreeBranch($branch ) + { + $json = new JSON(); + echo '<ul class="or-navtree-list">'; + + foreach( $branch as $b ) + { + $hasChildren = isset($b['children']) && !empty($b['children']); + + echo '<li class="or-navtree-node or-navtree-node--'.($hasChildren?'is-open':'is-closed').' or-draggable" data-id="'.$b['internalId'].'" data-type="'.$b['type'].'" data-extra="'.str_replace('"',"'",$json->encode($b['extraId'])).'"><div class="or-navtree-node-control"><i class="tree-icon image-icon image-icon--node-'.($hasChildren?'open':'closed').'"></i></div><div class="clickable"><a href="./#/'.$b['type'].($b['internalId']?'/'.$b['internalId']:'').'" class="entry" data-extra="'.str_replace('"',"'",$json->encode($b['extraId'])).'" data-id="'.$b['internalId'].'" data-action="'.$b['action'].'" data-type="open" title="'.$b['description'].'"><i class="image-icon image-icon--action-'.$b['icon'].'" ></i> '.$b['text'].'</a></div>'; + + if ($hasChildren) + { + $this->outputTreeBranch($b['children']); + } + + echo '</li>'; + } + + echo '</ul>'; + } + + + private function pathItem( $action, $id = 0, $name = '' ) { + return array('type'=>$this->typeToInternal($action),'action'=>$action ,'id'=>$id,'name'=>$name ); + } + + + private function typeToInternal($type) + { + switch( $type) { + + case 'projectlist': + return 'projects'; + + case 'userlist': + return 'users'; + + case 'grouplist': + return 'groups'; + + case 'templatelist': + return 'templates'; + + case 'languagelist': + return 'languages'; + + case 'modellist': + return 'models'; + + default: + return $type; + } + + } + + /** + * @param $type + * @param $id + * @return string + */ + protected function calculateName($type, $id) + { + $name = ''; + $o = ModelFactory::create($type, $id); + + if ($o) { + $o->load(); + $name = $o->getName(); + } + return $name; + } + + +} diff --git a/modules/cms/ui/require.php b/modules/cms/ui/require.php @@ -1,4 +0,0 @@ -<?php - -require_once(__DIR__ . "/action/IndexAction.class.php"); -require_once(__DIR__ . "/action/TitleAction.class.php");