openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

PageelementAction.class.php (39762B)


      1 <?php
      2 
      3 namespace cms\action;
      4 
      5 use cms\model\Acl;
      6 use cms\model\Project;
      7 use cms\model\User;
      8 use cms\model\Value;
      9 use cms\model\Element;
     10 use cms\model\Template;
     11 use cms\model\Page;
     12 use cms\model\Folder;
     13 use cms\model\BaseObject;
     14 use cms\publish\PublishEdit;
     15 use cms\publish\PublishPreview;
     16 use cms\publish\PublishShow;
     17 use Html;
     18 use Http;
     19 use LogicException;
     20 use Session;
     21 use Transformer;
     22 use \Text;
     23 use ValidationException;
     24 
     25 // OpenRat Content Management System
     26 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
     27 //
     28 // This program is free software; you can redistribute it and/or
     29 // modify it under the terms of the GNU General Public License
     30 // as published by the Free Software Foundation; either version 2
     31 // of the License, or (at your option) any later version.
     32 //
     33 // This program is distributed in the hope that it will be useful,
     34 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     35 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     36 // GNU General Public License for more details.
     37 //
     38 // You should have received a copy of the GNU General Public License
     39 // along with this program; if not, write to the Free Software
     40 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     41 
     42 
     43 /**
     44  * Action-Klasse zum Bearbeiten eines Seitenelementes
     45  * @author $Author$
     46  * @version $Revision$
     47  * @package openrat.actions
     48  */
     49 class PageelementAction extends BaseAction
     50 {
     51 	public $security = Action::SECURITY_USER;
     52 
     53 
     54 	/**
     55 	 * Enthaelt das Seitenobjekt
     56 	 * @type Page
     57 	 */
     58 	var $page;
     59 
     60 	/**
     61 	 * Enthaelt das Elementobjekt
     62 	 * @type Element
     63 	 */
     64 	var $element;
     65 
     66 
     67 	/**
     68 	 * Enth�lt den Inhalt
     69 	 *
     70 	 * @var Value
     71 	 */
     72 	var $value;
     73 
     74 
     75 
     76 	/**
     77 	 * Konstruktor
     78 	 */
     79 	function __construct()
     80 	{
     81         parent::__construct();
     82     }
     83 
     84 
     85     public function init()
     86     {
     87 
     88         $this->value = new Value();
     89         $this->value->publisher = new PublishPreview();
     90 
     91 		$id = $this->request->id;
     92 		$ids = explode('_',$id);
     93 		if	( count($ids) > 1 )
     94 		{
     95 			list( $pageid, $elementid ) = $ids;
     96 		}
     97 		else
     98 		{
     99 			$pageid    = $this->getRequestId();
    100 			$elementid = $this->getRequestVar('elementid');
    101 		}
    102 
    103 		if	( $pageid != 0  )
    104 		{
    105 			$this->page = new Page( $pageid );
    106 
    107             if  ( $this->hasRequestVar('languageid'))
    108                 $this->page->languageid = $this->getRequestId('languageid');
    109 
    110             $this->page->load();
    111 		}
    112 
    113 		if	( $elementid != 0 )
    114 		{
    115 			$this->elementid = $elementid;
    116 			$this->element   = new Element( $elementid );
    117 		}
    118 	}
    119 
    120 
    121 
    122 	/**
    123 	 * Anzeigen des Element-Inhaltes.
    124 	 */
    125 	public function propView()
    126 	{
    127 		$this->value->languageid = $this->page->languageid;
    128 		$this->value->objectid   = $this->page->objectid;
    129 		$this->value->pageid     = $this->page->pageid;
    130 		$this->value->page       = $this->page;
    131 		$this->value->simple = false;
    132 		$this->value->element = &$this->element;
    133 		$this->value->element->load();
    134 		$this->value->load();
    135 
    136 		$this->setTemplateVar('name'        ,$this->value->element->name     );
    137 		$this->setTemplateVar('description' ,$this->value->element->desc     );
    138 		$this->setTemplateVar('elementid'   ,$this->value->element->elementid);
    139 		$this->setTemplateVar('element_type',$this->value->element->type     );
    140 
    141 		$user = new User( $this->value->lastchangeUserId );
    142 		$user->load();
    143 		$this->setTemplateVar('lastchange_user',$user->getProperties());
    144 		$this->setTemplateVar('lastchange_date',$this->value->lastchangeTimeStamp);
    145 
    146 		$t = new Template( $this->page->templateid );
    147 		$t->load();
    148 		$this->setTemplateVar('template_name',$t->name );
    149 		$this->setTemplateVar('template_url' ,Html::url('template','prop',$t->templateid) );
    150 
    151 		$this->setTemplateVar('element_name' ,$this->value->element->name );
    152 		$this->setTemplateVar('element_url'  ,Html::url('element','name',$this->value->element->elementid) );
    153 
    154 	}
    155 
    156 
    157 
    158 	/**
    159 	 * Anzeigen des Element-Inhaltes.
    160 	 */
    161 	public function infoView()
    162 	{
    163 		$this->value->languageid = $this->page->languageid;
    164 		$this->value->objectid   = $this->page->objectid;
    165 		$this->value->pageid     = $this->page->pageid;
    166 		$this->value->page       = $this->page;
    167 		$this->value->simple = false;
    168 		$this->value->element = &$this->element;
    169 		$this->value->element->load();
    170 		$this->value->load();
    171 
    172 		$this->setTemplateVar('name'          ,$this->value->element->name     );
    173 		$this->setTemplateVar('description'   ,$this->value->element->desc     );
    174 		$this->setTemplateVar('elementid'     ,$this->value->element->elementid);
    175         $this->setTemplateVar('element_id'    ,$this->value->element->elementid );
    176         $this->setTemplateVar('element_name'  ,$this->value->element->name );
    177 		$this->setTemplateVar('element_type'  ,$this->value->element->getTypeName() );
    178 		$this->setTemplateVar('element_format',Element::getAvailableFormats()[ $this->value->element->format] );
    179 		$this->setTemplateVar('format'        ,@Element::getAvailableFormats()[ $this->value->format         ] );
    180 
    181 		$user = new User( $this->value->lastchangeUserId );
    182 
    183 		try{
    184             $user->load();
    185         }catch (\ObjectNotFoundException $e) {
    186 		    $user = new User(); // Empty User.
    187         }
    188 
    189         $this->setTemplateVar('lastchange_user',$user->getProperties());
    190         $this->setTemplateVar('lastchange_date',$this->value->lastchangeTimeStamp);
    191 
    192 		$t = new Template( $this->page->templateid );
    193 		$t->load();
    194 		$this->setTemplateVar('template_name',$t->name );
    195 		$this->setTemplateVar('template_id'  ,$t->templateid );
    196 
    197 
    198 	}
    199 
    200 
    201 
    202 	/**
    203 	 * Anzeigen des Element-Inhaltes.
    204 	 */
    205 	public function structureView()
    206 	{
    207 		$this->value->languageid = $this->page->languageid;
    208 		$this->value->objectid   = $this->page->objectid;
    209 		$this->value->pageid     = $this->page->pageid;
    210 		$this->value->page       = $this->page;
    211 		$this->value->simple = false;
    212 		$this->value->element = &$this->element;
    213 		$this->value->element->load();
    214 		$this->value->load();
    215 
    216 		if	( $this->value->element->type == 'longtext' && $this->value->element->wiki )
    217 		{
    218 			$this->setTemplateVar('text',$this->value->text);
    219 		}
    220 
    221 	}
    222 
    223 
    224 
    225 	/**
    226 	 * Normaler Editiermodus.
    227 	 *
    228 	 * Es wird ein Formular erzeugt, mit dem der Benutzer den Inhalt bearbeiten kann.
    229 	 */
    230 	public function editView()
    231 	{
    232 		$this->value->objectid   = $this->page->objectid;
    233 		$this->value->pageid     = $this->page->pageid;
    234 		$this->value->page       = $this->page;
    235 		$this->value->element = &$this->element;
    236 		$this->value->element->load();
    237 		$this->value->publisher = new PublishEdit();
    238 
    239 		$this->setTemplateVar('name'       ,$this->value->element->label    );
    240 		$this->setTemplateVar('description',$this->value->element->desc     );
    241 		$this->setTemplateVar('elementid'  ,$this->value->element->elementid);
    242 		$this->setTemplateVar('type'       ,$this->value->element->getTypeName() );
    243 
    244 		$languages = array();
    245 
    246 		foreach ( $this->page->getProject()->getLanguages() as $languageId=>$languageName )
    247         {
    248             $this->value->languageid = $languageId;
    249             $this->value->load();
    250 
    251             $languages[$languageId] = array(
    252                 'languageid'   => $languageId,
    253                 'languagename' => $languageName,
    254                 'value'        => $this->value->generate()
    255             );
    256         }
    257 
    258         $this->setTemplateVar('languages',$languages);
    259 	}
    260 
    261 
    262 
    263 
    264 
    265 
    266 	/**
    267 	 * Erweiterter Modus.
    268 	 */
    269 	public function advancedView()
    270 	{
    271 		$this->value->objectid   = $this->page->objectid;
    272 		$this->value->pageid     = $this->page->pageid;
    273 		$this->value->page       = $this->page;
    274 		$this->value->element = &$this->element;
    275 		$this->value->element->load();
    276 		$this->value->publisher = new PublishEdit();
    277 
    278 		$this->setTemplateVar('name'       ,$this->value->element->label    );
    279 		$this->setTemplateVar('description',$this->value->element->desc     );
    280 		$this->setTemplateVar('elementid'  ,$this->value->element->elementid);
    281 		$this->setTemplateVar('type'       ,$this->value->element->getTypeName() );
    282 
    283 		$languages = array();
    284 
    285 		foreach ( $this->page->getProject()->getLanguages() as $languageId=>$languageName )
    286         {
    287             $this->value->languageid = $languageId;
    288             $this->value->load();
    289 
    290             $languages[$languageId] = array(
    291                 'languageid'   => $languageId,
    292                 'languagename' => $languageName,
    293                 'value'        => $this->value->generate(),
    294                 'editors'      => Element::getAvailableFormats()
    295             );
    296         }
    297 
    298         $this->setTemplateVar('languages',$languages);
    299 	}
    300 
    301 
    302 
    303 	public function valueView()
    304 	{
    305 		$this->value->languageid = $this->page->languageid;
    306 		$this->value->objectid   = $this->page->objectid;
    307 		$this->value->pageid     = $this->page->pageid;
    308 		$this->value->element = &$this->element;
    309 		$this->value->element->load();
    310 		$this->value->publish = false;
    311 
    312 		if	( intval($this->value->valueid)!=0 )
    313 		$this->value->loadWithId();
    314 		else
    315 		$this->value->load();
    316 
    317 		$this->setTemplateVar('name'     ,$this->value->element->name     );
    318 		$this->setTemplateVar('desc'     ,$this->value->element->desc     );
    319 		$this->setTemplateVar('elementid',$this->value->element->elementid);
    320 		$this->setTemplateVar('languageid',$this->value->languageid       );
    321 		$this->setTemplateVar('type'     ,$this->value->element->getTypeName() );
    322 		$this->setTemplateVar('value_time',time() );
    323 
    324 
    325 		$this->value->page             = new Page( $this->page->objectid );
    326 		$this->value->page->languageid = $this->value->languageid;
    327 		$this->value->page->load();
    328 
    329 		$this->setTemplateVar( 'objectid',$this->value->page->objectid );
    330 
    331 		if	( $this->value->page->hasRight(Acl::ACL_RELEASE) )
    332 		$this->setTemplateVar( 'release',true  );
    333 		if	( $this->value->page->hasRight(Acl::ACL_PUBLISH) )
    334 		$this->setTemplateVar( 'publish',false );
    335 
    336 		$funktionName = 'edit'.$this->value->element->type;
    337 
    338 		if	( ! method_exists($this,$funktionName) )
    339 		throw new \LogicException('Method does not exist: PageElementAction#'.$funktionName );
    340 
    341 		$this->$funktionName(); // Aufruf der Funktion "edit<Elementtyp>()".
    342 	}
    343 
    344 
    345 
    346 	/**
    347 	 * Vorschau.
    348 	 */
    349 	public function previewView()
    350 	{
    351 		$this->value->languageid = $this->page->languageid;
    352 		$this->value->objectid   = $this->page->objectid;
    353 		$this->value->pageid     = $this->page->pageid;
    354 		$this->value->element = &$this->element;
    355 		$this->value->element->load();
    356 
    357 		if	( intval($this->value->valueid)!=0 )
    358 		$this->value->loadWithId();
    359 		else
    360 		$this->value->load();
    361 
    362 
    363 		$this->value->page             = new Page( $this->page->objectid );
    364 		$this->value->page->languageid = $this->value->languageid;
    365 		$this->value->page->load();
    366 
    367 		$this->value->generate();
    368 		$this->setTemplateVar('preview' ,$this->value->value );
    369 	}
    370 
    371 
    372 
    373 	/**
    374 	 * Datum bearbeiten.
    375 	 *
    376 	 */
    377 	private function editdate()
    378 	{
    379         $this->setTemplateVar( 'date' ,$this->value->date==null?'':date('Y-m-d',$this->value->date) );
    380         $this->setTemplateVar( 'time' ,$this->value->date==null?'':date('H:i'  ,$this->value->date) );
    381     }
    382 
    383 
    384 
    385 	/**
    386 	 * Verkn�pfung bearbeiten.
    387 	 *
    388 	 */
    389 	private function editlink()
    390 	{
    391         $project = new Project($this->page->projectid);
    392 		$this->setTemplateVar('rootfolderid',$project->getRootObjectId() );
    393 		
    394 		// Ermitteln, welche Objekttypen verlinkt werden d�rfen.
    395 		$type = $this->value->element->subtype;
    396 
    397 		if	( substr($type,0,5) == 'image' )
    398 		$type = 'file';
    399 			
    400 		if	( !in_array($type,array('file','page','link','folder')) )
    401 			$types = array('file','page','link'); // Fallback: Der Link kann auf Seiten,Dateien und Verknüpfungen zeigen
    402 		else
    403 			$types = array($type); // gewünschten Typ verwenden
    404 
    405         $oid  = $this->value->linkToObjectId;
    406         $name = '';
    407 
    408         if   ( $oid ) {
    409             $o = new BaseObject($oid);
    410             $o->load();
    411             $name = $o->filename;
    412         }
    413 
    414 		$this->setTemplateVar('objects'         ,array() );
    415 		$this->setTemplateVar('linkobjectid',$oid );
    416 		$this->setTemplateVar('linkname'    ,$name);
    417 
    418 		$this->setTemplateVar('types',implode(',',$types));
    419 
    420 		if	( $this->getSessionVar('pageaction') != '' )
    421     		$this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
    422 		else
    423 	    	$this->setTemplateVar('old_pageaction','show'                            );
    424 	}
    425 
    426 
    427 
    428 	function linkView()
    429 	{
    430 		$this->value->languageid = $this->page->languageid;
    431 		$this->value->objectid   = $this->page->objectid;
    432 		$this->value->pageid     = $this->page->pageid;
    433 		$this->value->element = &$this->element;
    434 		$this->value->element->load();
    435 		$this->value->load();
    436 
    437 		$this->setTemplateVar('name'     ,$this->value->element->name     );
    438 		$this->setTemplateVar('desc'     ,$this->value->element->desc     );
    439 
    440         $project = new Project($this->page->projectid);
    441         $this->setTemplateVar('rootfolderid'     ,$project->getRootObjectId() );
    442 		
    443 		// Ermitteln, welche Objekttypen verlinkt werden d�rfen.
    444 		if	( empty($this->value->element->subtype) )
    445 		$types = array('page','file','link'); // Fallback: Alle erlauben :)
    446 		else
    447 		$types = explode(',',$this->value->element->subtype );
    448 
    449 		$objects = array();
    450 			
    451 		$objects[ 0 ] = lang('LIST_ENTRY_EMPTY'); // Wert "nicht ausgewählt"
    452 
    453 		
    454 		$t = new Template( $this->page->templateid );
    455 
    456 		foreach( $t->getDependentObjectIds() as $id )
    457 		{
    458 			$o = new BaseObject( $id );
    459 			$o->load();
    460 				
    461 			//			if	( in_array( $o->getType(),$types ))
    462 			//			{
    463 			$f = new Folder( $o->parentid );
    464 			//					$f->load();
    465 
    466 			$objects[ $id ]  = lang( $o->getType() ).': ';
    467 			$objects[ $id ] .=  implode( FILE_SEP,$f->parentObjectNames(false,true) );
    468 			$objects[ $id ] .= FILE_SEP.$o->name;
    469 			//			}
    470 		}
    471 
    472         asort( $objects ); // Sortieren
    473 
    474         $this->setTemplateVar('objects'         ,$objects);
    475         $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId);
    476 
    477         if	( $this->getSessionVar('pageaction') != '' )
    478         $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
    479         else	$this->setTemplateVar('old_pageaction','show'                            );
    480 
    481         $this->value->page             = new Page( $this->page->objectid );
    482         $this->value->page->languageid = $this->value->languageid;
    483         $this->value->page->load();
    484 
    485         $this->setTemplateVar( 'release',$this->value->page->hasRight(Acl::ACL_RELEASE) );
    486         $this->setTemplateVar( 'publish',$this->value->page->hasRight(Acl::ACL_PUBLISH) );
    487 
    488         $this->setTemplateVar( 'objectid',$this->value->page->objectid );
    489     }
    490 
    491 
    492 
    493     /**
    494      * Auswahlbox.
    495      *
    496      */
    497     private function editselect()
    498     {
    499         $this->setTemplateVar( 'items',$this->value->element->getSelectItems() );
    500         $this->setTemplateVar( 'text' ,$this->value->text                      );
    501 
    502 
    503         if	( $this->getSessionVar('pageaction') != '' )
    504         $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
    505         else	$this->setTemplateVar('old_pageaction','show'                            );
    506     }
    507 
    508 
    509 
    510     /**
    511      * Einf�gen-Element.
    512      *
    513      */
    514     private function editlist()
    515     {
    516         $this->editinsert();
    517     }
    518 
    519 
    520 
    521     /**
    522      * Einf�gen-Element.
    523      *
    524      */
    525     private function editinsert()
    526     {
    527         // Auswahl ueber alle Elementtypen
    528         $objects = array();
    529         //Änderung der möglichen Types
    530         $types = array('file','page','link');
    531         $objects[ 0 ] = lang('LIST_ENTRY_EMPTY'); // Wert "nicht ausgewählt"
    532 
    533         $project = new Project( $this->page->projectid );
    534         $folder = new Folder($project->getRootObjectId());
    535         $folder->load();
    536 
    537         //Auch Dateien dazu
    538         foreach( $project->getAllObjectIds($types) as $id )
    539         {
    540             $f = new Folder( $id );
    541             $f->load();
    542 
    543             $objects[ $id ]  = lang( $f->getType() ).': ';
    544             $objects[ $id ] .=  implode( ' &raquo; ',$f->parentObjectNames(false,true) );
    545         }
    546 
    547         foreach( $project->getAllFolders() as $id )
    548         {
    549             $f = new Folder( $id );
    550             $f->load();
    551 
    552             $objects[ $id ]  = lang( $f->getType() ).': ';
    553             $objects[ $id ] .=  implode( ' &raquo; ',$f->parentObjectNames(false,true) );
    554         }
    555 
    556         asort( $objects ); // Sortieren
    557 
    558         $this->setTemplateVar('objects'         ,$objects);
    559         $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId);
    560 
    561 
    562         if	( $this->getSessionVar('pageaction') != '' )
    563         $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
    564         else	$this->setTemplateVar('old_pageaction','show'                            );
    565     }
    566 
    567 
    568 
    569     /**
    570      * Zahl bearbeiten.
    571      *
    572      */
    573     private function editnumber()
    574     {
    575         $this->setTemplateVar('number',$this->value->number / pow(10,$this->value->element->decimals) );
    576 
    577         if	( $this->getSessionVar('pageaction') != '' )
    578         $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
    579         else	$this->setTemplateVar('old_pageaction','show'                            );
    580     }
    581 
    582 
    583     /**
    584      * Ein Element der Seite bearbeiten
    585      *
    586      * Es wird ein Formular erzeugt, mit dem der Benutzer den Inhalt bearbeiten kann.
    587      */
    588     private function editlongtext()
    589     {
    590 
    591         if   ( $this->hasRequestVar('format') )
    592             // Individual format from request.
    593             $format = $this->getRequestId('format');
    594         elseif   ( $this->value->format != null )
    595             $format = $this->value->format;
    596         else
    597             // There is no saved value. Get the format from the template element.
    598             $format = $this->element->format;
    599 
    600         $this->setTemplateVar('format'   ,$format );
    601         $this->setTemplateVar( 'editor',Element::getAvailableFormats()[ $format ] );
    602 
    603         if ( !isset($this->templateVars['text']))
    604             // Möglicherweise ist die Ausgabevariable bereits gesetzt, wenn man bereits
    605             // einen Text eingegeben hat (Vorschaufunktion).
    606             $this->setTemplateVar( 'text',$this->linkifyOIDs( $this->value->text ) );
    607 
    608 
    609         if	( $this->getSessionVar('pageaction') != '' )
    610         $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
    611         else	$this->setTemplateVar('old_pageaction','show'                            );
    612 
    613 
    614 
    615         if	( $this->element->wiki && false /* OLD */ )
    616         {
    617             $project = new Project( $this->page->projectid );
    618             $languages = $project->getLanguages();
    619 
    620             if	( count($languages) > 1 )
    621             {
    622                 $languages[$this->value->languageid] = $languages[$this->value->languageid].' *';
    623                 $this->setTemplateVar('languages',$languages);
    624             }
    625 
    626             if	( $this->hasRequestVar('otherlanguageid') )
    627             {
    628                 $lid = $this->getRequestVar('otherlanguageid');
    629                 $otherValue = new Value();
    630                 $otherValue->languageid = $lid;
    631                 $otherValue->pageid     = $this->value->pageid;
    632                 $otherValue->element    = $this->value->element;
    633                 $otherValue->elementid  = $this->value->elementid;
    634                 $otherValue->publisher    = $this->value->publisher;
    635                 $otherValue->load();
    636                 $this->setTemplateVar('languagetext'   ,wordwrap($otherValue->text,100)  );
    637                 $this->setTemplateVar('languagename'   ,$languages[$lid]   );
    638                 $this->setTemplateVar('otherlanguageid',$lid               );
    639             }
    640 
    641             if ( !isset($this->templateVars['text']))
    642             // Möglicherweise ist die Ausgabevariable bereits gesetzt, wenn man bereits
    643             // einen Text eingegeben hat (Vorschaufunktion).
    644             $this->setTemplateVar( 'text',$this->value->text          );
    645         }
    646 
    647     }
    648 
    649 
    650 
    651     /**
    652      * Ein Element der Seite bearbeiten
    653      *
    654      * Es wird ein Formular erzeugt, mit dem der Benutzer den Inhalt bearbeiten kann.
    655      */
    656     private function edittext()
    657     {
    658         $this->setTemplateVar( 'text',$this->value->text );
    659 
    660         if	( $this->getSessionVar('pageaction') != '' )
    661         $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction'));
    662         else	$this->setTemplateVar('old_pageaction','show'                            );
    663     }
    664 
    665 
    666 
    667     /**
    668      * Wiederherstellung eines alten Inhaltes.
    669      */
    670     public function usePost()
    671     {
    672         $this->value->valueid = $this->getRequestVar('valueid');
    673         $this->value->loadWithId();
    674         $this->value->element = new Element( $this->value->elementid );
    675 
    676         if	( $this->value->pageid != $this->page->pageid )
    677             throw new \LogicException( 'Cannot find value','page-id does not match' );
    678 
    679         // Pruefen, ob Berechtigung zum Freigeben besteht
    680         //$this->value->release = $this->page->hasRight(Acl::ACL_RELEASE);
    681         $this->value->release = false;
    682 
    683         // Inhalt wieder herstellen, in dem er neu gespeichert wird.
    684         $this->value->save();
    685 
    686         $this->addNotice('pageelement',$this->value->element->name,'PAGEELEMENT_USE_FROM_ARCHIVE',OR_NOTICE_OK);
    687     }
    688 
    689 
    690 
    691     /**
    692      * Freigeben eines Inhaltes
    693      */
    694     public function releasePost()
    695     {
    696         $this->value->valueid = intval($this->getRequestVar('valueid'));
    697         $this->value->loadWithId();
    698 
    699         if	( $this->value->pageid != $this->page->pageid )
    700             throw new LogicException( 'cannot release, bad page' );
    701 
    702         // Pruefen, ob Berechtigung zum Freigeben besteht
    703         if	( !$this->page->hasRight(Acl::ACL_RELEASE) )
    704             throw new \SecurityException( 'Cannot release','no right' );
    705 
    706         // Inhalt freigeben
    707         $this->value->release();
    708 
    709         $this->addNotice('pageelement',$this->value->element->name,'PAGEELEMENT_RELEASED',OR_NOTICE_OK);
    710     }
    711 
    712 
    713     /**
    714      * Erzeugt eine Liste aller Versionsst?nde zu diesem Inhalt
    715      */
    716     public function historyView()
    717     {
    718         $this->page->load();
    719         $this->value->page = &$this->page;
    720 
    721         $this->value->publisher  = $this->page->publisher;
    722         $this->value->languageid = $this->page->languageid;
    723         $this->value->objectid   = $this->page->objectid;
    724         $this->value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
    725         $this->value->element    = &$this->element;
    726         $this->value->element->load();
    727 
    728         $list         = array();
    729         //		$version_list = array();
    730         $lfd_nr       = 0;
    731 
    732         foreach( $this->value->getVersionList() as $value )
    733         {
    734             $lfd_nr++;
    735             $value->element = &$this->element;
    736             $value->page    = &$this->page;
    737             $value->publisher = &$this->page->publisher;
    738             $value->generate();
    739 
    740 
    741             //			$date = date( lang('DATE_FORMAT'),$value->lastchangeTimeStamp);
    742 
    743             //			if	( in_array(	$this->element->type,array('text','longtext') ) )
    744             //				$version_list[ $value->valueid ] = '('.$lfd_nr.') '.$date;
    745 
    746             $zeile = array(  'value'     => Text::maxLength($value->value, 50),
    747                          'objectid'  => $this->page->objectid,
    748                          'date'      => $value->lastchangeTimeStamp,
    749                          'lfd_nr'    => $lfd_nr,
    750                          'id'        => $value->valueid,
    751                          'valueid'   => $value->valueid,
    752                          'user'      => $value->lastchangeUserName );
    753 
    754             // Nicht aktive Inhalte k�nnen direkt bearbeitet werden und sind
    755             // nach dem Speichern dann wieder aktiv (nat�rlich als n�chster/neuer Inhalt)
    756             if	( ! $value->active )
    757             $zeile['useUrl'] = Html::url('pageelement','usevalue',$this->page->objectid,array('valueid'  =>$value->valueid,'mode'=>'edit'));
    758 
    759             // Freigeben des Inhaltes.
    760             // Nur das aktive Inhaltselement kann freigegeben werden. Nat�rlich auch nur,
    761             // wenn es nicht schon freigegeben ist.
    762             if	( ! $value->publish && $value->active )
    763             $zeile['releaseUrl'] = Html::url('pageelement','release',$this->page->objectid,array('valueid'  =>$value->valueid ));
    764 
    765             $zeile['public'] = $value->publish;
    766             $zeile['active'] = $value->active;
    767 
    768             $list[$lfd_nr] = $zeile;
    769 
    770         }
    771 
    772         if	( in_array( $this->value->element->type, array('longtext') ) && $lfd_nr >= 2 )
    773         {
    774             $this->setTemplateVar('compareid',$list[$lfd_nr-1]['id']);
    775             $this->setTemplateVar('withid'   ,$list[$lfd_nr  ]['id']);
    776         }
    777 
    778         $this->setTemplateVar('name'     ,$this->element->name);
    779         $this->setTemplateVar('el'       ,$list                );
    780     }
    781 
    782 
    783     /**
    784      * Vergleicht 2 Versionen eines Inhaltes
    785      */
    786     function diffView()
    787     {
    788         $value1id = $this->getRequestVar('compareid');
    789         $value2id = $this->getRequestVar('withid'   );
    790 
    791         // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen
    792         if	( $value1id == $value2id )
    793         {
    794             $this->addValidationError('compareid'   );
    795             $this->addValidationError('withid'   ,'');
    796             $this->callSubAction('archive');
    797             return;
    798         }
    799 
    800         // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen
    801         if	( $value1id > $value2id )
    802         list($value1id,$value2id) = array( $value2id,$value1id );
    803 
    804 
    805         $value1 = new Value( $value1id );
    806         $value2 = new Value( $value2id );
    807         $value1->valueid = $value1id;
    808         $value2->valueid = $value2id;
    809 
    810         $value1->loadWithId();
    811         $value2->loadWithId();
    812 
    813         $this->setTemplateVar('date_left' ,$value1->lastchangeTimeStamp);
    814         $this->setTemplateVar('date_right',$value2->lastchangeTimeStamp);
    815 
    816         $text1 = explode("\n",$value1->text);
    817         $text2 = explode("\n",$value2->text);
    818 
    819         // Unterschiede feststellen.
    820         $res_diff = Text::diff($text1,$text2);
    821 
    822         list( $text1,$text2 ) = $res_diff;
    823 
    824         $diff = array();
    825         $i = 0;
    826         while( isset($text1[$i]) || isset($text2[$i]) )
    827         {
    828             $line = array();
    829 
    830             if	( isset($text1[$i]['text']) )
    831             $line['left'] = $text1[$i];
    832 
    833             if	( isset($text2[$i]['text']) )
    834             $line['right'] = $text2[$i];
    835 
    836             $i++;
    837             $diff[] = $line;
    838         }
    839         $this->setTemplateVar('diff',$diff );
    840     }
    841 
    842 
    843 
    844     /**
    845      * Ein Element der Seite speichern.
    846      */
    847     public function valuePost()
    848     {
    849         $this->element->load();
    850         $type = $this->element->type;
    851 
    852         if	( empty($type))
    853             throw new \InvalidArgumentException('No element type available');
    854 
    855         $funktionName = 'save'.$type;
    856 
    857         if  ( !method_exists($this,$funktionName))
    858             throw new \InvalidArgumentException('Function not available: '.$funktionName);
    859 
    860         $this->$funktionName(); // Aufruf Methode "save<ElementTyp>()"
    861     }
    862 
    863 
    864 
    865     /**
    866      * Element speichern
    867      *
    868      * Der Inhalt eines Elementes wird abgespeichert
    869      */
    870     private function savetext()
    871     {
    872         $value = new Value();
    873         $value->publisher  = $this->page->publisher;
    874         $value->languageid = $this->page->languageid;
    875         $value->objectid   = $this->page->objectid;
    876         $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
    877 
    878         if	( !$this->hasRequestVar('elementid') )
    879             throw new ValidationException('elementid');
    880         $value->element = new Element( $this->getRequestVar('elementid') );
    881 
    882         $value->element->load();
    883         $value->load();
    884 
    885         if   ( $this->hasRequestVar('linkobjectid') )
    886         $value->linkToObjectId = $this->getRequestVar('linkobjectid');
    887         else
    888         $value->text           = $this->getRequestVar('text','raw');
    889 
    890         $this->afterSave($value);
    891     }
    892 
    893 
    894 
    895     /**
    896      * Nach dem Speichern weitere Dinge ausfuehren.<br>
    897      * - Inhalt freigeben<br>
    898      * - Seite veroeffentlichen<br>
    899      * - Inhalt fuer andere Sprachen speichern<br>
    900      * - Hinweis ueber erfolgtes Speichern ausgeben<br>
    901      * <br>
    902      * Nicht zu verwechseln mit <i>Aftershave</i> :)
    903      * @param $value Value
    904      * @throws \ObjectNotFoundException
    905      */
    906     private function afterSave( $value )
    907     {
    908         $value->page = new Page( $value->objectid );
    909         $value->page->load();
    910 
    911 
    912         // Inhalt sofort freigegeben, wenn
    913         // - Recht vorhanden
    914         // - Freigabe gewuenscht
    915         if	( $value->page->hasRight( Acl::ACL_RELEASE ) && $this->hasRequestVar('release') )
    916         $value->publish = true;
    917         else
    918         $value->publish = false;
    919 
    920         // Up-To-Date-Check
    921         $lastChangeTime = $value->getLastChangeTime();
    922         if	( $lastChangeTime > $this->getRequestVar('value_time') )
    923         {
    924             $this->addNotice('pageelement',$value->element->name,'CONCURRENT_VALUE_CHANGE',OR_NOTICE_WARN,array('last_change_time'=>date(lang('DATE_FORMAT'),$lastChangeTime)));
    925         }
    926 
    927         // Inhalt speichern
    928 
    929         // Wenn Inhalt in allen Sprachen gleich ist, dann wird der Inhalt
    930         // fuer jede Sprache einzeln gespeichert.
    931         if	( $value->element->allLanguages )
    932         {
    933             $project = new Project( $this->page->projectid );
    934             foreach( $project->getLanguageIds() as $languageid )
    935             {
    936                 $value->languageid = $languageid;
    937                 $value->save();
    938             }
    939         }
    940         else
    941         {
    942             // sonst nur 1x speichern (fuer die aktuelle Sprache)
    943             $value->save();
    944         }
    945 
    946         $this->addNotice('pageelement',$value->element->name,'SAVED',OR_NOTICE_OK);
    947         $this->page->setTimestamp(); // "Letzte Aenderung" setzen
    948 
    949         // Falls ausgewaehlt die Seite sofort veroeffentlichen
    950         if	( $value->page->hasRight( Acl::ACL_PUBLISH ) && $this->hasRequestVar('publish') )
    951         {
    952             $this->page->publish();
    953             $this->addNotice('pageelement',$value->element->name,'PUBLISHED',OR_NOTICE_OK);
    954         }
    955     }
    956 
    957 
    958     /**
    959      * Element speichern
    960      *
    961      * Der Inhalt eines Elementes wird abgespeichert
    962      */
    963     private function savelongtext()
    964     {
    965         $value = new Value();
    966         $value->languageid = $this->page->languageid;
    967         $value->objectid   = $this->page->objectid;
    968         $value->publisher  = $this->page->publisher;
    969 
    970         $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
    971 
    972         if	( !$this->hasRequestVar('elementid') )
    973             throw new ValidationException('elementid');
    974         $value->element = new Element( $this->getRequestVar('elementid') );
    975 
    976         $value->element->load();
    977         $value->load();
    978 
    979         if   ( $this->hasRequestVar('format') )
    980             $value->format     = $this->getRequestId('format');
    981         else
    982             // Fallback: Format of the element.
    983             $value->format     = $this->element->format;
    984 
    985         $value->text           = $this->compactOIDs( $this->getRequestVar('text','raw') );
    986 
    987         // Vorschau anzeigen
    988         if	( $this->hasRequestVar('preview'  ) ||
    989         $this->hasRequestVar('addmarkup')    )
    990         {
    991             $inputText = $this->getRequestVar('text','raw');
    992 
    993             if	( $this->hasRequestVar('preview') )
    994             {
    995                 $value->page             = $this->page;
    996                 $value->simple           = false;
    997                 $value->page->languageid = $value->languageid;
    998                 $value->page->load();
    999                 $value->generate();
   1000                 $this->setTemplateVar('preview',$value->value );
   1001             }
   1002 
   1003 
   1004             $this->setTemplateVar( 'release' ,$this->page->hasRight(Acl::ACL_RELEASE) );
   1005             $this->setTemplateVar( 'publish' ,$this->page->hasRight(Acl::ACL_PUBLISH) );
   1006             $this->setTemplateVar( 'html'    ,$value->element->html );
   1007             $this->setTemplateVar( 'wiki'    ,$value->element->wiki );
   1008             $this->setTemplateVar( 'text'    ,$inputText );
   1009             $this->setTemplateVar( 'name'    ,$value->element->name );
   1010             $this->setTemplateVar( 'desc'    ,$value->element->desc );
   1011             $this->setTemplateVar( 'objectid',$this->page->objectid );
   1012 
   1013             $this->setTemplateVar( 'mode'    ,'edit' );
   1014         }
   1015         else
   1016         {
   1017             $this->afterSave($value);
   1018         }
   1019 
   1020     }
   1021 
   1022 
   1023     /**
   1024      * Element speichern
   1025      *
   1026      * Der Inhalt eines Elementes wird abgespeichert
   1027      */
   1028     private function savedate()
   1029     {
   1030         $value = new Value();
   1031         $value->languageid = $this->page->languageid;
   1032         $value->objectid   = $this->page->objectid;
   1033         $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
   1034         $value->publisher  = $this->page->publisher;
   1035 
   1036         if	( !$this->hasRequestVar('elementid') )
   1037             throw new ValidationException('elementid');
   1038 
   1039         $value->element = new Element( $this->getRequestVar('elementid') );
   1040         $value->element->load();
   1041         $value->load();
   1042 
   1043         if   ( $this->hasRequestVar('linkobjectid') )
   1044             $value->linkToObjectId = $this->getRequestVar('linkobjectid');
   1045         else {
   1046             $value->date = strtotime( $this->getRequestVar( 'date' ).' '.$this->getRequestVar( 'time' ) );
   1047 
   1048         }
   1049 
   1050         $this->afterSave($value);
   1051     }
   1052 
   1053 
   1054 
   1055     /**
   1056      * Element speichern
   1057      *
   1058      * Der Inhalt eines Elementes wird abgespeichert
   1059      */
   1060     private function saveselect()
   1061     {
   1062         $value = new Value();
   1063         $value->languageid = $this->page->languageid;
   1064         $value->objectid   = $this->page->objectid;
   1065         $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
   1066         $value->publisher  = $this->page->publisher;
   1067 
   1068         if	( !$this->hasRequestVar('elementid') )
   1069             throw new ValidationException('elementid');
   1070         $value->element = new Element( $this->getRequestVar('elementid') );
   1071 
   1072         $value->element->load();
   1073         $value->load();
   1074 
   1075         $value->text           = $this->getRequestVar('text');
   1076 
   1077         $this->afterSave($value);
   1078     }
   1079 
   1080 
   1081 
   1082     /**
   1083      * Element speichern
   1084      *
   1085      * Der Inhalt eines Elementes wird abgespeichert
   1086      */
   1087     private function savelink()
   1088     {
   1089         $value = new Value();
   1090         $value->publisher  = $this->page->publisher;
   1091         $value->languageid = $this->page->languageid;
   1092         $value->objectid   = $this->page->objectid;
   1093         $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
   1094 
   1095         if	( !$this->hasRequestVar('elementid') )
   1096             throw new ValidationException('elementid');
   1097         $value->element = new Element( $this->getRequestVar('elementid') );
   1098 
   1099         $value->element->load();
   1100         $value->load();
   1101 
   1102         if	( $this->hasRequestVar('linkurl') )
   1103             $value->linkToObjectId = $this->parseSimpleOID($this->getRequestVar('linkurl'));
   1104         else
   1105             $value->linkToObjectId = intval($this->getRequestVar('linkobjectid'));
   1106 
   1107         $this->afterSave($value);
   1108     }
   1109 
   1110 
   1111 
   1112     /**
   1113      * Element speichern
   1114      *
   1115      * Der Inhalt eines Elementes wird abgespeichert
   1116      */
   1117     private function savelist()
   1118     {
   1119         $this->saveinsert();
   1120     }
   1121 
   1122 
   1123 
   1124     /**
   1125      * Element speichern
   1126      *
   1127      * Der Inhalt eines Elementes wird abgespeichert
   1128      */
   1129     private function saveinsert()
   1130     {
   1131         $value = new Value();
   1132         $value->publisher = $this->page->publisher;
   1133         $value->languageid = $this->page->languageid;
   1134         $value->objectid   = $this->page->objectid;
   1135         $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
   1136 
   1137         if	( !$this->hasRequestVar('elementid') )
   1138             throw new ValidationException('elementid');
   1139         $value->element = new Element( $this->getRequestVar('elementid') );
   1140 
   1141         $value->element->load();
   1142         $value->load();
   1143 
   1144         $value->linkToObjectId = intval($this->getRequestVar('linkobjectid'));
   1145 
   1146         $this->afterSave($value);
   1147     }
   1148 
   1149 
   1150 
   1151     /**
   1152      * Element speichern
   1153      *
   1154      * Der Inhalt eines Elementes wird abgespeichert
   1155      */
   1156     private function savenumber()
   1157     {
   1158         $value = new Value();
   1159         $value->publisher  = $this->page->publisher;
   1160         $value->languageid = $this->page->languageid;
   1161         $value->objectid   = $this->page->objectid;
   1162         $value->pageid     = Page::getPageIdFromObjectId( $this->page->objectid );
   1163 
   1164         if	( !$this->hasRequestVar('elementid') )
   1165             throw new ValidationException('elementid');
   1166         $value->element = new Element( $this->getRequestVar('elementid') );
   1167 
   1168         $value->element->load();
   1169         $value->load();
   1170 
   1171         if   ( $this->hasRequestVar('linkobjectid') )
   1172         $value->linkToObjectId = $this->getRequestVar('linkobjectid');
   1173         else
   1174         $value->number         = $this->getRequestVar('number') * pow(10,$value->element->decimals);
   1175 
   1176         $this->afterSave($value);
   1177     }
   1178 
   1179 
   1180     function exportlongtext()
   1181     {
   1182         $types = array();
   1183 
   1184         foreach( array('odf','plaintext') as $type )
   1185         {
   1186             $types[$type] = lang('FILETYPE_'.$type);
   1187         }
   1188 
   1189         $this->setTemplateVar('types',$types);
   1190     }
   1191 
   1192 
   1193     function importlongtext()
   1194     {
   1195         $types = array();
   1196 
   1197         foreach( array('odf','plaintext') as $type )
   1198         {
   1199             $types[$type] = lang('FILETYPE_'.$type);
   1200         }
   1201         $this->setTemplateVar('types',$types);
   1202     }
   1203 
   1204 
   1205     function doexportlongtext()
   1206     {
   1207         $type = $this->getRequestVar('type');
   1208         switch($type)
   1209         {
   1210             case 'odf':
   1211 
   1212                 // Angabe Content-Type
   1213                 //				header('Content-Type: '.$this->file->mimeType());
   1214                 //				header('X-File-Id: '.$this->file->fileid);
   1215 
   1216                 //				header('Content-Disposition: inline; filename='.$this->id.'.odt');
   1217                 header('Content-Transfer-Encoding: binary');
   1218                 //				header('Content-Description: '.$this->file->name);
   1219 
   1220                 echo $this->createOdfDocument();
   1221 
   1222                 exit;
   1223 
   1224             default:
   1225         }
   1226 
   1227         exit;
   1228     }
   1229 
   1230 
   1231     /**
   1232      * ODF erzeugen.<br>
   1233      * vorerst ZURUECKGESTELLT!
   1234      *
   1235      * @return unknown
   1236      */
   1237     private function createOdfDocument()
   1238     {
   1239         // TODO: ODF ist nicht ganz ohne.
   1240         $transformer = new Transformer();
   1241         $transformer->text = $this->value->text;
   1242         $transformer->type = 'odf';
   1243         $transformer->transform();
   1244         return $transformer->text;
   1245     }
   1246 
   1247 
   1248 
   1249 
   1250     private function linkifyOIDs( $text )
   1251     {
   1252         foreach( Text::parseOID($text) as $oid=>$t )
   1253         {
   1254             $url = $this->page->path_to_object($oid);
   1255             foreach( $t as $match)
   1256                 $text = str_replace($match,$url,$text);
   1257         }
   1258 
   1259         return $text;
   1260     }
   1261 
   1262 
   1263     private function compactOIDs( $text )
   1264     {
   1265         foreach( Text::parseOID($text) as $oid=>$t )
   1266         {
   1267             foreach( $t as $match)
   1268                 $text = str_replace($match,'?__OID__'.$oid.'__',$text);
   1269         }
   1270 
   1271         return $text;
   1272     }
   1273 
   1274 
   1275     /**
   1276      * Gets the Object-Id from an string.
   1277      *
   1278      * @param $text
   1279      * @return int
   1280      */
   1281     private function parseSimpleOID($text )
   1282     {
   1283         $treffer = Text::parseOID( $text );
   1284 
   1285         if   ( isset($treffer[0]))
   1286             // Found an Object-Id.
   1287             return $treffer[0][0];
   1288         else
   1289             return intval($text);
   1290     }
   1291 
   1292 	/**
   1293 	 * Seite veroeffentlichen
   1294 	 *
   1295 	 * Es wird ein Formular angzeigt, mit dem die Seite veroeffentlicht
   1296 	 * werden kann 
   1297 	 */
   1298 	public function pubView()
   1299 	{
   1300 	}
   1301 
   1302 
   1303 
   1304 	/**
   1305 	 * Seite veroeffentlichen
   1306 	 *
   1307 	 * Die Seite wird generiert.
   1308 	 */
   1309 	function pubPost()
   1310 	{
   1311 		if	( !$this->page->hasRight( Acl::ACL_PUBLISH ) )
   1312             throw new \SecurityException( 'no right for publish' );
   1313 
   1314 		$this->page->public = true;
   1315 		$this->page->publish();
   1316 		$this->page->publisher->close();
   1317 
   1318 		$this->addNotice( 'page',
   1319 		                  $this->page->fullFilename,
   1320 		                  'PUBLISHED',
   1321 		                  OR_NOTICE_OK,
   1322 		                  array(),
   1323 		                  $this->page->publisher->log  );
   1324 	}
   1325 	
   1326 }
   1327 	
   1328 ?>