[Phpcms-plugins-cvs] admin4phpCMS/modules/layout layout.dtd,NONE,1.1 layout.xml,NONE,1.1 class.layou
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2004-05-30 18:03:52
|
Update of /cvsroot/phpcms-plugins/admin4phpCMS/modules/layout In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9898/modules/layout Modified Files: class.layout_phpcms.php class.module_layout.php Added Files: layout.dtd layout.xml Log Message: restructuring of some files --- NEW FILE: layout.xml --- <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE layout SYSTEM "layout.dtd"> <layout> <document> <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de"> <head> <title>Verwaltungsoberfläche</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="Administrationsoberfläche von phpCMS" /> <meta name="robots" content="noindex,nofollow" /> <meta name="author" content="Martin Jahn" /> <meta name="language" content="de" /> <meta http-equiv="imagetoolbar" content="no" /> </head> <body> <content /> </body> </html> ]]> </document> <block> <![CDATA[ <div class="block"> <content /> </div> ]]> </block> <paragraph> <![CDATA[ <p> <content /> </p> ]]> </paragraph> <headline> <![CDATA[ <h2> <content /> </h2> ]]> </headline> <image> <![CDATA[ <div> <img src="<file />" width="<width />" height="<height />" title="<title />" alt="Bild"> </div> ]]> </image> <form> <![CDATA[ <form id="<id />" name="<name />" enctype="x-form/multipart"> <content /> </form> ]]> </form> <form_input_hidden> <![CDATA[ <input type="hidden" name="<name />" id="<id />" value="<value />" /> ]]> </form_input_hidden> <form_input_text> <![CDATA[ <label> <span> <label /> </span> <input type="text" name="<name />" id="<id />" value="<value />" /> </label> ]]> </form_input_text> <form_input_password> <![CDATA[ <label> <span> <label /> </span> <input type="password" name="<name />" id="<id />" value="<value />" /> </label> ]]> </form_input_password> <form_radio> <![CDATA[ <label><input type="radio" name="<name />" id="<id />" value="<value />" /><label /></label> ]]> </form_radio> <form_checkbox> <![CDATA[ <label> <span> <label /> </span> <input type="checkbox" name="<name />" id="<id />" value="<value />" /> </label> ]]> </form_checkbox> <form_textarea> <![CDATA[ <label> <span> <label /> </span> <textarea name="<name />" id="<id />"> <value /> </textarea> </label> ]]> </form_textarea> <form_button> <![CDATA[ <button type="<type />" name="<name />" id="<id />" value="<value />"> <text /> </button> ]]> </form_button> <menu_main> <![CDATA[ <ul id="menu"> <entries /> </ul> ]]> </menu_main> <menu_main_entry> <![CDATA[ <li class="<status />"> <a href="<link />"> <name /> </a> </li> ]]> </menu_main_entry> <menu_sub> <![CDATA[ <ul> <entries /> </ul> ]]> </menu_sub> <menu_sub_entry> <![CDATA[ <li class="<status />"> <a href="<link />"> <name /> </a> </li> ]]> </menu_sub_entry> </layout> Index: class.module_layout.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/layout/class.module_layout.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- class.module_layout.php 30 May 2004 03:55:27 -0000 1.3 +++ class.module_layout.php 30 May 2004 18:03:41 -0000 1.4 @@ -1,96 +1,172 @@ <?php /** -* Das Layout-Modul -* * Das Layout-Modul erzeugt durch Ereignisse gesteuert einen Baum aus Objekten. -* Diese Objekte verkörpern die unterschiedlichen Elemente, die ausgegeben werden -* können. +* Diese Objekte repräsentieren die unterschiedlichen Elemente, die ausgegeben +* werden können. +* +* 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 * * @author Martin Jahn <mj...@us...> * @license GPL -* @copyright (C) Urheberrecht liegt beim Autor -* @date $Date$ -* @version $Id$ // $Revision$ // +* @copyright Copyright (c) 2004, Martin Jahn +* @version $Id$ +* @package admin4phpCMS +* @subpackage module_layout +* **/ -/** CVS-data -$Id$ - -$Log$ -Revision 1.3 2004/05/30 03:55:27 mjahn -test - -Revision 1.2 2004/05/30 03:48:55 mjahn -test +/* +* $Log$ +* Revision 1.4 2004/05/30 18:03:41 mjahn +* restructuring of some files +* +* Revision 1.3 2004/05/30 03:55:27 mjahn +* test +* Revision 1.2 2004/05/30 03:48:55 mjahn +* test +*/ +/** +* include the layout-class **/ - -include_once ('XML/Tree.php'); include_once (dirname (__FILE__).'/class.layout_phpcms.php'); +/** +* Standard-Klasse des Layout-Modules +* +* <p>Ãbersicht über die von diesem Modul verwendete Events</p> +* <ul> +* <li><b>LAYOUT_ADD_ELEMENT</b> fügt ein Layout-Element zum Dokument hinzu.</li> +* </ul> +* +* @package admin4phpCMS +* @subpackage module_layout +**/ class module_layout extends module { - var $elements = array (); - var $ids = array (); + /** + * @var array Container für die Objekthierarchie, die das Layout repräsentiert + * @access private + **/ + var $_elements = array (); + + /** + * @var array Container für Referenzen auf die Layout-Objekte für den Schnellzugriff + * @access private + **/ + var $_ids = array (); + /** + * @var array Container für die Template-Daten + * @example /home/martin/devel/admin4phpCMS/modules/layout/layout.xml mitgelieferte Templatedatei + * @access private + **/ + var $_layout = array (); + + /** + * Initialisierungsmethode + * + * Registriert die vom Modul benötigten Events und Aktionen + * @access public + **/ function init () { $this->_registerEvent ('LAYOUT_ADD_ELEMENT', 'doLayoutAddElement'); $this->_registerAction ('doLayoutAddElement', 'addElement'); - $this->_registerAction ('doDisplay', 'displayLayout'); - $this->elements =& new layout_phpcms (); + $this->_registerAction ('doDisplay', 'display'); + $this->_elements =& new layout_phpcms (); } + /** + * Fügt der Elementeliste ein neues Element hinzu + * + * <p>Das Array $actiondata beinhaltet die Daten für das neue Layout-Objekt</p> + * <ul> + * <li><b>type</b> Typ des Elementes (=Name des Feldes in der Datei layout.xml)</li> + * <li><b>id</b> eindeutige Id des Elementes, dient zur Objekt-Referenzierung</li> + * </ul> + * + * @param array $actionhandler Daten des einzufügenden Elementes + **/ function addElement (&$actiondata) { - $parent =& $this->elements; + $parent =& $this->_elements; if (isset ($actiondata['root'])) { - $parent =& $this->ids[$actiondata['root']]; + $parent =& $this->_ids[$actiondata['root']]; } $id = $actiondata['id']; - $this->ids[$id] =& $parent->addElement($actiondata); + $this->_ids[$id] =& $parent->addElement($actiondata); } + /** + * @param string $id Id des gesuchten Objektes + * @return layout_phpcms Referenz auf das gesuchte Objekt + **/ function &getElement ($id) { - if (!isset($this->ids[$id])) { + if (!isset($this->_ids[$id])) { return false; } - return $this->ids[$id]; + return $this->_ids[$id]; } - function display () { - echo '<p>Meine Ausgabe</p>'; + /** + * Anzeigen der Layout-Felder + * + * @param array $actionhandler + **/ + function display (&$actiondata) { + $this->_readLayoutFile (); - if (!isset ($this->elements) || !is_array ($this->elements)) { + if (!isset ($this->_elements->elements) || !is_array ($this->_elements->elements)) { return false; } - for ($i = 0; $i < count($this->elements); $i++) { - $this->elements[$i]->display(); + + $o = ''; + for ($i = 0; $i < count($this->_elements->elements); $i++) { + $o .= $this->_elements->elements[$i]->display($this->_layout); } + + echo str_replace ('<content />', $o, $this->_layout['document']); } - function displayLayout (&$actiondata) { - $this->layoutfile = dirname(__FILE__).'/layout.xml'; + /** + * Einlesen der Templatedatei + * + * @access private + **/ + function _readLayoutFile () { + $layoutfile = dirname(__FILE__).'/layout.xml'; - if (!isset($this->layoutfile)) { + if (!isset($layoutfile)) { $actiondata = array ('errortext'=>'Layoutdatei konnte nicht geladen werden!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } - if (!file_exists ($this->layoutfile)) { + if (!file_exists ($layoutfile)) { unset ($this->configfile); $actiondata = array ('errortext'=>'Layoutdatei konnte nicht geladen werden!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } - $XML =& new XML_Tree ($this->layoutfile); + $XML =& new XML_Tree ($layoutfile); $layout =& $XML->getTreeFromFile (); foreach ($layout->children as $a) { if (!isset($a->name)) { continue; } - $this->layout[$a->name] =& $a->content; + $this->_layout[$a->name] =& $a->content; } - } } --- NEW FILE: layout.dtd --- <?xml version="1.0" encoding="UTF-8"?> <!ELEMENT layout ( block, paragraph, headline, image, form, form_input_hidden, form_input_text, form_input_password, form_checkbox, form_radio, form_textarea, form_button, menu_main_entry, menu_main, menu_sub_entry, menu_sub )> <!ELEMENT form (#PCDATA)> <!ELEMENT block (#PCDATA)> <!ELEMENT paragraph (#PCDATA)> <!ELEMENT headline (#PCDATA)> <!ELEMENT image (#PCDATA)> <!ELEMENT form_input_hidden (#PCDATA)> <!ELEMENT form_input_text (#PCDATA)> <!ELEMENT form_input_password (#PCDATA)> <!ELEMENT form_checkbox (#PCDATA)> <!ELEMENT form_radio (#PCDATA)> <!ELEMENT form_textarea (#PCDATA)> <!ELEMENT form_button (#PCDATA)> <!ELEMENT menu_main_entry (#PCDATA)> <!ELEMENT menu_main (#PCDATA)> <!ELEMENT menu_sub_entry (#PCDATA)> <!ELEMENT menu_sub (#PCDATA)> Index: class.layout_phpcms.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/layout/class.layout_phpcms.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- class.layout_phpcms.php 28 May 2004 12:07:45 -0000 1.1 +++ class.layout_phpcms.php 30 May 2004 18:03:41 -0000 1.2 @@ -1,29 +1,112 @@ <?php +/** +* Die Layout-Klasse dient der Kapselung der einzelnen Layout-Elemente. +* +* 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 +* +* @author Martin Jahn <mj...@us...> +* @license GPL +* @copyright Copyright (c) 2004, Martin Jahn +* @version $Id$ +* @package admin4phpCMS +* @subpackage module_layout +* +**/ +/* +* $Log$ +* Revision 1.2 2004/05/30 18:03:41 mjahn +* restructuring of some files +* +*/ +/** +* Layout-Klasse +* +* @access private +* @package admin4phpCMS +* @subpackage module_layout +**/ class layout_phpcms { - function &addElement () { - $id = ''; - $this->ids[$id] =& new layout_phpcms () - $this->elements[] =& $this->ids[$id]; + /** + * @var array Parameter des Layout-Objektes + * @access private + **/ + var $_params = array (); + + /** + * Konstruktor der Layoutklasse + * nach PHP4-Syntax + * + * @param array $params Parameter des neuen Layout-Objektes + * @ignore + **/ + function layout_phpcms ($params = '') { + $this->__construct ($params); } - function &getElement ($id) { - if (!isset($this->ids[$id])) { - return false; - } - return $this->ids[$id]; + /** + * Konstruktor der Layoutklasse + * nach PHP5-Syntax + * + * @param array $params Parameter des neuen Layout-Objektes + * @ignore + **/ + function __construct ($params = '') { + $this->_params = $params; } - function display () { - echo '<p>Meine Ausgabe</p>'; + /** + * Erstellt ein neues Layout-Element + * + * @param array $params Parameter des neuen Layout-Objektes + * @return layout_phpcms Referenz auf das neu angelegte Layout-Objekt + **/ + function &addElement ($params) { + $id = $params['id']; + $element =& new layout_phpcms ($params); + $this->elements[] =& $element; + return $element; + } + + /** + * Anzeigen der Layout-Felder + * + * @param array $layout Layouttemplate + * @return string kompilierte Ausgabe + **/ + function display ($layout) { - if (!isset ($this->elements) || !is_array ($this->elements)) { - return false; + $search = $replace = array (); + foreach ($this->_params as $id=>$value) { + $search[] = '<'.$id.' />'; + $replace[] = $value; } - for ($i = 0; $i < count($this->elements); $i++) { - $this->elements[$i]->display(); + + $o = ''; + + if (isset ($layout[$this->_params['type']])) { + $o .= str_replace ($search, $replace, $layout[$this->_params['type']]); } + + if (isset ($this->elements) || !is_array ($this->elements)) { + for ($i = 0; $i < count($this->elements); $i++) { + $o .= $this->elements[$i]->display(); + } + } + return $o; } } |