| Server IP : 46.105.57.169 / Your IP : 216.73.216.144 Web Server : Apache System : Linux webd003.cluster120.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : maitricfuz ( 93378) PHP Version : 8.4.10 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/maitricfuz/www/saint-martin-lg/plugins/pagebuilderck/contact2/ |
Upload File : |
<?php
/**
* @copyright Copyright (C) 2016 Cédric KEIFLIN alias ced1870
* https://www.template-creator.com
* https://www.joomlack.fr
* @license GNU/GPL
* */
use Joomla\String\StringHelper;
use Pagebuilderck\CKFof;
defined('_JEXEC') or die('Restricted access');
jimport('joomla.event.plugin');
class plgPagebuilderckContact2Helper {
private static $options;
private static $id;
public static function processSubmit() {
// Check for request forgeries.
\Joomla\CMS\Session\Session::checkToken() or jexit(Pagebuilderck\CKText::_('JINVALID_TOKEN'));
// get current uri
$uri = Pagebuilderck\CKUri::getInstance();
$current_url = $uri->toString();
$app = Pagebuilderck\CKFof::getApplication();
$input = $app->input;
$id = $input->post->get('pagebuilderckid', '', 'string');
self::$id = $id;
$data = $_REQUEST[$id];
// get the params from the plugin options
$plugin = Pagebuilderck\CKFof::getPlugin('pagebuilderck', 'contact2');
$pluginParams = new Pagebuilderck\CKRegistry($plugin->params);
// check for the captcha validation
// this does not work well in some case, disable 19-09-22
// $plugin = Pagebuilderck\CKFof::getApplication()->getParams()->get('captcha', \Joomla\CMS\Factory::getConfig()->get('captcha'));
// replaced with this line which get the plugin from the website config, by default the recaptcha
$plugin = \Joomla\CMS\Factory::getConfig()->get('captcha', 'recaptcha');
//log the action
// self::writeLog($data); // disbaled for now, just uncomment this line to enable the logs
if ($pluginParams->get('enablecaptcha', '1', 'int') == '1') {
\Joomla\CMS\Plugin\PluginHelper::importPlugin('captcha');
$captcha = '';
$captcha = \Joomla\CMS\Captcha\Captcha::getInstance($plugin, array('namespace' => 'plg_pagebuilderck_contact'));
if ($captcha != null) {
// $dispatcher = JDispatcher::getInstance();
try {
if (version_compare(JVERSION,'4') < 1) {
$dispatcher = JEventDispatcher::getInstance();
$result = $dispatcher->trigger('onCheckAnswer', array());
} else {
// $result = Pagebuilderck\CKFof::getApplication()->triggerEvent('onCheckAnswer');
$result = $captcha->checkAnswer(null);
}
// $result = Pagebuilderck\CKFof::getApplication()->triggerEvent('onCheckAnswer', array());
// $result = $dispatcher->trigger('onCheckAnswer', $input->get('g-recaptcha-response', false));
} catch (Exception $e) {
// echo 'Exception reçue : ', $e->getMessage(), "\n";die;
$msg = Pagebuilderck\CKText::_('PLG_PAGEBUILDERCK_CONTACT_INVALID_CAPTCHA');
CKFof::redirect($current_url, $msg, 'error');
exit();
}
if(!$result[0] && $result !== true){
$msg = Pagebuilderck\CKText::_('PLG_PAGEBUILDERCK_CONTACT_INVALID_CAPTCHA');
CKFof::redirect($current_url, $msg, 'error');
exit();
}
} else {
$msg = Pagebuilderck\CKText::_('PLG_PAGEBUILDERCK_CONTACT_INVALID_CAPTCHA');
CKFof::redirect($current_url, $msg, 'error');
exit();
}
}
$toEmail = base64_decode($input->post->get('pagebuilderckto', ''));
// send the email
$sent = self::_sendEmail($data, $toEmail, false);
$key = 'successmessage_' . $id;
$successMessage = self::getPluginOption('contact2', $key);
$successMessage = $successMessage ? $successMessage : 'PLG_PAGEBUILDERCK_EMAIL_THANKS';
$session = \Joomla\CMS\Factory::getSession();
$custom_redirect = self::getPluginOption('contact2', 'successredirect_' . $id);
$custom_redirect = strpos($custom_redirect, 'CURRENT_URI') > -1 ? str_replace('CURRENT_URI', $current_url, $custom_redirect) : $custom_redirect;
$url = $custom_redirect ? $custom_redirect : $current_url;
// Set the success message if it was a success
if (!($sent instanceof Exception))
{
$msg = Pagebuilderck\CKText::_($successMessage);
$session->set('pagebuilderck_contact_' . $key, array($msg, 'success'));
// $app->redirect($current_url, $msg, 'success');
CKFof::redirect($url);
}
else
{
$msg = Pagebuilderck\CKText::_('PLG_PAGEBUILDERCK_CONTACT_EMAIL_ERROR');
$session->set('pagebuilderck_contact_' . $key, array($msg, 'error'));
// $app->redirect($current_url, $msg, 'error');
CKFof::redirect($url);
}
}
private static function getPluginOption($plugin, $key) {
if (empty(self::$options)) {
$data = PagebuilderckHelper::getOption($plugin . '.' . self::$id);
self::$options = unserialize((string)$data);
if (empty(self::$options)) {
$query = "SELECT custom_data FROM #__extensions WHERE type='plugin' AND element ='" . $plugin . "' AND folder='pagebuilderck'";
$db = Pagebuilderck\CKFof::getDbo();
$db->setQuery($query);
$data = $db->loadResult();
self::$options = unserialize((string)$data);
}
}
return isset(self::$options[$key]) ? self::$options[$key] : false;
}
/**
* Method to get a model object, loading it if required.
*
* @param array $data The data to send in the email.
* @param string $to The user email to send the email to
* @param boolean $copy_email_activated True to send a copy of the email to the user.
*
* @return boolean True on success sending the email, false on failure.
*
* @since 1.6.4
*/
private static function _sendEmail($data, $toEmail, $copy_email_activated = false)
{
$app = Pagebuilderck\CKFof::getApplication();
$input = $app->input;
$mailfrom = $app->get('mailfrom');
$fromname = $app->get('fromname');
$sitename = $app->get('sitename');
$name = isset($data['name']) ? $data['name'] : 'Contact Form';
$email = \Joomla\CMS\String\PunycodeHelper::emailToPunycode($data['email']); // not removable
$subject = $data['subject']; // not removable
$labels = unserialize($input->post->get('labels' , '', 'html'));
$isValid = true;
// check the filter to avoid unwanted emails
$bannedEmail = self::getPluginOption('contact2', 'banned_email_' . self::$id);
$bannedSubject = self::getPluginOption('contact2', 'banned_subject_' . self::$id);
$bannedText = self::getPluginOption('contact2', 'banned_text_' . self::$id);
if ($bannedEmail) $isValid = self::test($email, $bannedEmail);
if (! $isValid) self::messageNotValid();
if ($bannedSubject) $isValid = self::test($subject, $bannedSubject);
if (! $isValid) self::messageNotValid();
$body = '';
foreach ($data as $k => $value) {
if ($k === 'copyemail') continue;
if (is_array($value)) {
$value = implode(',', $value);
}
if ($bannedText) $isValid = self::test($value, $bannedText);
if (! $isValid) self::messageNotValid();
$body .= '<p><h4>' . Pagebuilderck\CKText::_($labels[$k]) . ' :</h4> <span>' . htmlspecialchars($value) . '</span></p>';
}
// $id = $input->post->get('pagebuilderckid', '', 'string');
$emailMessage = self::getPluginOption('contact2', 'emailmessage_' . self::$id);
if (trim($emailMessage)) {
if (! strpos($emailMessage, '{fieldslist}')) {
$emailMessage .= '{fieldslist}';
}
$body = str_replace('{fieldslist}', $body, $emailMessage);
}
// Prepare email body
$prefix = Pagebuilderck\CKText::sprintf('PLG_PAGEBUILDERCK_CONTACT_EMAIL_REQUEST', Pagebuilderck\CKUri::base());
$body = $prefix . "\r\n<p>" . $name . " - " . $email . " " . "</p>\r\n\r\n" . stripslashes($body);
// B/C before 2.1.0
$toEmail_BC = $toEmail;
$toEmail = self::getPluginOption('contact2', 'contactemail_' . self::$id);
$toEmail = $toEmail ? $toEmail : $toEmail_BC;
$toCC = self::getPluginOption('contact2', 'contactccemail_' . self::$id);
$toBCC = self::getPluginOption('contact2', 'contactbccemail_' . self::$id);
$mail = \Joomla\CMS\Factory::getMailer();
$mail->isHTML(true);
$mail->addRecipient($toEmail);
if ($toCC) $mail->addCc($toCC);
if ($toBCC) $mail->addBcc($toBCC);
if ($email) $mail->addReplyTo($email, $name);
$mail->setSender(array($mailfrom, $fromname));
$mail->setSubject($sitename . ': ' . $subject);
$mail->setBody($body);
$sent = $mail->Send();
// If we are supposed to copy the sender, do so.
// Check whether email copy function activated
if (isset($data['copyemail'][0]) && $data['copyemail'][0] == '1')
{
$copytext = Pagebuilderck\CKText::sprintf('PLG_PAGEBUILDERCK_CONTACT_COPYTEXT_OF', $contact->name, $sitename);
$copytext .= "\r\n\r\n" . $body;
$copysubject = Pagebuilderck\CKText::sprintf('PLG_PAGEBUILDERCK_CONTACT_COPYSUBJECT_OF', $subject);
$mail = \Joomla\CMS\Factory::getMailer();
$mail->isHTML(true);
$mail->addRecipient($email);
$mail->addReplyTo($email, $name);
$mail->setSender(array($mailfrom, $fromname));
$mail->setSubject($copysubject);
$mail->setBody($copytext);
$sent = $mail->Send();
}
return $sent;
}
private function writeLog($data) {
$path = JPATH_ROOT . '/plugins/pagebuilderck/contact2/logs';
if (! file_exists($path)) {
mkdir($path);
}
$logFile = $path . '/' . date('d-M-Y-H-i-s') . '.txt';
$logContent = @json_encode($data);
@file_put_contents($logFile, $logContent);
}
/**
* Method to test for banned email data
*
* @param mixed $value The form field value to validate.
* @param string $filter The filter to check.
*
* @return boolean True if the value is valid, false otherwise.
*/
private static function test($value, $filter)
{
if ($filter) {
foreach (explode(';', $filter) as $item) {
$item = trim($item);
if ($item != '' && StringHelper::stristr($value, $item) !== false) {
return false;
}
}
}
return true;
}
private static function messageNotValid() {
$uri = Pagebuilderck\CKUri::getInstance();
$current_url = $uri->toString();
$app = Pagebuilderck\CKFof::getApplication();
$msg = Pagebuilderck\CKText::_('PLG_PAGEBUILDERCK_CONTACT_INVALID_MESSAGE');
$app->enqueueMessage($msg, 'error');
$app->redirect($current_url);
exit();
}
}