Your IP : 216.73.216.224


Current Path : /var/www/html/components/com_jdownloads/src/Controller/
Upload File :
Current File : /var/www/html/components/com_jdownloads/src/Controller/DisplayController.php

<?php
/**
 * @package     com_jdownloads
 * @version     4.1
 * @copyright   (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace JDownloads\Component\JDownloads\Site\Controller;

\defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;


/**
 * Content Component Controller
 *
 * @since  1.5
 */
class DisplayController extends BaseController
{
	/**
	 * @param   array                         $config   An optional associative array of configuration settings.
	 *                                                  Recognized key values include 'name', 'default_task', 'model_path', and
	 *                                                  'view_path' (this list is not meant to be comprehensive).
	 * @param   MVCFactoryInterface|null      $factory  The factory.
	 * @param   CMSApplication|null           $app      The Application for the dispatcher
	 * @param   \Joomla\Input\Input|null  $input    The Input object for the request
	 *
	 * @since   3.0.1
	 */
	public function __construct($config = array(), ?MVCFactoryInterface $factory = null, $app = null, $input = null)
	{
		$this->input = Factory::getApplication()->getInput();

		// Article frontpage Editor:
		if ($this->input->get('view') === 'downloads' && $this->input->get('layout') === 'modal') 
		{
			$this->input->set('Itemid', 0);
			$config['base_path'] = JPATH_ADMINISTRATOR . '/components/com_jdownloads/';
            
            BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_jdownloads/src/Model');

		}

		parent::__construct($config, $factory, $app, $input);
	}

	/**
	 * Method to display a view.
	 *
	 * @param   boolean  $cachable   If true, the view output will be cached.
	 * @param   boolean  $urlparams  An array of safe URL parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
	 *
	 * @return  DisplayController  This object to support chaining.
	 *
	 * @since   1.5
	 */
	public function display($cachable = false, $urlparams = false)
	{
		$cachable = true;

		/**
		 * Set the default view name and format from the Request.
		 * Note we are using a_id to avoid collisions with the router and the return page.
		 * Frontend is a bit messier than the backend.
		 */
		$id    = $this->input->getInt('a_id');
		$vName = $this->input->getCmd('view', 'categories');
		$this->input->set('view', $vName);

		$user = $this->app->getIdentity();

		if ($user->get('id'))
		{
			$cachable = false;
		}

		$safeurlparams = array(
			'catid' => 'INT',
			'id' => 'INT',
			'cid' => 'ARRAY',
			'year' => 'INT',
			'month' => 'INT',
			'limit' => 'UINT',
			'limitstart' => 'UINT',
			'showall' => 'INT',
			'return' => 'BASE64',
			'filter' => 'STRING',
			'filter_order' => 'CMD',
			'filter_order_Dir' => 'CMD',
			'filter-search' => 'STRING',
			'print' => 'BOOLEAN',
			'lang' => 'CMD',
			'Itemid' => 'INT');

		// Check for edit form.
		if ($vName === 'form' && !$this->checkEditId('com_jdownloads.edit.download', $id))
		{
			// Somehow the person just went to the form - we don't allow that.
			throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 403);
		}

		if ($vName === 'download')
		{
			// Get/Create the model
			if ($model = $this->getModel($vName))
			{
				/* if (ComponentHelper::getParams('com_jdownloads')->get('record_hits', 1) == 1)
				{
					$model->hit();
				} */
			}
		}

		parent::display($cachable, $safeurlparams);

		return $this;
	}
}