PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.31
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.31
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.31, at app/Hooks/Handlers/ExternalPages.php

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