CoreFiles by mySites.guru
HtmlView.php164 lines, 3,773 bytes, from Joomla_4.0.0-alpha10-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha9
md5
ae00c7ce6cd7720241637a5476733cd1
sha1
56b8eb89774c5527a4167aaf18e9c6f7c336b000
sha256
121e7fbcc668f5f4cf261657d3116943b9c26713cec69c613be151b1fc85f2ae
<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_csp
 *
 * @copyright   Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Csp\Administrator\View\Reports;

defined('_JEXEC') or die;

use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Csp\Administrator\Helper\ReporterHelper;

/**
 * Reports view class for the Csp package.
 *
 * @since  4.0.0
 */
class HtmlView extends BaseHtmlView
{
	/**
	 * An array of items
	 *
	 * @var    array
	 * @since  4.0.0
	 */
	protected $items;

	/**
	 * The pagination object
	 *
	 * @var    \Joomla\CMS\Pagination\Pagination
	 * @since  4.0.0
	 */
	protected $pagination;

	/**
	 * The model state
	 *
	 * @var    \JObject
	 * @since  4.0.0
	 */
	protected $state;

	/**
	 * Form object for search filters
	 *
	 * @var    \JForm
	 * @since  4.0.0
	 */
	public $filterForm;

	/**
	 * The active search filters
	 *
	 * @var    array
	 * @since  4.0.0
	 */
	public $activeFilters;

	/**
	 * The id of the httpheaders plugin in mysql
	 *
	 * @var    integer
	 * @since  4.0.0
	 */
	protected $httpHeadersId = 0;

	/**
	 * Execute and display a template script.
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  mixed   A string if successful, otherwise an Error object.
	 *
	 * @since   4.0.0
	 */
	public function display($tpl = null)
	{
		$this->items         = $this->get('Items');
		$this->pagination    = $this->get('Pagination');
		$this->state         = $this->get('State');
		$this->activeFilters = $this->get('ActiveFilters');
		$this->filterForm    = $this->get('FilterForm');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new GenericDataException(implode("\n", $errors), 500);
		}

		if (!(PluginHelper::isEnabled('system', 'httpheaders')))
		{
			$this->httpHeadersId = ReporterHelper::getHttpHeadersPluginId();
		}

		$this->addToolbar();

		return parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return void
	 *
	 * @since   4.0.0
	 */
	protected function addToolbar()
	{
		$canDo = ContentHelper::getActions('com_csp');

		ToolbarHelper::title(Text::_('COM_CSP_REPORTS'), 'generic');

		if ($canDo->get('core.edit.state'))
		{
			ToolbarHelper::publish('reports.publish', 'JTOOLBAR_PUBLISH', true);
			ToolbarHelper::unpublish('reports.unpublish', 'JTOOLBAR_UNPUBLISH', true);
		}

		if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete'))
		{
			ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'reports.delete', 'JTOOLBAR_EMPTY_TRASH');
		}
		elseif ($canDo->get('core.edit.state'))
		{
			ToolbarHelper::trash('reports.trash');
		}

		if ($canDo->get('core.admin') || $canDo->get('core.options'))
		{
			ToolbarHelper::preferences('com_csp');
		}

		ToolbarHelper::help('JHELP_COMPONENTS_CSP_REPORTS');
	}

	/**
	 * Returns an array of fields the table can be sorted by
	 *
	 * @return  array  Array containing the field name to sort by as the key and display text as value
	 *
	 * @since   4.0.0
	 */
	protected function getSortFields()
	{
		return [
			'a.state'        => Text::_('JSTATUS'),
			'a.blocked_uri'  => Text::_('COM_CSP_HEADING_BLOCKED_URI'),
			'a.document_uri' => Text::_('COM_CSP_HEADING_DOCUMENT_URI'),
			'a.directive'    => Text::_('COM_CSP_HEADING_DIRECTIVE'),
			'a.client'       => Text::_('JCLIENT'),
			'a.id'           => Text::_('JGRID_HEADING_ID'),
		];
	}
}

The same content is in 2 releases, Joomla 4.0.0-alpha9 to 4.0.0-alpha10. See them all, or every version of this file.