diff --git a/framework/elements/formbuilder/ajax.php b/framework/elements/formbuilder/ajax.php index 61b12341..94d39f26 100644 --- a/framework/elements/formbuilder/ajax.php +++ b/framework/elements/formbuilder/ajax.php @@ -22,142 +22,146 @@ $mainframe = Factory::getApplication(); $asformbuilder = $mainframe->input->get('as-form-builder-', array(), 'RAW'); $unqid = $mainframe->input->get('form_id', '', 'ALNUM'); -$element = Helper::getElement($unqid, $template); -if (!empty($asformbuilder) && !empty($element)) { - header('Content-Type: application/json'); - header('Access-Control-Allow-Origin: *'); - $return = array(); - try { - $params = $element['params']; - $mail = Factory::getContainer()->get(MailerFactoryInterface::class)->createMailer();; - $message = $params->get('email_body', ''); - $email_headers = $params->get('email_headers', ''); - $gcaptcha = ''; - - foreach ($asformbuilder as $field => $value) { - $message = str_replace('{{'.$field.'}}', $value, $message); - $email_headers = str_replace('{{'.$field.'}}', $value, $email_headers); - if ($field == 'g-recaptcha-response') { - $gcaptcha = $value; - } +$element = Helper::getElement($unqid); +header('Content-Type: application/json'); +header('Access-Control-Allow-Origin: *'); +$return = array(); +try { + if (!empty($asformbuilder)) { + throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_FORM_DATA')); + } + if (!empty($element)) { + throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_FORM_ID')); + } + $params = $element['params']; + $mail = Factory::getContainer()->get(MailerFactoryInterface::class)->createMailer(); + $message = $params->get('email_body', ''); + $email_headers = $params->get('email_headers', ''); + $gcaptcha = ''; + + foreach ($asformbuilder as $field => $value) { + $message = str_replace('{{'.$field.'}}', $value, $message); + $email_headers = str_replace('{{'.$field.'}}', $value, $email_headers); + if ($field == 'g-recaptcha-response') { + $gcaptcha = $value; } + } - $replyToMail = $replyToName = ''; + $replyToMail = $replyToName = ''; - if (intval($params->get('enable_captcha', 0))) { - $captcha_type = $params->get('captcha_type', 'default'); - if ($captcha_type == 'recaptcha' || $captcha_type == 'recaptcha_invisible') { - if($gcaptcha == ''){ - throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_CAPTCHA')); + if (intval($params->get('enable_captcha', 0))) { + $captcha_type = $params->get('captcha_type', 'default'); + if ($captcha_type == 'recaptcha' || $captcha_type == 'recaptcha_invisible') { + if($gcaptcha == ''){ + throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_CAPTCHA')); + } else { + if($captcha_type == 'recaptcha_invisible') { + PluginHelper::importPlugin('captcha', 'recaptcha_invisible'); } else { - if($captcha_type == 'recaptcha_invisible') { - PluginHelper::importPlugin('captcha', 'recaptcha_invisible'); - } else { - PluginHelper::importPlugin('captcha', 'recaptcha'); - } - $dispatcher = Factory::getApplication()->getDispatcher(); - $event = new Joomla\Event\Event('onCheckAnswer', [$gcaptcha]); - $res = $dispatcher->dispatch('onCheckAnswer', $event); - - if (!$res[0]) { - throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_CAPTCHA')); - } + PluginHelper::importPlugin('captcha', 'recaptcha'); } - } else { - if (!Helper::getCaptcha('as-formbuilder-captcha')) { + $dispatcher = Factory::getApplication()->getDispatcher(); + $event = new Joomla\Event\Event('onCheckAnswer', [$gcaptcha]); + $res = $dispatcher->dispatch('onCheckAnswer', $event); + + if (!$res[0]) { throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_CAPTCHA')); } } + } else { + if (!Helper::getCaptcha('as-formbuilder-captcha')) { + throw new \Exception(Text::_('ASTROID_AJAX_ERROR_INVALID_CAPTCHA')); + } } + } - //get sender UP - $senderip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; - // Subject Structure - $site_name = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ''; - $mail_subject = $params->get('email_subject', '') . ' - ' . $site_name; - $mail_subject = preg_replace_callback('/\{\{(\S+?)\}\}/siU', function ($matches) use (&$asformbuilder, &$site_name) { - if (isset($asformbuilder[$matches[1]])) { - return $asformbuilder[$matches[1]]; - } elseif ($matches[1] == 'site-name') { - return $site_name; - } - return $matches[0]; - }, $mail_subject); - // Message structure - $mail_body = $message; - $mail_body .= '

