File modules/cms/action/folder/FolderCreatetextAction.class.php

Last commit: Tue Feb 14 00:23:13 2023 +0100	Jan Dankert	New filters: Robots (for robots.txt) and Sitemap.
1 <?php 2 namespace cms\action\folder; 3 use cms\action\FolderAction; 4 use cms\action\Method; 5 use cms\model\BaseObject; 6 use cms\model\Permission; 7 use cms\model\Text; 8 use language\Messages; 9 use util\exception\ValidationException; 10 use util\Http; 11 use util\Upload; 12 13 14 class FolderCreatetextAction extends FolderAction implements Method { 15 public function getRequiredPermission() { 16 return Permission::ACL_CREATE_FILE; 17 } 18 19 public function view() { 20 // Maximale Dateigroesse. 21 $maxSizeBytes = $this->maxFileSize(); 22 $this->setTemplateVar('max_size' ,($maxSizeBytes/1024).' KB' ); 23 $this->setTemplateVar('maxlength',$maxSizeBytes ); 24 25 $this->setTemplateVar('objectid',$this->folder->objectid ); 26 } 27 28 29 public function post() { 30 31 $name = $this->request->getText('name' ); 32 $description = $this->request->getText('description'); 33 34 $text = new Text(); 35 $text->parentid = $this->folder->objectid; 36 $text->projectid = $this->folder->projectid; 37 38 // Die neue Datei wird über eine URL geladen und dann im CMS gespeichert. 39 $this->request->handleText('url', function($url) use ($text) 40 { 41 if ( !$url ) 42 return; // URl was empty. 43 44 $http = new Http(); 45 $http->setUrl( $url ); 46 47 $ok = $http->request(); 48 49 if ( !$ok ) 50 { 51 //$this->addNotice($http->error); 52 // TODO: What to do with $http->error ? 53 throw new ValidationException('url',Messages::COMMON_VALIDATION_ERROR); 54 } 55 56 $text->filename = BaseObject::urlify( basename($url) ); 57 $text->size = strlen($http->body); 58 $text->value = $http->body; 59 }); 60 61 $this->request->handleText('text',function($value) use ($text) { 62 $text->filename = $this->request->getRequiredText('filename' ); 63 $text->extension = $this->request->getRequiredText('extension'); 64 $text->value = $this->request->getRequiredText('text' ); 65 $text->size = strlen( $text->value ); 66 }); 67 68 $upload = new Upload(); 69 70 if ( $upload->isAvailable() ) { 71 72 try 73 { 74 $upload->processUpload(); 75 } 76 catch( \Exception $e ) 77 { 78 // TODO: make a UIException? 79 throw $e; 80 } 81 82 $text->filename = BaseObject::urlify( $upload->filename ); 83 $text->extension = $upload->extension; 84 $text->size = $upload->size; 85 86 $text->value = $upload->value; 87 } 88 89 $text->persist(); // Datei hinzufuegen 90 $text->setNameForAllLanguages( $name,$description ); 91 92 $this->addNoticeFor($text, Messages::ADDED); 93 $this->setTemplateVar('objectid',$text->objectid); 94 95 $this->folder->setTimestamp(); 96 } 97 }
Download modules/cms/action/folder/FolderCreatetextAction.class.php
History Tue, 14 Feb 2023 00:23:13 +0100 Jan Dankert New filters: Robots (for robots.txt) and Sitemap. Wed, 9 Mar 2022 13:28:52 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()' Sun, 13 Feb 2022 21:52:50 +0100 dankert Fix: Create text objects by direct input of the value. Sat, 6 Mar 2021 03:42:38 +0100 Jan Dankert New: Better permission checks. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Wed, 18 Nov 2020 01:46:36 +0100 Jan Dankert Refactoring of model classes: New method persist() and some other cleanups. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.