PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.22
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.22
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / app / Hooks / Handlers / ExternalPages.php

ExternalPages.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.22, at app/Hooks/Handlers/ExternalPages.php

105 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Hooks\Handlers;
4
5 use FluentBoards\App\Models\Attachment;
6 use FluentBoards\App\App;
7 use FluentBoards\App\Models\CommentImage;
8 use FluentBoards\App\Models\Meta;
9 use FluentBoards\App\Services\Constant;
10 use FluentBoards\App\Services\Libs\FileSystem;
11
12 class ExternalPages
13 {
14 public function view_uploaded_comment_image()
15 {
16 $attachmentHash = sanitize_text_field($_REQUEST['fbs_comment_image']);
17 $boardId = sanitize_text_field($_REQUEST['fbs_bid']);
18
19 if (empty($attachmentHash)) {
20 die('Invalid Attachment Hash');
21 }
22
23 $attachment = $this->getUploadedImageByHash($attachmentHash);
24
25 if (!$attachment) {
26 die('Invalid Attachment Hash');
27 }
28
29 $fileName = $attachment->file_path;
30 $boardId = $boardId;
31 $filePath = FileSystem::setSubDir('board_' . $boardId)->getDir() . DIRECTORY_SEPARATOR . $fileName;
32 if (!file_exists($filePath)) {
33 die('File could not be found.');
34 }
35
36 $this->serveLocalAttachment($attachment, $filePath);
37 }
38
39 public function view_comment_image()
40 {
41 $attachmentHash = sanitize_text_field($_REQUEST['fbs_comment_image']);
42
43 if (empty($attachmentHash)) {
44 die('Invalid Attachment Hash');
45 }
46
47 $attachment = $this->getUploadedImageByHash($attachmentHash);
48
49 if (in_array($attachment->object_type, [Constant::TASK_DESCRIPTION, Constant::COMMENT_IMAGE])) {
50 $attachment->load('comment');
51 }
52
53 if (!$attachment) {
54 die('Invalid Attachment Hash');
55 }
56
57 // check signature hash
58 if (!$this->validateAttachmentSignature($attachment)) {
59 $dieMessage = __('Sorry, Your secure sign is invalid, Please reload the previous page and get new signed url', 'fluent-support');
60 die($dieMessage);
61 }
62
63 //If external file
64 if ('local' !== $attachment->driver) {
65 if(!empty($attachment->file_path)){
66 $this->redirectToExternalAttachment($attachment->full_url);
67 }else{
68 die('File could not be found');
69 }
70 }
71
72 //Handle Local file
73 if (in_array($attachment->object_type, [Constant::TASK_DESCRIPTION, Constant::COMMENT_IMAGE])) {
74 $fileName = $attachment->file_path;
75 $boardId = $attachment->comment->board_id;
76 }
77
78 $filePath = FileSystem::setSubDir('board_' . $boardId)->getDir() . DIRECTORY_SEPARATOR . $fileName;
79 if (!file_exists($filePath)) {
80 die('File could not be found.');
81 }
82
83 $this->serveLocalAttachment($attachment, $filePath);
84 }
85
86 private function getUploadedImageByHash($attachmentHash)
87 {
88 return CommentImage::where('file_hash', $attachmentHash)->first();
89 }
90
91 private function serveLocalAttachment($attachment, $filePath)
92 {
93 ob_get_clean();
94 header("Content-Type: {$attachment->attachment_type}");
95 header("Content-Disposition: inline; filename=\"{$attachment->title}\"");;
96 echo readfile($filePath);
97 die();
98 }
99
100 private function validateAttachmentSignature($attachment)
101 {
102 $sign = md5($attachment->id . date('YmdH'));
103 return $sign === $_REQUEST['secure_sign'];
104 }
105 }