' . Text::_('ASTROID_FORMBUILDER_SENDER_IP'). ': ' . $senderip .'

'; + //get sender UP + $senderip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; + // Subject Structure + $site_name = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ''; + $mail_subject = $params->get('email_subject', '') . ' - ' . $site_name; + $mail_subject = preg_replace_callback('/\{\{(\S+?)\}\}/siU', function ($matches) use (&$asformbuilder, &$site_name) { + if (isset($asformbuilder[$matches[1]])) { + return $asformbuilder[$matches[1]]; + } elseif ($matches[1] == 'site-name') { + return $site_name; + } + return $matches[0]; + }, $mail_subject); + // Message structure + $mail_body = $message; + $mail_body .= '

' . Text::_('ASTROID_FORMBUILDER_SENDER_IP'). ': ' . $senderip .'

'; - $config = Factory::getConfig(); + $config = Factory::getConfig(); - $sender = array( $config->get( 'mailfrom' ), $config->get( 'fromname' ) ); - $recipient = $config->get( 'mailfrom' ); + $sender = array( $config->get( 'mailfrom' ), $config->get( 'fromname' ) ); + $recipient = $config->get( 'mailfrom' ); - // $sender = array( $email, $name ); + // $sender = array( $email, $name ); - $from_email = $params->get('from_email', ''); - if (!empty($from_email)) { - $sender = array($from_email, $from_email); - $mail->addReplyTo($from_email, $from_email); - } + $from_email = $params->get('from_email', ''); + if (!empty($from_email)) { + $sender = array($from_email, $from_email); + $mail->addReplyTo($from_email, $from_email); + } - $recipient = $params->get('recipient', ''); + $recipient = $params->get('recipient', ''); - if (!empty($email_headers)) { - $additional_header_ajax = explode("\n", $email_headers); - foreach ($additional_header_ajax as $_header) + if (!empty($email_headers)) { + $additional_header_ajax = explode("\n", $email_headers); + foreach ($additional_header_ajax as $_header) + { + $_header = explode(':', $_header); + if (count($_header) > 0) { - $_header = explode(':', $_header); - if (count($_header) > 0) + if (strtolower($_header[0]) == 'reply-to') { - if (strtolower($_header[0]) == 'reply-to') - { - $replyToMail = isset($_header[1]) ? trim($_header[1]) : ''; - } - if (strtolower($_header[0]) == 'reply-name') - { - $replyToName = isset($_header[1]) ? trim($_header[1]) : ''; - } - if (strtolower($_header[0]) == 'cc' && isset($_header[1])) - { - $mail->addCc(trim($_header[1])); - } - if (strtolower($_header[0]) == 'bcc' && isset($_header[1])) - { - $mail->addCc(trim($_header[1])); - } + $replyToMail = isset($_header[1]) ? trim($_header[1]) : ''; } - } - if (!empty($replyToMail)) { - if (!empty($replyToName)) { - $mail->addReplyTo($replyToMail, $replyToName); - } else { - $mail->addReplyTo($replyToMail); + if (strtolower($_header[0]) == 'reply-name') + { + $replyToName = isset($_header[1]) ? trim($_header[1]) : ''; + } + if (strtolower($_header[0]) == 'cc' && isset($_header[1])) + { + $mail->addCc(trim($_header[1])); + } + if (strtolower($_header[0]) == 'bcc' && isset($_header[1])) + { + $mail->addCc(trim($_header[1])); } } } - - $mail->setSender($sender); - $mail->addRecipient($recipient); - $mail->setSubject($mail_subject); - $mail->isHTML(true); - $mail->Encoding = 'base64'; - $mail->setBody($mail_body); - - $message_success = $params->get('success_message', Text::_('ASTROID_FORMBUILDER_SENT_SUCCESSFULLY')); - $message_failed = $params->get('failed_message', Text::_('ASTROID_FORMBUILDER_SENT_MAIL_FAILED')); - - if ($mail->Send()) { - $return["status"] = 'success'; - $return["message"] = $message_success; - $return["code"] = 200; - } else { - throw new \Exception($message_failed); + if (!empty($replyToMail)) { + if (!empty($replyToName)) { + $mail->addReplyTo($replyToMail, $replyToName); + } else { + $mail->addReplyTo($replyToMail); + } } - } catch (\Exception $e) { - $return["status"] = "error"; - $return["code"] = $e->getCode(); - $return["message"] = $e->getMessage(); } - echo \json_encode($return); -} \ No newline at end of file + + $mail->setSender($sender); + $mail->addRecipient($recipient); + $mail->setSubject($mail_subject); + $mail->isHTML(true); + $mail->Encoding = 'base64'; + $mail->setBody($mail_body); + + $message_success = $params->get('success_message', Text::_('ASTROID_FORMBUILDER_SENT_SUCCESSFULLY')); + $message_failed = $params->get('failed_message', Text::_('ASTROID_FORMBUILDER_SENT_MAIL_FAILED')); + + if ($mail->Send()) { + $return["status"] = 'success'; + $return["message"] = $message_success; + $return["code"] = 200; + } else { + throw new \Exception($message_failed); + } +} catch (\Exception $e) { + $return["status"] = "error"; + $return["code"] = $e->getCode(); + $return["message"] = $e->getMessage(); +} +echo \json_encode($return); \ No newline at end of file diff --git a/framework/elements/rawhtml/rawhtml.php b/framework/elements/rawhtml/rawhtml.php new file mode 100644 index 00000000..27357a7b --- /dev/null +++ b/framework/elements/rawhtml/rawhtml.php @@ -0,0 +1,17 @@ +get('custom_html', ''); \ No newline at end of file diff --git a/framework/elements/rawhtml/rawhtml.xml b/framework/elements/rawhtml/rawhtml.xml new file mode 100644 index 00000000..f1b93816 --- /dev/null +++ b/framework/elements/rawhtml/rawhtml.xml @@ -0,0 +1,23 @@ + + + ASTROID_WIDGET_RAWHTML_LABEL + ASTROID_WIDGET_RAWHTML_LABEL + fa-brands fa-html5 + ASTROID_ELEMENT_CATEGORY_ADVANCED,ASTROID_ELEMENT_CATEGORY_UTILITY + widget +
+ +
+ +
+
+ + + + + + +
+
+
+
diff --git a/language/en-GB/en-GB.astroid.ini b/language/en-GB/en-GB.astroid.ini index 507b92e5..c412fa79 100644 --- a/language/en-GB/en-GB.astroid.ini +++ b/language/en-GB/en-GB.astroid.ini @@ -1676,6 +1676,8 @@ ASTROID_FORMBUILDER_SENDER_IP="Sender IP" ASTROID_FORMBUILDER_SENT_SUCCESSFULLY="Message sent successfully!" ASTROID_FORMBUILDER_SENT_MAIL_FAILED="Message sent failed!" ASTROID_WIDGET_FORM_SHOW_LABEL_LABEL="Show Label" +ASTROID_AJAX_ERROR_INVALID_FORM_DATA="Invalid Form Data" +ASTROID_AJAX_ERROR_INVALID_FORM_ID="Invalid Form ID" ; Accordion ASTROID_WIDGET_ACCORDION_LABEL="Accordion" @@ -1721,4 +1723,7 @@ ASTROID_WIDGET_CODEPEN_EXTERNAL_CSS_LABEL="External CSS" ASTROID_WIDGET_CODEPEN_EXTERNAL_CSS_URL_LABEL="External CSS URL" ASTROID_LIBRARIES="Astroid Libraries" ASTROID_LIBRARIES_DESC="The system will automatically load Astroid libraries to support your scripts." -ASTROID_LIBRARIES_HINT="Select an Astroid Library" \ No newline at end of file +ASTROID_LIBRARIES_HINT="Select an Astroid Library" + +; RawHTML +ASTROID_WIDGET_RAWHTML_LABEL="HTML" \ No newline at end of file