File modules/cms/action/pageelement/PageelementDiffAction.class.php

Last commit: Mon Dec 6 01:00:00 2021 +0100	dankert	New: Show a version from file history; New: Text history.
1 <?php 2 namespace cms\action\pageelement; 3 use cms\action\Method; 4 use cms\action\PageelementAction; 5 use cms\generator\PublishEdit; 6 use cms\generator\PublishPreview; 7 use cms\model\Value; 8 use util\exception\ValidationException; 9 use util\Text; 10 11 class PageelementDiffAction extends PageelementAction implements Method { 12 13 public function view() { 14 $value1id = $this->request->getNumber('compareid'); 15 $value2id = $this->request->getNumber('withid' ); 16 17 // Wenn Value1-Id = Value2-Id 18 if ( $value1id == $value2id ) 19 throw new ValidationException('withid' ); 20 21 // Value 2 must be greater than value 1. 22 if ( $value1id > $value2id ) 23 list($value1id,$value2id) = array( $value2id,$value1id ); 24 25 $value1 = new Value(); 26 $value2 = new Value(); 27 28 $value1->loadWithId( $value1id ); 29 $value2->loadWithId( $value2id ); 30 31 // both values must be part of the same content. 32 if ( $value1->contentid != $value2->contentid ) 33 throw new ValidationException('compareid'); 34 35 // Security-Check: 36 // Content must be a part of the page. 37 $this->ensureContentIdIsPartOfPage( $value1->contentid ); 38 39 $this->setTemplateVar('date_left' ,$value1->lastchangeTimeStamp); 40 $this->setTemplateVar('date_right',$value2->lastchangeTimeStamp); 41 42 // Split whole text into lines. 43 $text1 = explode("\n",$value1->text); 44 $text2 = explode("\n",$value2->text); 45 46 // Make the diff 47 $diffResult = Text::diff($text1,$text2); 48 49 $outputResult = array_map( function( $left,$right) { 50 return [ 51 'left' => $left, 52 'right'=> $right 53 ]; 54 },$diffResult[0],$diffResult[1] ); 55 56 $this->setTemplateVar('diff',$outputResult ); 57 } 58 59 60 public function post() { 61 } 62 }
Download modules/cms/action/pageelement/PageelementDiffAction.class.php
History Mon, 6 Dec 2021 01:00:00 +0100 dankert New: Show a version from file history; New: Text history. Sun, 5 Dec 2021 22:09:08 +0100 dankert Fix: The Diff function was broken. Sun, 14 Mar 2021 23:51:49 +0100 Jan Dankert Refactoring: Using the ValidationException where possible. Wed, 10 Mar 2021 23:51:22 +0100 Jan Dankert Refactoring: Cleaned the Request params. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Thu, 19 Nov 2020 12:36:44 +0100 Jan Dankert Fix: nextSubAction() is depracated and should not be used. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.