| | |
| | | <?php |
| | | namespace JVBase\rest\routes; |
| | | |
| | | use JVBase\Instance; |
| | | use JVBase\integrations\services\Cloudflare; |
| | | use JVBase\managers\Emails; |
| | | use JVBase\meta\Sanitizer; |
| | | use JVBase\meta\Validator; |
| | | use JVBase\rest\PermissionHandler; |
| | |
| | | */ |
| | | class FormRoutes extends Rest |
| | | { |
| | | use Instance; |
| | | protected FormBlock $form_block; |
| | | |
| | | public function __construct() |
| | |
| | | |
| | | protected function verifyTurnstile(string $token): bool |
| | | { |
| | | if (!Site::hasIntegration('cloudflare') || !JVB()->connect('cloudflare')->isSetUp()) { |
| | | if (!Site::hasIntegration('cloudflare') ) { |
| | | return true; |
| | | } |
| | | |
| | | $cloudflare = Cloudflare::getInstance(); |
| | | if (!$cloudflare->isSetUp()) { |
| | | return true; |
| | | } |
| | | if (empty($token)) { |
| | | return false; |
| | | } |
| | | |
| | | return JVB()->connect('cloudflare')->verifyTurnstile($token); |
| | | return $cloudflare->verifyTurnstile($token); |
| | | } |
| | | |
| | | /** |
| | |
| | | } catch (\Exception $e) { |
| | | return new WP_Error('validation_failed', 'Data validation error: ' . $e->getMessage()); |
| | | } |
| | | |
| | | if (array_key_exists('success', $processed_data) && $processed_data['success'] === false) { |
| | | return $processed_data; |
| | | } |
| | |
| | | } |
| | | |
| | | // Build email body |
| | | $body = JVB()->email()->h2($form_config['title']); |
| | | $body .= '<p style="font-size:13px;color:' . JVB()->email()->colours['dark-200'] . ';"> |
| | | $body = Emails::getInstance()->h2($form_config['title']); |
| | | $body .= '<p style="font-size:13px;color:' . Emails::getInstance()->colours['dark-200'] . ';"> |
| | | Submitted: ' . current_time('F j, Y \a\t g:i A') . ' |
| | | </p>'; |
| | | |
| | | // Add thread notice if CC'd |
| | | if ($submitter_email) { |
| | | $body .= JVB()->email()->notice( |
| | | $body .= Emails::getInstance()->notice( |
| | | '<strong>Email Thread Created</strong><br>Reply to this email to continue the conversation with ' . |
| | | esc_html($submitter_name ?: 'the submitter') . '.' |
| | | ); |
| | |
| | | ]; |
| | | } |
| | | |
| | | $body .= JVB()->email()->spacer(20); |
| | | $body .= JVB()->email()->table($form); |
| | | $body .= Emails::getInstance()->spacer(20); |
| | | $body .= Emails::getInstance()->table($form); |
| | | |
| | | // Show attachment info |
| | | $attachments = $this->processFileAttachments($files); |
| | | if (!empty($attachments)) { |
| | | $body .= JVB()->email()->spacer(10); |
| | | $body .= JVB()->email()->alert( |
| | | $body .= Emails::getInstance()->spacer(10); |
| | | $body .= Emails::getInstance()->alert( |
| | | sprintf('%d file(s) attached to this email', count($attachments)), |
| | | 'info' |
| | | ); |
| | | } |
| | | |
| | | // Send the email |
| | | return JVB()->email()->sendEmail( |
| | | return Emails::getInstance()->sendEmail( |
| | | $to, |
| | | $subject, |
| | | $body, |