File modules/cms/macros/macro/ClassicMenu.class.php
Last commit: Sun Dec 5 20:33:24 2021 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'.
1 <?php 2 namespace cms\macros\macro; 3 // OpenRat Content Management System 4 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de 5 // 6 // This program is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU General Public License 8 // as published by the Free Software Foundation; either version 2 9 // of the License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 use cms\model\BaseObject; 20 use cms\model\Folder; 21 use cms\model\Page; 22 use util\Macro; 23 24 25 /** 26 * Erstellen eines Menues 27 * @author Jan Dankert 28 */ 29 class ClassicMenu extends Macro 30 { 31 /** 32 * Beschreibung dieser Klasse 33 * @type String 34 */ 35 var $description = 'This is a dynamic Menue which contains all pages. Folders are opened when useful. Nice standard menu :-)'; 36 37 38 /** 39 * Zeichenkette, die vor einem aktiven Menuepunkt gezeigt wird 40 */ 41 var $css_class = 'macro-classicmenu'; 42 var $onlySameTemplate = true; 43 44 45 // Erstellen des Hauptmenues 46 /** 47 * @var array 48 */ 49 private $parentFolders; 50 51 public function execute() 52 { 53 $rootId = $this->getRootObjectId(); 54 // Erstellen eines Untermenues 55 56 $f = new Folder( $this->getPage()->parentid ); 57 $this->parentFolders = $f->parentObjectFileNames(false,true); 58 $this->showFolder( $rootId ); 59 } 60 61 private function showFolder( $oid ) 62 { 63 $this->outputLn('<ul class="'.$this->css_class.'">'); 64 $f = new Folder( $oid ); 65 66 // Schleife ueber alle Objekte im aktuellen Ordner 67 /** @var BaseObject $o */ 68 foreach($f->getObjects() as $o ) 69 { 70 $o->load(); 71 72 // Wenn aktuelle Seite, dann markieren, sonst Link 73 $name = $o->getNameForLanguage($this->pageContext->languageId)->name; 74 75 // Ordner anzeigen 76 if ($o->isFolder ) 77 { 78 $nf = new Folder($o->objectid); 79 $fp = $nf->getFirstPageOrLink(); 80 81 if ( is_object($fp) ) 82 { 83 if ( $this->getPage()->objectid == $fp->objectid ) 84 // aktuelle Seite 85 $this->outputLn( '<li class="active">'.$name.'' ); 86 else 87 // Link erzeugen 88 $this->outputLn( '<li><a href="'.$this->pathToObject($fp->objectid).'">'.$name.'</a>' ); 89 90 if ( in_array($o->objectid,array_keys($this->parentFolders)) ) 91 { 92 $this->showFolder($o->objectid); 93 } 94 95 $this->outputLn( '</li>' ); 96 } 97 } 98 99 if ($o->isPage) 100 { 101 $page = new Page($o->objectid); 102 $page->load(); 103 if ( $page->templateid != $this->getPage()->templateid && $this->onlySameTemplate ) 104 continue; 105 } 106 107 // Seiten und Verknuepfungen anzeigen 108 if ($o->isPage || $o->isLink ) 109 { 110 // Wenn aktuelle Seite, dann markieren, sonst Link 111 if ( $this->getObjectId() == $o->objectid) 112 // aktuelle Seite 113 $this->output( '<li class="active">'.$name.'</li>' ); 114 elseif ( $o->isLink ) 115 // Link mit HTML-Sonderzeichenumwandlung erzeugen 116 $this->output( '<li><a href="'.htmlspecialchars($this->pathToObject($o->objectid)).'">'.$name.'</a></li>' ); 117 else 118 // Link erzeugen 119 $this->output( '<li><a href="'.$this->pathToObject($o->objectid).'">'.$name.'</a></li>' ); 120 } 121 } 122 $this->output('</ul>'); 123 } 124 125 }
Downloadmodules/cms/macros/macro/ClassicMenu.class.php
History Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Mon, 21 Sep 2020 22:48:59 +0200 Jan Dankert Complexe refactoring: Moving all generation logic from the model (Value,Page,File) to generators classes. Sun, 23 Feb 2020 04:49:34 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 2. Sun, 23 Feb 2020 04:01:30 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 1: moving.