CoreFiles by mySites.guru
ReporterHelper.php145 lines, 3,232 bytes, from Joomla_4.0.0-beta7-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta6
md5
667b243cd19c8ed5a45c198361bf3db3
sha1
698795eb40a94df197d05506ec11ccf6469e5462
sha256
f19ae16738616a605128efa1357f7c9e81554d609f040412fb0cee0991c5be26
<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_csp
 *
 * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Csp\Administrator\Helper;

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;

/**
 * Reporter component helper.
 *
 * @since  4.0.0
 */
class ReporterHelper
{
	/**
	 * Gets the httpheaders system plugin extension id.
	 *
	 * @return  mixed  The httpheaders system plugin extension id or false in case of an error.
	 *
	 * @since   4.0.0
	 */
	public static function getHttpHeadersPluginId()
	{
		$db = Factory::getDbo();
		$query = $db->getQuery(true)
			->select($db->quoteName('extension_id'))
			->from($db->quoteName('#__extensions'))
			->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
			->where($db->quoteName('element') . ' = ' . $db->quote('httpheaders'));
		$db->setQuery($query);

		try
		{
			$result = (int) $db->loadResult();
		}
		catch (\RuntimeException $e)
		{
			Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');

			return false;
		}

		return $result;
	}

	/**
	 * Check the com_csp trash to show a warning in this case
	 *
	 * @return  boolean  The status of the trash; Do items exists in the trash
	 *
	 * @since   4.0.0
	 */
	public static function getCspTrashStatus()
	{
		$db = Factory::getDbo();
		$query = $db->getQuery(true)
			->select('COUNT(*)')
			->from($db->quoteName('#__csp'))
			->where($db->quoteName('published') . ' = ' . $db->quote('-2'));
		$db->setQuery($query);

		try
		{
			$result = (int) $db->loadResult();
		}
		catch (\RuntimeException $e)
		{
			Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');

			return false;
		}

		return boolval($result);
	}

	/**
	 * Check whether there are unsafe-inline rules published
	 *
	 * @return  boolean  Whether there are unsafe-inline rules published
	 *
	 * @since   4.0.0
	 */
	public static function getCspUnsafeInlineStatus()
	{
		$db = Factory::getDbo();
		$query = $db->getQuery(true)
			->select('COUNT(*)')
			->from($db->quoteName('#__csp'))
			->where($db->quoteName('blocked_uri') . ' = ' . $db->quote("'unsafe-inline'"))
			->where($db->quoteName('published') . ' = 1');
		$db->setQuery($query);

		try
		{
			$result = (int) $db->loadResult();
		}
		catch (\RuntimeException $e)
		{
			Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');

			return false;
		}

		return boolval($result);
	}

	/**
	 * Check whether there are unsafe-eval rules published
	 *
	 * @return  boolean  Whether there are unsafe-eval rules published
	 *
	 * @since   4.0.0
	 */
	public static function getCspUnsafeEvalStatus()
	{
		$db = Factory::getDbo();
		$query = $db->getQuery(true)
			->select('COUNT(*)')
			->from($db->quoteName('#__csp'))
			->where($db->quoteName('blocked_uri') . ' = ' . $db->quote("'unsafe-eval'"))
			->where($db->quoteName('published') . ' = 1');
		$db->setQuery($query);

		try
		{
			$result = (int) $db->loadResult();
		}
		catch (\RuntimeException $e)
		{
			Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');

			return false;
		}

		return boolval($result);
	}
}

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