openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 61eec9e60e34e7eadaf19d431146fd059d9b2f2a
parent bedb228114fede8c97c3fb52b453be7931af95e4
Author: dankert <devnull@localhost>
Date:   Fri,  9 Jul 2004 22:57:29 +0200

Dynamische Bereiche (IFEMPTY...)

Diffstat:
actionClasses/TemplateAction.class.php | 874++++++++++++++++++++++++++++++++++++++++++-------------------------------------
objectClasses/Page.class.php | 1273++++++++++++++++++++++++++++++++++++++++---------------------------------------
2 files changed, 1110 insertions(+), 1037 deletions(-)

diff --git a/actionClasses/TemplateAction.class.php b/actionClasses/TemplateAction.class.php @@ -1,413 +1,465 @@ -<?php -// --------------------------------------------------------------------------- -// $Id$ -// --------------------------------------------------------------------------- -// OpenRat Content Management System -// Copyright (C) 2002-2004 Jan Dankert, cms@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. -// --------------------------------------------------------------------------- +<?php +// --------------------------------------------------------------------------- +// $Id$ +// --------------------------------------------------------------------------- +// OpenRat Content Management System +// Copyright (C) 2002-2004 Jan Dankert, cms@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. +// --------------------------------------------------------------------------- // $Log$ -// Revision 1.3 2004-05-07 21:34:58 dankert -// Url über Html::url erzeugen -// -// Revision 1.2 2004/05/02 14:49:37 dankert -// Einfügen package-name (@package) -// -// Revision 1.1 2004/04/24 15:14:52 dankert -// Initiale Version -// -// --------------------------------------------------------------------------- - -/** - * Action-Klasse zum Bearbeiten einer Seitenvorlage - * @author $Author$ - * @version $Revision$ - * @package openrat.actions - */ - -class TemplateAction extends Action -{ - var $defaultSubAction = 'show'; - var $template; - var $element; - - - function TemplateAction() - { - $this->template = new Template( $this->getSessionVar('templateid') ); - $this->template->load(); - - if ( $this->getSessionVar('elementid') != '' ) - { - $this->element = new Element( $this->getSessionVar('elementid') ); - $this->element->load(); - } - } - - - function srcsave() - { - // Speichern des Quelltextes - // - $text = $this->getRequestVar('src'); - - // Falls dieses Element hinzugefügt werden soll - if ( $this->getRequestVar('addelement') != '' ) - { - $text .= "\n".'{{'.$this->getRequestVar('elementid').'}}'; - } - - if ( $this->getRequestVar('addicon') != '' ) - { - $text .= "\n".'{{->'.$this->getRequestVar('iconid').'}}'; - } - - foreach( $this->template->getElementNames() as $elid=>$elname ) - { - $text = str_replace('{{'.$elname.'}}' ,'{{'.$elid.'}}',$text ); - $text = str_replace('{{->'.$elname.'}}','{{->'.$elid.'}}',$text ); - } - - $this->template->src = $text; - $this->template->save(); - $this->template->load(); - - // Wenn Element hinzugefügt wurde, dann bleibt es beim Quelltext-Modus. - // Sonst wird zur Anzeige umgeschaltet - - if ( $this->getRequestVar('addelement') != '' || - $this->getRequestVar('addicon' ) != '' ) - { - $this->callSubAction('src'); - } - else - { - $this->callSubAction('show'); - } - } - - - // Speichern der Template-Eigenschaftens - // - function propsave() - { - if ( $this->getRequestVar('delete') != '' ) - { - $this->template->delete(); - - $this->callSubAction('listing'); - } - else - { - $this->template->name = $this->getRequestVar('name'); - $this->template->save(); - - $this->callSubAction('show'); - } - } - - - // Speichern der Dateiendung - // - function extensionsave() - { - if ( $this->getRequestVar('extension') != '' ) - { - $this->template->extension = $this->getRequestVar('extension'); - $this->template->save(); - } - - $this->callSubAction('show'); - } - - - // Element hinzufügen - // - function addelement() - { - if ( $this->getRequestVar('name') != '' ) - { - $this->template->addElement( $this->getRequestVar('name') ); - } - - $this->setTemplateVar('tree_refresh',true); - - $this->callSubAction('el'); - } - - - function add() - { - // Hinzufügen eines Templates - if ( $this->getRequestVar('name') != '' ) - { - Template::add( $this->getRequestVar('name') ); - } - - $this->setTemplateVar('tree_refresh',true); - - $this->callSubAction('listing'); - } - - - /** - * Umbenennen des Elementes - */ - function elementrename() - { - if ($this->getRequestVar('delete') != '') - { - $this->element->delete(); - } - elseif ($this->getRequestVar('deletevalues') != '') - { - $this->element->deleteValues(); - } - else - { - $this->element->name = $this->getRequestVar('name'); - $this->element->desc = $this->getRequestVar('desc'); - - $this->element->save(); - $this->element->load(); - } - - $this->setTemplateVar('tree_refresh',true); - - $this->callSubAction('el'); - } - - - /** - * Speichern der Element-Eigenschaften - */ - function elementsave() - { - $ini_date_format = parse_ini_file( CONF_LANGUAGEDIR.'/dateformat.ini.'.CONF_PHP ); - - foreach( $this->element->getRelatedProperties() as $propertyName ) - { - switch( $propertyName ) - { - case 'dateformat': - $this->element->dateformat = $ini_date_format[$this->getRequestVar('dateformat')]; - break; - - case 'subtype': - $this->element->subtype = $this->getRequestVar('subtype'); - break; - - case 'defaultText': - $this->element->defaultText = $this->getRequestVar('default_text'); - break; - - case 'wiki': - $this->element->wiki = $this->getRequestVar('wiki') != ''; - break; - - case 'html': - $this->element->html = $this->getRequestVar('html') != ''; - break; - - case 'withIcon': - $this->element->withIcon = $this->getRequestVar('with_icon') != ''; - break; - - case 'allLanguages': - $this->element->allLanguages = $this->getRequestVar('all_languages') != ''; - break; - - case 'writable': - $this->element->writable = $this->getRequestVar('writable') != ''; - break; - - case 'decimals': - $this->element->decimals = $this->getRequestVar('decimals'); - break; - - case 'decPoint': - $this->element->decPoint = $this->getRequestVar('dec_point'); - break; - - case 'thousandSep': - $this->element->thousandSep = $this->getRequestVar('thousand_sep'); - break; - - case 'folderObjectId': - $this->element->folderObjectId = $this->getRequestVar('folderobjectid' ); - break; - - case 'defaultObjectId': - $this->element->defaultObjectId = $this->getRequestVar('default_objectid'); - break; - - case 'code': - $this->element->code = $this->getRequestVar('code' ); - break; - } - } - $this->element->save(); - - $this->callSubAction('el'); - } - - - function prop() - { - $this->setTemplateVar('extension',$this->template->extension); - $this->setTemplateVar('name' ,$this->template->name ); - - // von diesem Template abhängige Seiten ermitteln - // - $list = array(); - foreach( $this->template->getDependentObjectIds() as $oid ) - { - $page = new Page( $oid ); - $page->load(); - $list[$oid] = array(); - $list[$oid]['name'] = $page->name; - $list[$oid]['url' ] = Html::url(array('action'=>'main','callAction'=>'page','objectid'=>$oid)); - } - $this->setTemplateVar('pages',$list ); - - $this->forward('template_prop'); - } - - - // Bearbeiten - // - function show() - { - global $conf_php; - - $text = htmlentities( $this->template->src ); - $text = str_replace("\n",'<br>',$text); - - foreach( $this->template->getElementIds() as $elid ) - { - $element = new Element( $elid ); - $element->load(); - - $text = str_replace('{{'.$elid.'}}', - '<a href="'.Html::url(array('action'=>'element','subaction'=>'edit','elementid'=>$elid)). - '" class="el_'. - $element->type.'" target="cms_main_main" title="'.$element->desc.'">{{'. - $element->name.'}}</a>', - $text ); - $text = str_replace('{{-&gt;'.$elid.'}}', - '<a href="'.Html::url(array('action'=>'element','subaction'=>'edit','elementid'=>$elid)). - '" class="el_'. - $element->type.'" target="cms_main_main" title="'.$element->desc.'">{{-&gt;'. - $element->name.'}}</a>', - $text ); - - unset( $element ); - } - - $this->setTemplateVar('text',$text); - - $this->forward('template_show'); - } - - - // Anzeigen der Template-Elemente - // - function el() - { - global $conf_php; - $list = array(); - - foreach( $this->template->getElementIds() as $elid ) - { - $element = new Element( $elid ); - $element->load(); - - $list[$elid] = array(); - $list[$elid]['url' ] = Html::url(array('action'=>'element','subaction'=>'edit','elementid'=>$elid)); - $list[$elid]['name'] = $element->name; - $list[$elid]['desc'] = $element->desc; - $list[$elid]['type'] = $element->type; - - unset( $element ); - } - $this->setTemplateVar('el',$list); - $this->forward('template_el'); - } - - - // Anzeigen des Template-Quellcodes - // - function src() - { - $elements = array(); - $icon_elements = array(); - $text = $this->template->src; - - foreach( $this->template->getElementIds() as $elid ) - { - $element = new Element( $elid ); - $element->load(); - - $elements[$elid] = $element->name; - - $element = new Element( $elid ); - $element->load(); - - if ( $element->type != 'info' && - $element->type != 'infodate' && - $element->type != 'code' ) - $icon_elements[$elid] = lang('icon').' '.$element->name; - - $text = str_replace('{{'.$elid.'}}', - '{{'.$element->name.'}}', - $text ); - $text = str_replace('{{->'.$elid.'}}', - '{{->'.$element->name.'}}', - $text ); - } - - $this->setTemplateVar('elements' ,$elements ); - $this->setTemplateVar('icon_elements',$icon_elements ); - $this->setTemplateVar('text' ,htmlentities($text)); - - $this->forward('template_src'); - } - - - // Anzeigen aller Templates - // - function listing() - { - global $conf_php; - - $list = array(); - - foreach( Template::getAll() as $id=>$name ) - { - $list[$id] = array(); - $list[$id]['name'] = $name; - $list[$id]['url'] = Html::url(array('action'=>'main','callAction'=>'template','templateid'=>$id)); - } - -// $var['templatemodelid'] = htmlentities( $id ); -// $var['text'] = htmlentities( $text ); - $this->setTemplateVar('templates',$list); - - $this->forward('template_list'); - - } - +// Revision 1.4 2004-07-09 20:57:29 dankert +// Dynamische Bereiche (IFEMPTY...) +// +// Revision 1.3 2004/05/07 21:34:58 dankert +// Url über Html::url erzeugen +// +// Revision 1.2 2004/05/02 14:49:37 dankert +// Einfügen package-name (@package) +// +// Revision 1.1 2004/04/24 15:14:52 dankert +// Initiale Version +// +// --------------------------------------------------------------------------- + +/** + * Action-Klasse zum Bearbeiten einer Seitenvorlage + * @author $Author$ + * @version $Revision$ + * @package openrat.actions + */ + +class TemplateAction extends Action +{ + var $defaultSubAction = 'show'; + var $template; + var $element; + + + function TemplateAction() + { + $this->template = new Template( $this->getSessionVar('templateid') ); + $this->template->load(); + + if ( $this->getSessionVar('elementid') != '' ) + { + $this->element = new Element( $this->getSessionVar('elementid') ); + $this->element->load(); + } + } + + + function srcsave() + { + // Speichern des Quelltextes + // + $text = $this->getRequestVar('src'); + + // Falls dieses Element hinzugefügt werden soll + if ( $this->getRequestVar('addelement') != '' ) + { + $text .= "\n".'{{'.$this->getRequestVar('elementid').'}}'; + } + + if ( $this->getRequestVar('addicon') != '' ) + { + $text .= "\n".'{{->'.$this->getRequestVar('iconid').'}}'; + } + + if ( $this->getRequestVar('addifempty') != '' ) + { + $text .= "\n".'{{IFEMPTY:'.$this->getRequestVar('ifemptyid').':BEGIN}} {{IFEMPTY:'.$this->getRequestVar('ifemptyid').':END}}'; + } + if ( $this->getRequestVar('addifnotempty') != '' ) + { + $text .= "\n".'{{IFNOTEMPTY:'.$this->getRequestVar('ifnotemptyid').':BEGIN}} {{IFNOTEMPTY:'.$this->getRequestVar('ifnotemptyid').':END}}'; + } + + foreach( $this->template->getElementNames() as $elid=>$elname ) + { + $text = str_replace('{{'.$elname.'}}' ,'{{'.$elid.'}}',$text ); + $text = str_replace('{{->'.$elname.'}}','{{->'.$elid.'}}',$text ); + $text = str_replace('{{'.lang('IFEMPTY' ).':'.$elname.':'.lang('BEGIN').'}}','{{IFEMPTY:' .$elid.':BEGIN}}',$text ); + $text = str_replace('{{'.lang('IFEMPTY' ).':'.$elname.':'.lang('END' ).'}}','{{IFEMPTY:' .$elid.':END}}' ,$text ); + $text = str_replace('{{'.lang('IFNOTEMPTY').':'.$elname.':'.lang('BEGIN').'}}','{{IFNOTEMPTY:'.$elid.':BEGIN}}',$text ); + $text = str_replace('{{'.lang('IFNOTEMPTY').':'.$elname.':'.lang('END' ).'}}','{{IFNOTEMPTY:'.$elid.':END}}' ,$text ); + } + + $this->template->src = $text; + $this->template->save(); + $this->template->load(); + + // Wenn Element hinzugefügt wurde, dann bleibt es beim Quelltext-Modus. + // Sonst wird zur Anzeige umgeschaltet + + if ( $this->getRequestVar('addelement' ) != '' || + $this->getRequestVar('addicon' ) != '' || + $this->getRequestVar('addifempty' ) != '' || + $this->getRequestVar('addifnotempty') != '' ) + { + $this->callSubAction('src'); + } + else + { + $this->callSubAction('show'); + } + } + + + // Speichern der Template-Eigenschaftens + // + function propsave() + { + if ( $this->getRequestVar('delete') != '' ) + { + $this->template->delete(); + + $this->callSubAction('listing'); + } + else + { + $this->template->name = $this->getRequestVar('name'); + $this->template->save(); + + $this->callSubAction('show'); + } + } + + + // Speichern der Dateiendung + // + function extensionsave() + { + if ( $this->getRequestVar('extension') != '' ) + { + $this->template->extension = $this->getRequestVar('extension'); + $this->template->save(); + } + + $this->callSubAction('show'); + } + + + // Element hinzufügen + // + function addelement() + { + if ( $this->getRequestVar('name') != '' ) + { + $this->template->addElement( $this->getRequestVar('name') ); + } + + $this->setTemplateVar('tree_refresh',true); + + $this->callSubAction('el'); + } + + + function add() + { + // Hinzufügen eines Templates + if ( $this->getRequestVar('name') != '' ) + { + Template::add( $this->getRequestVar('name') ); + } + + $this->setTemplateVar('tree_refresh',true); + + $this->callSubAction('listing'); + } + + + /** + * Umbenennen des Elementes + */ + function elementrename() + { + if ($this->getRequestVar('delete') != '') + { + $this->element->delete(); + } + elseif ($this->getRequestVar('deletevalues') != '') + { + $this->element->deleteValues(); + } + else + { + $this->element->name = $this->getRequestVar('name'); + $this->element->desc = $this->getRequestVar('desc'); + + $this->element->save(); + $this->element->load(); + } + + $this->setTemplateVar('tree_refresh',true); + + $this->callSubAction('el'); + } + + + /** + * Speichern der Element-Eigenschaften + */ + function elementsave() + { + $ini_date_format = parse_ini_file( CONF_LANGUAGEDIR.'/dateformat.ini.'.CONF_PHP ); + + foreach( $this->element->getRelatedProperties() as $propertyName ) + { + switch( $propertyName ) + { + case 'dateformat': + $this->element->dateformat = $ini_date_format[$this->getRequestVar('dateformat')]; + break; + + case 'subtype': + $this->element->subtype = $this->getRequestVar('subtype'); + break; + + case 'defaultText': + $this->element->defaultText = $this->getRequestVar('default_text'); + break; + + case 'wiki': + $this->element->wiki = $this->getRequestVar('wiki') != ''; + break; + + case 'html': + $this->element->html = $this->getRequestVar('html') != ''; + break; + + case 'withIcon': + $this->element->withIcon = $this->getRequestVar('with_icon') != ''; + break; + + case 'allLanguages': + $this->element->allLanguages = $this->getRequestVar('all_languages') != ''; + break; + + case 'writable': + $this->element->writable = $this->getRequestVar('writable') != ''; + break; + + case 'decimals': + $this->element->decimals = $this->getRequestVar('decimals'); + break; + + case 'decPoint': + $this->element->decPoint = $this->getRequestVar('dec_point'); + break; + + case 'thousandSep': + $this->element->thousandSep = $this->getRequestVar('thousand_sep'); + break; + + case 'folderObjectId': + $this->element->folderObjectId = $this->getRequestVar('folderobjectid' ); + break; + + case 'defaultObjectId': + $this->element->defaultObjectId = $this->getRequestVar('default_objectid'); + break; + + case 'code': + $this->element->code = $this->getRequestVar('code' ); + break; + } + } + $this->element->save(); + + $this->callSubAction('el'); + } + + + function prop() + { + $this->setTemplateVar('extension',$this->template->extension); + $this->setTemplateVar('name' ,$this->template->name ); + + // von diesem Template abhängige Seiten ermitteln + // + $list = array(); + foreach( $this->template->getDependentObjectIds() as $oid ) + { + $page = new Page( $oid ); + $page->load(); + $list[$oid] = array(); + $list[$oid]['name'] = $page->name; + $list[$oid]['url' ] = Html::url(array('action'=>'main','callAction'=>'page','objectid'=>$oid)); + } + $this->setTemplateVar('pages',$list ); + + $this->forward('template_prop'); + } + + + // Bearbeiten + // + function show() + { + global $conf_php; + + $text = htmlentities( $this->template->src ); + $text = str_replace("\n",'<br>',$text); + + foreach( $this->template->getElementIds() as $elid ) + { + $element = new Element( $elid ); + $element->load(); + $url = Html::url(array('action'=>'element','subaction'=>'edit','elementid'=>$elid)); + + $text = str_replace('{{'.$elid.'}}', + '<a href="'.$url.'" class="el_'. + $element->type.'" target="cms_main_main" title="'.$element->desc.'">{{'. + $element->name.'}}</a>', + $text ); + $text = str_replace('{{-&gt;'.$elid.'}}', + '<a href="'.$url.'" class="el_'. + $element->type.'" target="cms_main_main" title="'.$element->desc.'">{{-&gt;'. + $element->name.'}}</a>', + $text ); + + $text = str_replace('{{IFEMPTY:'.$elid.':BEGIN}}', + '<a href="'.$url.'" class="el_'.$element->type.'" title="'.$element->desc.'">{{'.lang('IFEMPTY').':'. + $element->name.':'.lang('BEGIN').'}}</a>', + $text ); + $text = str_replace('{{IFEMPTY:'.$elid.':END}}', + '<a href="'.$url.'" class="el_'.$element->type.'" title="'.$element->desc.'">{{'.lang('IFEMPTY').':'. + $element->name.':'.lang('END').'}}</a>', + $text ); + + $text = str_replace('{{IFNOTEMPTY:'.$elid.':BEGIN}}', + '<a href="'.$url.'" class="el_'.$element->type.'" title="'.$element->desc.'">{{'.lang('IFNOTEMPTY').':'. + $element->name.':'.lang('BEGIN').'}}</a>', + $text ); + $text = str_replace('{{IFNOTEMPTY:'.$elid.':END}}', + '<a href="'.$url.'" class="el_'.$element->type.'" title="'.$element->desc.'">{{'.lang('IFNOTEMPTY').':'. + $element->name.':'.lang('END').'}}</a>', + $text ); + + unset( $element ); + } + + $this->setTemplateVar('text',$text); + + $this->forward('template_show'); + } + + + // Anzeigen der Template-Elemente + // + function el() + { + global $conf_php; + $list = array(); + + foreach( $this->template->getElementIds() as $elid ) + { + $element = new Element( $elid ); + $element->load(); + + $list[$elid] = array(); + $list[$elid]['url' ] = Html::url(array('action'=>'element','subaction'=>'edit','elementid'=>$elid)); + $list[$elid]['name'] = $element->name; + $list[$elid]['desc'] = $element->desc; + $list[$elid]['type'] = $element->type; + + unset( $element ); + } + $this->setTemplateVar('el',$list); + $this->forward('template_el'); + } + + + /** + * Anzeigen des Template-Quellcodes + */ + function src() + { + $elements = array(); + $icon_elements = array(); + $text = $this->template->src; + + foreach( $this->template->getElementIds() as $elid ) + { + $element = new Element( $elid ); + $element->load(); + + $elements[$elid] = $element->name; + + $element = new Element( $elid ); + $element->load(); + + if ( $element->isWritable() ) + { + $icon_elements [$elid] = lang('icon' ).' '.$element->name; + $ifempty_elements [$elid] = lang('ifempty' ).' '.$element->name; + $ifnotempty_elements[$elid] = lang('ifnotempty').' '.$element->name; + } + + $text = str_replace('{{'.$elid.'}}', + '{{'.$element->name.'}}', + $text ); + $text = str_replace('{{->'.$elid.'}}', + '{{->'.$element->name.'}}', + $text ); + $text = str_replace('{{IFEMPTY:'.$elid.':BEGIN}}', + '{{'.lang('IFEMPTY').':'.$element->name.':'.lang('BEGIN').'}}', + $text ); + $text = str_replace('{{IFEMPTY:'.$elid.':END}}', + '{{'.lang('IFEMPTY').':'.$element->name.':'.lang('END').'}}', + $text ); + $text = str_replace('{{IFNOTEMPTY:'.$elid.':BEGIN}}', + '{{'.lang('IFNOTEMPTY').':'.$element->name.':'.lang('BEGIN').'}}', + $text ); + $text = str_replace('{{IFNOTEMPTY:'.$elid.':END}}', + '{{'.lang('IFNOTEMPTY').':'.$element->name.':'.lang('END').'}}', + $text ); + } + + $this->setTemplateVar('elements' ,$elements ); + $this->setTemplateVar('icon_elements' ,$icon_elements ); + $this->setTemplateVar('ifempty_elements' ,$ifempty_elements ); + $this->setTemplateVar('ifnotempty_elements',$ifnotempty_elements ); + $this->setTemplateVar('text' ,htmlentities($text) ); + + $this->forward('template_src'); + } + + + // Anzeigen aller Templates + // + function listing() + { + global $conf_php; + + $list = array(); + + foreach( Template::getAll() as $id=>$name ) + { + $list[$id] = array(); + $list[$id]['name'] = $name; + $list[$id]['url'] = Html::url(array('action'=>'main','callAction'=>'template','templateid'=>$id)); + } + +// $var['templatemodelid'] = htmlentities( $id ); +// $var['text'] = htmlentities( $text ); + $this->setTemplateVar('templates',$list); + + $this->forward('template_list'); + + } + } \ No newline at end of file diff --git a/objectClasses/Page.class.php b/objectClasses/Page.class.php @@ -1,629 +1,650 @@ -<?php -// --------------------------------------------------------------------------- -// $Id$ -// --------------------------------------------------------------------------- -// DaCMS 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. -// --------------------------------------------------------------------------- +<?php +// --------------------------------------------------------------------------- +// $Id$ +// --------------------------------------------------------------------------- +// DaCMS 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. +// --------------------------------------------------------------------------- // $Log$ -// Revision 1.6 2004-07-07 20:47:22 dankert +// Revision 1.7 2004-07-09 20:57:14 dankert +// Dynamische Bereiche (IFEMPTY...) +// +// Revision 1.6 2004/07/07 20:47:22 dankert // Korrektur f. Verkn?pfungen -// -// Revision 1.5 2004/05/07 21:41:14 dankert -// Url ?ber Html::url erzeugen -// -// Revision 1.4 2004/05/02 14:41:31 dankert -// Einf?gen package-name (@package) -// -// Revision 1.3 2004/05/02 11:40:00 dankert -// Freigabestatus der Seiteninhalte verarbeiten -// -// Revision 1.2 2004/04/24 15:28:17 dankert -// Korrektur: relative Pfad bei Listen -// -// Revision 1.1 2004/04/24 15:15:12 dankert -// Initiale Version -// -// Revision 1.1 2004/03/20 14:15:00 dankert -// Kommentare -// -// --------------------------------------------------------------------------- - - -/** - * Darstellen einer Seite - * - * @version $Revision$ - * @author $Author$ - * @package openrat.objects - */ - -class Page extends Object -{ - var $pageid; - var $templateid; - - var $simple = false; - var $public = false; - - var $el = array(); - - var $icons = false; - var $src = ''; - var $tmpfile; - var $edit = false; - - var $content_negotiation = false; - var $cut_index = false; - var $default_language = false; - var $link = false; - - var $log_filenames = array(); - var $projectmodelid = 0; - - var $publish = null; - var $up_path = ''; - - - function Page( $objectid='' ) - { - $this->Object( $objectid ); - $this->isPage = true; - } - - - function tmpfile() - { - $this->tmpfile = parent::tmpfile(); - $this->tmpfile .= '.php'; - return $this->tmpfile; - } - - - /** - * Ermitteln der Objekt-ID (Tabelle object) anhand der Seiten-ID (Tablle page) - * - * @deprecated pageid sollte nicht mehr benutzt werden - * @return Integer objectid - */ - function getObjectIdFromPageId( $pageid ) - { - $db = db_connection(); - - $sql = new Sql( 'SELECT objectid FROM {t_page} '. - ' WHERE id={pageid}' ); - $sql->setInt('pageid',$pageid); - - return $db->getOne( $sql->query ); - } - - - /** - * Ermitteln der Seiten-ID anhand der Objekt-ID - * - * @deprecated pageid sollte nicht mehr benutzt werden - * @return Integer pageid - */ - function getPageIdFromObjectId( $objectid ) - { - $db = db_connection(); - - $sql = new Sql( 'SELECT id FROM {t_page} '. - ' WHERE objectid={objectid}' ); - $sql->setInt('objectid',$objectid); - - return $db->getOne( $sql->query ); - } - - - /** - * Ermitteln aller Eigenschaften - * - * @return Array - */ - function getProperties() - { - return array_merge( parent::getProperties(), - Array('full_filename'=>$this->full_filename(), - 'pageid' =>$this->pageid, - 'templateid' =>$this->templateid ) ); - } - - - /** - * Ermitteln der Ordner, in dem sich die Seite befindet - * @return Array - */ - function parentfolder() - { - $folder = new Folder(); - $folder->folderid = $this->folderid; - - return $folder->parentfolder( false,false ); - } - - -/* - function path_to_file( $fileid ) - { - global $conf_php; - - if ( $this->public ) - { - $inhalt = $this->up_path(); - - $file = new File(); - $file->fileid = $fileid; - $file->load(); - - $inhalt .= $file->full_filename(); - } - else - { - $inhalt = "file.$conf_php?fileaction=show&fileid=".$fileid; - $inhalt = sid($inhalt); - } - - return $inhalt; - } -*/ - - /** - * Ermittelt den Pfad zu einem beliebigen Objekt - * - * @param Integer Objekt-ID des Zielobjektes - * @return String Relative Link-angabe, Beispiel: '../../pfad/datei.jpeg' - */ - function path_to_object( $objectid ) - { - global $conf_php, - $SESS; - $inhalt = ''; - $object = new Object( $objectid ); - $object->objectLoad(); - - - if ( $this->public ) - { - switch( $object->getType() ) - { - case 'file': - - $inhalt = $this->up_path(); - - $f = new File( $objectid ); - $f->load(); - $inhalt .= $f->full_filename(); - break; - - case 'page': - - $inhalt = $this->up_path(); - - $p = new Page( $objectid ); - $p->languageid = $this->languageid; - $p->load(); - $inhalt .= $p->full_filename(); - break; - - case 'link': - $link = new Link( $objectid ); - $link->load(); - - if ( $link->isLinkToObject ) - { - $linkedObject = new Object( $link->linkedObjectId ); - $linkedObject->load(); - - switch( $linkedObject->getType() ) - { - case 'file': - $f = new File( $link->linkedObjectId ); - $f->load(); - $inhalt = $this->up_path(); - $inhalt .= $f->full_filename(); - break; - - case 'page': - $p = new Page( $link->linkedObjectId ); - $p->languageid = $this->languageid; - $p->load(); - $inhalt = $this->up_path(); - $inhalt .= $p->full_filename(); - break; - } - } - else - { - $inhalt = $link->url; - } - break; - } - } - else - { - // Interne Verlinkungen in der Seitenvorschau - switch( $object->getType() ) - { - case 'file': - $inhalt = Html::url(array('action'=>'file','subaction'=>'show','objectid'=>$objectid)); - break; - - case 'page': - $inhalt = Html::url(array('action'=>'page','objectid'=>$objectid)); - break; - - case 'link': - $link = new Link( $objectid ); - $link->load(); - - if ( $link->isLinkToObject ) - { - $linkedObject = new Object( $link->linkedObjectId ); - $linkedObject->load(); - - switch( $linkedObject->getType() ) - { - case 'file': - $inhalt = Html::url(array('action'=>'file','subaction'=>'show','objectid'=>$link->linkedObjectId)); - break; - - case 'page': - $inhalt = Html::url(array('action'=>'page','objectid'=>$link->linkedObjectId)); - break; - } - } - else - { - $inhalt = $link->url; - } - break; - } - } - - return $inhalt; - } - - - - /** - * Erzeugt Pr?fix f?r eine relative Pfadangabe - * Beispiel: Seite liegt in Ordner /pfad/pfad dann '../../' - * - * @return String Pfadangabe - * @access private - */ - function up_path() - { - if ( $this->up_path != '' ) - return $this->up_path; - - $folder = new Folder( $this->parentid ); - $folder->load(); - $folder->parentObjectIds(false,true); - $f = count( $folder->parentfolders ); - - //echo $this->parentid; - //print_r( $folder->parentfolders ); - - if ( $f == 0 ) - { - $this->up_path = './'; - } - else - { - $this->up_path = str_repeat( '../',$f ); - } - - return $this->up_path; - } - - - /** - * getter-Methode f?r den Dateinamen - * - * @return String Dateiname - */ - function filename() - { - return $this->filename; - } - - - /** - * Eine Seite hinzufuegen - */ - function add() - { - $db = db_connection(); - - $this->objectAdd(); // Hinzuf?gen von Objekt (dabei wird Objekt-ID ermittelt) - - $sql = new Sql('SELECT MAX(id) FROM {t_page}'); - $this->pageid = intval($db->getOne($sql->query))+1; - - $sql = new Sql('INSERT INTO {t_page}'. - ' (id,objectid,templateid)'. - ' VALUES( {pageid},{objectid},{templateid} )' ); - $sql->setInt ('pageid' ,$this->pageid ); - $sql->setInt ('objectid' ,$this->objectid ); - $sql->setInt ('templateid',$this->templateid ); - - $db->query( $sql->query ); - } - - - /** - * Seite laden - */ - function load() - { - $db = db_connection(); - - $sql = new Sql( 'SELECT * FROM {t_page} '. - ' WHERE objectid={objectid}' ); - $sql->setInt('objectid',$this->objectid); - $row = $db->getRow( $sql->query ); - - $this->pageid = $row['id' ]; - $this->templateid = $row['templateid']; - - $this->objectLoad(); - } - - - function delete() - { - global $db; - - $sql = new Sql( 'DELETE FROM {t_value} '. - ' WHERE pageid={pageid}' ); - $sql->setInt('pageid',$this->pageid); - $db->query( $sql->query ); - - $sql = new Sql( 'DELETE FROM {t_page} '. - ' WHERE objectid={objectid}' ); - $sql->setInt('objectid',$this->objectid); - $db->query( $sql->query ); - - $this->objectDelete(); - } - - - function save() - { - $db = db_connection(); - - $sql = new Sql('UPDATE {t_page}'. - ' SET templateid ={templateid}'. - ' WHERE objectid={objectid}' ); - $sql->setInt('templateid' ,$this->templateid); - $sql->setInt('objectid' ,$this->objectid ); - $db->query( $sql->query ); - - $this->objectSave(); - } - - - - /** - * Ermitteln des Dateinamens dieser Seite - * - * @return String Kompletter Dateiname, z.B. '/pfad/seite.en.html' - */ - function full_filename() - { - $filename = parent::full_filename(); - - if ( !$this->default_language ) - { - $l = new Language( $this->languageid ); - $l->load(); - $filename .= '.'.$l->isoCode; - } - - $t = new Template( $this->templateid ); - $t->projectmodelid = $this->modelid; - $t->load(); - $filename .= '.'.$t->extension; - - if ( $this->default_language ) - { - $filename .= '.'.$t->extension; - } - - return $filename; - } - - - function language_filename() - { - global $SESS; - - $db = db_connection(); - - $sql = new Sql( 'SELECT COUNT(*) FROM {t_language}'. - ' WHERE projectid={projectid}' ); - $sql->setInt('projectid',$SESS['projectid']); - - if ( $db->getOne( $sql->query ) == 1 ) - { - // Wenn es nur eine Sprache gibt, keine Sprachangabe im Dateinamen - return ''; - } - else - { - $sql = new Sql( 'SELECT isocode FROM {t_language}'. - ' WHERE id={languageid}' ); - $sql->setInt('languageid',$this->languageid); - $isocode = $db->getOne( $sql->query ); - - return strtolower( $isocode ); - } - } - - - /** - * Erzeugen der Inhalte zu allen Elementen dieser Seite - * wird von generate() aufgerufen - * - * @access private - */ - function generate_elements() - { - $this->values = array(); - - $t = new Template( $this->templateid ); - - foreach( $t->getElementIds() as $elementid ) - { - // neues Elementobjekt erzeugen - $val = new Value(); - $val->publish = $this->public; - $val->element = new Element( $elementid ); - $val->element->load(); - - $val->objectid = $this->objectid; - $val->pageid = Page::getPageIdFromObjectId( $this->objectid ); - $val->languageid = $this->languageid; - $val->simple = $this->simple; - $val->modelid = $this->modelid; - $val->page = &$this; - $val->generate(); - $this->values[$elementid] = $val; - } - } - - - /** - * Erzeugen des Inhaltes der gesamten Seite - * @return String Inhalt - */ - function generate() - { - - global $conf, - $conf_php, - $db, - $conf_tmpdir, - $sess_vars, - $SESS; - - $this->generate_elements(); - - $template = new Template( $this->templateid ); - $template->load(); - - $this->ext = $template->extension; - - $src = $template->src; - - // Ersetzen der Platzhalter durch die Element-Inhalte - // - - foreach( $this->values as $id=>$value ) - { - $inh = $value->value; - $src = str_replace( '{{'.$id.'}}',$inh,$src ); - - if ( $this->icons ) - $src = str_replace( '{{->'.$id.'}}','<a href="'.Html::url(array('action'=>'pagelement','elementid'=>$id,'subaction'=>'edit')).'" title="'.$value->element->desc.'" target="cms_main_main"><img src="'.$conf['directories']['themedir'].'/images/icon_el_'.$value->element->type.'.png" border="0"></a>',$src ); - else $src = str_replace( '{{->'.$id.'}}','',$src ); - } - - $this->value = &$src; - - return $this->value; - } - - - /** - * Schreiben des Seiteninhaltes in die temporaere Datei - */ - function write() - { - // Schreiben der Cache-Datei - // - - $f = fopen( $this->tmpfile(),'w' ); - fwrite( $f,$this->value ); - fclose( $f ); - } - - - /** - * Generieren dieser Seite in Dateisystem und/oder auf FTP-Server - */ - function publish() - { - global $SESS; - $db = db_connection(); - - if ( ! is_object($this->publish) ) - $this->publish = new Publish(); - - $this->content_negotiation = $this->publish->content_negotiation; - $this->cut_index = $this->publish->cut_index; - $this->public = true; - - // Schleife ?ber alle Sprachvarianten - foreach( Language::getAll() as $languageid=>$x ) - { - $this->languageid = $languageid; - - // Schleife ?ber alle Projektvarianten - foreach( Model::getAll() as $projectmodelid ) - { - $this->projectmodelid = $projectmodelid; - - $this->load(); - $this->generate(); - $this->write(); - - //echo $this->tmpfile().' &gt; '.$this->full_filename().'<br>'; - $this->publish->copy( $this->tmpfile(),$this->full_filename() ); - } - } - - // Bei Verwendung der Content-Negotiation wird eine Default-Variante - // ohne Sprachversion, aber mit doppelter Extension - // z.B. index.html.html erzeugt - if ( $this->publish->content_negotiation && count(Language::getAll())>1 ) - { - $this->languageid = Language::getDefaultId(); - $this->default_language = true; - - // Schleife ?ber alle Projektvarianten - foreach( Model::getAll() as $projectmodelid ) - { - $this->projectmodelid = $projectmodelid; - - $this->load(); - $this->generate(); - $this->write(); - - //echo $this->tmpfile().' &gt; '.$this->full_filename().'<br>'; - $publish->copy( $this->tmpfile(),$this->full_filename() ); - } - } - -// $this->log_filenames = $this->publish->log_filenames; - } -} - - +// +// Revision 1.5 2004/05/07 21:41:14 dankert +// Url ?ber Html::url erzeugen +// +// Revision 1.4 2004/05/02 14:41:31 dankert +// Einf?gen package-name (@package) +// +// Revision 1.3 2004/05/02 11:40:00 dankert +// Freigabestatus der Seiteninhalte verarbeiten +// +// Revision 1.2 2004/04/24 15:28:17 dankert +// Korrektur: relative Pfad bei Listen +// +// Revision 1.1 2004/04/24 15:15:12 dankert +// Initiale Version +// +// Revision 1.1 2004/03/20 14:15:00 dankert +// Kommentare +// +// --------------------------------------------------------------------------- + + +/** + * Darstellen einer Seite + * + * @version $Revision$ + * @author $Author$ + * @package openrat.objects + */ + +class Page extends Object +{ + var $pageid; + var $templateid; + + var $simple = false; + var $public = false; + + var $el = array(); + + var $icons = false; + var $src = ''; + var $tmpfile; + var $edit = false; + + var $content_negotiation = false; + var $cut_index = false; + var $default_language = false; + var $link = false; + + var $log_filenames = array(); + var $projectmodelid = 0; + + var $publish = null; + var $up_path = ''; + + + function Page( $objectid='' ) + { + $this->Object( $objectid ); + $this->isPage = true; + } + + + function tmpfile() + { + $this->tmpfile = parent::tmpfile(); + $this->tmpfile .= '.php'; + return $this->tmpfile; + } + + + /** + * Ermitteln der Objekt-ID (Tabelle object) anhand der Seiten-ID (Tablle page) + * + * @deprecated pageid sollte nicht mehr benutzt werden + * @return Integer objectid + */ + function getObjectIdFromPageId( $pageid ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT objectid FROM {t_page} '. + ' WHERE id={pageid}' ); + $sql->setInt('pageid',$pageid); + + return $db->getOne( $sql->query ); + } + + + /** + * Ermitteln der Seiten-ID anhand der Objekt-ID + * + * @deprecated pageid sollte nicht mehr benutzt werden + * @return Integer pageid + */ + function getPageIdFromObjectId( $objectid ) + { + $db = db_connection(); + + $sql = new Sql( 'SELECT id FROM {t_page} '. + ' WHERE objectid={objectid}' ); + $sql->setInt('objectid',$objectid); + + return $db->getOne( $sql->query ); + } + + + /** + * Ermitteln aller Eigenschaften + * + * @return Array + */ + function getProperties() + { + return array_merge( parent::getProperties(), + Array('full_filename'=>$this->full_filename(), + 'pageid' =>$this->pageid, + 'templateid' =>$this->templateid ) ); + } + + + /** + * Ermitteln der Ordner, in dem sich die Seite befindet + * @return Array + */ + function parentfolder() + { + $folder = new Folder(); + $folder->folderid = $this->folderid; + + return $folder->parentfolder( false,false ); + } + + +/* + function path_to_file( $fileid ) + { + global $conf_php; + + if ( $this->public ) + { + $inhalt = $this->up_path(); + + $file = new File(); + $file->fileid = $fileid; + $file->load(); + + $inhalt .= $file->full_filename(); + } + else + { + $inhalt = "file.$conf_php?fileaction=show&fileid=".$fileid; + $inhalt = sid($inhalt); + } + + return $inhalt; + } +*/ + + /** + * Ermittelt den Pfad zu einem beliebigen Objekt + * + * @param Integer Objekt-ID des Zielobjektes + * @return String Relative Link-angabe, Beispiel: '../../pfad/datei.jpeg' + */ + function path_to_object( $objectid ) + { + global $conf_php, + $SESS; + $inhalt = ''; + $object = new Object( $objectid ); + $object->objectLoad(); + + + if ( $this->public ) + { + switch( $object->getType() ) + { + case 'file': + + $inhalt = $this->up_path(); + + $f = new File( $objectid ); + $f->load(); + $inhalt .= $f->full_filename(); + break; + + case 'page': + + $inhalt = $this->up_path(); + + $p = new Page( $objectid ); + $p->languageid = $this->languageid; + $p->load(); + $inhalt .= $p->full_filename(); + break; + + case 'link': + $link = new Link( $objectid ); + $link->load(); + + if ( $link->isLinkToObject ) + { + $linkedObject = new Object( $link->linkedObjectId ); + $linkedObject->load(); + + switch( $linkedObject->getType() ) + { + case 'file': + $f = new File( $link->linkedObjectId ); + $f->load(); + $inhalt = $this->up_path(); + $inhalt .= $f->full_filename(); + break; + + case 'page': + $p = new Page( $link->linkedObjectId ); + $p->languageid = $this->languageid; + $p->load(); + $inhalt = $this->up_path(); + $inhalt .= $p->full_filename(); + break; + } + } + else + { + $inhalt = $link->url; + } + break; + } + } + else + { + // Interne Verlinkungen in der Seitenvorschau + switch( $object->getType() ) + { + case 'file': + $inhalt = Html::url(array('action'=>'file','subaction'=>'show','objectid'=>$objectid)); + break; + + case 'page': + $inhalt = Html::url(array('action'=>'page','objectid'=>$objectid)); + break; + + case 'link': + $link = new Link( $objectid ); + $link->load(); + + if ( $link->isLinkToObject ) + { + $linkedObject = new Object( $link->linkedObjectId ); + $linkedObject->load(); + + switch( $linkedObject->getType() ) + { + case 'file': + $inhalt = Html::url(array('action'=>'file','subaction'=>'show','objectid'=>$link->linkedObjectId)); + break; + + case 'page': + $inhalt = Html::url(array('action'=>'page','objectid'=>$link->linkedObjectId)); + break; + } + } + else + { + $inhalt = $link->url; + } + break; + } + } + + return $inhalt; + } + + + + /** + * Erzeugt Pr?fix f?r eine relative Pfadangabe + * Beispiel: Seite liegt in Ordner /pfad/pfad dann '../../' + * + * @return String Pfadangabe + * @access private + */ + function up_path() + { + if ( $this->up_path != '' ) + return $this->up_path; + + $folder = new Folder( $this->parentid ); + $folder->load(); + $folder->parentObjectIds(false,true); + $f = count( $folder->parentfolders ); + + //echo $this->parentid; + //print_r( $folder->parentfolders ); + + if ( $f == 0 ) + { + $this->up_path = './'; + } + else + { + $this->up_path = str_repeat( '../',$f ); + } + + return $this->up_path; + } + + + /** + * getter-Methode f?r den Dateinamen + * + * @return String Dateiname + */ + function filename() + { + return $this->filename; + } + + + /** + * Eine Seite hinzufuegen + */ + function add() + { + $db = db_connection(); + + $this->objectAdd(); // Hinzuf?gen von Objekt (dabei wird Objekt-ID ermittelt) + + $sql = new Sql('SELECT MAX(id) FROM {t_page}'); + $this->pageid = intval($db->getOne($sql->query))+1; + + $sql = new Sql('INSERT INTO {t_page}'. + ' (id,objectid,templateid)'. + ' VALUES( {pageid},{objectid},{templateid} )' ); + $sql->setInt ('pageid' ,$this->pageid ); + $sql->setInt ('objectid' ,$this->objectid ); + $sql->setInt ('templateid',$this->templateid ); + + $db->query( $sql->query ); + } + + + /** + * Seite laden + */ + function load() + { + $db = db_connection(); + + $sql = new Sql( 'SELECT * FROM {t_page} '. + ' WHERE objectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $row = $db->getRow( $sql->query ); + + $this->pageid = $row['id' ]; + $this->templateid = $row['templateid']; + + $this->objectLoad(); + } + + + function delete() + { + global $db; + + $sql = new Sql( 'DELETE FROM {t_value} '. + ' WHERE pageid={pageid}' ); + $sql->setInt('pageid',$this->pageid); + $db->query( $sql->query ); + + $sql = new Sql( 'DELETE FROM {t_page} '. + ' WHERE objectid={objectid}' ); + $sql->setInt('objectid',$this->objectid); + $db->query( $sql->query ); + + $this->objectDelete(); + } + + + function save() + { + $db = db_connection(); + + $sql = new Sql('UPDATE {t_page}'. + ' SET templateid ={templateid}'. + ' WHERE objectid={objectid}' ); + $sql->setInt('templateid' ,$this->templateid); + $sql->setInt('objectid' ,$this->objectid ); + $db->query( $sql->query ); + + $this->objectSave(); + } + + + + /** + * Ermitteln des Dateinamens dieser Seite + * + * @return String Kompletter Dateiname, z.B. '/pfad/seite.en.html' + */ + function full_filename() + { + $filename = parent::full_filename(); + + if ( !$this->default_language ) + { + $l = new Language( $this->languageid ); + $l->load(); + $filename .= '.'.$l->isoCode; + } + + $t = new Template( $this->templateid ); + $t->projectmodelid = $this->modelid; + $t->load(); + $filename .= '.'.$t->extension; + + if ( $this->default_language ) + { + $filename .= '.'.$t->extension; + } + + return $filename; + } + + + function language_filename() + { + global $SESS; + + $db = db_connection(); + + $sql = new Sql( 'SELECT COUNT(*) FROM {t_language}'. + ' WHERE projectid={projectid}' ); + $sql->setInt('projectid',$SESS['projectid']); + + if ( $db->getOne( $sql->query ) == 1 ) + { + // Wenn es nur eine Sprache gibt, keine Sprachangabe im Dateinamen + return ''; + } + else + { + $sql = new Sql( 'SELECT isocode FROM {t_language}'. + ' WHERE id={languageid}' ); + $sql->setInt('languageid',$this->languageid); + $isocode = $db->getOne( $sql->query ); + + return strtolower( $isocode ); + } + } + + + /** + * Erzeugen der Inhalte zu allen Elementen dieser Seite + * wird von generate() aufgerufen + * + * @access private + */ + function generate_elements() + { + $this->values = array(); + + $t = new Template( $this->templateid ); + + foreach( $t->getElementIds() as $elementid ) + { + // neues Elementobjekt erzeugen + $val = new Value(); + $val->publish = $this->public; + $val->element = new Element( $elementid ); + $val->element->load(); + + $val->objectid = $this->objectid; + $val->pageid = Page::getPageIdFromObjectId( $this->objectid ); + $val->languageid = $this->languageid; + $val->simple = $this->simple; + $val->modelid = $this->modelid; + $val->page = &$this; + $val->generate(); + $this->values[$elementid] = $val; + } + } + + + /** + * Erzeugen des Inhaltes der gesamten Seite + * @return String Inhalt + */ + function generate() + { + + global $conf, + $conf_php, + $db, + $conf_tmpdir, + $sess_vars, + $SESS; + + $this->generate_elements(); + + $template = new Template( $this->templateid ); + $template->load(); + + $this->ext = $template->extension; + + $src = $template->src; + + // Ersetzen der Platzhalter durch die Element-Inhalte + // + + foreach( $this->values as $id=>$value ) + { + $inh = $value->value; + $src = str_replace( '{{'.$id.'}}',$inh,$src ); + + // Dynamische Bereiche ein- oder ausblenden + if ( $inh == '' ) + { + // Wenn Feld leer + $src = str_replace( '{{IFEMPTY:'.$id.':BEGIN}}','',$src ); + $src = str_replace( '{{IFEMPTY:'.$id.':END}}' ,'',$src ); + + $src = eregi_replace( '{{IFNOTEMPTY:'.$id.':BEGIN}}.*{{IFNOTEMPTY:'.$id.':END}}','',$src ); + } + else + { + // Wenn Feld gefüllt + $src = str_replace( '{{IFNOTEMPTY:'.$id.':BEGIN}}','',$src ); + $src = str_replace( '{{IFNOTEMPTY:'.$id.':END}}' ,'',$src ); + + $src = eregi_replace( '{{IFEMPTY:'.$id.':BEGIN}}.*{{IFEMPTY:'.$id.':END}}','',$src ); + } + + if ( $this->icons ) + $src = str_replace( '{{->'.$id.'}}','<a href="'.Html::url(array('action'=>'pagelement','elementid'=>$id,'subaction'=>'edit')).'" title="'.$value->element->desc.'" target="cms_main_main"><img src="'.$conf['directories']['themedir'].'/images/icon_el_'.$value->element->type.'.png" border="0"></a>',$src ); + else $src = str_replace( '{{->'.$id.'}}','',$src ); + } + + $this->value = &$src; + + return $this->value; + } + + + /** + * Schreiben des Seiteninhaltes in die temporaere Datei + */ + function write() + { + // Schreiben der Cache-Datei + // + + $f = fopen( $this->tmpfile(),'w' ); + fwrite( $f,$this->value ); + fclose( $f ); + } + + + /** + * Generieren dieser Seite in Dateisystem und/oder auf FTP-Server + */ + function publish() + { + global $SESS; + $db = db_connection(); + + if ( ! is_object($this->publish) ) + $this->publish = new Publish(); + + $this->content_negotiation = $this->publish->content_negotiation; + $this->cut_index = $this->publish->cut_index; + $this->public = true; + + // Schleife ?ber alle Sprachvarianten + foreach( Language::getAll() as $languageid=>$x ) + { + $this->languageid = $languageid; + + // Schleife ?ber alle Projektvarianten + foreach( Model::getAll() as $projectmodelid ) + { + $this->projectmodelid = $projectmodelid; + + $this->load(); + $this->generate(); + $this->write(); + + //echo $this->tmpfile().' &gt; '.$this->full_filename().'<br>'; + $this->publish->copy( $this->tmpfile(),$this->full_filename() ); + } + } + + // Bei Verwendung der Content-Negotiation wird eine Default-Variante + // ohne Sprachversion, aber mit doppelter Extension + // z.B. index.html.html erzeugt + if ( $this->publish->content_negotiation && count(Language::getAll())>1 ) + { + $this->languageid = Language::getDefaultId(); + $this->default_language = true; + + // Schleife ?ber alle Projektvarianten + foreach( Model::getAll() as $projectmodelid ) + { + $this->projectmodelid = $projectmodelid; + + $this->load(); + $this->generate(); + $this->write(); + + //echo $this->tmpfile().' &gt; '.$this->full_filename().'<br>'; + $publish->copy( $this->tmpfile(),$this->full_filename() ); + } + } + +// $this->log_filenames = $this->publish->log_filenames; + } +} + + ?> \ No newline at end of file