File modules/util/Macro.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 // OpenRat Content Management System 3 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 2 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 namespace util; 19 20 use cms\base\DB; 21 use cms\generator\PageContext; 22 use cms\model\BaseObject; 23 use cms\model\Page; 24 use cms\model\Project; 25 use util\Session; 26 27 28 /** 29 * Service-Klasse fuer allgemeine Interface-Methoden. Insbesondere 30 * in Code-Elementen kann und soll auf diese Methoden zurueckgegriffen 31 * werden. 32 * 33 * @author Jan Dankert 34 */ 35 class Macro 36 { 37 /** 38 * @var PageContext 39 */ 40 protected $pageContext; 41 42 /** 43 * @var Page 44 * @deprecated use getPage() 45 */ 46 protected $page; 47 48 /** 49 * @param $pageContext PageContext 50 */ 51 public function setPageContext( $pageContext) { 52 $this->pageContext = $pageContext; 53 $this->page = new Page( $pageContext->objectId ); 54 } 55 56 /** 57 * Ausführen des Makros. Diese Methode sollte durch die Unterklasse überschrieben werden. 58 */ 59 public function execute() 60 { 61 // overwrite this in subclasses 62 } 63 64 65 /** 66 * Holt die aktuellen Datenbankverbindung. 67 */ 68 protected function db() 69 { 70 return DB::get(); 71 } 72 73 74 /** 75 * Holt die aktuelle Objekt-Id. 76 * @return number 77 */ 78 protected function getObjectId() 79 { 80 return $this->pageContext->objectId; 81 } 82 83 84 /** 85 * Holt die aktuelle Seite. 86 * @return \cms\model\Page 87 */ 88 protected function getPage() 89 { 90 $page = new Page($this->pageContext->objectId); 91 $page->load(); 92 93 return $page; 94 } 95 96 97 protected function getPageName() { 98 return $this->getPage()->getNameForLanguage( $this->pageContext->languageId )->name; 99 } 100 101 /** 102 * Holt das aktuelle Objekt. 103 * @return Object 104 */ 105 protected function &getObject() 106 { 107 return new Page( $this->pageContext->objectId ); 108 } 109 110 111 /** 112 * Ermittelt die Id des Wurzelordners im aktuellen Projekt. 113 */ 114 protected function getRootObjectId() 115 { 116 $page = new Page( $this->pageContext->objectId ); 117 $page->load(); 118 $project = $page->getProject(); 119 ; 120 return $project->getRootObjectId(); 121 } 122 123 124 /** 125 * Löscht die bisher erzeugte Ausgabe. 126 * @deprecated useless 127 */ 128 public function delOutput() 129 { 130 } 131 132 /** 133 * Ergänzt die Standardausgabe um den gewünschten Wert. 134 * @deprecated use echo() 135 */ 136 public function output($text) 137 { 138 echo $text; 139 } 140 141 142 /** 143 * Ergänzt die Standardausgabe um den gewünschten Wert. Es wird ein Zeilenendezeichen ergänzt. 144 * @deprecated use echo() 145 */ 146 public function outputLn($text) 147 { 148 echo $text . "\n"; 149 } 150 151 152 /** 153 * Setzt eine Sitzungsvariable. 154 * 155 * @param String $var 156 * @param Object $value 157 */ 158 public function setSessionVar($var, $value) 159 { 160 Session::set($var, $value); 161 } 162 163 164 /** 165 * Ermittelt eine Sitzungsvariable. 166 * 167 * @param String $var 168 * @return string 169 */ 170 public function getSessionVar($var) 171 { 172 return Session::get($var); 173 } 174 175 176 /** 177 * Ermittelt den Pfad auf ein Objekt. 178 * @param Object 179 * @return string 180 */ 181 public function pathToObject($targetObject) 182 { 183 if (is_numeric($targetObject)) 184 $targetObject = new BaseObject( $targetObject ); 185 186 $targetObject->load(); 187 $linkFormat = $this->pageContext->getLinkScheme(); 188 189 return $linkFormat->linkToObject( new Page( $this->pageContext->sourceObjectId), $targetObject ); 190 } 191 192 }
Download modules/util/Macro.class.php
History Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Sat, 26 Sep 2020 02:26:39 +0200 Jan Dankert Refactoring: No global functions any more, the database object is read from the Db class. 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. Sat, 22 Feb 2020 23:58:02 +0100 Jan Dankert Refactoring: Namespacing for module 'util'. Fri, 15 Nov 2019 02:09:02 +0100 Jan Dankert Refactoring: No public attributes in Macro class; using YAML for macro parameters. Sun, 10 Nov 2019 22:38:49 +0100 Jan Dankert Log a warning, if code execution is requested, but disabled by configuration. Sun, 10 Nov 2019 22:07:48 +0100 Jan Dankert Refactoring: Macro classes should be able to do a simple 'echo'. Sun, 9 Dec 2018 23:36:39 +0100 Jan Dankert Neues Makro für den Aufbau eines Suchindexes. Thu, 16 Aug 2018 00:36:25 +0200 Jan Dankert Aufgeräumt: Veraltete Session-Funktionen entfernt, da Projekt,Sprache,Model nicht mehr in der Session gehalten werden. Fri, 20 Jul 2018 00:20:52 +0200 Jan Dankert Fixes: Laden von URLs, die weitere Parameter wie languageid und modelid enthalten. Sat, 16 Dec 2017 23:21:31 +0100 Jan Dankert Eigenes Modul für alle Util-Klassen.