openrat-cms

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

commit 173f7d61f87647de3df4dd12ada241df8de67971
parent 935acc898773ac238a5261b49827a8f1269acf21
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 18 May 2019 01:47:32 +0200

Refactoring: Erkennung der Objekt-Ids in __OID__nnn__ verbessert, New: Bilder in Markdown werden nun richtig erkannt.

Diffstat:
modules/cms-core/action/PageelementAction.class.php | 1365++++++++++++++++++++++++++++++++++++++-----------------------------------------
modules/cms-core/model/Value.class.php | 4+++-
modules/template-engine/components/html/editor/editor.js | 34++--------------------------------
modules/template-engine/components/html/editor/editor.min.js | 4++--
modules/template-engine/components/html/image/image.js | 13++++---------
modules/template-engine/components/html/image/image.min.js | 4++--
modules/util/Text.class.php | 42+++++++++++++++++++-----------------------
7 files changed, 686 insertions(+), 780 deletions(-)

diff --git a/modules/cms-core/action/PageelementAction.class.php b/modules/cms-core/action/PageelementAction.class.php @@ -634,891 +634,834 @@ class PageelementAction extends Action $objects[ $id ] .= implode( FILE_SEP,$f->parentObjectNames(false,true) ); $objects[ $id ] .= FILE_SEP.$o->name; // } - } + } - asort( $objects ); // Sortieren + asort( $objects ); // Sortieren - $this->setTemplateVar('objects' ,$objects); - $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId); + $this->setTemplateVar('objects' ,$objects); + $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId); - if ( $this->getSessionVar('pageaction') != '' ) - $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); - else $this->setTemplateVar('old_pageaction','show' ); + if ( $this->getSessionVar('pageaction') != '' ) + $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); + else $this->setTemplateVar('old_pageaction','show' ); - $this->value->page = new Page( $this->page->objectid ); - $this->value->page->languageid = $this->value->languageid; - $this->value->page->load(); + $this->value->page = new Page( $this->page->objectid ); + $this->value->page->languageid = $this->value->languageid; + $this->value->page->load(); - $this->setTemplateVar( 'release',$this->value->page->hasRight(ACL_RELEASE) ); - $this->setTemplateVar( 'publish',$this->value->page->hasRight(ACL_PUBLISH) ); + $this->setTemplateVar( 'release',$this->value->page->hasRight(ACL_RELEASE) ); + $this->setTemplateVar( 'publish',$this->value->page->hasRight(ACL_PUBLISH) ); - $this->setTemplateVar( 'objectid',$this->value->page->objectid ); - } + $this->setTemplateVar( 'objectid',$this->value->page->objectid ); + } - /** - * Auswahlbox. - * - */ - private function editselect() - { - $this->setTemplateVar( 'items',$this->value->element->getSelectItems() ); - $this->setTemplateVar( 'text' ,$this->value->text ); + /** + * Auswahlbox. + * + */ + private function editselect() + { + $this->setTemplateVar( 'items',$this->value->element->getSelectItems() ); + $this->setTemplateVar( 'text' ,$this->value->text ); - if ( $this->getSessionVar('pageaction') != '' ) - $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); - else $this->setTemplateVar('old_pageaction','show' ); - } + if ( $this->getSessionVar('pageaction') != '' ) + $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); + else $this->setTemplateVar('old_pageaction','show' ); + } - /** - * Einf�gen-Element. - * - */ - private function editlist() - { - $this->editinsert(); - } + /** + * Einf�gen-Element. + * + */ + private function editlist() + { + $this->editinsert(); + } - /** - * Einf�gen-Element. - * - */ - private function editinsert() - { - // Auswahl ueber alle Elementtypen - $objects = array(); - //Änderung der möglichen Types - $types = array('file','page','link'); - $objects[ 0 ] = lang('LIST_ENTRY_EMPTY'); // Wert "nicht ausgewählt" + /** + * Einf�gen-Element. + * + */ + private function editinsert() + { + // Auswahl ueber alle Elementtypen + $objects = array(); + //Änderung der möglichen Types + $types = array('file','page','link'); + $objects[ 0 ] = lang('LIST_ENTRY_EMPTY'); // Wert "nicht ausgewählt" + + $project = new Project( $this->page->projectid ); + $folder = new Folder($project->getRootObjectId()); + $folder->load(); + + //Auch Dateien dazu + foreach( $project->getAllObjectIds($types) as $id ) + { + $f = new Folder( $id ); + $f->load(); - $project = new Project( $this->page->projectid ); - $folder = new Folder($project->getRootObjectId()); - $folder->load(); + $objects[ $id ] = lang( $f->getType() ).': '; + $objects[ $id ] .= implode( ' &raquo; ',$f->parentObjectNames(false,true) ); + } - //Auch Dateien dazu - foreach( $project->getAllObjectIds($types) as $id ) - { - $f = new Folder( $id ); - $f->load(); + foreach( $project->getAllFolders() as $id ) + { + $f = new Folder( $id ); + $f->load(); - $objects[ $id ] = lang( $f->getType() ).': '; - $objects[ $id ] .= implode( ' &raquo; ',$f->parentObjectNames(false,true) ); - } + $objects[ $id ] = lang( $f->getType() ).': '; + $objects[ $id ] .= implode( ' &raquo; ',$f->parentObjectNames(false,true) ); + } - foreach( $project->getAllFolders() as $id ) - { - $f = new Folder( $id ); - $f->load(); - - $objects[ $id ] = lang( $f->getType() ).': '; - $objects[ $id ] .= implode( ' &raquo; ',$f->parentObjectNames(false,true) ); - } + asort( $objects ); // Sortieren - asort( $objects ); // Sortieren + $this->setTemplateVar('objects' ,$objects); + $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId); - $this->setTemplateVar('objects' ,$objects); - $this->setTemplateVar('linkobjectid',$this->value->linkToObjectId); + if ( $this->getSessionVar('pageaction') != '' ) + $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); + else $this->setTemplateVar('old_pageaction','show' ); + } - if ( $this->getSessionVar('pageaction') != '' ) - $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); - else $this->setTemplateVar('old_pageaction','show' ); - } + /** + * Zahl bearbeiten. + * + */ + private function editnumber() + { + $this->setTemplateVar('number',$this->value->number / pow(10,$this->value->element->decimals) ); - /** - * Zahl bearbeiten. - * - */ - private function editnumber() - { - $this->setTemplateVar('number',$this->value->number / pow(10,$this->value->element->decimals) ); + if ( $this->getSessionVar('pageaction') != '' ) + $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); + else $this->setTemplateVar('old_pageaction','show' ); + } - if ( $this->getSessionVar('pageaction') != '' ) - $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); - else $this->setTemplateVar('old_pageaction','show' ); - } + /** + * Ein Element der Seite bearbeiten + * + * Es wird ein Formular erzeugt, mit dem der Benutzer den Inhalt bearbeiten kann. + */ + private function editlongtext() + { - /** - * Ein Element der Seite bearbeiten - * - * Es wird ein Formular erzeugt, mit dem der Benutzer den Inhalt bearbeiten kann. - */ - private function editlongtext() - { + if ( $this->hasRequestVar('format') ) + // Individual format from request. + $format = $this->getRequestId('format'); + elseif ( $this->value->format != null ) + $format = $this->value->format; + else + // There is no saved value. Get the format from the template element. + $format = $this->element->format; - if ( $this->hasRequestVar('format') ) - // Individual format from request. - $format = $this->getRequestId('format'); - elseif ( $this->value->format != null ) - $format = $this->value->format; - else - // There is no saved value. Get the format from the template element. - $format = $this->element->format; + $this->setTemplateVar('format' ,$format ); + $this->setTemplateVar( 'editor',Element::getAvailableFormats()[ $format ] ); - $this->setTemplateVar('format' ,$format ); - $this->setTemplateVar( 'editor',Element::getAvailableFormats()[ $format ] ); + if ( !isset($this->templateVars['text'])) + // Möglicherweise ist die Ausgabevariable bereits gesetzt, wenn man bereits + // einen Text eingegeben hat (Vorschaufunktion). + $this->setTemplateVar( 'text',$this->linkifyOIDs( $this->value->text ) ); - if ( !isset($this->templateVars['text'])) - // Möglicherweise ist die Ausgabevariable bereits gesetzt, wenn man bereits - // einen Text eingegeben hat (Vorschaufunktion). - $this->setTemplateVar( 'text',$this->linkifyOIDs( $this->value->text ) ); + if ( $this->getSessionVar('pageaction') != '' ) + $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); + else $this->setTemplateVar('old_pageaction','show' ); - if ( $this->getSessionVar('pageaction') != '' ) - $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); - else $this->setTemplateVar('old_pageaction','show' ); - - if ( $this->element->wiki && false /* OLD */ ) - { - $project = new Project( $this->page->projectid ); - $languages = $project->getLanguages(); + if ( $this->element->wiki && false /* OLD */ ) + { + $project = new Project( $this->page->projectid ); + $languages = $project->getLanguages(); + + if ( count($languages) > 1 ) + { + $languages[$this->value->languageid] = $languages[$this->value->languageid].' *'; + $this->setTemplateVar('languages',$languages); + } + + if ( $this->hasRequestVar('otherlanguageid') ) + { + $lid = $this->getRequestVar('otherlanguageid'); + $otherValue = new Value(); + $otherValue->languageid = $lid; + $otherValue->pageid = $this->value->pageid; + $otherValue->element = $this->value->element; + $otherValue->elementid = $this->value->elementid; + $otherValue->publisher = $this->value->publisher; + $otherValue->load(); + $this->setTemplateVar('languagetext' ,wordwrap($otherValue->text,100) ); + $this->setTemplateVar('languagename' ,$languages[$lid] ); + $this->setTemplateVar('otherlanguageid',$lid ); + } + + if ( !isset($this->templateVars['text'])) + // Möglicherweise ist die Ausgabevariable bereits gesetzt, wenn man bereits + // einen Text eingegeben hat (Vorschaufunktion). + $this->setTemplateVar( 'text',$this->value->text ); + } - if ( count($languages) > 1 ) - { - $languages[$this->value->languageid] = $languages[$this->value->languageid].' *'; - $this->setTemplateVar('languages',$languages); - } + } - if ( $this->hasRequestVar('otherlanguageid') ) - { - $lid = $this->getRequestVar('otherlanguageid'); - $otherValue = new Value(); - $otherValue->languageid = $lid; - $otherValue->pageid = $this->value->pageid; - $otherValue->element = $this->value->element; - $otherValue->elementid = $this->value->elementid; - $otherValue->publisher = $this->value->publisher; - $otherValue->load(); - $this->setTemplateVar('languagetext' ,wordwrap($otherValue->text,100) ); - $this->setTemplateVar('languagename' ,$languages[$lid] ); - $this->setTemplateVar('otherlanguageid',$lid ); - } - if ( !isset($this->templateVars['text'])) - // Möglicherweise ist die Ausgabevariable bereits gesetzt, wenn man bereits - // einen Text eingegeben hat (Vorschaufunktion). - $this->setTemplateVar( 'text',$this->value->text ); - } - } + /** + * Ein Element der Seite bearbeiten + * + * Es wird ein Formular erzeugt, mit dem der Benutzer den Inhalt bearbeiten kann. + */ + private function edittext() + { + $this->setTemplateVar( 'text',$this->value->text ); + if ( $this->getSessionVar('pageaction') != '' ) + $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); + else $this->setTemplateVar('old_pageaction','show' ); + } - /** - * Ein Element der Seite bearbeiten - * - * Es wird ein Formular erzeugt, mit dem der Benutzer den Inhalt bearbeiten kann. - */ - private function edittext() - { - $this->setTemplateVar( 'text',$this->value->text ); - if ( $this->getSessionVar('pageaction') != '' ) - $this->setTemplateVar('old_pageaction',$this->getSessionVar('pageaction')); - else $this->setTemplateVar('old_pageaction','show' ); - } + /** + * Wiederherstellung eines alten Inhaltes. + */ + public function usePost() + { + $this->value->valueid = $this->getRequestVar('valueid'); + $this->value->loadWithId(); + $this->value->element = new Element( $this->value->elementid ); + if ( $this->value->pageid != $this->page->pageid ) + throw new \LogicException( 'Cannot find value','page-id does not match' ); + // Pruefen, ob Berechtigung zum Freigeben besteht + //$this->value->release = $this->page->hasRight(ACL_RELEASE); + $this->value->release = false; - /** - * Wiederherstellung eines alten Inhaltes. - */ - public function usePost() - { - $this->value->valueid = $this->getRequestVar('valueid'); - $this->value->loadWithId(); - $this->value->element = new Element( $this->value->elementid ); + // Inhalt wieder herstellen, in dem er neu gespeichert wird. + $this->value->save(); - if ( $this->value->pageid != $this->page->pageid ) - throw new \LogicException( 'Cannot find value','page-id does not match' ); + $this->addNotice('pageelement',$this->value->element->name,'PAGEELEMENT_USE_FROM_ARCHIVE',OR_NOTICE_OK); + } - // Pruefen, ob Berechtigung zum Freigeben besteht - //$this->value->release = $this->page->hasRight(ACL_RELEASE); - $this->value->release = false; - - // Inhalt wieder herstellen, in dem er neu gespeichert wird. - $this->value->save(); - - $this->addNotice('pageelement',$this->value->element->name,'PAGEELEMENT_USE_FROM_ARCHIVE',OR_NOTICE_OK); - } + /** + * Freigeben eines Inhaltes + */ + public function releasePost() + { + $this->value->valueid = intval($this->getRequestVar('valueid')); + $this->value->loadWithId(); - /** - * Freigeben eines Inhaltes - */ - public function releasePost() - { - $this->value->valueid = intval($this->getRequestVar('valueid')); - $this->value->loadWithId(); + if ( $this->value->pageid != $this->page->pageid ) + throw new LogicException( 'cannot release, bad page' ); - if ( $this->value->pageid != $this->page->pageid ) - throw new LogicException( 'cannot release, bad page' ); + // Pruefen, ob Berechtigung zum Freigeben besteht + if ( !$this->page->hasRight(ACL_RELEASE) ) + throw new \SecurityException( 'Cannot release','no right' ); - // Pruefen, ob Berechtigung zum Freigeben besteht - if ( !$this->page->hasRight(ACL_RELEASE) ) - throw new \SecurityException( 'Cannot release','no right' ); + // Inhalt freigeben + $this->value->release(); - // Inhalt freigeben - $this->value->release(); - - $this->addNotice('pageelement',$this->value->element->name,'PAGEELEMENT_RELEASED',OR_NOTICE_OK); - } + $this->addNotice('pageelement',$this->value->element->name,'PAGEELEMENT_RELEASED',OR_NOTICE_OK); + } - /** - * Erzeugt eine Liste aller Versionsst?nde zu diesem Inhalt - */ - public function historyView() - { - $this->page->load(); - $this->value->page = &$this->page; + /** + * Erzeugt eine Liste aller Versionsst?nde zu diesem Inhalt + */ + public function historyView() + { + $this->page->load(); + $this->value->page = &$this->page; - $this->value->publisher = $this->page->publisher; - $this->value->languageid = $this->page->languageid; - $this->value->objectid = $this->page->objectid; - $this->value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - $this->value->element = &$this->element; - $this->value->element->load(); + $this->value->publisher = $this->page->publisher; + $this->value->languageid = $this->page->languageid; + $this->value->objectid = $this->page->objectid; + $this->value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); + $this->value->element = &$this->element; + $this->value->element->load(); - $list = array(); - // $version_list = array(); - $lfd_nr = 0; + $list = array(); + // $version_list = array(); + $lfd_nr = 0; - foreach( $this->value->getVersionList() as $value ) - { - $lfd_nr++; - $value->element = &$this->element; - $value->page = &$this->page; - $value->publisher = &$this->page->publisher; - $value->generate(); - - - // $date = date( lang('DATE_FORMAT'),$value->lastchangeTimeStamp); - - // if ( in_array( $this->element->type,array('text','longtext') ) ) - // $version_list[ $value->valueid ] = '('.$lfd_nr.') '.$date; - - $zeile = array( 'value' => Text::maxLaenge( 50,$value->value), - 'objectid' => $this->page->objectid, - 'date' => $value->lastchangeTimeStamp, - 'lfd_nr' => $lfd_nr, - 'id' => $value->valueid, - 'valueid' => $value->valueid, - 'user' => $value->lastchangeUserName ); - - // Nicht aktive Inhalte k�nnen direkt bearbeitet werden und sind - // nach dem Speichern dann wieder aktiv (nat�rlich als n�chster/neuer Inhalt) - if ( ! $value->active ) - $zeile['useUrl'] = Html::url('pageelement','usevalue',$this->page->objectid,array('valueid' =>$value->valueid,'mode'=>'edit')); - - // Freigeben des Inhaltes. - // Nur das aktive Inhaltselement kann freigegeben werden. Nat�rlich auch nur, - // wenn es nicht schon freigegeben ist. - if ( ! $value->publish && $value->active ) - $zeile['releaseUrl'] = Html::url('pageelement','release',$this->page->objectid,array('valueid' =>$value->valueid )); - - $zeile['public'] = $value->publish; - $zeile['active'] = $value->active; - - $list[$lfd_nr] = $zeile; + foreach( $this->value->getVersionList() as $value ) + { + $lfd_nr++; + $value->element = &$this->element; + $value->page = &$this->page; + $value->publisher = &$this->page->publisher; + $value->generate(); - } - if ( in_array( $this->value->element->type, array('longtext') ) && $lfd_nr >= 2 ) - { - $this->setTemplateVar('compareid',$list[$lfd_nr-1]['id']); - $this->setTemplateVar('withid' ,$list[$lfd_nr ]['id']); - } + // $date = date( lang('DATE_FORMAT'),$value->lastchangeTimeStamp); - $this->setTemplateVar('name' ,$this->element->name); - $this->setTemplateVar('el' ,$list ); - } + // if ( in_array( $this->element->type,array('text','longtext') ) ) + // $version_list[ $value->valueid ] = '('.$lfd_nr.') '.$date; + $zeile = array( 'value' => Text::maxLaenge( 50,$value->value), + 'objectid' => $this->page->objectid, + 'date' => $value->lastchangeTimeStamp, + 'lfd_nr' => $lfd_nr, + 'id' => $value->valueid, + 'valueid' => $value->valueid, + 'user' => $value->lastchangeUserName ); - /** - * Vergleicht 2 Versionen eines Inhaltes - */ - function diffView() - { - $value1id = $this->getRequestVar('compareid'); - $value2id = $this->getRequestVar('withid' ); + // Nicht aktive Inhalte k�nnen direkt bearbeitet werden und sind + // nach dem Speichern dann wieder aktiv (nat�rlich als n�chster/neuer Inhalt) + if ( ! $value->active ) + $zeile['useUrl'] = Html::url('pageelement','usevalue',$this->page->objectid,array('valueid' =>$value->valueid,'mode'=>'edit')); - // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen - if ( $value1id == $value2id ) - { - $this->addValidationError('compareid' ); - $this->addValidationError('withid' ,''); - $this->callSubAction('archive'); - return; - } + // Freigeben des Inhaltes. + // Nur das aktive Inhaltselement kann freigegeben werden. Nat�rlich auch nur, + // wenn es nicht schon freigegeben ist. + if ( ! $value->publish && $value->active ) + $zeile['releaseUrl'] = Html::url('pageelement','release',$this->page->objectid,array('valueid' =>$value->valueid )); - // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen - if ( $value1id > $value2id ) - list($value1id,$value2id) = array( $value2id,$value1id ); + $zeile['public'] = $value->publish; + $zeile['active'] = $value->active; + $list[$lfd_nr] = $zeile; - $value1 = new Value( $value1id ); - $value2 = new Value( $value2id ); - $value1->valueid = $value1id; - $value2->valueid = $value2id; + } - $value1->loadWithId(); - $value2->loadWithId(); + if ( in_array( $this->value->element->type, array('longtext') ) && $lfd_nr >= 2 ) + { + $this->setTemplateVar('compareid',$list[$lfd_nr-1]['id']); + $this->setTemplateVar('withid' ,$list[$lfd_nr ]['id']); + } - $this->setTemplateVar('date_left' ,$value1->lastchangeTimeStamp); - $this->setTemplateVar('date_right',$value2->lastchangeTimeStamp); + $this->setTemplateVar('name' ,$this->element->name); + $this->setTemplateVar('el' ,$list ); + } - $text1 = explode("\n",$value1->text); - $text2 = explode("\n",$value2->text); - // Unterschiede feststellen. - $res_diff = Text::diff($text1,$text2); + /** + * Vergleicht 2 Versionen eines Inhaltes + */ + function diffView() + { + $value1id = $this->getRequestVar('compareid'); + $value2id = $this->getRequestVar('withid' ); - list( $text1,$text2 ) = $res_diff; + // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen + if ( $value1id == $value2id ) + { + $this->addValidationError('compareid' ); + $this->addValidationError('withid' ,''); + $this->callSubAction('archive'); + return; + } - $diff = array(); - $i = 0; - while( isset($text1[$i]) || isset($text2[$i]) ) - { - $line = array(); + // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen + if ( $value1id > $value2id ) + list($value1id,$value2id) = array( $value2id,$value1id ); - if ( isset($text1[$i]['text']) ) - $line['left'] = $text1[$i]; - if ( isset($text2[$i]['text']) ) - $line['right'] = $text2[$i]; + $value1 = new Value( $value1id ); + $value2 = new Value( $value2id ); + $value1->valueid = $value1id; + $value2->valueid = $value2id; - $i++; - $diff[] = $line; - } - $this->setTemplateVar('diff',$diff ); - } + $value1->loadWithId(); + $value2->loadWithId(); + $this->setTemplateVar('date_left' ,$value1->lastchangeTimeStamp); + $this->setTemplateVar('date_right',$value2->lastchangeTimeStamp); + $text1 = explode("\n",$value1->text); + $text2 = explode("\n",$value2->text); - /** - * Ein Element der Seite speichern. - */ - public function valuePost() - { - $this->element->load(); - $type = $this->element->type; + // Unterschiede feststellen. + $res_diff = Text::diff($text1,$text2); - if ( empty($type)) - throw new \InvalidArgumentException('No element type available'); + list( $text1,$text2 ) = $res_diff; - $funktionName = 'save'.$type; + $diff = array(); + $i = 0; + while( isset($text1[$i]) || isset($text2[$i]) ) + { + $line = array(); - if ( !method_exists($this,$funktionName)) - throw new \InvalidArgumentException('Function not available: '.$funktionName); + if ( isset($text1[$i]['text']) ) + $line['left'] = $text1[$i]; - $this->$funktionName(); // Aufruf Methode "save<ElementTyp>()" - } + if ( isset($text2[$i]['text']) ) + $line['right'] = $text2[$i]; + $i++; + $diff[] = $line; + } + $this->setTemplateVar('diff',$diff ); + } - /** - * Element speichern - * - * Der Inhalt eines Elementes wird abgespeichert - */ - private function savetext() - { - $value = new Value(); - $value->languageid = $this->page->languageid; - $value->objectid = $this->page->objectid; - $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - if ( !$this->hasRequestVar('elementid') ) - throw new ValidationException('elementid'); - $value->element = new Element( $this->getRequestVar('elementid') ); + /** + * Ein Element der Seite speichern. + */ + public function valuePost() + { + $this->element->load(); + $type = $this->element->type; - $value->element->load(); - $value->load(); + if ( empty($type)) + throw new \InvalidArgumentException('No element type available'); - if ( $this->hasRequestVar('linkobjectid') ) - $value->linkToObjectId = $this->getRequestVar('linkobjectid'); - else - $value->text = $this->getRequestVar('text','raw'); + $funktionName = 'save'.$type; - $this->afterSave($value); - } + if ( !method_exists($this,$funktionName)) + throw new \InvalidArgumentException('Function not available: '.$funktionName); + $this->$funktionName(); // Aufruf Methode "save<ElementTyp>()" + } - /** - * Nach dem Speichern weitere Dinge ausfuehren.<br> - * - Inhalt freigeben<br> - * - Seite veroeffentlichen<br> - * - Inhalt fuer andere Sprachen speichern<br> - * - Hinweis ueber erfolgtes Speichern ausgeben<br> - * <br> - * Nicht zu verwechseln mit <i>Aftershave</i> :) - * @param $value Value - * @throws \ObjectNotFoundException - */ - private function afterSave( $value ) - { - $value->page = new Page( $value->objectid ); - $value->page->load(); + /** + * Element speichern + * + * Der Inhalt eines Elementes wird abgespeichert + */ + private function savetext() + { + $value = new Value(); + $value->languageid = $this->page->languageid; + $value->objectid = $this->page->objectid; + $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - // Inhalt sofort freigegeben, wenn - // - Recht vorhanden - // - Freigabe gewuenscht - if ( $value->page->hasRight( ACL_RELEASE ) && $this->hasRequestVar('release') ) - $value->publish = true; - else - $value->publish = false; + if ( !$this->hasRequestVar('elementid') ) + throw new ValidationException('elementid'); + $value->element = new Element( $this->getRequestVar('elementid') ); - // Up-To-Date-Check - $lastChangeTime = $value->getLastChangeTime(); - if ( $lastChangeTime > $this->getRequestVar('value_time') ) - { - $this->addNotice('pageelement',$value->element->name,'CONCURRENT_VALUE_CHANGE',OR_NOTICE_WARN,array('last_change_time'=>date(lang('DATE_FORMAT'),$lastChangeTime))); - } + $value->element->load(); + $value->load(); - // Inhalt speichern + if ( $this->hasRequestVar('linkobjectid') ) + $value->linkToObjectId = $this->getRequestVar('linkobjectid'); + else + $value->text = $this->getRequestVar('text','raw'); - // Wenn Inhalt in allen Sprachen gleich ist, dann wird der Inhalt - // fuer jede Sprache einzeln gespeichert. - if ( $value->element->allLanguages ) - { - $project = new Project( $this->page->projectid ); - foreach( $project->getLanguageIds() as $languageid ) - { - $value->languageid = $languageid; - $value->save(); - } - } - else - { - // sonst nur 1x speichern (fuer die aktuelle Sprache) - $value->save(); - } + $this->afterSave($value); + } - $this->addNotice('pageelement',$value->element->name,'SAVED',OR_NOTICE_OK); - $this->page->setTimestamp(); // "Letzte Aenderung" setzen - // Falls ausgewaehlt die Seite sofort veroeffentlichen - if ( $value->page->hasRight( ACL_PUBLISH ) && $this->hasRequestVar('publish') ) - { - $this->page->publish(); - $this->addNotice('pageelement',$value->element->name,'PUBLISHED',OR_NOTICE_OK); - } - } + /** + * Nach dem Speichern weitere Dinge ausfuehren.<br> + * - Inhalt freigeben<br> + * - Seite veroeffentlichen<br> + * - Inhalt fuer andere Sprachen speichern<br> + * - Hinweis ueber erfolgtes Speichern ausgeben<br> + * <br> + * Nicht zu verwechseln mit <i>Aftershave</i> :) + * @param $value Value + * @throws \ObjectNotFoundException + */ + private function afterSave( $value ) + { + $value->page = new Page( $value->objectid ); + $value->page->load(); - /** - * Element speichern - * - * Der Inhalt eines Elementes wird abgespeichert - */ - private function savelongtext() - { - global $conf; - $value = new Value(); - $value->languageid = $this->page->languageid; - $value->objectid = $this->page->objectid; - $value->publisher = $this->page->publisher; - - $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - - if ( !$this->hasRequestVar('elementid') ) - throw new ValidationException('elementid'); - $value->element = new Element( $this->getRequestVar('elementid') ); - - $value->element->load(); - $value->load(); - - if ( $this->hasRequestVar('format') ) - $value->format = $this->getRequestId('format'); - else - // Fallback: Format of the element. - $value->format = $this->element->format; - - if ( $this->hasRequestVar('linkobjectid') ) - $value->linkToObjectId = $this->getRequestVar('linkobjectid'); - else - $value->text = $this->compactOIDs( $this->getRequestVar('text','raw') ); - - // Vorschau anzeigen - if ( $this->hasRequestVar('preview' ) || - $this->hasRequestVar('addmarkup') ) - { - $inputText = $this->getRequestVar('text','raw'); - if ( $this->hasRequestVar('preview') ) - { - $value->page = $this->page; - $value->simple = false; - $value->page->languageid = $value->languageid; - $value->page->load(); - $value->generate(); - $this->setTemplateVar('preview',$value->value ); - } + // Inhalt sofort freigegeben, wenn + // - Recht vorhanden + // - Freigabe gewuenscht + if ( $value->page->hasRight( ACL_RELEASE ) && $this->hasRequestVar('release') ) + $value->publish = true; + else + $value->publish = false; - if ( $this->hasRequestVar('addmarkup') ) - { - $conf_tags = $conf['editor']['text-markup']; - - if ( $this->hasRequestVar('addtext') ) // Nur, wenn ein Text eingegeben wurde - { - $addText = $this->getRequestVar('addtext','raw'); - - if ( $this->hasRequestVar('strong') ) - $inputText .= $conf_tags['strong-begin'].$addText.$conf_tags['strong-end']; - - if ( $this->hasRequestVar('emphatic') ) - $inputText .= $conf_tags['emphatic-begin'].$addText.$conf_tags['emphatic-end']; - - if ( $this->hasRequestVar('link') ) - $inputText .= '"'.$addText.'"'.$conf_tags['linkto'].'"'.$this->parseOID($this->getRequestVar('objectid')).'"'; - } - - if ( $this->hasRequestVar('table') ) - $inputText .= "\n". - $conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep']."\n". - $conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep']."\n". - $conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep'].' '.$addText.' '.$conf_tags['table-cell-sep']."\n"; - - if ( $this->hasRequestVar('list') ) - $inputText .= "\n". - $conf_tags['list-unnumbered'].' '.$addText."\n". - $conf_tags['list-unnumbered'].' '.$addText."\n". - $conf_tags['list-unnumbered'].' '.$addText."\n"; - - if ( $this->hasRequestVar('numlist') ) - $inputText .= "\n". - $conf_tags['list-numbered'].' '.$addText."\n". - $conf_tags['list-numbered'].' '.$addText."\n". - $conf_tags['list-numbered'].' '.$addText."\n"; - - if ( $this->hasRequestVar('image') ) - $inputText .= $conf_tags['image-begin'].$this->parseOID($this->getRequestVar('objectid')).$conf_tags['image-end']; - } + // Up-To-Date-Check + $lastChangeTime = $value->getLastChangeTime(); + if ( $lastChangeTime > $this->getRequestVar('value_time') ) + { + $this->addNotice('pageelement',$value->element->name,'CONCURRENT_VALUE_CHANGE',OR_NOTICE_WARN,array('last_change_time'=>date(lang('DATE_FORMAT'),$lastChangeTime))); + } - // Ermitteln aller verlinkbaren Objekte (fuer Editor) - /* - $objects = array(); + // Inhalt speichern - foreach( Folder::getAllObjectIds() as $id ) - { - $o = new Object( $id ); - $o->load(); + // Wenn Inhalt in allen Sprachen gleich ist, dann wird der Inhalt + // fuer jede Sprache einzeln gespeichert. + if ( $value->element->allLanguages ) + { + $project = new Project( $this->page->projectid ); + foreach( $project->getLanguageIds() as $languageid ) + { + $value->languageid = $languageid; + $value->save(); + } + } + else + { + // sonst nur 1x speichern (fuer die aktuelle Sprache) + $value->save(); + } - if ( $o->getType() != 'folder' ) - { - $f = new Folder( $o->parentid ); - $objects[ $id ] = lang( 'GLOBAL_'.$o->getType() ).': '; - $objects[ $id ] .= implode( FILE_SEP,$f->parentObjectNames(false,true) ); - $objects[ $id ] .= FILE_SEP.$o->name; - } - } - asort($objects); - $this->setTemplateVar( 'objects' ,$objects ); - */ - - $this->setTemplateVar( 'release' ,$this->page->hasRight(ACL_RELEASE) ); - $this->setTemplateVar( 'publish' ,$this->page->hasRight(ACL_PUBLISH) ); - $this->setTemplateVar( 'html' ,$value->element->html ); - $this->setTemplateVar( 'wiki' ,$value->element->wiki ); - $this->setTemplateVar( 'text' ,$inputText ); - $this->setTemplateVar( 'name' ,$value->element->name ); - $this->setTemplateVar( 'desc' ,$value->element->desc ); - $this->setTemplateVar( 'objectid',$this->page->objectid ); - - $this->setTemplateVar( 'mode' ,'edit' ); - } - else - { - $this->afterSave($value); - } + $this->addNotice('pageelement',$value->element->name,'SAVED',OR_NOTICE_OK); + $this->page->setTimestamp(); // "Letzte Aenderung" setzen - } + // Falls ausgewaehlt die Seite sofort veroeffentlichen + if ( $value->page->hasRight( ACL_PUBLISH ) && $this->hasRequestVar('publish') ) + { + $this->page->publish(); + $this->addNotice('pageelement',$value->element->name,'PUBLISHED',OR_NOTICE_OK); + } + } - /** - * Element speichern - * - * Der Inhalt eines Elementes wird abgespeichert - */ - private function savedate() - { - $value = new Value(); - $value->languageid = $this->page->languageid; - $value->objectid = $this->page->objectid; - $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - - if ( !$this->hasRequestVar('elementid') ) - throw new ValidationException('elementid'); - - $value->element = new Element( $this->getRequestVar('elementid') ); - $value->element->load(); - $value->load(); - - if ( $this->hasRequestVar('linkobjectid') ) - $value->linkToObjectId = $this->getRequestVar('linkobjectid'); - elseif ( $this->hasRequestVar('date') ) - // Wenn ein Timestamp übergeben wurde, dann dieses verwenden - $value->date = $this->getRequestVar('date'); - elseif ( $this->getRequestVar('ansidate') != $this->getRequestVar('ansidate_orig') ) - // Wenn ein ANSI-Datum eingegeben wurde, dann dieses verwenden - $value->date = strtotime($this->getRequestVar('ansidate') ); - else - // Sonst die Zeitwerte einzeln zu einem Datum zusammensetzen - $value->date = mktime( $this->getRequestVar('hour' ), - $this->getRequestVar('minute'), - $this->getRequestVar('second'), - $this->getRequestVar('month' ), - $this->getRequestVar('day' ), - $this->getRequestVar('year' ) ); + /** + * Element speichern + * + * Der Inhalt eines Elementes wird abgespeichert + */ + private function savelongtext() + { + global $conf; + $value = new Value(); + $value->languageid = $this->page->languageid; + $value->objectid = $this->page->objectid; + $value->publisher = $this->page->publisher; - $this->afterSave($value); - } + $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); + if ( !$this->hasRequestVar('elementid') ) + throw new ValidationException('elementid'); + $value->element = new Element( $this->getRequestVar('elementid') ); + $value->element->load(); + $value->load(); - /** - * Element speichern - * - * Der Inhalt eines Elementes wird abgespeichert - */ - private function saveselect() - { - $value = new Value(); - $value->languageid = $this->page->languageid; - $value->objectid = $this->page->objectid; - $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); + if ( $this->hasRequestVar('format') ) + $value->format = $this->getRequestId('format'); + else + // Fallback: Format of the element. + $value->format = $this->element->format; - if ( !$this->hasRequestVar('elementid') ) - throw new ValidationException('elementid'); - $value->element = new Element( $this->getRequestVar('elementid') ); + $value->text = $this->compactOIDs( $this->getRequestVar('text','raw') ); - $value->element->load(); - $value->load(); + // Vorschau anzeigen + if ( $this->hasRequestVar('preview' ) || + $this->hasRequestVar('addmarkup') ) + { + $inputText = $this->getRequestVar('text','raw'); + + if ( $this->hasRequestVar('preview') ) + { + $value->page = $this->page; + $value->simple = false; + $value->page->languageid = $value->languageid; + $value->page->load(); + $value->generate(); + $this->setTemplateVar('preview',$value->value ); + } + + + $this->setTemplateVar( 'release' ,$this->page->hasRight(ACL_RELEASE) ); + $this->setTemplateVar( 'publish' ,$this->page->hasRight(ACL_PUBLISH) ); + $this->setTemplateVar( 'html' ,$value->element->html ); + $this->setTemplateVar( 'wiki' ,$value->element->wiki ); + $this->setTemplateVar( 'text' ,$inputText ); + $this->setTemplateVar( 'name' ,$value->element->name ); + $this->setTemplateVar( 'desc' ,$value->element->desc ); + $this->setTemplateVar( 'objectid',$this->page->objectid ); + + $this->setTemplateVar( 'mode' ,'edit' ); + } + else + { + $this->afterSave($value); + } - $value->text = $this->getRequestVar('text'); + } - $this->afterSave($value); - } + /** + * Element speichern + * + * Der Inhalt eines Elementes wird abgespeichert + */ + private function savedate() + { + $value = new Value(); + $value->languageid = $this->page->languageid; + $value->objectid = $this->page->objectid; + $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); + + if ( !$this->hasRequestVar('elementid') ) + throw new ValidationException('elementid'); + + $value->element = new Element( $this->getRequestVar('elementid') ); + $value->element->load(); + $value->load(); + + if ( $this->hasRequestVar('linkobjectid') ) + $value->linkToObjectId = $this->getRequestVar('linkobjectid'); + elseif ( $this->hasRequestVar('date') ) + // Wenn ein Timestamp übergeben wurde, dann dieses verwenden + $value->date = $this->getRequestVar('date'); + elseif ( $this->getRequestVar('ansidate') != $this->getRequestVar('ansidate_orig') ) + // Wenn ein ANSI-Datum eingegeben wurde, dann dieses verwenden + $value->date = strtotime($this->getRequestVar('ansidate') ); + else + // Sonst die Zeitwerte einzeln zu einem Datum zusammensetzen + $value->date = mktime( $this->getRequestVar('hour' ), + $this->getRequestVar('minute'), + $this->getRequestVar('second'), + $this->getRequestVar('month' ), + $this->getRequestVar('day' ), + $this->getRequestVar('year' ) ); + + $this->afterSave($value); + } - /** - * Element speichern - * - * Der Inhalt eines Elementes wird abgespeichert - */ - private function savelink() - { - $value = new Value(); - $value->publisher = $this->page->publisher; - $value->languageid = $this->page->languageid; - $value->objectid = $this->page->objectid; - $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - if ( !$this->hasRequestVar('elementid') ) - throw new ValidationException('elementid'); - $value->element = new Element( $this->getRequestVar('elementid') ); + /** + * Element speichern + * + * Der Inhalt eines Elementes wird abgespeichert + */ + private function saveselect() + { + $value = new Value(); + $value->languageid = $this->page->languageid; + $value->objectid = $this->page->objectid; + $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - $value->element->load(); - $value->load(); + if ( !$this->hasRequestVar('elementid') ) + throw new ValidationException('elementid'); + $value->element = new Element( $this->getRequestVar('elementid') ); - if ( $this->hasRequestVar('linkurl') ) - $value->linkToObjectId = $this->parseOID($this->getRequestVar('linkurl')); - else - $value->linkToObjectId = intval($this->getRequestVar('linkobjectid')); + $value->element->load(); + $value->load(); - $this->afterSave($value); - } + $value->text = $this->getRequestVar('text'); + $this->afterSave($value); + } - /** - * Element speichern - * - * Der Inhalt eines Elementes wird abgespeichert - */ - private function savelist() - { - $this->saveinsert(); - } + /** + * Element speichern + * + * Der Inhalt eines Elementes wird abgespeichert + */ + private function savelink() + { + $value = new Value(); + $value->publisher = $this->page->publisher; + $value->languageid = $this->page->languageid; + $value->objectid = $this->page->objectid; + $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); + if ( !$this->hasRequestVar('elementid') ) + throw new ValidationException('elementid'); + $value->element = new Element( $this->getRequestVar('elementid') ); - /** - * Element speichern - * - * Der Inhalt eines Elementes wird abgespeichert - */ - private function saveinsert() - { - $value = new Value(); - $value->publisher = $this->page->publisher; - $value->languageid = $this->page->languageid; - $value->objectid = $this->page->objectid; - $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); + $value->element->load(); + $value->load(); - if ( !$this->hasRequestVar('elementid') ) - throw new ValidationException('elementid'); - $value->element = new Element( $this->getRequestVar('elementid') ); + if ( $this->hasRequestVar('linkurl') ) + $value->linkToObjectId = $this->parseSimpleOID($this->getRequestVar('linkurl')); + else + $value->linkToObjectId = intval($this->getRequestVar('linkobjectid')); - $value->element->load(); - $value->load(); + $this->afterSave($value); + } - $value->linkToObjectId = intval($this->getRequestVar('linkobjectid')); - $this->afterSave($value); - } + /** + * Element speichern + * + * Der Inhalt eines Elementes wird abgespeichert + */ + private function savelist() + { + $this->saveinsert(); + } - /** - * Element speichern - * - * Der Inhalt eines Elementes wird abgespeichert - */ - private function savenumber() - { - $value = new Value(); - $value->languageid = $this->page->languageid; - $value->objectid = $this->page->objectid; - $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - if ( !$this->hasRequestVar('elementid') ) - throw new ValidationException('elementid'); - $value->element = new Element( $this->getRequestVar('elementid') ); + /** + * Element speichern + * + * Der Inhalt eines Elementes wird abgespeichert + */ + private function saveinsert() + { + $value = new Value(); + $value->publisher = $this->page->publisher; + $value->languageid = $this->page->languageid; + $value->objectid = $this->page->objectid; + $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); - $value->element->load(); - $value->load(); + if ( !$this->hasRequestVar('elementid') ) + throw new ValidationException('elementid'); + $value->element = new Element( $this->getRequestVar('elementid') ); - if ( $this->hasRequestVar('linkobjectid') ) - $value->linkToObjectId = $this->getRequestVar('linkobjectid'); - else - $value->number = $this->getRequestVar('number') * pow(10,$value->element->decimals); + $value->element->load(); + $value->load(); - $this->afterSave($value); - } + $value->linkToObjectId = intval($this->getRequestVar('linkobjectid')); + $this->afterSave($value); + } - function exportlongtext() - { - $types = array(); - foreach( array('odf','plaintext') as $type ) - { - $types[$type] = lang('FILETYPE_'.$type); - } - $this->setTemplateVar('types',$types); - } + /** + * Element speichern + * + * Der Inhalt eines Elementes wird abgespeichert + */ + private function savenumber() + { + $value = new Value(); + $value->languageid = $this->page->languageid; + $value->objectid = $this->page->objectid; + $value->pageid = Page::getPageIdFromObjectId( $this->page->objectid ); + if ( !$this->hasRequestVar('elementid') ) + throw new ValidationException('elementid'); + $value->element = new Element( $this->getRequestVar('elementid') ); - function importlongtext() - { - $types = array(); + $value->element->load(); + $value->load(); - foreach( array('odf','plaintext') as $type ) - { - $types[$type] = lang('FILETYPE_'.$type); - } - $this->setTemplateVar('types',$types); - } + if ( $this->hasRequestVar('linkobjectid') ) + $value->linkToObjectId = $this->getRequestVar('linkobjectid'); + else + $value->number = $this->getRequestVar('number') * pow(10,$value->element->decimals); + $this->afterSave($value); + } - function doexportlongtext() - { - $type = $this->getRequestVar('type'); - switch($type) - { - case 'odf': - // Angabe Content-Type - // header('Content-Type: '.$this->file->mimeType()); - // header('X-File-Id: '.$this->file->fileid); + function exportlongtext() + { + $types = array(); - // header('Content-Disposition: inline; filename='.$this->id.'.odt'); - header('Content-Transfer-Encoding: binary'); - // header('Content-Description: '.$this->file->name); + foreach( array('odf','plaintext') as $type ) + { + $types[$type] = lang('FILETYPE_'.$type); + } - echo $this->createOdfDocument(); + $this->setTemplateVar('types',$types); + } - exit; - default: - } + function importlongtext() + { + $types = array(); - exit; - } + foreach( array('odf','plaintext') as $type ) + { + $types[$type] = lang('FILETYPE_'.$type); + } + $this->setTemplateVar('types',$types); + } - /** - * ODF erzeugen.<br> - * vorerst ZURUECKGESTELLT! - * - * @return unknown - */ - private function createOdfDocument() - { - // TODO: ODF ist nicht ganz ohne. - $transformer = new Transformer(); - $transformer->text = $this->value->text; - $transformer->type = 'odf'; - $transformer->transform(); - return $transformer->text; - } + function doexportlongtext() + { + $type = $this->getRequestVar('type'); + switch($type) + { + case 'odf': + // Angabe Content-Type + // header('Content-Type: '.$this->file->mimeType()); + // header('X-File-Id: '.$this->file->fileid); + // header('Content-Disposition: inline; filename='.$this->id.'.odt'); + header('Content-Transfer-Encoding: binary'); + // header('Content-Description: '.$this->file->name); + echo $this->createOdfDocument(); - function linkifyOIDs( $text ) - { - foreach( Text::parseOID($text) as $oid=>$t ) - { - $url = $this->page->path_to_object($oid); - $text = str_replace($t,'"'.$url.'"',$text); - } + exit; - return $text; - } + default: + } + + exit; + } - function compactOIDs( $text ) - { - foreach( Text::parseOID($text) as $oid=>$t ) - { - $text = str_replace($t,'"?__OID__'.$oid.'__"',$text); - } + /** + * ODF erzeugen.<br> + * vorerst ZURUECKGESTELLT! + * + * @return unknown + */ + private function createOdfDocument() + { + // TODO: ODF ist nicht ganz ohne. + $transformer = new Transformer(); + $transformer->text = $this->value->text; + $transformer->type = 'odf'; + $transformer->transform(); + return $transformer->text; + } - return $text; - } - function parseOID( $text ) - { - $treffer = array(); - preg_match_all('/(.*)__OID__([0-9]+)__(.*)/', $text, $treffer,PREG_SET_ORDER); - $oid = $treffer[0][2]; - - if ( !empty($oid) ) - return $oid; - else - return intval($text); - } + private function linkifyOIDs( $text ) + { + foreach( Text::parseOID($text) as $oid=>$t ) + { + $url = $this->page->path_to_object($oid); + foreach( $t as $match) + $text = str_replace($match,$url,$text); + } + + return $text; + } + + + private function compactOIDs( $text ) + { + foreach( Text::parseOID($text) as $oid=>$t ) + { + foreach( $t as $match) + $text = str_replace($match,'?__OID__'.$oid.'__',$text); + } + + return $text; + } + + + /** + * Gets the Object-Id from an string. + * + * @param $text + * @return int + */ + private function parseSimpleOID($text ) + { + $treffer = Text::parseOID( $text ); + + if ( isset($treffer[0])) + // Found an Object-Id. + return $treffer[0][0]; + else + return intval($text); + } /** * Seite veroeffentlichen diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php @@ -1186,7 +1186,9 @@ SQL foreach( Text::parseOID($inhalt) as $oid=>$t ) { $url = $this->page->path_to_object($oid); - $inhalt = str_replace($t,'"'.$url.'"',$inhalt); + + foreach( $t as $match ) + $inhalt = str_replace($match,$url,$inhalt); } break; diff --git a/modules/template-engine/components/html/editor/editor.js b/modules/template-engine/components/html/editor/editor.js @@ -5,36 +5,6 @@ $(document).on('orViewLoaded',function(event, data) { $(event.target).find('textarea').orAutoheight(); - // ACE-Editor anzeigen - $(event.target).find("textarea.editor.ace-editor").each( function() { - alert('ACE is not supported') - throw new Error('No ACE available'); - - var textareaEl = $(this); - var aceEl = $("<div class=\"editor__code-editor\" />").insertAfter(textareaEl); - var editor = ace.edit( aceEl.get(0) ); - var mode = textareaEl.data('mode'); - - editor.renderer.setShowGutter(true); - editor.setTheme("ace/theme/github"); - -// editor.setReadOnly(true); - editor.getSession().setTabSize(4); - editor.getSession().setUseWrapMode(true); - editor.setHighlightActiveLine(true); - editor.getSession().setValue( textareaEl.val() ); - editor.getSession().setMode("ace/mode/" + mode); - editor.getSession().on('change', function(e) { - textareaEl.val(editor.getSession().getValue()); - } ); - - // copy back to textarea on form submit... - textareaEl.closest('form').submit(function() { - textareaEl.val( editor.getSession().getValue() ); - }) - } ); - - // Codemirror-Editor anzeigen $(event.target).find("textarea.editor.code-editor").each( function() { @@ -221,7 +191,7 @@ $(document).on('orViewLoaded',function(event, data) { let insertText = ''; let id = dropped.data('id'); - let url = 'object:'+id; + let url = '__OID__'+id+'__'; if ( dropped.data('type') == 'image') insertText = '![]('+url+')'; else @@ -258,7 +228,7 @@ $(document).on('orViewLoaded',function(event, data) { let dropped = ui.draggable; let id = dropped.data('id'); - let url = './?_='+dropped.data('type')+'-'+id+'&subaction=show&embed=1&oid='+dropped.data('id'); + let url = './?_='+dropped.data('type')+'-'+id+'&subaction=show&embed=1&__OID__'+id+'__='+id; let insertText = ''; if ( dropped.data('type') == 'image') insertText = '<img src="'+url+'" alt="" />'; diff --git a/modules/template-engine/components/html/editor/editor.min.js b/modules/template-engine/components/html/editor/editor.min.js @@ -1 +1 @@ -;$(document).on('orViewLoaded',function(e,t){$(e.target).find('textarea').orAutoheight();$(e.target).find('textarea.editor.ace-editor').each(function(){alert('ACE is not supported');throw new Error('No ACE available');var t=$(this),i=$('<div class="editor__code-editor" />').insertAfter(t),e=ace.edit(i.get(0)),o=t.data('mode');e.renderer.setShowGutter(!0);e.setTheme('ace/theme/github');e.getSession().setTabSize(4);e.getSession().setUseWrapMode(!0);e.setHighlightActiveLine(!0);e.getSession().setValue(t.val());e.getSession().setMode('ace/mode/'+o);e.getSession().on('change',function(i){t.val(e.getSession().getValue())});t.closest('form').submit(function(){t.val(e.getSession().getValue())})});$(e.target).find('textarea.editor.code-editor').each(function(){let mode=$(this).data('mode');let mimetype=$(this).data('mimetype');if(mimetype.length>0)mode=mimetype;let textareaEl=this;let editor=CodeMirror.fromTextArea(textareaEl,{lineNumbers:!0,viewportMargin:Infinity,mode:mode});editor.on('change',function(){let newValue=editor.getValue();$(textareaEl).val(newValue)});$(editor.getWrapperElement()).droppable({accept:'.or-draggable',hoverClass:'or-droppable--hover',activeClass:'or-droppable--active',drop:function(e,t){let dropped=t.draggable;let pos=editor.getCursor();editor.setSelection(pos,pos);let insertText=dropped.data('id');let toInsert=''+insertText;editor.replaceSelection(toInsert)}})});$(e.target).find('textarea.editor.markdown-editor').each(function(){let textarea=this;let toolbar=[{name:'bold',action:SimpleMDE.toggleBold,className:'image-icon image-icon--editor-bold',title:'Bold',},{name:'italic',action:SimpleMDE.toggleItalic,className:'image-icon image-icon--editor-italic',title:'Italic',},{name:'heading',action:SimpleMDE.toggleHeadingBigger,className:'image-icon image-icon--editor-headline',title:'Headline',},'|',{name:'quote',action:SimpleMDE.toggleBlockquote,className:'image-icon image-icon--editor-quote',title:'Quote',},{name:'code',action:SimpleMDE.toggleCodeBlock,className:'image-icon image-icon--editor-code',title:'Code',},'|',{name:'generic list',action:SimpleMDE.toggleUnorderedList,className:'image-icon image-icon--editor-unnumberedlist',title:'Unnumbered list',},{name:'numbered list',action:SimpleMDE.toggleOrderedList,className:'image-icon image-icon--editor-numberedlist',title:'Numbered list',},'|',{name:'table',action:SimpleMDE.drawTable,className:'image-icon image-icon--editor-table',title:'Table',},{name:'horizontalrule',action:SimpleMDE.drawHorizontalRule,className:'image-icon image-icon--editor-horizontalrule',title:'Horizontal rule',},'|',{name:'undo',action:SimpleMDE.undo,className:'image-icon image-icon--editor-undo',title:'Undo',},{name:'redo',action:SimpleMDE.redo,className:'image-icon image-icon--editor-redo',title:'Redo',},'|',{name:'link',action:SimpleMDE.drawLink,className:'image-icon image-icon--editor-link',title:'Link',},{name:'image',action:SimpleMDE.drawImage,className:'image-icon image-icon--editor-image',title:'Image',},'|',{name:'guide',action:'https://simplemde.com/markdown-guide',className:'image-icon image-icon--editor-help',title:'Howto markdown',},];let mde=new SimpleMDE({element:$(this)[0],toolbar:toolbar});let codemirror=mde.codemirror;$(codemirror.getWrapperElement()).droppable({accept:'.or-draggable',hoverClass:'or-droppable--hover',activeClass:'or-droppable--active',drop:function(e,t){let dropped=t.draggable;let insertText='';let id=dropped.data('id');let url='object:'+id;if(dropped.data('type')=='image')insertText='![]('+url+')';else insertText='['+id+']('+url+')';let pos=codemirror.getCursor();codemirror.setSelection(pos,pos);codemirror.replaceSelection(insertText)}});codemirror.on('change',function(){let newValue=codemirror.getValue();$(textarea).val(newValue)})});$(e.target).find('textarea.editor.html-editor').each(function(){let textarea=this;$.trumbowyg.svgPath='./modules/editor/trumbowyg/ui/icons.svg';$(textarea).trumbowyg();$(textarea).closest('form').find('.trumbowyg-editor').droppable({accept:'.or-draggable',hoverClass:'or-droppable--hover',activeClass:'or-droppable--active',drop:function(e,t){let dropped=t.draggable;let id=dropped.data('id');let url='./?_='+dropped.data('type')+'-'+id+'&subaction=show&embed=1&oid='+dropped.data('id');let insertText='';if(dropped.data('type')=='image')insertText='<img src="'+url+'" alt="" />';else insertText='<a href="'+url+'" />'+id+'</a>';$(textarea).trumbowyg('execCmd',{cmd:'insertHTML',param:insertText,forceCss:!1,})}})})});- \ No newline at end of file +;$(document).on('orViewLoaded',function(e,t){$(e.target).find('textarea').orAutoheight();$(e.target).find('textarea.editor.code-editor').each(function(){let mode=$(this).data('mode');let mimetype=$(this).data('mimetype');if(mimetype.length>0)mode=mimetype;let textareaEl=this;let editor=CodeMirror.fromTextArea(textareaEl,{lineNumbers:!0,viewportMargin:Infinity,mode:mode});editor.on('change',function(){let newValue=editor.getValue();$(textareaEl).val(newValue)});$(editor.getWrapperElement()).droppable({accept:'.or-draggable',hoverClass:'or-droppable--hover',activeClass:'or-droppable--active',drop:function(t,e){let dropped=e.draggable;let pos=editor.getCursor();editor.setSelection(pos,pos);let insertText=dropped.data('id');let toInsert=''+insertText;editor.replaceSelection(toInsert)}})});$(e.target).find('textarea.editor.markdown-editor').each(function(){let textarea=this;let toolbar=[{name:'bold',action:SimpleMDE.toggleBold,className:'image-icon image-icon--editor-bold',title:'Bold',},{name:'italic',action:SimpleMDE.toggleItalic,className:'image-icon image-icon--editor-italic',title:'Italic',},{name:'heading',action:SimpleMDE.toggleHeadingBigger,className:'image-icon image-icon--editor-headline',title:'Headline',},'|',{name:'quote',action:SimpleMDE.toggleBlockquote,className:'image-icon image-icon--editor-quote',title:'Quote',},{name:'code',action:SimpleMDE.toggleCodeBlock,className:'image-icon image-icon--editor-code',title:'Code',},'|',{name:'generic list',action:SimpleMDE.toggleUnorderedList,className:'image-icon image-icon--editor-unnumberedlist',title:'Unnumbered list',},{name:'numbered list',action:SimpleMDE.toggleOrderedList,className:'image-icon image-icon--editor-numberedlist',title:'Numbered list',},'|',{name:'table',action:SimpleMDE.drawTable,className:'image-icon image-icon--editor-table',title:'Table',},{name:'horizontalrule',action:SimpleMDE.drawHorizontalRule,className:'image-icon image-icon--editor-horizontalrule',title:'Horizontal rule',},'|',{name:'undo',action:SimpleMDE.undo,className:'image-icon image-icon--editor-undo',title:'Undo',},{name:'redo',action:SimpleMDE.redo,className:'image-icon image-icon--editor-redo',title:'Redo',},'|',{name:'link',action:SimpleMDE.drawLink,className:'image-icon image-icon--editor-link',title:'Link',},{name:'image',action:SimpleMDE.drawImage,className:'image-icon image-icon--editor-image',title:'Image',},'|',{name:'guide',action:'https://simplemde.com/markdown-guide',className:'image-icon image-icon--editor-help',title:'Howto markdown',},];let mde=new SimpleMDE({element:$(this)[0],toolbar:toolbar,autoDownloadFontAwesome:!1});let codemirror=mde.codemirror;$(codemirror.getWrapperElement()).droppable({accept:'.or-draggable',hoverClass:'or-droppable--hover',activeClass:'or-droppable--active',drop:function(t,e){let dropped=e.draggable;let insertText='';let id=dropped.data('id');let url='__OID__'+id+'__';if(dropped.data('type')=='image')insertText='![]('+url+')';else insertText='['+id+']('+url+')';let pos=codemirror.getCursor();codemirror.setSelection(pos,pos);codemirror.replaceSelection(insertText)}});codemirror.on('change',function(){let newValue=codemirror.getValue();$(textarea).val(newValue)})});$(e.target).find('textarea.editor.html-editor').each(function(){let textarea=this;$.trumbowyg.svgPath='./modules/editor/trumbowyg/ui/icons.svg';$(textarea).trumbowyg();$(textarea).closest('form').find('.trumbowyg-editor').droppable({accept:'.or-draggable',hoverClass:'or-droppable--hover',activeClass:'or-droppable--active',drop:function(t,e){let dropped=e.draggable;let id=dropped.data('id');let url='./?_='+dropped.data('type')+'-'+id+'&subaction=show&embed=1&__OID__'+id+'__='+id;let insertText='';if(dropped.data('type')=='image')insertText='<img src="'+url+'" alt="" />';else insertText='<a href="'+url+'" />'+id+'</a>';$(textarea).trumbowyg('execCmd',{cmd:'insertHTML',param:insertText,forceCss:!1,})}})})});+ \ No newline at end of file diff --git a/modules/template-engine/components/html/image/image.js b/modules/template-engine/components/html/image/image.js @@ -1,10 +1,5 @@ +/* $(document).on('orViewLoaded',function(event, data) { - // Convert linked SVG to an inline SVG, because we want to style it... - - // Elements to inject - var mySVGsToInject = document.querySelectorAll('img.image-icon'); - - // Do the injection - SVGInjector(mySVGsToInject); -}); - \ No newline at end of file +}); +*/+ \ No newline at end of file diff --git a/modules/template-engine/components/html/image/image.min.js b/modules/template-engine/components/html/image/image.min.js @@ -1 +1 @@ -;$(document).on('orViewLoaded',function(o,n){var e=document.querySelectorAll('img.image-icon');SVGInjector(e)});- \ No newline at end of file +;+ \ No newline at end of file diff --git a/modules/util/Text.class.php b/modules/util/Text.class.php @@ -340,25 +340,6 @@ class Text /** - * Entfernt einen Text-Bereich aus einer Zeichenkette.<br> - * Es wird angegeben, von wo bis wo entfernt werden soll. - * - * @param $text Text, aus dem entfernt wird - * @param $von der Text, AB dem entfernt wird - * @param $bis der Text, BIS ZU DEM entfernt wird - * @return String Text - */ - public static function entferneVonBis($text,$von,$bis) - { - $beg = strpos($text,$von); - $end = strpos($text,$bis); - if ( $beg!==false && $end !==false ) - $text = substr($text,0,$beg).substr($text,$end+strlen($bis)); - return $text; - } - - - /** * Saeubert eine Zeichenkette. * * Es werden ungueltige Zeichen aus einer Zeichenkette entfernt. Es wird mit einer Whitelist @@ -376,16 +357,31 @@ class Text } - + /** + * Searches for Object-Ids in a text. + * Searches in the provided text for URLs with "__OID__nnn__", where nnn is an object id. + * @param $text + * @return array + */ public static function parseOID( $text ) { $oids = array(); $treffer = array(); + + $urlChars = '[A-Za-z0-9_.:,\/=+&?-]'; - preg_match_all('/\"([^\"]*)__OID__([0-9]+)__([^\"]*)\"/', $text, $treffer,PREG_SET_ORDER); + preg_match_all('/('.$urlChars.'*)__OID__([0-9]+)__('.$urlChars.'*)/', $text, $treffer,PREG_SET_ORDER); - foreach( $treffer as $t ) - $oids[$t[2]] = $t[0]; + foreach( $treffer as $t ) { + + $id = $t[2]; + $match = $t[0]; + + if ( !isset( $oids[$id])) + $oids[$id] = array(); + + $oids[$id][] = $match; + } return $oids; }