File modules/cms/generator/link/PreviewLink.class.php

Last commit: Tue Feb 14 22:53:23 2023 +0100	Jan Dankert	Stupid error, quick fix.
1 <?php 2 3 namespace cms\generator\link; 4 5 use cms\action\RequestParams; 6 use cms\generator\BaseContext; 7 use cms\generator\PageContext; 8 use cms\model\Alias; 9 use cms\model\BaseObject; 10 use cms\model\Link; 11 use cms\model\Url; 12 use util\exception\GeneratorException; 13 14 /** 15 * Linkformatter for Preview. 16 */ 17 18 class PreviewLink implements LinkFormat 19 { 20 private $context; 21 22 /** 23 * PreviewLink constructor. 24 * @param $context BaseContext 25 */ 26 public function __construct($context) 27 { 28 $this->context = $context; 29 } 30 31 32 /** 33 * Calculates the Preview Link to an object. 34 * 35 * @param $from BaseObject unused in preview. 36 * @param $to BaseObject the target where the link points to. 37 */ 38 public function linkToObject( BaseObject $from, BaseObject $to ) 39 { 40 41 $param = [ 42 'oid' => '__OID__'.$to->objectid.'__', 43 RequestParams::PARAM_OUTPUT => 'preview', 44 ]; 45 46 if ( $this->context instanceof PageContext ) { 47 $param[ RequestParams::PARAM_MODEL_ID ] = $this->context->modelId; 48 $param[ RequestParams::PARAM_LANGUAGE_ID ] = $this->context->languageId; 49 } 50 51 switch( $to->typeid ) 52 { 53 case BaseObject::TYPEID_FOLDER: 54 $inhalt = \util\Html::url('folder','show',$to->objectid,$param); 55 break; 56 case BaseObject::TYPEID_FILE: 57 case BaseObject::TYPEID_IMAGE: 58 case BaseObject::TYPEID_TEXT: 59 $inhalt = \util\Html::url('file','show',$to->objectid,$param); 60 break; 61 case BaseObject::TYPEID_PAGE: 62 $inhalt = \util\Html::url('page','show',$to->objectid,$param); 63 break; 64 65 case BaseObject::TYPEID_LINK: 66 $link = new Link( $to->objectid ); 67 $link->load(); 68 69 $linkedObject = new BaseObject( $link->linkedObjectId ); 70 $linkedObject->objectLoad(); 71 72 $inhalt = \util\Html::url($linkedObject->getType(),'show',$link->linkedObjectId,$param); 73 break; 74 75 case BaseObject::TYPEID_ALIAS: 76 $alias = new Alias( $to->objectid ); 77 $alias->load(); 78 $alias->linkedObjectId; 79 80 $linkedObject = new BaseObject( $alias->linkedObjectId ); 81 $linkedObject->objectLoad(); 82 83 $inhalt = \util\Html::url($linkedObject->getType(),'show',$alias->linkedObjectId,$param); 84 break; 85 86 case BaseObject::TYPEID_URL: 87 $url = new Url( $to->objectid ); 88 $url->load(); 89 $inhalt = $url->url; 90 91 break; 92 default: 93 throw new GeneratorException('Unknown type '.$to->typeid.' in target '.$to->__toString() ); 94 95 } 96 97 return $inhalt; 98 99 } 100 101 }
Download modules/cms/generator/link/PreviewLink.class.php
History Tue, 14 Feb 2023 22:53:23 +0100 Jan Dankert Stupid error, quick fix. Tue, 14 Feb 2023 00:23:13 +0100 Jan Dankert New filters: Robots (for robots.txt) and Sitemap. Fri, 18 Mar 2022 22:38:42 +0100 dankert Refactoring: Extracted the TemplateGenerator out of the PageGenerator. Fri, 18 Mar 2022 14:02:20 +0100 dankert New: Show all page links in the folder preview. Sun, 13 Feb 2022 19:39:49 +0100 dankert Refactoring: Special output type "preview" for previewing pages and files. Sat, 13 Mar 2021 22:38:30 +0100 Jan Dankert New filter for using links in text nodes (useful in CSS or script files) Tue, 29 Sep 2020 23:29:40 +0200 Jan Dankert Cleanup the 'moorweide'-theme. Tue, 29 Sep 2020 22:17:11 +0200 Jan Dankert Refactoring: Do not use global constants. Wed, 23 Sep 2020 01:04:05 +0200 Jan Dankert Cleanup of deprecated methods and deprecated class attributes. Mon, 21 Sep 2020 22:48:59 +0200 Jan Dankert Complexe refactoring: Moving all generation logic from the model (Value,Page,File) to generators classes.