Sindbad~EG File Manager

Current Path : /var/www/ispania.gr/components/com_rsdirectory/models/
Upload File :
Current File : /var/www/ispania.gr/components/com_rsdirectory/models/contact.php

<?php
/**
 * @package	RSDirectory!
 * @copyright	(c) 2013 - 2021 RSJoomla!
 * @link		https://www.rsjoomla.com
 * @license	GNU General Public License http://www.gnu.org/licenses/gpl-3.0.en.html
 */

// No direct access.
defined('_JEXEC') or die('Restricted access');

/**
 * Contact model.
 */
class RSDirectoryModelContact extends JModelAdmin
{
	/**
	 * The entry from which the contact form was sent.
	 *
	 * @access protected
	 *
	 * @var object
	 */
	protected $entry;
		
	/**
	 * Submitted data.
	 *
	 * @access protected
	 *
	 * @var object
	 */
	protected $data;
		
	/**
     * Method for getting the form from the model.
     *
     * @access public
     * 
     * @param array $data
     * @param bool $loadData
     * 
     * @return mixed
     */
    public function getForm( $data = array(), $loadData = true )
    {
        // Get the form.
        $form = $this->loadForm( 'com_rsdirectory.contact', 'contact', array('control' => 'jform', 'load_data' => $loadData) );
		$config = RSDirectoryConfig::getInstance();

		// handle the phone_number field
		if (!$config->get('use_contact_phone_number')) {
			$form->removeField('phone_number');
		} else {
			if (!$config->get('required_contact_phone_number')) {
				$form->setFieldAttribute('phone_number', 'required', 'false');
			}
		}

		// handle the link field
		if (!$config->get('use_contact_link_url')) {
			$form->removeField('link');
		} else {
			if (!$config->get('required_contact_link_url')) {
				$form->setFieldAttribute('link', 'required', 'false');
			}
		}
            
        if ( empty($form) )
            return false;
            
        return $form;
    }
		
	/**
     * Method to get the data that should be injected in the form.
     *
     * @access protected
     * 
     * @return array
     */
    protected function loadFormData()
    {
        return JFactory::getApplication()->getUserState('com_rsdirectory.edit.contact.data');
    }
		
	/**
     * Validate form data.
     *
     * @access public
     * 
     * @param object $form The form to validate against.
     * @param array $data The data to validate.
     * @param string $group The name of the field group to validate.
     * 
     * @return mixed
     */
    public function validate($form, $data, $group = null)
    {
		$app = JFactory::getApplication();
		$user = JFactory::getUser();
			
		if ($user->id)
		{
			$data['name'] = $user->name;
			$data['email'] = $user->email;
		}
			
        $return = parent::validate($form, $data, $group);
			
		$entry_id = $app->input->getInt('entry_id');
			
		if ( !$entry_id || !( $this->entry = RSDirectoryHelper::getEntry($entry_id) ) )
		{
			$this->setError( JText::_('COM_RSDIRECTORY_INVALID_ENTRY_SPECIFIED') );
            $return = false;
		}

		$config = RSDirectoryConfig::getInstance();

		if ($config->get('use_consent_checkbox_on_contact_author_form', 0) && empty($data['consent'])) {
			$this->setError( JText::_('COM_RSDIRECTORY_CONSENT_DEFAULT_ERROR') );
			$return = false;
		}
			
		if ( RSDirectoryHelper::checkUserPermission('contact_captcha') )
		{

			if ( $config->get('captcha_type') == 'built_in' )
            {
	            require_once JPATH_ADMINISTRATOR . '/components/com_rsdirectory/helpers/captcha/captcha.php';
                    
                // Initialize the CAPTCHA object.
                $captcha = new RsdirectoryCaptcha('contact');
                $captcha->case_sensitive = $config->get('captcha_case_sensitive');
                    
                // Validate the CAPTCHA value.
                if ( empty($data['captcha']) || !$captcha->check( trim($data['captcha']) ) )
                {
                    $this->setError( JText::_('COM_RSDIRECTORY_CAPTCHA_ERROR') );
					$return = false;
                }
            }
			else 
			{
				try {
					$response = isset($data['g_recaptcha_response']) ? $data['g_recaptcha_response'] : '';
					$ip		  = $app->input->server->get('REMOTE_ADDR');
					$secretKey= $config->get('recaptcha_new_secret_key');

					$http = JHttpFactory::getHttp();
					if ($request = $http->get('https://www.google.com/recaptcha/api/siteverify?secret='.urlencode($secretKey).'&response='.urlencode($response).'&remoteip='.urlencode($ip))) {
						$json = json_decode($request->body);
					}
				} catch (Exception $e) {
					$this->setError( $e->getMessage() );
					$return = false;
				}
				
				if (!$json->success) {
					$this->setError( JText::_('COM_RSDIRECTORY_CAPTCHA_ERROR') );
					$return = false;
				}
			}
		}
			
		return $return;
    }
		
