PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.1.1
Fluent Support – Helpdesk & Customer Support Ticket System v2.1.1
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
← All changes | app/Http/Controllers/UploaderController.php +13 -84 2.3.22.1.1 View file →
@@ -26,34 +26,20 @@
26 26 public function uploadTicketFiles(Request $request)
27 27 {
28 28 $settings = (new Settings())->globalBusinessSettings();
29 29 $maxFileSize = floatval($settings['max_file_size']);
30 - $maxFileUpload = intval($settings['max_file_upload']);
31 30 $mimeHeadings = Helper::getAcceptedMimeHeadings();
32 31 $maxSizeBytes = $maxFileSize * 1024;
33 32 $imageType = $request->type ? $request->type : null;
34 33
35 - $files = $request->files();
36 -
37 - if ($partsError = $this->rejectUnexpectedFileParts($files)) {
38 - return $partsError;
39 - }
40 -
34 + $this->validateUploadedFiles($request->files(), $maxSizeBytes, $mimeHeadings, $maxFileSize);
41 35 $ticketId = $this->resolveTicketId($request);
42 36 $person = $this->resolvePerson($ticketId, $request);
43 37
44 - if ($permissionError = $this->checkPermissionToUploadFile($person)) {
45 - return $permissionError;
46 - }
38 + $this->checkPermissionToUploadFile($person);
47 39
48 - if ($quotaError = $this->checkAttachmentQuota($files, $person, $ticketId, $maxFileUpload)) {
49 - return $quotaError;
50 - }
51 -
52 - $this->validateUploadedFiles($files, $maxSizeBytes, $mimeHeadings, $maxFileSize);
53 -
54 40 try {
55 - $uploadedFiles = UploadService::handleTempFileUpload($files);
41 + $uploadedFiles = UploadService::handleTempFileUpload($request->files());
56 42 } catch (\Exception $e) {
57 43 return $this->sendError([
58 44 'message' => Helper::getSafeErrorMessage($e),
59 45 ]);
@@ -71,51 +57,8 @@
71 57 'attachments' => $attachmentHashes,
72 58 ];
73 59 }
74 60
75 - /**
76 - * Only the "file" multipart part is validated and processed downstream
77 - * (UploadService/FileSystem::put() loops every top-level part it is given), so
78 - * any other part name must be rejected here rather than silently passed through.
79 - */
80 - private function rejectUnexpectedFileParts($files)
81 - {
82 - $files = (array) $files;
83 - $unexpectedKeys = array_diff(array_keys($files), ['file']);
84 -
85 - if ($unexpectedKeys || empty($files['file'])) {
86 - return $this->sendError([
87 - 'message' => __('Invalid file upload request.', 'fluent-support'),
88 - ]);
89 - }
90 -
91 - return null;
92 - }
93 -
94 - private function checkAttachmentQuota($files, $person, $ticketId, $maxFileUpload)
95 - {
96 - if ($maxFileUpload <= 0) {
97 - return null;
98 - }
99 -
100 - $newFiles = isset($files['file']) ? $files['file'] : null;
101 - $newFilesCount = is_array($newFiles) ? count($newFiles) : 1;
102 -
103 - $existingCount = Attachment::where('person_id', $person->id)
104 - ->where('ticket_id', $ticketId)
105 - ->where('status', 'in-active')
106 - ->count();
107 -
108 - if (($existingCount + $newFilesCount) > $maxFileUpload) {
109 - return $this->sendError([
110 - // translators: %d is the maximum number of files allowed per ticket
111 - 'message' => sprintf(__('You can upload a maximum of %d files.', 'fluent-support'), $maxFileUpload),
112 - ]);
113 - }
114 -
115 - return null;
116 - }
117 -
118 61 private function validateUploadedFiles($files, $maxSizeBytes, $mimeHeadings, $maxFileSize)
119 62 {
120 63 $validationRules = [
121 64 'file' => 'max:' . $maxSizeBytes . '|mimetypes:' . implode(',', Helper::ticketAcceptedFileMiles()),
@@ -133,27 +76,15 @@
133 76
134 77 private function resolveTicketId($request)
135 78 {
136 79 $ticketId = $request->getSafe('ticket_id', 'intval');
137 -
138 - if ($ticketId == 'undefined' || !$ticketId) {
139 - return null;
140 - }
141 -
142 - if (Helper::getCurrentAgent()) {
143 - return $ticketId;
144 - }
145 -
146 - $ticket = Ticket::wherePublicIdentifier($ticketId)->first();
147 -
148 - return $ticket ? $ticket->id : null;
80 + return $ticketId == 'undefined' ? null : $ticketId;
149 81 }
150 82
151 83 private function resolvePerson($ticketId, Request $request)
152 84 {
153 - $agent = Helper::getCurrentAgent();
154 - if ($agent) {
155 - return $agent;
85 + if ($request->getSafe('is_agent', 'sanitize_text_field') == 'yes') {
86 + return Helper::getCurrentAgent();
156 87 }
157 88
158 89 if ($ticketId && Helper::isPublicSignedTicketEnabled()) {
159 90 $intendedTicketHash = $request->getSafe('intended_ticket_hash', 'sanitize_text_field');
@@ -159,10 +90,9 @@
159 90 $intendedTicketHash = $request->getSafe('intended_ticket_hash', 'sanitize_text_field');
160 91 if ($intendedTicketHash && $intendedTicketHash != 'undefined') {
161 92 $ticket = Ticket::with(['customer'])
162 93 ->where('hash', $intendedTicketHash)
163 - ->wherePublicIdentifier($ticketId)
164 - ->first();
94 + ->find($ticketId);
165 95
166 96 if ($ticket && $ticket->customer) {
167 97 return $ticket->customer;
168 98 }
@@ -192,9 +122,9 @@
192 122
193 123 private function createAttachmentRecords($uploadedFiles, $ticketId, $person, $imageType)
194 124 {
195 125 $attachments = [];
196 - $directPasteUrl = null;
126 + $full_path = null;
197 127
198 128 foreach ($uploadedFiles as $file) {
199 129 if (empty($file['file_path'])) continue;
200 130
@@ -211,16 +141,15 @@
211 141 'local_temp_path' => $file['file_path'],
212 142 ]
213 143 ];
214 144
145 + if($imageType == 'direct_paste'){
146 + $full_path = esc_url($file['url']);
147 + }
148 +
215 149 try {
216 150 $attachment = Attachment::create($fileData);
217 151 $attachments[] = $attachment->file_hash;
218 -
219 - if ($imageType == 'direct_paste') {
220 - $directPasteUrl = $attachment->secureUrl;
221 - }
222 -
223 152 do_action('fluent_support/attachment_uploaded_as_temp', $attachment, $ticketId);
224 153 $driver = Helper::getUploadDriverKey();
225 154
226 155 do_action_ref_array('fluent_support/attachment_uploaded_as_temp_' . $driver, [&$attachment, $ticketId]);
@@ -228,9 +157,9 @@
228 157 continue;
229 158 }
230 159 }
231 160
232 - return $imageType == 'direct_paste' ? $directPasteUrl : $attachments;
161 + return $imageType == 'direct_paste' ? $full_path : $attachments;
233 162 }
234 163
235 164 public function uploadImage(Request $request)
236 165 {