File manager - Edit - /home/jardides/www/Jardi-design/old/plugins/pagebuilderck/contact2/contact2helper.php
Back
<?php /** * @copyright Copyright (C) 2016 Cédric KEIFLIN alias ced1870 * https://www.template-creator.com * https://www.joomlack.fr * @license GNU/GPL * */ 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. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // get current uri $uri = JUri::getInstance(); $current_url = $uri->toString(); $app = JFactory::getApplication(); $input = $app->input; $id = $input->post->get('pagebuilderckid', '', 'string'); self::$id = $id; $data = $_REQUEST[$id]; // get the params from the plugin options $plugin = JPluginHelper::getPlugin('pagebuilderck', 'contact2'); $pluginParams = new JRegistry($plugin->params); // check for the captcha validation // this does not work well in some case, disable 19-09-22 // $plugin = JFactory::getApplication()->getParams()->get('captcha', JFactory::getConfig()->get('captcha')); // replaced with this line which get the plugin from the website config, by default the recaptcha $plugin = JFactory::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') { JPluginHelper::importPlugin('captcha'); $captcha = ''; $captcha = JCaptcha::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 = JFactory::getApplication()->triggerEvent('onCheckAnswer'); $result = $captcha->checkAnswer(null); } // $result = JFactory::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 = JText::_('PLG_PAGEBUILDERCK_CONTACT_INVALID_CAPTCHA'); $app->redirect($current_url, $msg, 'error'); exit(); } if(!$result[0] && $result !== true){ $msg = JText::_('PLG_PAGEBUILDERCK_CONTACT_INVALID_CAPTCHA'); $app->redirect($current_url, $msg, 'error'); exit(); } } else { $msg = JText::_('PLG_PAGEBUILDERCK_CONTACT_INVALID_CAPTCHA'); $app->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 = JFactory::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 = JText::_($successMessage); $session->set('pagebuilderck_contact_' . $key, array($msg, 'success')); // $app->redirect($current_url, $msg, 'success'); $app->redirect($url); } else { $msg = JText::_('PLG_PAGEBUILDERCK_CONTACT_EMAIL_ERROR'); $session->set('pagebuilderck_contact_' . $key, array($msg, 'error')); // $app->redirect($current_url, $msg, 'error'); $app->redirect($url); } } private static function getPluginOption($plugin, $key) { if (empty(self::$options)) { $data = PagebuilderckHelper::getOption($plugin . '.' . self::$id); self::$options = unserialize($data); if (empty(self::$options)) { $query = "SELECT custom_data FROM #__extensions WHERE type='plugin' AND element ='" . $plugin . "' AND folder='pagebuilderck'"; $db = JFactory::getDbo(); $db->setQuery($query); $data = $db->loadResult(); self::$options = unserialize($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 = JFactory::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 = JStringPunycode::emailToPunycode($data['email']); // not removable $subject = $data['subject']; // not removable $labels = unserialize($input->post->get('labels' , '', 'html')); $body = ''; foreach ($data as $k => $value) { if ($k === 'copyemail') continue; if (is_array($value)) { $value = implode(',', $value); } $body .= '<p><h4>' . JText::_($labels[$k]) . ' :</h4> <span>' . htmlspecialchars($value) . '</span></p>'; } // $id = $input->post->get('pagebuilderckid', '', 'string'); $key = 'emailmessage_' . self::$id; $emailMessage = self::getPluginOption('contact2', $key); if (trim($emailMessage)) { if (! strpos($emailMessage, '{fieldslist}')) { $emailMessage .= '{fieldslist}'; } $body = str_replace('{fieldslist}', $body, $emailMessage); } // Prepare email body $prefix = JText::sprintf('PLG_PAGEBUILDERCK_CONTACT_EMAIL_REQUEST', JUri::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 = JFactory::getMailer(); $mail->isHTML(true); $mail->addRecipient($toEmail); if ($toCC) $mail->addCc($toCC); if ($toBCC) $mail->addBcc($toBCC); $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 = JText::sprintf('PLG_PAGEBUILDERCK_CONTACT_COPYTEXT_OF', $contact->name, $sitename); $copytext .= "\r\n\r\n" . $body; $copysubject = JText::sprintf('PLG_PAGEBUILDERCK_CONTACT_COPYSUBJECT_OF', $subject); $mail = JFactory::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); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings