openrat-cms

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

ValueGenerator.class.php (27487B)


      1 <?php
      2 
      3 
      4 namespace cms\generator;
      5 
      6 
      7 use cms\base\Configuration;
      8 use cms\base\Configuration as C;
      9 use cms\base\DB;
     10 use cms\base\Startup;
     11 use cms\macros\MacroRunner;
     12 use cms\model\BaseObject;
     13 use cms\model\Element;
     14 use cms\model\File;
     15 use cms\model\Folder;
     16 use cms\model\Image;
     17 use cms\model\Language;
     18 use cms\model\Link;
     19 use cms\model\Page;
     20 use cms\model\Project;
     21 use cms\model\Template;
     22 use cms\model\Value;
     23 use logger\Logger;
     24 use LogicException;
     25 use util\Code;
     26 use util\exception\GeneratorException;
     27 use util\exception\ObjectNotFoundException;
     28 use util\exception\PublisherException;
     29 use util\Html;
     30 use util\Http;
     31 use util\Text;
     32 use util\Transformer;
     33 
     34 
     35 /**
     36  * Generates a value.
     37  */
     38 class ValueGenerator extends BaseGenerator
     39 {
     40 
     41 	/**
     42 	 * Constructor.
     43 	 *
     44 	 * @param $valueContext ValueContext
     45 	 */
     46 	public function __construct($valueContext )
     47 	{
     48 		$this->context = $valueContext;
     49 	}
     50 
     51 
     52 
     53 	protected function generate()
     54 	{
     55 		return $this->generateValue();
     56 	}
     57 
     58 
     59 
     60 
     61 	/**
     62 	 * Hier findet die eigentliche Bereitstellung des Inhaltes statt, zu
     63 	 * jedem Elementtyp wird ein Inhalt ermittelt.
     64 	 *
     65 	 * @return string
     66 	 */
     67 	private function generateValue()
     68 	{
     69 		$pageContext = $this->context->pageContext;
     70 		$page = new Page( $pageContext->objectId );
     71 		$page->load();
     72 
     73 		$element = new Element( $this->context->elementid );
     74 		$element->load();
     75 
     76 		$value = new Value();
     77 		$value->pageid    = $page->pageid;
     78 		$value->elementid = $this->context->elementid;
     79 		$value->languageid = $pageContext->languageId;
     80 		$value->load();
     81 		$value->element = $element;
     82 
     83 		if	( ! $this->isValueHasContent( $value ) )
     84 		{
     85 			$pageForDefaultValue = $page->getPageAsDefault();
     86 
     87 			if   ( $pageForDefaultValue ) {
     88 
     89 				$pageContext = clone $this->context->pageContext;
     90 				$pageContext->objectId = $pageForDefaultValue->objectid;
     91 
     92 				$valueContext = clone $this->context;
     93 				$valueContext->pageContext = $pageContext;
     94 
     95 				$generator = new ValueGenerator( $valueContext );
     96 
     97 				return $generator->getCache()->get();
     98 			}
     99 		}
    100 
    101 		$inhalt = '';
    102 
    103 		switch( $element->typeid )
    104 		{
    105 			case Element::ELEMENT_TYPE_INSERT:
    106 
    107 				$objectid = $value->linkToObjectId;
    108 
    109 				if   ( intval($objectid) == 0 )
    110 					$objectid = $element->defaultObjectId;
    111 
    112 				if	( ! BaseObject::available( $objectid) )
    113 					return;
    114 
    115 				$object = new BaseObject( $objectid );
    116 				$object->objectLoadRaw();
    117 
    118 				if	( $object->isFolder )
    119 				{
    120 					if   ( false&&$value->publisher->isSimplePreview() ) // FIXME
    121 					{
    122 						$f = new Folder( $objectid );
    123 						$f->load();
    124 						$inhalt = $f->filename;
    125 						unset( $f );
    126 					}
    127 					else
    128 					{
    129 						if	( $objectid != $page->objectid ) // Rekursion vermeiden
    130 						{
    131 							$f = new Folder( $objectid );
    132 							foreach( $f->getObjectIds() as $oid )
    133 							{
    134 								if	( $oid != $page->objectid )  // Rekursion vermeiden
    135 								{
    136 									switch( $element->subtype )
    137 									{
    138 										case '':
    139 										case 'inline':
    140 											$o = new BaseObject( $oid );
    141 											$o->load();
    142 											switch( $o->typeid )
    143 											{
    144 												case BaseObject::TYPEID_PAGE:
    145 													$newPageContext = clone $pageContext;
    146 													$newPageContext->objectId = $oid;
    147 													$pageGenerator = new PageGenerator( $newPageContext );
    148 
    149 													$inhalt = $pageGenerator->getCache()->get();
    150 													//$inhalt = $oid;
    151 
    152 													break;
    153 												case BaseObject::TYPEID_LINK:
    154 													$l = new Link( $oid );
    155 													$l->load();
    156 													$op = new BaseObject( $l->linkedObjectId );
    157 													$op->load();
    158 													if	( $op->isPage )
    159 													{
    160 														$newPageContext = clone $pageContext;
    161 														$newPageContext->objectId = $l->linkedObjectId;
    162 														$pageGenerator = new PageGenerator( $newPageContext );
    163 
    164 														$inhalt .= $pageGenerator->getCache()->get();
    165 													}
    166 													break;
    167 											}
    168 											break;
    169 
    170 										case 'ssi':
    171 											$linkScheme = $pageContext->getLinkScheme();
    172 											$inhalt .= '<!--#include virtual="'.$linkScheme->linkToObject( $page,new BaseObject($oid)).'" -->';
    173 											break;
    174 
    175 										default:
    176 											$inhalt = '?'.$element->subtype.'?';
    177 									}
    178 								}
    179 								else throw new \LogicException('FATAL: recursion detected');
    180 							}
    181 						}
    182 						else throw new LogicException('FATAL: recursion detected');
    183 					}
    184 				}
    185 				elseif	( $object->isPage )
    186 				{
    187 					if   ( false&&$value->publisher->isSimplePreview() )
    188 					{
    189 						$p = new Page( $objectid );
    190 						$p->load();
    191 						$inhalt = $p->filename;
    192 						unset( $p );
    193 					}
    194 					else
    195 					{
    196 						if	( $objectid != $page->objectid ) // Rekursion vermeiden
    197 						{
    198 							switch( $element->subtype )
    199 							{
    200 								case '':
    201 								case 'inline':
    202 									$newPageContext = clone $pageContext;
    203 									$newPageContext->objectId = $objectid;
    204 									$pageGenerator = new PageGenerator( $newPageContext );
    205 
    206 									$inhalt = $pageGenerator->getCache()->get();
    207 									unset( $p );
    208 									break;
    209 
    210 								case 'ssi':
    211 									$linkScheme = $pageContext->getLinkScheme();
    212 									$inhalt = '<!--#include virtual="'.$linkScheme->linkToObject( $page,new BaseObject($objectid)).'" -->';
    213 									break;
    214 
    215 								default:
    216 									$inhalt = '?'.$element->subtype.'?';
    217 									break;
    218 							}
    219 						}
    220 						else throw new LogicException('FATAL: recursion detected');
    221 					}
    222 				}
    223 
    224 				if	( false&& $value->publisher->isSimplePreview() )
    225 				{
    226 					$inhalt = strip_tags( $inhalt );
    227 					$inhalt = str_replace( "\n",'',$inhalt );
    228 					$inhalt = str_replace( "\r",'',$inhalt );
    229 				}
    230 
    231 				break;
    232 
    233 
    234 			case Element::ELEMENT_TYPE_LINK:
    235 
    236 				$objectid = $value->linkToObjectId;
    237 				if   ( intval($objectid) == 0 )
    238 					$objectid = $element->defaultObjectId;
    239 
    240 				if   ( $objectid==0 )
    241 				{
    242 					// Link noch nicht gefuellt
    243 					$inhalt = '';
    244 				}
    245 				elseif	 ( ! BaseObject::available($objectid) )
    246 				{
    247 					$inhalt = /*$value->publisher->isSimplePreview()?'-':*/'';
    248 				}
    249 				elseif   ( /*$value->publisher->isSimplePreview()*/false )
    250 				{
    251 					$o = new BaseObject( $objectid );
    252 					$o->load();
    253 					$inhalt = $o->filename;
    254 				}
    255 				elseif	($element->subtype == 'image_data_uri' )
    256 				{
    257 					$context = new FileContext( $objectid,Producer::SCHEME_PUBLIC );
    258 					$generator = new FileGenerator( $context );
    259 					$file = new File($objectid);
    260 					$file->load();
    261 					$inhalt = 'data:'.$generator->getMimeType().';base64,'.base64_encode($generator->getCache()->get());
    262 				}
    263 				else
    264 				{
    265 					$sourcePage = new Page( $pageContext->sourceObjectId ); // the source page
    266 					$target     = new BaseObject( $objectid );
    267 					$target->load();
    268 
    269 					$linkScheme = $pageContext->getLinkScheme();
    270 					$inhalt     = $linkScheme->linkToObject( $sourcePage, $target );
    271 				}
    272 
    273 				break;
    274 
    275 
    276 			case Element::ELEMENT_TYPE_COPY:
    277 
    278 				list($linkElementName,$targetElementName) = explode('%',$element->name.'%');
    279 
    280 				if	( empty($targetElementName) )
    281 					break;
    282 
    283 				$element = new Element();
    284 				$element->name = $linkElementName;
    285 				$element->load();
    286 
    287 				if	( intval($element->elementid)==0 )
    288 					break;
    289 
    290 				$linkValue = new Value();
    291 				$linkValue->elementid = $element->elementid;
    292 				$linkValue->element   = $element;
    293 				$linkValue->pageid = $page->pageid;
    294 				$linkValue->page   = $page;
    295 				$linkValue->languageid = $value->languageid;
    296 				$linkValue->load();
    297 
    298 				if	( !BaseObject::available( $linkValue->linkToObjectId ) )
    299 					break;
    300 
    301 				$linkedPage = new Page( $linkValue->linkToObjectId );
    302 				$linkedPage->load();
    303 
    304 				$linkedPageTemplate = new Template( $linkedPage->templateid );
    305 				$targetElementId = array_search( $targetElementName, $linkedPageTemplate->getElementNames() );
    306 
    307 				if	( intval($targetElementId)==0 )
    308 					break;
    309 
    310 				$valueContext = new ValueContext( $pageContext );
    311 				$valueContext->elementid = $targetElementId;
    312 
    313 				$value = new ValueGenerator($valueContext);
    314 				$inhalt = $value->getCache()->get();
    315 
    316 				break;
    317 
    318 
    319 			case Element::ELEMENT_TYPE_LINKINFO:
    320 
    321 				@list( $linkElementName, $name ) = explode('%',$element->name);
    322 				if	( is_null($name) )
    323 					break;
    324 
    325 				$template = new Template( $page->templateid );
    326 				$elementId = array_search( $linkElementName, $template->getElementNames() );
    327 
    328 
    329 				$element = new Element($elementId);
    330 				$element->load();
    331 
    332 				$linkValue = new Value();
    333 				$linkValue->elementid = $element->elementid;
    334 				$linkValue->element   = $element;
    335 				$linkValue->pageid = $page->pageid;
    336 				$linkValue->languageid = $value->languageid;
    337 				$linkValue->load();
    338 
    339 				$objectid = $linkValue->linkToObjectId;
    340 
    341 				if   ( intval($objectid) == 0 )
    342 					$objectid = $linkValue->element->defaultObjectId;
    343 
    344 				if	( !BaseObject::available( $objectid ) )
    345 					break;
    346 
    347 				$linkedObject = new BaseObject( $objectid );
    348 				$linkedObject->languageid = $value->languageid;
    349 				$linkedObject->load();
    350 
    351 				switch( $element->subtype )
    352 				{
    353 					case 'width':
    354 						$f = new Image( $objectid );
    355 						$f->load();
    356 						if	( $f->typeid == BaseObject::TYPE_IMAGE )
    357 						{
    358 							$f->getImageSize();
    359 							$inhalt = $f->width;
    360 						}
    361 						unset($f);
    362 						break;
    363 
    364 					case 'height':
    365 						$f = new Image( $objectid );
    366 						$f->load();
    367 						if	( $f->typeid == BaseObject::TYPE_IMAGE )
    368 						{
    369 							$f->getImageSize();
    370 							$inhalt = $f->height;
    371 						}
    372 						unset($f);
    373 						break;
    374 
    375 					case 'id':
    376 						$inhalt = $objectid;
    377 						break;
    378 
    379 					case 'name':
    380 						$inhalt = $linkedObject->name;
    381 						break;
    382 
    383 					case 'description':
    384 						$inhalt = $linkedObject->description;
    385 						break;
    386 
    387 					case 'create_user_desc':
    388 						$user = $linkedObject->createUser;
    389 						try
    390 						{
    391 							$user->load();
    392 							$inhalt = $user->desc;
    393 						}
    394 						catch( ObjectNotFoundException $e )
    395 						{
    396 						}
    397 						break;
    398 
    399 					case 'create_user_fullname':
    400 						$user = $linkedObject->createUser;
    401 						try
    402 						{
    403 							$user->load();
    404 							$inhalt = $user->fullname;
    405 						}
    406 						catch( ObjectNotFoundException $e )
    407 						{
    408 						}
    409 						break;
    410 
    411 					case 'create_user_mail':
    412 						$user = $linkedObject->createUser;
    413 						try
    414 						{
    415 							$user->load();
    416 							$inhalt = $user->mail;
    417 						}
    418 						catch( ObjectNotFoundException $e )
    419 						{
    420 						}
    421 						break;
    422 
    423 					case 'create_user_tel':
    424 						$user = $linkedObject->createUser;
    425 						try
    426 						{
    427 							$user->load();
    428 							$inhalt = $user->tel;
    429 						}
    430 						catch( ObjectNotFoundException $e )
    431 						{
    432 						}
    433 						break;
    434 
    435 					case 'create_user_username':
    436 						$user = $linkedObject->createUser;
    437 						try
    438 						{
    439 							$user->load();
    440 							$inhalt = $user->name;
    441 						}
    442 						catch( ObjectNotFoundException $e )
    443 						{
    444 						}
    445 						break;
    446 
    447 					case 'lastch_user_desc':
    448 						$user = $linkedObject->lastchangeUser;
    449 						try
    450 						{
    451 							$user->load();
    452 							$inhalt = $user->desc;
    453 						}
    454 						catch( ObjectNotFoundException $e )
    455 						{
    456 						}
    457 						break;
    458 
    459 					case 'lastch_user_fullname':
    460 						$user = $linkedObject->lastchangeUser;
    461 						try
    462 						{
    463 							$user->load();
    464 							$inhalt = $user->fullname;
    465 						}
    466 						catch( ObjectNotFoundException $e )
    467 						{
    468 						}
    469 						break;
    470 
    471 					case 'lastch_user_mail':
    472 						$user = $linkedObject->lastchangeUser;
    473 						try
    474 						{
    475 							$user->load();
    476 							$inhalt = $user->mail;
    477 						}
    478 						catch( ObjectNotFoundException $e )
    479 						{
    480 						}
    481 						break;
    482 
    483 					case 'lastch_user_tel':
    484 						$user = $linkedObject->lastchangeUser;
    485 						try
    486 						{
    487 							$user->load();
    488 							$inhalt = $user->tel;
    489 						}
    490 						catch( ObjectNotFoundException $e )
    491 						{
    492 						}
    493 
    494 						break;
    495 
    496 					case 'lastch_user_username':
    497 						$user = $linkedObject->lastchangeUser;
    498 						try
    499 						{
    500 							$user->load();
    501 							$inhalt = $user->name;
    502 						}
    503 						catch( ObjectNotFoundException $e )
    504 						{
    505 						}
    506 						break;
    507 
    508 					case 'mime_type':
    509 						if	( $linkedObject->isFile || $linkedObject->isImage || $linkedObject->isText  )
    510 						{
    511 							$context = new FileContext( $objectid,Producer::SCHEME_PUBLIC );
    512 							$generator = new FileGenerator( $context );
    513 							$inhalt = $generator->getMimeType();
    514 							unset($f);
    515 						}
    516 						break;
    517 
    518 					case 'filename':
    519 						$inhalt = $linkedObject->filename();
    520 						break;
    521 
    522 					case 'full_filename':
    523 						$inhalt = $linkedObject->full_filename();
    524 						break;
    525 
    526 					default:
    527 						$inhalt = '';
    528 						Logger::warn('subtype for linkinfo not implemented:'.$element->subtype);
    529 				}
    530 
    531 				break;
    532 
    533 			case Element::ELEMENT_TYPE_LINKDATE:
    534 
    535 				@list( $linkElementName, $name ) = explode('%',$element->name);
    536 				if	( is_null($name) )
    537 					break;
    538 
    539 				$template = new Template( $page->templateid );
    540 				$elementId = array_search( $linkElementName, $template->getElementNames() );
    541 
    542 				$element = new Element($elementId);
    543 				$element->load();
    544 
    545 				$linkValue = new Value();
    546 				$linkValue->elementid = $element->elementid;
    547 				$linkValue->element   = $element;
    548 				$linkValue->pageid = $page->pageid;
    549 				$linkValue->languageid = $value->languageid;
    550 				$linkValue->load();
    551 
    552 				$objectid = $linkValue->linkToObjectId;
    553 
    554 				if   ( intval($objectid) == 0 )
    555 					$objectid = $linkValue->element->defaultObjectId;
    556 
    557 				if	( !BaseObject::available( $objectid ) )
    558 					break;
    559 
    560 				$linkedObject = new BaseObject( $objectid );
    561 				$linkedObject->load();
    562 
    563 
    564 				switch( $element->subtype )
    565 				{
    566 					case 'date_published':
    567 						// START_TIME wird zu Beginn im Controller gesetzt.
    568 						// So erh�lt jede Datei das gleiche Ver�ffentlichungsdatum.
    569 						$date = Startup::getStartTime();
    570 						break;
    571 
    572 					case 'date_saved':
    573 						$date = $linkedObject->lastchangeDate;
    574 						break;
    575 
    576 					case 'date_created':
    577 						$date = $linkedObject->createDate;
    578 						break;
    579 
    580 					default:
    581 						Logger::warn('element:'.$element->name.', '.
    582 							'type:'.$element->type.', '.
    583 							'unknown subtype:'.$element->subtype);
    584 						$date = Startup::getStartTime();
    585 				}
    586 
    587 				if	( strpos($element->dateformat,'%')!==FALSE )
    588 					$inhalt = strftime( $element->dateformat,$date );
    589 				else
    590 					$inhalt = date    ( $element->dateformat,$date );
    591 				break;
    592 
    593 			case Element::ELEMENT_TYPE_LONGTEXT:
    594 			case Element::ELEMENT_TYPE_TEXT:
    595 			case Element::ELEMENT_TYPE_SELECT:
    596 
    597 				$inhalt = $value->text;
    598 				$format = $value->format;
    599 
    600 				// Wenn Inhalt leer, dann versuchen, den Inhalt der Default-Sprache zu laden.
    601 				if   ( $inhalt == '' && Configuration::subset('content')->subset('language')->is('use_default_language',true) )
    602 				{
    603 					$project = new Project($page->projectid);
    604 					$value->languageid = $project->getDefaultLanguageId();
    605 					$value->load();
    606 					$inhalt = $value->text;
    607 				}
    608 
    609 				// Wenn Inhalt leer, dann Vorbelegung verwenden
    610 				if   ( $inhalt == '' )  {
    611 
    612 					$inhalt = $element->defaultText;
    613 					$format = $element->format;
    614 				}
    615 
    616 				// Wenn HTML nicht erlaubt und Wiki-Formatierung aktiv, dann einfache HTML-Tags in Wiki umwandeln
    617 				$pageIsHtml = $this->isHtml( (new PageGenerator( $this->context->pageContext ))->getMimeType());
    618 
    619 				//
    620 				switch( $format )
    621 				{
    622 					case Element::ELEMENT_FORMAT_TEXT:
    623 					case Element::ELEMENT_FORMAT_HTML:
    624 
    625 						if   ( !$element->html )
    626 						{
    627 							// HTML not allowed.
    628 							$inhalt = Text::encodeHtml( $inhalt );
    629 							$inhalt = Text::encodeHtmlSpecialChars( $inhalt );
    630 						}
    631 
    632 						break;
    633 
    634 					case Element::ELEMENT_FORMAT_WIKI:
    635 
    636 						$wikiConfig = C::subset('editor')->subset('wiki');
    637 
    638 						if   ( $wikiConfig->is('convert_bbcode',false ) )
    639 							$inhalt = Text::bbCode2Wiki( $inhalt );
    640 
    641 						if   ( !$element->html && $wikiConfig->is('convert_html',true) && $pageIsHtml)
    642 							$inhalt = Text::html2Wiki( $inhalt );
    643 
    644 						$transformer = new Transformer();
    645 						$transformer->text    = $inhalt;
    646 						$transformer->page    = $page;
    647 						$transformer->pageContext = $pageContext;
    648 						$transformer->element = $element;
    649 
    650 						$transformer->transform();
    651 						$inhalt = $transformer->text;
    652 						break;
    653 
    654 					case Element::ELEMENT_FORMAT_MARKDOWN:
    655 
    656 						$mdConfig = C::Conf()->subset('editor')->subset('markdown');
    657 
    658 						$parser = new \util\Parsedown();
    659 						$parser->setUrlsLinked( $mdConfig->is('urls-linked',true));
    660 						$parser->setMarkupEscaped( !$element->html );
    661 
    662 						$inhalt = $parser->parse( $inhalt );
    663 						break;
    664 
    665 					default:
    666 						throw new \LogicException('Unknown format: '.$value->format );
    667 				}
    668 
    669 				/*if   ( $value->publisher->isSimplePreview() )
    670 				{
    671 					// Simple Preview with bare text.
    672 					$inhalt = strip_tags( $inhalt );
    673 					$inhalt = str_replace( "\n",'',$inhalt );
    674 					$inhalt = str_replace( "\r",'',$inhalt );
    675 				}*/
    676 
    677 				// "__OID__nnn__" ersetzen durch einen richtigen Link
    678 				foreach( Text::parseOID($inhalt) as $oid=>$t )
    679 				{
    680 					$linkFormat = $pageContext->getLinkScheme();
    681 					$target = new BaseObject($oid);
    682 					$target->load();
    683 
    684 					$sourcePage = new Page( $pageContext->sourceObjectId );
    685 					$url        = $linkFormat->linkToObject($sourcePage,$target);
    686 
    687 					foreach( $t as $match )
    688 						$inhalt = str_replace($match,$url,$inhalt);
    689 				}
    690 
    691 				break;
    692 
    693 
    694 			// Zahl
    695 			//
    696 			// wird im entsprechenden Format angezeigt.
    697 			case Element::ELEMENT_TYPE_NUMBER:
    698 
    699 				if   ( $value->number == 0 )
    700 				{
    701 					// Zahl ist gleich 0, dann Default-Text
    702 					$inhalt = $element->defaultText;
    703 					break;
    704 				}
    705 
    706 				$number = $value->number / pow(10,$element->decimals);
    707 				$inhalt = number_format( $number,$element->decimals,$element->decPoint,$element->thousandSep );
    708 
    709 				break;
    710 
    711 
    712 			// Datum
    713 			case Element::ELEMENT_TYPE_DATE:
    714 
    715 				$date = $value->date;
    716 
    717 				if   ( intval($date) == 0 )
    718 				{
    719 					// Datum wurde noch nicht eingegeben
    720 					$inhalt = $element->defaultText;
    721 					break;
    722 				}
    723 
    724 				// Datum gemaess Elementeinstellung formatieren
    725 				if	( strpos($element->dateformat,'%')!==FALSE )
    726 					$inhalt = strftime( $element->dateformat,$date );
    727 				else
    728 					$inhalt = date    ( $element->dateformat,$date );
    729 				break;
    730 
    731 
    732 			// Programmcode (PHP)
    733 			case Element::ELEMENT_TYPE_CODE:
    734 
    735 				// Die Ausführung von benutzer-erzeugtem PHP-Code kann in der
    736 				// Konfiguration aus Sicherheitsgründen deaktiviert sein.
    737 				if	( Configuration::subset('security')->is('disable_dynamic_code',false) )
    738 				{
    739 					Logger::warn("Execution of dynamic code elements is disabled by configuration. Set security/disable_dynamic_code to true to allow this");
    740 					break;
    741 				}
    742 
    743 				$page->load();
    744 
    745 				// Das Ausführen geschieht über die Klasse "Code".
    746 				// In dieser wird der Code in eine Datei geschrieben und
    747 				// von dort eingebunden.
    748 				$code = new Code();
    749 				$code->setPageContext($this->context->pageContext );
    750 				$code->code = $element->code;
    751 
    752 				ob_start();
    753 
    754 				// Jetzt ausfuehren des temporaeren PHP-Codes
    755 				$code->execute();
    756 
    757 				$output = ob_get_contents();
    758 				ob_end_clean();
    759 
    760 				// Ausgabe ermitteln.
    761 				$inhalt = $output;
    762 
    763 
    764 				break;
    765 
    766 
    767 			// Makros (dynamische Klassen)
    768 			case Element::ELEMENT_TYPE_DYNAMIC:
    769 
    770 				/*if   ( $value->publisher->isSimplePreview() )
    771 					break;*/
    772 
    773 				$page->load();
    774 				$macroName     = $element->subtype;
    775 				$macroSettings = $element->getDynamicParameters();
    776 
    777 				$runner = new MacroRunner();
    778 				try {
    779 					$inhalt .= $runner->executeMacro( $macroName, $macroSettings,$page, $pageContext );
    780 				}
    781 				catch( \Exception $e ) {
    782 					throw new GeneratorException("Macro ".$macroName.' in value '.$value->__toString().' could not executed',$e);
    783 				}
    784 
    785 				// Wenn HTML-Ausgabe, dann Sonderzeichen in HTML �bersetzen
    786 				if   ( $this->isHtml( (new PageGenerator( $this->context->pageContext ))->getMimeType()))
    787 					$inhalt = Text::encodeHtmlSpecialChars( $inhalt );
    788 
    789 				break;
    790 
    791 
    792 			// Info-Feld als Datum
    793 			case Element::ELEMENT_TYPE_INFODATE:
    794 
    795 				/*if   ( $value->publisher->isSimplePreview() )
    796 					break;*/
    797 
    798 				switch( $element->subtype )
    799 				{
    800 					case 'date_published':
    801 						// START_TIME wird zu Beginn im Controller gesetzt.
    802 						// So erh�lt jede Datei das gleiche Ver�ffentlichungsdatum.
    803 						$date = Startup::getStartTime();
    804 						break;
    805 
    806 					case 'date_saved':
    807 						$date = $page->lastchangeDate;
    808 						break;
    809 
    810 					case 'date_created':
    811 						$date = $page->createDate;
    812 						break;
    813 
    814 					default:
    815 						throw new PublisherException('element:'.$element->name.', '.
    816 							'type:'.$element->type.', '.
    817 							'unknown subtype:'.$element->subtype);
    818 						/*if	( !$value->publisher->isPublic() )
    819 							$inhalt = \cms\base\Language::lang('ERROR_IN_ELEMENT');*/
    820 				}
    821 
    822 				if	( strpos($element->dateformat,'%')!==FALSE )
    823 					$inhalt = strftime( $element->dateformat,$date );
    824 				else
    825 					$inhalt = date    ( $element->dateformat,$date );
    826 
    827 				break;
    828 
    829 
    830 			// Info-Feld
    831 			case Element::ELEMENT_TYPE_INFO:
    832 
    833 				/*if   ( $value->publisher->isSimplePreview() )
    834 					break;*/
    835 
    836 				switch( $element->subtype )
    837 				{
    838 					case 'db_id':
    839 						$inhalt = DB::get()->id;
    840 						break;
    841 					case 'db_name':
    842 						$inhalt = @DB::get()->getLabel();
    843 						break;
    844 					case 'project_id':
    845 						$inhalt = $page->projectid;
    846 						break;
    847 					case 'project_name':
    848 						$inhalt = Project::create( $page->projectid )->load()->name;
    849 						break;
    850 					case 'language_id':
    851 						$inhalt = $page->languageid;
    852 						break;
    853 					case 'language_iso':
    854 						$language = new Language( $page->languageid );
    855 						$language->load();
    856 						$inhalt = $language->isoCode;
    857 						break;
    858 					case 'language_name':
    859 						$language = new Language( $page->languageid );
    860 						$language->load();
    861 						$inhalt = $language->name;
    862 						break;
    863 					case 'page_id':
    864 						$inhalt = $page->objectid;
    865 						break;
    866 					case 'page_name':
    867 						$inhalt = $page->getNameForLanguage( $pageContext->languageId )->name;
    868 						break;
    869 					case 'page_desc':
    870 						$inhalt = $page->getNameForLanguage( $pageContext->languageId )->description;
    871 						break;
    872 					case 'page_fullfilename':
    873 						$inhalt = $this->getPublicFilename();
    874 						break;
    875 					case 'page_filename':
    876 						$inhalt = $page->filename();
    877 						break;
    878 					case 'page_extension':
    879 						$inhalt = '';
    880 						break;
    881 					case 'edit_url':
    882 						$raw = true;
    883 						$db = \util\Session::getDatabase();
    884 						$inhalt = Html::url('page',null,$page->objectid,array('dbid'=>$db->id));
    885 						break;
    886 					case 'edit_fullurl':
    887 						$raw = true;
    888 						$inhalt = Http::getServer();
    889 
    890 						// Der Link soll nicht auf die API, sondern auf das UI zeigen.
    891 						if   ( substr($inhalt,-4) == 'api/' )
    892 							$inhalt = substr($inhalt,0,-4);
    893 
    894 						$inhalt .= '/#/page/'.$page->objectid;
    895 						break;
    896 					case 'lastch_user_username':
    897 						$user = $page->lastchangeUser;
    898 						if   ( $user->userid )
    899 							$user->load();
    900 						$inhalt = $user->name;
    901 						break;
    902 					case 'lastch_user_fullname':
    903 						$user = $page->lastchangeUser;
    904 						if   ( $user->userid )
    905 							$user->load();
    906 						$inhalt = $user->fullname;
    907 						break;
    908 					case 'lastch_user_mail':
    909 						$user = $page->lastchangeUser;
    910 						if   ( $user->userid )
    911 							$user->load();
    912 						$inhalt = $user->mail;
    913 						break;
    914 					case 'lastch_user_desc':
    915 						$user = $page->lastchangeUser;
    916 						if   ( $user->userid )
    917 							$user->load();
    918 						$inhalt = $user->desc;
    919 						break;
    920 					case 'lastch_user_tel':
    921 						$user = $page->lastchangeUser;
    922 						if   ( $user->userid )
    923 							$user->load();
    924 						$inhalt = $user->tel;
    925 						break;
    926 
    927 					case 'create_user_username':
    928 						$user = $page->createUser;
    929 						if   ( $user->userid )
    930 							$user->load();
    931 						$inhalt = $user->name;
    932 						break;
    933 					case 'create_user_fullname':
    934 						$user = $page->createUser;
    935 						if   ( $user->userid )
    936 							$user->load();
    937 						$inhalt = $user->fullname;
    938 						break;
    939 					case 'create_user_mail':
    940 						$user = $page->createUser;
    941 						if   ( $user->userid )
    942 							$user->load();
    943 						$inhalt = $user->mail;
    944 						break;
    945 					case 'create_user_desc':
    946 						$user = $page->createUser;
    947 						if   ( $user->userid )
    948 							$user->load();
    949 						$inhalt = $user->desc;
    950 						break;
    951 					case 'create_user_tel':
    952 						$user = $page->createUser;
    953 						if   ( $user->userid )
    954 							$user->load();
    955 						$inhalt = $user->tel;
    956 						break;
    957 
    958 					case 'act_user_username':
    959 						$user = \util\Session::getUser();
    960 						if   ( $user )
    961 							$inhalt = $user->name;
    962 						break;
    963 					case 'act_user_fullname':
    964 						$user = \util\Session::getUser();
    965 						if   ( $user )
    966 							$inhalt = $user->fullname;
    967 						break;
    968 					case 'act_user_mail':
    969 						$user = \util\Session::getUser();
    970 						if   ( $user )
    971 							$inhalt = $user->mail;
    972 						break;
    973 					case 'act_user_desc':
    974 						$user = \util\Session::getUser();
    975 						if   ( $user )
    976 							$inhalt = $user->desc;
    977 						break;
    978 					case 'act_user_tel':
    979 						$user = \util\Session::getUser();
    980 						if   ( $user )
    981 							$inhalt = $user->tel;
    982 						break;
    983 					default:
    984 						Logger::warn('element:'.$element->name.', '.
    985 							'type:'.$element->type.', '.
    986 							'unknown subtype:'.$element->subtype);
    987 					// Keine Fehlermeldung in erzeugte Seite schreiben.
    988 				}
    989 
    990 				break;
    991 
    992 			default:
    993 				// this should never happen in production.
    994 				// inform the user.
    995 				throw new GeneratorException( 'Error in element '.$element->name.': '.
    996 					'unknown type: '.$element->typeid.'');
    997 
    998 		}
    999 
   1000 
   1001 		switch( $element->type )
   1002 		{
   1003 			case 'longtext':
   1004 			case 'text':
   1005 			case 'select':
   1006 
   1007 				if	( Configuration::subset('publish')->is('encode_utf8_in_html') )
   1008 					// Wenn HTML-Ausgabe, dann UTF-8-Zeichen als HTML-Code uebersetzen
   1009 					if   ( $this->isHtml( (new PageGenerator( $this->context->pageContext ))->getMimeType()) )
   1010 						$inhalt = Text::translateutf8tohtml($inhalt);
   1011 				break;
   1012 
   1013 			default:
   1014 		}
   1015 
   1016 
   1017 
   1018 		if   ( $this->context->pageContext->scheme == Producer::SCHEME_PREVIEW && $element->withIcon && $this->isHtml( (new PageGenerator( $this->context->pageContext ))->getMimeType()) )
   1019 		{
   1020 			// Anklickbaren Link voranstellen.
   1021 			$iconLink = '<a href="javascript:parent.Openrat.Workbench.openNewAction(\''.$element->name.'\',\'pageelement\',\''.$page->objectid.'_'.$element->elementid.'\');" title="'.$element->desc.'">&rarr;<i class="or-image-icon or-image-icon--el-'.$element->getTypeName().'"></i></a>';
   1022 			$inhalt   = $iconLink.$inhalt;
   1023 		}
   1024 
   1025 		return $inhalt;
   1026 	}
   1027 
   1028 
   1029 	/**
   1030 	 * Determines if the value has meaningful content
   1031 	 *
   1032 	 * @param $value Value
   1033 	 */
   1034 	protected function isValueHasContent( $value ) {
   1035 
   1036 		return in_array($value->element->typeid,[
   1037 				Element::ELEMENT_TYPE_TEXT,
   1038 				Element::ELEMENT_TYPE_LONGTEXT,
   1039 				Element::ELEMENT_TYPE_SELECT,
   1040 			]) && $value->text != '' && $value->text != null ||
   1041 			in_array($value->element->typeid,[
   1042 				Element::ELEMENT_TYPE_NUMBER
   1043 			]) && $value->number != null ||
   1044 			in_array($value->element->typeid,[
   1045 				Element::ELEMENT_TYPE_LINK,
   1046 				Element::ELEMENT_TYPE_INSERT,
   1047 			]) && $value->linkToObjectId != null && $value->linkToObjectId != 0 ||
   1048 			in_array($value->element->typeid,[
   1049 				Element::ELEMENT_TYPE_DATE,
   1050 			]) && $value->date != null && $value->date != 0 ||
   1051 			in_array($value->element->typeid,[
   1052 				Element::ELEMENT_TYPE_CODE,
   1053 				Element::ELEMENT_TYPE_COPY,
   1054 				Element::ELEMENT_TYPE_DYNAMIC,
   1055 				Element::ELEMENT_TYPE_INFO,
   1056 				Element::ELEMENT_TYPE_INFODATE,
   1057 				Element::ELEMENT_TYPE_LINKDATE,
   1058 				Element::ELEMENT_TYPE_LINKINFO,
   1059 			]);
   1060 	}
   1061 
   1062 
   1063 	/**
   1064 	 * A pure value does not have a public filename. Therefor, this method returns nothing.
   1065 	 * @return string
   1066 	 */
   1067 	public function getPublicFilename()
   1068 	{
   1069 		return null;
   1070 	}
   1071 
   1072 
   1073 	/**
   1074 	 * @return string always blank
   1075 	 */
   1076 	public function getMimeType()
   1077 	{
   1078 		return ''; // Values does not have a mime type.
   1079 	}
   1080 
   1081 
   1082 	protected function isHtml( $mimeType )
   1083 	{
   1084 		return $mimeType == 'text/html';
   1085 	}
   1086 
   1087 }