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

165 lines 5.2 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 if ('local' !== $attachment->driver) {
31 if(!empty($attachment->file_path)){
32 $this->redirectToExternalAttachment($attachment->full_url);
33 }else{
34 die('File could not be found');
35 }
36 return;
37 }
38 $fileName = $attachment->file_path;
39 $boardId = $boardId;
40 $filePath = $fileName;
41 if(!file_exists($fileName)){
42 $filePath = FileSystem::setSubDir('board_' . $boardId)->getDir() . DIRECTORY_SEPARATOR . $fileName;
43 }
44
45 if (!file_exists($filePath)) {
46 die('File could not be found.');
47 }
48
49 $this->serveLocalAttachment($attachment, $filePath);
50 }
51
52 public function view_comment_image()
53 {
54 $attachmentHash = sanitize_text_field($_REQUEST['fbs_comment_image']);
55
56 if (empty($attachmentHash)) {
57 die('Invalid Attachment Hash');
58 }
59
60 $attachment = $this->getUploadedImageByHash($attachmentHash);
61
62 if (in_array($attachment->object_type, [Constant::COMMENT_IMAGE])) {
63 $attachment->load('comment');
64 } elseif (in_array($attachment->object_type, [Constant::TASK_DESCRIPTION])) {
65 $attachment['task'] = Task::find($attachment->object_id);
66 }
67
68 if (!$attachment) {
69 die('Invalid Attachment Hash');
70 }
71
72 // check signature hash
73 if (!$this->validateAttachmentSignature($attachment)) {
74 $dieMessage = __('Sorry, Your secure sign is invalid, Please reload the previous page and get new signed url', 'fluent-boards');
75 die($dieMessage);
76 }
77
78 //If external file
79 if ('local' !== $attachment->driver) {
80 if(!empty($attachment->file_path)){
81 $this->redirectToExternalAttachment($attachment->full_url);
82 }else{
83 die('File could not be found');
84 }
85 }
86
87 //Handle Local file
88 if (in_array($attachment->object_type, [Constant::COMMENT_IMAGE])) {
89 $fileName = $attachment->file_path;
90 $boardId = $attachment->comment->board_id;
91 } elseif (in_array($attachment->object_type, [Constant::TASK_DESCRIPTION])) {
92 $fileName = $attachment->file_path;
93 $boardId = $attachment->task->board_id;
94 }
95
96 $filePath = $fileName;
97 if(!file_exists($fileName)){
98 $filePath = FileSystem::setSubDir('board_' . $boardId)->getDir() . DIRECTORY_SEPARATOR . $fileName;
99 }
100
101 if (!file_exists($filePath)) {
102 die('File could not be found.');
103 }
104
105 $this->serveLocalAttachment($attachment, $filePath);
106 }
107
108 private function getUploadedImageByHash($attachmentHash)
109 {
110 return CommentImage::where('file_hash', $attachmentHash)->first();
111 }
112
113 private function serveLocalAttachment($attachment, $filePath)
114 {
115 ob_get_clean();
116 header("Content-Type: {$attachment->attachment_type}");
117 header("Content-Disposition: inline; filename=\"{$attachment->title}\"");;
118 echo readfile($filePath);
119 die();
120 }
121
122 private function validateAttachmentSignature($attachment)
123 {
124 $sign = md5($attachment->id . date('YmdH'));
125 return $sign === $_REQUEST['secure_sign'];
126 }
127
128 public function redirectToPage()
129 {
130 $taskId = $_GET['taskId'];
131 $task = Task::findOrFail($taskId);
132 if ($this->isFrontendEnabled() == 'no') {
133 $urlBase = apply_filters('fluent_boards/app_url', admin_url('admin.php?page=fluent-boards#/'));
134 $page_url = $urlBase . 'boards/' . $task->board_id . '/tasks/' . $task->id . '-' .substr($task->title, 0, 10);
135 wp_redirect($page_url);
136 exit;
137 } else {
138 $urlBase = apply_filters('fluent_boards/app_url');
139 $page_url = $urlBase . 'boards/' . $task->board_id . '/tasks/' . $task->id . '-' .substr($task->title, 0, 10);
140 wp_redirect($page_url);
141 exit;
142 }
143
144 die();
145 }
146
147 private function isFrontendEnabled()
148 {
149 $storedSettings = get_option('fluent_boards_modules', []);
150 if ($storedSettings && is_array($storedSettings)) {
151 $settings = maybe_serialize($storedSettings);
152 }
153
154 if (isset($settings['frontend']['enabled'])) {
155 return $settings['frontend']['enabled'];
156 }
157
158 return 'no';
159 }
160 private function redirectToExternalAttachment($redirectUrl)
161 {
162 wp_redirect($redirectUrl, 307);
163 exit();
164 }
165 }