| @@ -17,8 +17,10 @@ | ||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function getLogFilters() |
| 20 | 20 | { |
| 21 | + // SECURITY (H-02): unregistered handler; guard it so it is safe if ever wired to an action. | |
| 22 | + \FluentForm\App\Modules\Acl\Acl::verify('fluentform_settings_manager'); | |
| 21 | 23 | $statuses = wpFluent()->table('fluentform_logs') |
| 22 | 24 | ->select('status') |
| 23 | 25 | ->groupBy('status') |
| 24 | 26 | ->get(); |
| @@ -59,10 +61,11 @@ | ||
| 59 | 61 | |
| 60 | 62 | foreach ($forms as $form) { |
| 61 | 63 | $formattedForms[] = [ |
| 62 | 64 | 'form_id' => $form->parent_source_id, |
| 63 | - 'title' => $form->title | |
| 64 | - ];; | |
| 65 | + 'title' => $form->title, | |
| 66 | + ]; | |
| 67 | + | |
| 65 | 68 | } |
| 66 | 69 | |
| 67 | 70 | wp_send_json_success([ |
| 68 | 71 | 'available_statuses' => $formattedStatuses, |
| @@ -67,9 +70,9 @@ | ||
| 67 | 70 | wp_send_json_success([ |
| 68 | 71 | 'available_statuses' => $formattedStatuses, |
| 69 | 72 | 'available_components' => $formattedComponents, |
| 70 | 73 | 'available_forms' => $formattedForms, |
| 71 | - 'api_statuses' => $apiStatuses | |
| 74 | + 'api_statuses' => $apiStatuses, | |
| 72 | 75 | ]); |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | public function log($data) |
| @@ -76,8 +79,22 @@ | ||
| 76 | 79 | { |
| 77 | 80 | if (!$data) { |
| 78 | 81 | return; |
| 79 | 82 | } |
| 83 | + | |
| 84 | + if (isset($data['description'])) { | |
| 85 | + $data['description'] = wp_kses($data['description'], [ | |
| 86 | + 'br' => [], | |
| 87 | + 'b' => [], | |
| 88 | + 'strong' => [], | |
| 89 | + 'i' => [], | |
| 90 | + 'em' => [], | |
| 91 | + 'code' => [], | |
| 92 | + 'p' => [], | |
| 93 | + 'a' => ['href' => [], 'title' => [], 'target' => [], 'rel' => []], | |
| 94 | + ]); | |
| 95 | + } | |
| 96 | + | |
| 80 | 97 | $data['created_at'] = current_time('mysql'); |
| 81 | 98 | |
| 82 | 99 | if (!get_option('fluentform_db_fluentform_logs_added')) { |
| 83 | 100 | Logs::migrate(); |
| @@ -93,14 +110,14 @@ | ||
| 93 | 110 | ->where('source_id', $entry_id) |
| 94 | 111 | ->where('source_type', $sourceType) |
| 95 | 112 | ->orderBy('id', 'DESC') |
| 96 | 113 | ->get(); |
| 97 | - | |
| 114 | + | |
| 98 | 115 | $logs = apply_filters_deprecated( |
| 99 | 116 | 'fluentform_entry_logs', |
| 100 | 117 | [ |
| 101 | 118 | $logs, |
| 102 | - $entry_id | |
| 119 | + $entry_id, | |
| 103 | 120 | ], |
| 104 | 121 | FLUENTFORM_FRAMEWORK_UPGRADE, |
| 105 | 122 | 'fluentform/submission_logs', |
| 106 | 123 | 'Use fluentform/submission_logs instead of fluentform_entry_logs.' |
| @@ -113,19 +130,19 @@ | ||
| 113 | 130 | 'id', |
| 114 | 131 | 'action', |
| 115 | 132 | 'status', |
| 116 | 133 | 'note', |
| 117 | - 'created_at' | |
| 134 | + 'created_at', | |
| 118 | 135 | ]) |
| 119 | 136 | ->where('origin_id', $entry_id) |
| 120 | 137 | ->orderBy('id', 'DESC') |
| 121 | 138 | ->get(); |
| 122 | - | |
| 139 | + | |
| 123 | 140 | $logs = apply_filters_deprecated( |
| 124 | 141 | 'fluentform_entry_api_logs', |
| 125 | 142 | [ |
| 126 | 143 | $logs, |
| 127 | - $entry_id | |
| 144 | + $entry_id, | |
| 128 | 145 | ], |
| 129 | 146 | FLUENTFORM_FRAMEWORK_UPGRADE, |
| 130 | 147 | 'fluentform/submission_api_logs', |
| 131 | 148 | 'Use fluentform/submission_api_logs instead of fluentform_entry_api_logs.' |
| @@ -133,16 +150,17 @@ | ||
| 133 | 150 | |
| 134 | 151 | $logs = apply_filters('fluentform/submission_api_logs', $logs, $entry_id); |
| 135 | 152 | } |
| 136 | 153 | |
| 137 | - | |
| 138 | 154 | wp_send_json_success([ |
| 139 | - 'logs' => $logs | |
| 155 | + 'logs' => $logs, | |
| 140 | 156 | ], 200); |
| 141 | 157 | } |
| 142 | 158 | |
| 143 | 159 | public function getAllLogs() |
| 144 | 160 | { |
| 161 | + // SECURITY (H-02): unregistered handler; guard it so it is safe if ever wired to an action. | |
| 162 | + \FluentForm\App\Modules\Acl\Acl::verify('fluentform_settings_manager'); | |
| 145 | 163 | $limit = intval($this->app->request->get('per_page')); |
| 146 | 164 | $pageNumber = intval($this->app->request->get('page_number')); |
| 147 | 165 | |
| 148 | 166 | $skip = ($pageNumber - 1) * $limit; |
| @@ -152,15 +170,14 @@ | ||
| 152 | 170 | ->select([ |
| 153 | 171 | 'fluentform_logs.*', |
| 154 | 172 | wpFluent()->raw($wpdb->prefix . 'fluentform_forms.title as form_title'), |
| 155 | 173 | wpFluent()->raw($wpdb->prefix . 'fluentform_logs.parent_source_id as form_id'), |
| 156 | - wpFluent()->raw($wpdb->prefix . 'fluentform_logs.source_id as entry_id') | |
| 174 | + wpFluent()->raw($wpdb->prefix . 'fluentform_logs.source_id as entry_id'), | |
| 157 | 175 | ]) |
| 158 | 176 | ->leftJoin('fluentform_forms', 'fluentform_forms.id', '=', 'fluentform_logs.parent_source_id') |
| 159 | 177 | ->orderBy('fluentform_logs.id', 'DESC'); |
| 160 | 178 | // ->whereIn('fluentform_logs.source_type', ['submission_item', 'form_item']); |
| 161 | 179 | |
| 162 | - | |
| 163 | 180 | if ($parentSourceId = $this->app->request->get('parent_source_id')) { |
| 164 | 181 | $logsQuery = $logsQuery->where('fluentform_logs.parent_source_id', intval($parentSourceId)); |
| 165 | 182 | } |
| 166 | 183 | |
| @@ -182,17 +199,17 @@ | ||
| 182 | 199 | ->limit($limit) |
| 183 | 200 | ->get(); |
| 184 | 201 | |
| 185 | 202 | foreach ($logs as $log) { |
| 186 | - if($log->source_type == 'submission_item' && $log->entry_id) { | |
| 203 | + if ('submission_item' == $log->source_type && $log->entry_id) { | |
| 187 | 204 | $log->submission_url = admin_url('admin.php?page=fluent_forms&route=entries&form_id=' . $log->form_id . '#/entries/' . $log->entry_id); |
| 188 | 205 | } |
| 189 | 206 | } |
| 190 | - | |
| 207 | + | |
| 191 | 208 | $logs = apply_filters_deprecated( |
| 192 | 209 | 'fluentform_all_logs', |
| 193 | 210 | [ |
| 194 | - $logs | |
| 211 | + $logs, | |
| 195 | 212 | ], |
| 196 | 213 | FLUENTFORM_FRAMEWORK_UPGRADE, |
| 197 | 214 | 'fluentform/all_logs', |
| 198 | 215 | 'Use fluentform/all_logs instead of fluentform_all_logs.' |
| @@ -203,16 +220,17 @@ | ||
| 203 | 220 | $total = $logsQueryMain->count(); |
| 204 | 221 | |
| 205 | 222 | wp_send_json_success([ |
| 206 | 223 | 'logs' => $logs, |
| 207 | - 'total' => $total | |
| 224 | + 'total' => $total, | |
| 208 | 225 | ], 200); |
| 209 | - | |
| 210 | 226 | } |
| 211 | 227 | |
| 212 | 228 | |
| 213 | 229 | public function getApiLogs() |
| 214 | 230 | { |
| 231 | + // SECURITY (H-02): unregistered handler; guard it so it is safe if ever wired to an action. | |
| 232 | + \FluentForm\App\Modules\Acl\Acl::verify('fluentform_settings_manager'); | |
| 215 | 233 | $limit = intval($this->app->request->get('per_page')); |
| 216 | 234 | $pageNumber = intval($this->app->request->get('page_number')); |
| 217 | 235 | |
| 218 | 236 | $skip = ($pageNumber - 1) * $limit; |
| @@ -225,14 +243,13 @@ | ||
| 225 | 243 | 'ff_scheduled_actions.origin_id', |
| 226 | 244 | 'ff_scheduled_actions.status', |
| 227 | 245 | 'ff_scheduled_actions.note', |
| 228 | 246 | 'ff_scheduled_actions.created_at', |
| 229 | - wpFluent()->raw($wpdb->prefix . 'fluentform_forms.title as form_title') | |
| 247 | + wpFluent()->raw($wpdb->prefix . 'fluentform_forms.title as form_title'), | |
| 230 | 248 | ]) |
| 231 | 249 | ->join('fluentform_forms', 'fluentform_forms.id', '=', 'ff_scheduled_actions.form_id') |
| 232 | 250 | ->orderBy('ff_scheduled_actions.id', 'DESC'); |
| 233 | 251 | |
| 234 | - | |
| 235 | 252 | if ($formId = $this->app->request->get('form_id')) { |
| 236 | 253 | $logsQuery = $logsQuery->where('ff_scheduled_actions.form_id', intval($formId)); |
| 237 | 254 | } |
| 238 | 255 | |
| @@ -248,13 +265,13 @@ | ||
| 248 | 265 | |
| 249 | 266 | $logs = $logsQuery->offset($skip) |
| 250 | 267 | ->limit($limit) |
| 251 | 268 | ->get(); |
| 252 | - | |
| 269 | + | |
| 253 | 270 | $logs = apply_filters_deprecated( |
| 254 | 271 | 'fluentform_api_all_logs', |
| 255 | 272 | [ |
| 256 | - $logs | |
| 273 | + $logs, | |
| 257 | 274 | ], |
| 258 | 275 | FLUENTFORM_FRAMEWORK_UPGRADE, |
| 259 | 276 | 'fluentform/api_all_logs', |
| 260 | 277 | 'Use fluentform/api_all_logs instead of fluentform_api_all_logs.' |
| @@ -269,11 +286,10 @@ | ||
| 269 | 286 | $total = $logsQueryMain->count(); |
| 270 | 287 | |
| 271 | 288 | wp_send_json_success([ |
| 272 | 289 | 'logs' => $logs, |
| 273 | - 'total' => $total | |
| 290 | + 'total' => $total, | |
| 274 | 291 | ], 200); |
| 275 | - | |
| 276 | 292 | } |
| 277 | 293 | |
| 278 | 294 | public function deleteLogsByIds($ids = []) |
| 279 | 295 | { |
| @@ -282,9 +298,9 @@ | ||
| 282 | 298 | } |
| 283 | 299 | |
| 284 | 300 | if (!$ids) { |
| 285 | 301 | wp_send_json_error([ |
| 286 | - 'message' => 'No selections found' | |
| 302 | + 'message' => 'No selections found', | |
| 287 | 303 | ], 423); |
| 288 | 304 | } |
| 289 | 305 | |
| 290 | 306 | wpFluent()->table('fluentform_logs') |
| @@ -291,9 +307,9 @@ | ||
| 291 | 307 | ->whereIn('id', $ids) |
| 292 | 308 | ->delete(); |
| 293 | 309 | |
| 294 | 310 | wp_send_json_success([ |
| 295 | - 'message' => __('Selected log(s) successfully deleted', 'fluentform') | |
| 311 | + 'message' => __('Selected log(s) successfully deleted', 'fluentform'), | |
| 296 | 312 | ], 200); |
| 297 | 313 | } |
| 298 | 314 | |
| 299 | 315 | public function deleteApiLogsByIds($ids = []) |
| @@ -303,9 +319,9 @@ | ||
| 303 | 319 | } |
| 304 | 320 | |
| 305 | 321 | if (!$ids) { |
| 306 | 322 | wp_send_json_error([ |
| 307 | - 'message' => 'No selections found' | |
| 323 | + 'message' => 'No selections found', | |
| 308 | 324 | ], 423); |
| 309 | 325 | } |
| 310 | 326 | |
| 311 | 327 | wpFluent()->table('ff_scheduled_actions') |
| @@ -312,14 +328,16 @@ | ||
| 312 | 328 | ->whereIn('id', $ids) |
| 313 | 329 | ->delete(); |
| 314 | 330 | |
| 315 | 331 | wp_send_json_success([ |
| 316 | - 'message' => __('Selected log(s) successfully deleted', 'fluentform') | |
| 332 | + 'message' => __('Selected log(s) successfully deleted', 'fluentform'), | |
| 317 | 333 | ], 200); |
| 318 | 334 | } |
| 319 | 335 | |
| 320 | 336 | public function retryApiAction() |
| 321 | 337 | { |
| 338 | + // SECURITY (H-02): unregistered handler; guard it so it is safe if ever wired to an action. | |
| 339 | + \FluentForm\App\Modules\Acl\Acl::verify('fluentform_settings_manager'); | |
| 322 | 340 | $logId = $this->app->request->get('log_id'); |
| 323 | 341 | $actionFeed = wpFluent()->table('ff_scheduled_actions') |
| 324 | 342 | ->find($logId); |
| 325 | 343 | |
| @@ -324,15 +342,15 @@ | ||
| 324 | 342 | ->find($logId); |
| 325 | 343 | |
| 326 | 344 | if (!$actionFeed) { |
| 327 | 345 | wp_send_json_error([ |
| 328 | - 'message' => 'API log does not exist' | |
| 346 | + 'message' => 'API log does not exist', | |
| 329 | 347 | ], 423); |
| 330 | 348 | } |
| 331 | 349 | |
| 332 | 350 | if ($actionFeed->status == 'success') { |
| 333 | 351 | wp_send_json_error([ |
| 334 | - 'message' => 'API log already in success mode' | |
| 352 | + 'message' => 'API log already in success mode', | |
| 335 | 353 | ], 423); |
| 336 | 354 | } |
| 337 | 355 | |
| 338 | 356 | $form = wpFluent()->table('fluentform_forms')->find($actionFeed->form_id); |
| @@ -348,9 +366,9 @@ | ||
| 348 | 366 | ->where('id', $actionFeed->id) |
| 349 | 367 | ->update([ |
| 350 | 368 | 'status' => 'manual_retry', |
| 351 | 369 | 'retry_count' => $actionFeed->retry_count + 1, |
| 352 | - 'updated_at' => current_time('mysql') | |
| 370 | + 'updated_at' => current_time('mysql'), | |
| 353 | 371 | ]); |
| 354 | 372 | |
| 355 | 373 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Dynamic hook name from action feed |
| 356 | 374 | do_action($actionFeed->action, $feed, $formData, $entry, $form); |
| @@ -362,9 +380,9 @@ | ||
| 362 | 380 | ->find($logId); |
| 363 | 381 | |
| 364 | 382 | wp_send_json_success([ |
| 365 | 383 | 'message' => 'Retry completed', |
| 366 | - 'feed' => $actionFeed | |
| 384 | + 'feed' => $actionFeed, | |
| 367 | 385 | ], 200); |
| 368 | 386 | } |
| 369 | 387 | |
| 370 | 388 | private function getEntry($submission, $form) |
| @@ -406,15 +424,16 @@ | ||
| 406 | 424 | |
| 407 | 425 | foreach ($forms as $form) { |
| 408 | 426 | $formattedForms[] = [ |
| 409 | 427 | 'form_id' => $form->form_id, |
| 410 | - 'title' => $form->title | |
| 411 | - ];; | |
| 428 | + 'title' => $form->title, | |
| 429 | + ]; | |
| 430 | + | |
| 412 | 431 | } |
| 413 | 432 | |
| 414 | 433 | wp_send_json_success([ |
| 415 | 434 | 'available_components' => $formattedComponents, |
| 416 | 435 | 'available_forms' => $formattedForms, |
| 417 | - 'api_statuses' => $apiStatuses | |
| 436 | + 'api_statuses' => $apiStatuses, | |
| 418 | 437 | ]); |
| 419 | 438 | } |
| 420 | 439 | } |