	/**
     * Send email.
     *
     * @access public
     * 
     * @param array $data
     * 
     * @return bool
     */
    public function save($data)
    {
        // Do a few checks.
        if (!$data || !$this->entry)
            return false;
			
		require_once JPATH_ADMINISTRATOR . '/components/com_rsdirectory/helpers/placeholders.php';

	    // Get the RSDirectory! config object.
	    $config = RSDirectoryConfig::getInstance();
			
		$this->data = (object)$data;
		$this->entry = RSDirectoryHelper::getEntryData($this->entry);
		$form = $this->entry->form;
			
		// Process placeholders.
		$from_name = $this->processPlaceholders($form->contact_from_name);
		$reply_to_email = $this->processPlaceholders($form->contact_from_email);
		$to_name = $this->processPlaceholders($form->contact_to_name);
		$to_email = $this->processPlaceholders($form->contact_to_email);
		$cc = $this->processPlaceholders($form->contact_cc);
		$bcc = $this->processPlaceholders($form->contact_bcc);
		$subject = $this->processPlaceholders($form->contact_subject);
		$message = $this->processPlaceholders($form->contact_message);

		// Get mailer.
        $mailer = JFactory::getMailer();
			
		// Set sender.
	    $mailer->setSender( array($config->get('from_email'), $from_name ));

	    // Set Reply to
	    $mailer->addReplyTo($reply_to_email);
			
		// Add recipient(s).
		$mailer->addRecipient(
			explode(',', $to_email),
			explode(',', $to_name)
		);
			
		// Set CC.	
		if ($cc)
		{
			$mailer->addCC( explode(',', $cc) );
		}
			
		// Set BCC.
		if ($bcc)
		{
			$mailer->addBCC( explode(',', $bcc) );
		}
			
		// Set subject.
		$mailer->setSubject($subject);
			
		// Set body.
		$mailer->setBody($message);
			
		// Send as HTML.
		$mailer->isHtml($form->contact_send_html);
			
		if ( !empty($mailer->ErrorInfo) )
		{
			$this->setError($mailer->ErrorInfo);
			return false;
		}
			
		// Unset the contact form data.	
        JFactory::getApplication()->setUserState('com_rsdirectory.edit.contact.data', null);

		try
		{
			$result = $mailer->Send();

			if (is_a($result, 'JException'))
			{
				throw new Exception($result->getMessage());
			}

			return $result;
		}
		catch (Exception $e)
		{
			$this->setError($e->getMessage());
			return false;
		}
	}
		
	/**
	 * Get an array of fields that should be skipped when displaying the form to the current user.
	 *
	 * @access public
	 *
	 * @return array
	 */
	public function getSkippedFields()
	{
		if ( JFactory::getUser()->id )
		{
			return array(
				'name',
				'email',
			);
		}
			
		return array();
	}
		
	/**
	 * Process placeholders.
	 *
	 * @access protected
	 *
	 * @param string $text
	 * 
	 * @return string
	 */
	protected function processPlaceholders($text)
	{
		// Process the regular placeholders.
		$text = RSDirectoryPlaceholders::getInstance($text, $this->entry->form->fields, $this->entry, $this->entry->form)
              ->setParams('email')
              ->process();
			  
		// Process the contact specific placeholders.
		$replace = array(
			'{contact.name}',
			'{contact.email}',
			'{contact.message}',
			'{contact.phone_number}',
			'{contact.link}'
		);

		$replace_with = array(
			strip_tags($this->data->name),
			strip_tags($this->data->email),
			strip_tags($this->data->message),
			(!empty($this->data->phone_number) ? strip_tags($this->data->phone_number) : ''),
			(!empty($this->data->link) ? strip_tags($this->data->link) : '')
		);
		
		$text = (string) $text;
		$text = str_replace($replace,$replace_with, $text);
			
		return $text;
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists