| @@ -3,10 +3,11 @@ | ||
| 3 | 3 | namespace FluentSupport\App\Http\Controllers; |
| 4 | 4 | |
| 5 | 5 | use FluentSupport\App\Models\MailBox; |
| 6 | 6 | use FluentSupport\App\Services\EmailNotification\Settings; |
| 7 | +use FluentSupport\App\Services\Helper; | |
| 7 | 8 | use FluentSupport\App\Services\MailerInbox\MailBoxService; |
| 8 | -use FluentSupport\Framework\Request\Request; | |
| 9 | +use FluentSupport\Framework\Http\Request\Request; | |
| 9 | 10 | |
| 10 | 11 | class MailBoxController extends Controller |
| 11 | 12 | { |
| 12 | 13 | /** |
| @@ -42,9 +43,10 @@ | ||
| 42 | 43 | * @throws \FluentSupport\Framework\Validator\ValidationException |
| 43 | 44 | */ |
| 44 | 45 | public function save(Request $request, MailBox $mailBox) |
| 45 | 46 | { |
| 46 | - $data = wp_unslash( $request->getSafe('business') ); | |
| 47 | + $data = wp_unslash( $request->get('business', null) ); | |
| 48 | + $data = $this->sanitizeMailboxData($data); | |
| 47 | 49 | |
| 48 | 50 | $this->validate($data, [ |
| 49 | 51 | 'name' => 'required', |
| 50 | 52 | 'email' => 'required' |
| @@ -66,9 +68,10 @@ | ||
| 66 | 68 | */ |
| 67 | 69 | public function update(Request $request, MailBox $mailBox, $id) |
| 68 | 70 | { |
| 69 | 71 | try{ |
| 70 | - $data = wp_unslash( $request->getSafe('business') ); | |
| 72 | + $data = wp_unslash( $request->get('business', null) ); | |
| 73 | + $data = $this->sanitizeMailboxData($data); | |
| 71 | 74 | |
| 72 | 75 | $this->validate($data, [ |
| 73 | 76 | 'name' => 'required', |
| 74 | 77 | 'email' => 'required' |
| @@ -79,9 +82,9 @@ | ||
| 79 | 82 | 'mailbox' => $mailBox->updateMailBox( $data, $id ) |
| 80 | 83 | ]; |
| 81 | 84 | }catch (\Exception $e){ |
| 82 | 85 | return [ |
| 83 | - 'message' => $e->getMessage(), | |
| 86 | + 'message' => Helper::getSafeErrorMessage($e), | |
| 84 | 87 | ]; |
| 85 | 88 | } |
| 86 | 89 | } |
| 87 | 90 | |
| @@ -98,9 +101,9 @@ | ||
| 98 | 101 | try { |
| 99 | 102 | return $mailBoxService->deleteMailBox( $id, $request->getSafe('fallback_id', 'intval') ); |
| 100 | 103 | } catch (\Exception $e) { |
| 101 | 104 | return [ |
| 102 | - 'message' => $e->getMessage(), | |
| 105 | + 'message' => Helper::getSafeErrorMessage($e), | |
| 103 | 106 | ]; |
| 104 | 107 | } |
| 105 | 108 | } |
| 106 | 109 | |
| @@ -118,9 +121,9 @@ | ||
| 118 | 121 | try { |
| 119 | 122 | $data = $request->only(['ticket_ids', 'new_box_id', 'move_type']); |
| 120 | 123 | return $mailBoxService->moveTickets( $data, $id ); |
| 121 | 124 | } catch (\Exception $e) { |
| 122 | - return $this->sendError($e->getMessage()); | |
| 125 | + return $this->sendError(Helper::getSafeErrorMessage($e)); | |
| 123 | 126 | } |
| 124 | 127 | } |
| 125 | 128 | |
| 126 | 129 | /** |
| @@ -160,9 +163,19 @@ | ||
| 160 | 163 | * @throws \FluentSupport\Framework\Validator\ValidationException |
| 161 | 164 | */ |
| 162 | 165 | public function saveEmailSettings( Request $request, MailBoxService $mailBoxService, $id ) |
| 163 | 166 | { |
| 164 | - $data = wp_unslash($request->getSafe('email_settings')); | |
| 167 | + $data = wp_unslash($request->get('email_settings', null)); | |
| 168 | + $data = is_array($data) ? [ | |
| 169 | + 'key' => isset($data['key']) ? sanitize_key($data['key']) : '', | |
| 170 | + 'title' => isset($data['title']) ? sanitize_text_field($data['title']) : '', | |
| 171 | + 'email_subject' => isset($data['email_subject']) ? sanitize_text_field($data['email_subject']) : '', | |
| 172 | + 'email_body' => isset($data['email_body']) ? wp_kses_post($data['email_body']) : '', | |
| 173 | + 'status' => isset($data['status']) ? sanitize_text_field($data['status']) : '', | |
| 174 | + 'can_edit_subject' => isset($data['can_edit_subject']) ? sanitize_text_field($data['can_edit_subject']) : '', | |
| 175 | + 'send_attachments' => isset($data['send_attachments']) ? sanitize_text_field($data['send_attachments']) : '', | |
| 176 | + ] : []; | |
| 177 | + | |
| 165 | 178 | $emailType = $request->getSafe('email_type', 'sanitize_text_field'); |
| 166 | 179 | |
| 167 | 180 | $this->validate($data, [ |
| 168 | 181 | 'email_subject' => 'required', |
| @@ -191,7 +204,50 @@ | ||
| 191 | 204 | * @return array |
| 192 | 205 | */ |
| 193 | 206 | public function getTickets(Request $request, MailBoxService $mailBoxService, $id) |
| 194 | 207 | { |
| 195 | - return $mailBoxService->getTickets( $request->getSafe('filters'), $id ); | |
| 208 | + $filters = $request->get('filters', null); | |
| 209 | + $filters = is_array($filters) ? [ | |
| 210 | + 'status_type' => isset($filters['status_type']) ? sanitize_text_field($filters['status_type']) : '', | |
| 211 | + 'customer_id' => isset($filters['customer_id']) ? intval($filters['customer_id']) : 0, | |
| 212 | + 'product_id' => isset($filters['product_id']) ? intval($filters['product_id']) : 0, | |
| 213 | + 'mailbox_id' => isset($filters['mailbox_id']) ? intval($filters['mailbox_id']) : 0, | |
| 214 | + 'ticket_title' => isset($filters['ticket_title']) ? sanitize_text_field($filters['ticket_title']) : '', | |
| 215 | + 'notes' => isset($filters['notes']) ? sanitize_text_field($filters['notes']) : '', | |
| 216 | + ] : []; | |
| 217 | + | |
| 218 | + return $mailBoxService->getTickets( $filters, $id ); | |
| 219 | + } | |
| 220 | + | |
| 221 | + /** | |
| 222 | + * Sanitize mailbox data array | |
| 223 | + * | |
| 224 | + * @param mixed $data | |
| 225 | + * @return array | |
| 226 | + */ | |
| 227 | + private function sanitizeMailboxData($data) | |
| 228 | + { | |
| 229 | + if (!is_array($data)) { | |
| 230 | + return []; | |
| 231 | + } | |
| 232 | + | |
| 233 | + $sanitized = [ | |
| 234 | + 'name' => isset($data['name']) ? sanitize_text_field($data['name']) : '', | |
| 235 | + 'email' => isset($data['email']) ? sanitize_email($data['email']) : '', | |
| 236 | + 'box_type' => isset($data['box_type']) ? sanitize_key($data['box_type']) : '', | |
| 237 | + 'mapped_email' => isset($data['mapped_email']) ? sanitize_email($data['mapped_email']) : '', | |
| 238 | + 'email_footer' => isset($data['email_footer']) ? wp_kses_post($data['email_footer']) : '', | |
| 239 | + 'is_default' => isset($data['is_default']) ? sanitize_text_field($data['is_default']) : 'no', | |
| 240 | + ]; | |
| 241 | + | |
| 242 | + // Handle nested settings array | |
| 243 | + if (isset($data['settings']) && is_array($data['settings'])) { | |
| 244 | + $sanitized['settings'] = map_deep($data['settings'], 'sanitize_text_field'); | |
| 245 | + // Preserve email in settings | |
| 246 | + if (isset($data['settings']['admin_email_address'])) { | |
| 247 | + $sanitized['settings']['admin_email_address'] = sanitize_email($data['settings']['admin_email_address']); | |
| 248 | + } | |
| 249 | + } | |
| 250 | + | |
| 251 | + return $sanitized; | |
| 196 | 252 | } |
| 197 | 253 | } |