From e07184ea29b9f59ec9faaa76116b5487098a38d4 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 Sep 2023 18:05:07 -0700 Subject: [PATCH 1/7] Update FileController.php --- src/controllers/FileController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/FileController.php b/src/controllers/FileController.php index 9d1ec50..fb9b2af 100644 --- a/src/controllers/FileController.php +++ b/src/controllers/FileController.php @@ -47,12 +47,12 @@ public function actionUpload() } } - public function actionDownload($id) + public function actionDownload($id,$inline=false) { $file = File::findOne(['id' => $id]); $filePath = $this->getModule()->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type; - return Yii::$app->response->sendFile($filePath, "$file->name.$file->type"); + return Yii::$app->response->sendFile($filePath, "$file->name.$file->type",['inline'=>$inline]); } public function actionDelete($id) From 5468587d58085358c16393b4cfb756ecdc543de0 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 Sep 2023 18:05:41 -0700 Subject: [PATCH 2/7] Update File.php --- src/models/File.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/File.php b/src/models/File.php index 316d293..1481842 100644 --- a/src/models/File.php +++ b/src/models/File.php @@ -70,9 +70,9 @@ public function attributeLabels() ]; } - public function getUrl() + public function getUrl($inline = false) { - return Url::to(['/attachments/file/download', 'id' => $this->id]); + return Url::to(['/attachments/file/download', 'id' => $this->id,'inline'=>$inline]); } public function getPath() From 517615c7913575af8f7491a39288c3d1b6e06ee0 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 Sep 2023 18:20:28 -0700 Subject: [PATCH 3/7] Update FileBehavior.php --- src/behaviors/FileBehavior.php | 40 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/behaviors/FileBehavior.php b/src/behaviors/FileBehavior.php index 4be4b3b..499f04d 100644 --- a/src/behaviors/FileBehavior.php +++ b/src/behaviors/FileBehavior.php @@ -102,15 +102,7 @@ public function getInitialPreview() } foreach ($this->getFiles() as $file) { - if (substr($file->mime, 0, 5) === 'image') { - $initialPreview[] = Html::img($file->getUrl(), ['class' => 'file-preview-image']); - } else { - $initialPreview[] = Html::beginTag('div', ['class' => 'file-preview-other']) . - Html::beginTag('h2') . - Html::tag('i', '', ['class' => 'glyphicon glyphicon-file']) . - Html::endTag('h2') . - Html::endTag('div'); - } + $initialPreview[] =$file->getUrl(true); } return $initialPreview; @@ -132,14 +124,28 @@ public function getInitialPreviewConfig() } foreach ($this->getFiles() as $index => $file) { - $initialPreviewConfig[] = [ - 'caption' => "$file->name.$file->type", - 'url' => Url::toRoute(['/attachments/file/delete', - 'id' => $file->id - ]), - ]; - } + if(str_contains($file->mime,"image") + { + $initialPreviewConfig[] = [ + 'type'=>'image', + 'caption' => "$file->name.$file->type", + 'url' => Url::toRoute(['/attachments/file/delete', + 'id' => $file->id + ]), + ]; + } + else + { + $initialPreviewConfig[] = [ + 'type'=>$file->type, + 'caption' => "$file->name.$file->type", + 'url' => Url::toRoute(['/attachments/file/delete', + 'id' => $file->id + ]), + ]; + + } return $initialPreviewConfig; } -} \ No newline at end of file +} From 8c93052f31bf2d649e5310da9f26845e7485bee1 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 Sep 2023 18:22:46 -0700 Subject: [PATCH 4/7] Update AttachmentsInput.php --- src/components/AttachmentsInput.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/AttachmentsInput.php b/src/components/AttachmentsInput.php index bd662fa..3493cb1 100644 --- a/src/components/AttachmentsInput.php +++ b/src/components/AttachmentsInput.php @@ -40,6 +40,8 @@ public function init() FileHelper::removeDirectory($this->getModule()->getUserDirPath()); // Delete all uploaded files in past $this->pluginOptions = array_replace($this->pluginOptions, [ + 'initialPreviewFileType'=> 'image', + 'initialPreviewAsData'=> 'true', //let kartik deal with the previews! 'uploadUrl' => Url::toRoute('/attachments/file/upload'), 'uploadAsync' => false ]); From 2a882b81e997f40ad21acb625e2e97f639d7dc8f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 Sep 2023 18:24:20 -0700 Subject: [PATCH 5/7] Update FileBehavior.php --- src/behaviors/FileBehavior.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/behaviors/FileBehavior.php b/src/behaviors/FileBehavior.php index 499f04d..77f1962 100644 --- a/src/behaviors/FileBehavior.php +++ b/src/behaviors/FileBehavior.php @@ -124,7 +124,7 @@ public function getInitialPreviewConfig() } foreach ($this->getFiles() as $index => $file) { - if(str_contains($file->mime,"image") + if(str_contains($file->mime,"image")) { $initialPreviewConfig[] = [ 'type'=>'image', From 67899ccffab7ab4508a4e90a8893097a33e14bff Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 Sep 2023 18:27:53 -0700 Subject: [PATCH 6/7] Update FileBehavior.php --- src/behaviors/FileBehavior.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/behaviors/FileBehavior.php b/src/behaviors/FileBehavior.php index 77f1962..5c69645 100644 --- a/src/behaviors/FileBehavior.php +++ b/src/behaviors/FileBehavior.php @@ -124,7 +124,7 @@ public function getInitialPreviewConfig() } foreach ($this->getFiles() as $index => $file) { - if(str_contains($file->mime,"image")) + if(str_contains($file->mime,"image")) { $initialPreviewConfig[] = [ 'type'=>'image', @@ -134,8 +134,8 @@ public function getInitialPreviewConfig() ]), ]; } - else - { + else + { $initialPreviewConfig[] = [ 'type'=>$file->type, 'caption' => "$file->name.$file->type", @@ -145,7 +145,7 @@ public function getInitialPreviewConfig() ]; } - + } return $initialPreviewConfig; } } From e83ca75424c4aa936a171154155e2fd7a6953751 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 Sep 2023 18:43:28 -0700 Subject: [PATCH 7/7] Update FileBehavior.php --- src/behaviors/FileBehavior.php | 45 ++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/behaviors/FileBehavior.php b/src/behaviors/FileBehavior.php index 5c69645..0f62ccf 100644 --- a/src/behaviors/FileBehavior.php +++ b/src/behaviors/FileBehavior.php @@ -125,25 +125,44 @@ public function getInitialPreviewConfig() foreach ($this->getFiles() as $index => $file) { if(str_contains($file->mime,"image")) - { - $initialPreviewConfig[] = [ - 'type'=>'image', + { + $initialPreviewConfig[] = [ 'caption' => "$file->name.$file->type", 'url' => Url::toRoute(['/attachments/file/delete', - 'id' => $file->id - ]), + 'id' => $file->id]) ]; - } - else - { - $initialPreviewConfig[] = [ - 'type'=>$file->type, + } + elseif(str_contains($file->mime,"text")){ + $initialPreviewConfig[] = [ + 'type'=> "text", + 'caption' => "$file->name.$file->type", + 'url' => Url::toRoute(['/attachments/file/delete', + 'id' => $file->id]) + ]; + } + elseif(str_contains($file->mime,"video")){ + $initialPreviewConfig[] = [ + 'type'=> "video", + 'caption' => "$file->name.$file->type", + 'url' => Url::toRoute(['/attachments/file/delete', + 'id' => $file->id]) + ]; + } + elseif(str_contains($file->mime,"doc")||str_contains($file->mime,".ppt")||str_contains($file->mime,".xls")){ + $initialPreviewConfig[] = [ + 'type'=> "office", + 'caption' => "$file->name.$file->type", + 'url' => Url::toRoute(['/attachments/file/delete', + 'id' => $file->id]) + ]; + } + else{ + $initialPreviewConfig[] = [ + 'type'=> $file->type, 'caption' => "$file->name.$file->type", 'url' => Url::toRoute(['/attachments/file/delete', - 'id' => $file->id - ]), + 'id' => $file->id]) ]; - } } return $initialPreviewConfig;