| Current Path : /var/www/html/components/com_flexicontact/ |
| Current File : /var/www/html/components/com_flexicontact/controller.php |
<?php
/********************************************************************
Product : Flexicontact
Date : 24 June 2024
Copyright : Les Arbres Design 2010-2024
Contact : https://www.lesarbresdesign.info
Licence : GNU General Public License
*********************************************************************/
// namespace Joomla\Component\Flexicontact;
defined('_JEXEC') or die('Restricted Access');
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
class FlexicontactController extends BaseController
{
function display($cachable = false, $urlparams = false)
{
$this->addModelPath(JPATH_ADMINISTRATOR.'/components/com_flexicontact/models'); // the log and config models are in the back end
$config_model = $this->getModel('config');
$config_data = $config_model->getData(); // get config data merged with menu parameters
FC_trace::trace("Displaying the contact form. Config structure: ".print_r($config_data,true));
$email_model = $this->getModel('email');
$post_data = $email_model->init_data($config_data);
$msg = $email_model->email_check($config_data); // Check the email-to address
if ($msg != '')
{
FC_trace::trace("Stopping because the email to address is not valid");
echo $msg;
return;
}
$view = $this->getView('contact','html');
$view->config_data = $config_data;
$view->post_data = $post_data;
$view->display();
}
function send()
{
FC_trace::trace("Send request received");
$this->addModelPath(JPATH_ADMINISTRATOR.'/components/com_flexicontact/models'); // the log and config models are in the back end
$config_model = $this->getModel('config');
$config_data = $config_model->getData(); // get config data merged with menu parameters
$email_model = $this->getModel('email');
$email_model->getPostData($config_data);
$errors = array();
FC_trace::trace("Calling validate function");
$email_model->validate($errors, $config_data);
FC_trace::trace("Returned from validate function");
if (!empty($errors))
FC_trace::trace("Validation failed: ".print_r($errors,true));
if (isset($errors['kill']))
{ // too many captcha attempts
$session = Factory::getApplication()->getSession(); // kill the session
$session->destroy();
echo Text::_('JINVALID_TOKEN');
return;
}
if (isset($errors['top']))
{ // session token didn't match
$view = $this->getView('contact','html');
$view->config_data = $config_data;
$view->errors = $errors;
$view->post_data = $email_model->data;
$view->display();
return;
}
if (isset($errors['block'])) // blocked word detected
{
$view = $this->getView('_confirm','html');
$view->message = $config_data->blocked_words_response;
$view->display();
return;
}
if (!empty($errors)) // if validation failed
{
$view = $this->getView('contact','html');
$view->config_data = $config_data;
$view->errors = $errors;
$view->post_data = $email_model->data;
$view->display();
return;
}
// here if validation ok
FC_trace::trace("Validation ok, calling sendEmail function");
$email_status = $email_model->sendEmail($config_data);
FC_trace::trace("Returned from sendEmail function with status: $email_status");
if ($config_data->logging)
{
FC_trace::trace("Logging the message");
$log_model = $this->getModel('log');
$log_model->purge($config_data); // purge expired log entries
$log_model->store($email_model->data);
}
if ($email_status != '1') // if send failed, show status using our _confirm view
{
$view = $this->getView('_confirm','html');
$failed_message = Text::_('COM_FLEXICONTACT_MESSAGE_FAILED').': '.$email_status;
$view->message = $failed_message;
$view->display();
return;
}
// here if the email was sent ok
if ($config_data->confirm_link)
{
FC_trace::trace("Redirecting to ".$config_data->confirm_link);
$link = strtolower($config_data->confirm_link);
if (substr($link,0,4) != 'http')
$link = Uri::root().$link;
$this->setRedirect($link);
}
else
{
$view = $this->getView('_confirm','html');
$view->message = $email_model->email_merge($config_data->confirm_text, $config_data);
$view->display();
}
}
//---------------------------------------------------------------------------------------------
// Serve a captcha image
//
function image()
{
require_once(LAFC_HELPER_PATH.'/flexi_captcha.php');
Flexi_captcha::show_image();
}
}