[Phpcms-plugins-cvs] admin4phpCMS/modules/layout layout.css,NONE,1.1 class.module_layout.php,1.4,1.5
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2004-06-04 11:12:09
|
Update of /cvsroot/phpcms-plugins/admin4phpCMS/modules/layout In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12823/modules/layout Modified Files: class.module_layout.php layout.dtd layout.xml Added Files: layout.css Removed Files: class.layout_phpcms.php Log Message: several changes Index: layout.xml =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/layout/layout.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- layout.xml 30 May 2004 18:03:41 -0000 1.1 +++ layout.xml 4 Jun 2004 11:11:58 -0000 1.2 @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?> <!DOCTYPE layout SYSTEM "layout.dtd"> <layout> @@ -7,16 +7,17 @@ <!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> + <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" /> + <link rel="stylesheet" href="./modules/layout/layout.css" type="text/css" /> </head> <body> - <content /> + <content /> </body> </html> ]]> @@ -24,7 +25,7 @@ <block> <![CDATA[ - <div class="block"> + <div id="<id />" class="<class />"> <content /> </div> ]]> @@ -33,16 +34,22 @@ <paragraph> <![CDATA[ - <p> + <p id="<id />" class="<class />"> <content /> </p> ]]> </paragraph> + <hr> + <![CDATA[ + <hr id="<id />" class="<class />" /> + ]]> + </hr> + <headline> <![CDATA[ - <h2> + <h2 id="<id />" class="<class />"> <content /> </h2> ]]> @@ -51,16 +58,14 @@ <image> <![CDATA[ - <div> - <img src="<file />" width="<width />" height="<height />" title="<title />" alt="Bild"> - </div> + <img src="<src />" width="<width />" height="<height />" title="<title />" alt="<alt />"> ]]> </image> <form> <![CDATA[ - <form id="<id />" name="<name />" enctype="x-form/multipart"> + <form id="<id />" name="<name />" method="<method />" enctype="x-form/multipart"> <content /> </form> ]]> @@ -143,19 +148,10 @@ </form_button> - <menu_main> - <![CDATA[ - <ul id="menu"> - <entries /> - </ul> - ]]> - </menu_main> - - <menu_main_entry> <![CDATA[ - <li class="<status />"> - <a href="<link />"> + <li class="<class />" id="<id />"> + <a href="?moduleid=<module />&<params />"> <name /> </a> </li> @@ -163,24 +159,41 @@ </menu_main_entry> - <menu_sub> + <ulist> <![CDATA[ - <ul> - <entries /> + <ul id="<id />" class="<class />"> + <content /> </ul> ]]> - </menu_sub> + </ulist> <menu_sub_entry> <![CDATA[ - <li class="<status />"> - <a href="<link />"> - <name /> - </a> + <li class="<class />" id="<id />"> + <a href="?moduleid=<module />&action=<action />&<param />"> + <name /> + </a> </li> ]]> </menu_sub_entry> + + + <list_entry> + <![CDATA[ + <li class="<class />"> + <content /> + </li> + ]]> + </list_entry> + + + <fm_file_entry> + <![CDATA[ + + ]]> + + </fm_file_entry> </layout> \ No newline at end of file Index: class.module_layout.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/layout/class.module_layout.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- class.module_layout.php 30 May 2004 18:03:41 -0000 1.4 +++ class.module_layout.php 4 Jun 2004 11:11:58 -0000 1.5 @@ -1,25 +1,26 @@ <?php /** -* Das Layout-Modul erzeugt durch Ereignisse gesteuert einen Baum aus Objekten. -* Diese Objekte repräsentieren die unterschiedlichen Elemente, die ausgegeben -* werden können. +* the layout-module is eventbased and creates the layout from a tree of layout-elements. +* These elements contain all the attributes to generate the output. * -* 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. +* License GPL * -* 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. +* 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. * -* 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 +* 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 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2004, Martin Jahn * @version $Id$ * @package admin4phpCMS @@ -29,6 +30,9 @@ /* * $Log$ +* Revision 1.5 2004/06/04 11:11:58 mjahn +* several changes +* * Revision 1.4 2004/05/30 18:03:41 mjahn * restructuring of some files * @@ -37,17 +41,33 @@ * Revision 1.2 2004/05/30 03:48:55 mjahn * test */ + /** -* include the layout-class +* include the PEAR::XML_Tree-class for parsing the layout.xml-file +* +* There is a little bug in the Node.php in this package. It replaces the entities '<', '>', '"' and '''. +* With this the output is not interpretable for clients **/ -include_once (dirname (__FILE__).'/class.layout_phpcms.php'); +include_once ('XML/Tree.php'); + /** -* Standard-Klasse des Layout-Modules +* standard-class * -* <p>Ãbersicht über die von diesem Modul verwendete Events</p> +* <p>overview of the events <b>used</b> by this module</p> * <ul> -* <li><b>LAYOUT_ADD_ELEMENT</b> fügt ein Layout-Element zum Dokument hinzu.</li> +* <li><b>LAYOUT_ADD_ELEMENT</b> adds a layout-element at the end of the element-list</li> +* <li><b>DISPLAY</b> displays the content of the modules</li> +* </ul> +* +* <p>overview of the events <b>provided</b> by this module</p> +* <ul> +* <li><b>DISPLAY_GET_CONTENT</b> let the modules create their layout by using the event +* LAYOUT_ADD_ELEMENT</li> +* <li><b>DISPLAY_GET_CONTENTBAR</b> let the modules create their layout for the statusbar +* by using the event LAYOUT_ADD_ELEMENT</li> +* <li><b>DISPLAY_GET_ERRORS</b> let the modules create their layout for error-messages +* using the event LAYOUT_ADD_ELEMENT</li> * </ul> * * @package admin4phpCMS @@ -56,7 +76,7 @@ class module_layout extends module { /** - * @var array Container für die Objekthierarchie, die das Layout repräsentiert + * @var array saves the object-hierarchie of the layout-elements * @access private **/ var $_elements = array (); @@ -78,66 +98,198 @@ * Initialisierungsmethode * * Registriert die vom Modul benötigten Events und Aktionen - * @access public **/ function init () { $this->_registerEvent ('LAYOUT_ADD_ELEMENT', 'doLayoutAddElement'); + $this->_registerEvent ('DISPLAY_PARSE_MENU_MAIN', 'doParseMenuMain'); + $this->_registerEvent ('DISPLAY_PARSE_STATUSBAR', 'doParseStatusbar'); + $this->_registerEvent ('DISPLAY_PARSE_MENU_SUB', 'doParseMenuSub'); + $this->_registerEvent ('DISPLAY_PARSE_ERROR', 'doParseError'); + $this->_registerEvent ('DISPLAY_PARSE_CONTENT', 'doParseContent'); + $this->_registerAction ('doLayoutAddElement', 'addElement'); - $this->_registerAction ('doDisplay', 'display'); - $this->_elements =& new layout_phpcms (); + $this->_registerAction ('doDisplay', 'displayLayout'); + + $this->_elements[0] = array ('_type'=>'document', 'id'=>'root'); + } /** - * Fügt der Elementeliste ein neues Element hinzu + * adds an object to the elements-list * - * <p>Das Array $actiondata beinhaltet die Daten für das neue Layout-Objekt</p> + * <p>$actiondata must provide the following information * <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> + * <li><b>type</b> type of the element in the file {@link /home/martin/devel/admin4phpCMS/modules/layout/layout.xml Example of the layoutfile)</li> + * <li><b>id</b> unique id of the element</li> * </ul> * * @param array $actionhandler Daten des einzufügenden Elementes **/ function addElement (&$actiondata) { - $parent =& $this->_elements; - if (isset ($actiondata['root'])) { - $parent =& $this->_ids[$actiondata['root']]; + + // get a reference to the parental element + $parent =& $this->_elements[0]; + if (isset ($actiondata['_root'])) { + $parent =& $this->_ids[$actiondata['_root']]; } - $id = $actiondata['id']; - $this->_ids[$id] =& $parent->addElement($actiondata); + + $id = ''; + if (!isset ($actiondata['_id'])) { + return false; + } + $this->_ids[$actiondata['_id']] = $actiondata; + + if (isset ($parent['_sub'])) { + $parent['_sub'][] =& $this->_ids[$actiondata['_id']]; + } else { + $parent['_sub'][0] =& $this->_ids[$actiondata['_id']]; + } } /** - * @param string $id Id des gesuchten Objektes - * @return layout_phpcms Referenz auf das gesuchte Objekt + * generate the output for the framework + * + * @param array $actionhandler **/ - function &getElement ($id) { - if (!isset($this->_ids[$id])) { - return false; + function displayLayout (&$actiondata) { + + $this->_readLayoutFile(); + + // set the left content block + $actiondata = array ('_type'=>'block', '_id'=>'menu', 'id'=>'menu', 'name'=>'menu'); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // set the phpcms-logo + $actiondata = array ('_type'=>'image', '_root'=>'menu', '_id'=>'logo', 'id'=>'', 'class'=>'', 'src'=>'phpcms.png', 'width'=>'181', 'height'=>'60', 'alt'=>'', 'title'=>'phpCMS-Logo v2'); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // set the menu-root + $actiondata = array ('_type'=>'ulist', '_root'=>'menu', '_id'=>'mainmenu', 'id'=>'', 'class'=>''); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // get the main-menu-tree + $actiondata = array ('_root'=>'mainmenu'); + $this->_callEvent ('DISPLAY_PARSE_MENU_MAIN', $actiondata); + + // set container for statusbar + $actiondata = array ('_type'=>'block', '_root'=>'menu', '_id'=>'statusbar', 'id'=>'', 'class'=>''); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // get the statusbar-entries + $actiondata = array ('_root'=>'statusbar'); + $this->_callEvent ('DISPLAY_PARSE_STATUSBAR', $actiondata); + + // set the copyright-message + $actiondata = array ('_type'=>'paragraph', '_root'=>'menu', '_id'=>'copyright', 'id'=>'', 'class'=>'', 'content'=>'© 2004, Alle Rechte bei phpcms-plugin-Team'); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // set right content block + $actiondata = array ('_type'=>'block', '_id'=>'content', 'id'=>'content', 'class'=>''); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // set the submenu block + $actiondata = array ('_type'=>'ulist', '_id'=>'submenu', 'id'=>'submenu', 'class'=>'', '_root'=>'content'); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // get the error-messages + $actiondata = array ('_root'=>'submenu'); + $this->_callEvent ('DISPLAY_PARSE_MENU_SUB', $actiondata); + + // set the error-message block + $actiondata = array ('_type'=>'block', '_id'=>'error', 'id'=>'', 'class'=>'error', '_root'=>'content'); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // get the error-messages + $actiondata = array ('_root'=>'error'); + $this->_callEvent ('DISPLAY_PARSE_ERROR', $actiondata); + + // set the content block + $actiondata = array ('_type'=>'block', '_id'=>'inhalt', 'id'=>'', 'class'=>'content', '_root'=>'content'); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + + // get the content + $actiondata = array ('_root'=>'inhalt'); + $this->_callEvent ('DISPLAY_PARSE_CONTENT', $actiondata); + + /* + echo '<pre>'; + print_r($this->_elements); + echo '</pre>'; + */ + // generate output + echo $this->displayGroup ($this->_elements); + + } + + /** + * displays an array of elements + * + * This function walks recursively through the element-structure and parses the output of any element. + * + * @param array $elements array with the element-arrays + **/ + function displayGroup (&$elements) { + $o = ''; + $num = count ($elements); + for ($i = 0; $i < $num; $i++) { + + // if entry does not exists jump over + if (!isset ($elements[$i])) { + continue; + } + + // check if sub-elements exist + + if (isset ($elements[$i]['_sub']) && is_array ($elements[$i]['_sub'])) { + + // get the content of the sub-elements + $content = $this->displayGroup ($elements[$i]['_sub']); + + // merge the sub-element-content with the params of the element + if (!isset ($elements[$i]['content'])) { + $elements[$i]['content'] = $content; + } + } + + $o .= $this->displayElement ($elements[$i]); } - return $this->_ids[$id]; + return $o; } /** - * Anzeigen der Layout-Felder + * displays a single element * - * @param array $actionhandler + * $element['_type'] specifies, which template is used for displaying this element + * + * @param array $element array with all the attributes for the element **/ - function display (&$actiondata) { - $this->_readLayoutFile (); + function displayElement (&$element) { - if (!isset ($this->_elements->elements) || !is_array ($this->_elements->elements)) { - return false; + // check if there is a layout-template for the type of this element + if (!isset ($element['_type']) || !isset ($this->_layout[$element['_type']])) { + return ''; + } + + if (!isset($element['content'])) { + $element['content'] = ''; } - $o = ''; - for ($i = 0; $i < count($this->_elements->elements); $i++) { - $o .= $this->_elements->elements[$i]->display($this->_layout); + // create the search- and replace-arrays + $replace = $search = array(); + foreach (array_keys ($element) as $id) { + if (substr ($id, 0, 1) == '_') { + continue; + } + $search[] = '<'.$id.' />'; + $replace[] = $element[$id]; } - echo str_replace ('<content />', $o, $this->_layout['document']); + return str_replace ($search, $replace, $this->_layout[$element['_type']]."\n"); } + + + /** * Einlesen der Templatedatei * @@ -153,20 +305,38 @@ } 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 ($layoutfile); - $layout =& $XML->getTreeFromFile (); - foreach ($layout->children as $a) { - if (!isset($a->name)) { + $this->_layoutdata =& $XML->getTreeFromFile (); + $num = count ($this->_layoutdata->children); + for ($i = 0; $i < $num; $i++) { + if (!isset($this->_layoutdata->children[$i]->name)) { continue; } - $this->_layout[$a->name] =& $a->content; + $this->_layout[$this->_layoutdata->children[$i]->name] =& $this->_layoutdata->children[$i]->content; + } + } + + + /** + * save the templatedata into the xml-file + * + * @access private + **/ + function _saveLayoutFile () { + $layoutfile = dirname(__FILE__).'/layout.xml'; + + $fh = fopen ($layoutfile, 'wb'); + if ($fh === false) { + $actiondata = array ('errortext'=>'Layoutdatei konnte nicht geöffnet werden!'); + $this->_callEvent ('ERROR_NOTICE', $actiondata); } + fwrite ($fh, $this->_layoutdata->get()); + fclose ($fh); } } --- class.layout_phpcms.php DELETED --- Index: layout.dtd =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/layout/layout.dtd,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- layout.dtd 30 May 2004 18:03:41 -0000 1.1 +++ layout.dtd 4 Jun 2004 11:11:58 -0000 1.2 @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!ELEMENT layout ( + document, block, paragraph, headline, @@ -18,11 +19,12 @@ menu_sub )> -<!ELEMENT form (#PCDATA)> +<!ELEMENT document (#PCDATA)> <!ELEMENT block (#PCDATA)> <!ELEMENT paragraph (#PCDATA)> <!ELEMENT headline (#PCDATA)> <!ELEMENT image (#PCDATA)> +<!ELEMENT form (#PCDATA)> <!ELEMENT form_input_hidden (#PCDATA)> <!ELEMENT form_input_text (#PCDATA)> <!ELEMENT form_input_password (#PCDATA)> --- NEW FILE: layout.css --- html, body { width:100%; font-size:100.01%; padding:0; border:0; margin:0; background:#fff; } #content { margin-left:190px; padding:0; } .content { padding:0.5em; } #menu { position:fixed; top:0; left:0; height:100%; width:190px; margin:0; padding:0; border-right:0.1em solid #000; border-bottom:0.1em solid #000; } #menu ul { list-style-type:none; padding:0; margin:0; } #menu ul li { padding:0.2em; margin:0.1em; } #menu ul li ul { margin-left:1em; } #menu ul li ul li { margin-left:1em; } .content { background:#fff; } label span { display:block; } textarea { width:95%; height:10em; } #submenu { padding: 3px 0; margin: 0; border-bottom: 1px solid #778; font: bold 12px Verdana, sans-serif; } #submenu li { list-style: none; margin: 0; display: inline; } #submenu li a { padding: 3px 0.5em; margin-left: 3px; border: 1px solid #778; border-bottom: none; background: #DDE; text-decoration: none; } #submenu li a:link { color: #448; } #submenu li a:visited { color: #667; } #submenu li a:hover { color: #000; background: #AAE; border-color: #227; } #submenu li#current a { background: white; border-bottom: 1px solid white; } |