CoreFiles by mySites.guru
actionlogs.php125 lines, 3,040 bytes, from Joomla_3.9.0-alpha-Alpha-Full_Package.zip
Raw History Compare with 3.7.0-alpha2
md5
c7777d48fe200874bc8b1875f24e21f5
sha1
a0eb1a628e8f37d099df4a6cf3c19a06b3ef5b5f
sha256
ebee4a10ac58bb0b8d0ceac8c5a4024a5bbc9005b62220a2890b3b63c96fd67e
<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_actionlogs
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\Utilities\ArrayHelper;

JLoader::register('ActionlogsHelper', JPATH_COMPONENT . '/helpers/actionlogs.php');

/**
 * Actionlogs list controller class.
 *
 * @since  3.9.0
 */
class ActionlogsControllerActionlogs extends JControllerAdmin
{
	/**
	 * Constructor.
	 *
	 * @param   array  $config  An optional associative array of configuration settings.
	 *
	 * @since   3.9.0
	 */
	public function __construct(array $config = array())
	{
		parent::__construct($config);

		$this->registerTask('exportSelectedLogs', 'exportLogs');
	}

	/**
	 * Method to get a model object, loading it if required.
	 *
	 * @param   string  $name    The model name. Optional.
	 * @param   string  $prefix  The class prefix. Optional.
	 * @param   array   $config  Configuration array for model. Optional.
	 *
	 * @return  object  The model.
	 *
	 * @since   3.9.0
	 */
	public function getModel($name = 'Actionlogs', $prefix = 'ActionlogsModel', $config = array('ignore_request' => true))
	{
		// Return the model
		return parent::getModel($name, $prefix, $config);
	}

	/**
	 * Method to export logs
	 *
	 * @return  void
	 *
	 * @since   3.9.0
	 */
	public function exportLogs()
	{
		// Check for request forgeries.
		JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));

		// Get selected logs
		$pks = ArrayHelper::toInteger($this->input->post->get('cid', array(), 'array'));

		// Get the logs data
		$data = $this->getModel()->getLogsData($pks);

		if (count($data))
		{
			$rows = ActionlogsHelper::getCsvData($data);
			$filename     = 'logs_' . JFactory::getDate()->format('Y-m-d_His_T');
			$csvDelimiter = ComponentHelper::getComponent('com_actionlogs')->getParams()->get('csv_delimiter', ',');

			$app = JFactory::getApplication();
			$app->setHeader('Content-Type', 'application/csv', true)
				->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '.csv"', true)
				->setHeader('Cache-Control', 'must-revalidate', true)
				->sendHeaders();

			$output = fopen("php://output", "w");

			foreach ($rows as $row)
			{
				fputcsv($output, $row, $csvDelimiter);
			}

			fclose($output);

			$app->close();
		}
		else
		{
			$this->setMessage(JText::_('COM_ACTIONLOGS_NO_LOGS_TO_EXPORT'));
			$this->setRedirect(JRoute::_('index.php?option=com_actionlogs&view=actionlogs', false));
		}
	}

	/**
	 * Clean out the logs
	 *
	 * @return  void
	 *
	 * @since   3.9.0
	 */
	public function purge()
	{
		$model = $this->getModel();

		if ($model->purge())
		{
			$message = JText::_('COM_ACTIONLOGS_PURGE_SUCCESS');
		}
		else
		{
			$message = JText::_('COM_ACTIONLOGS_PURGE_FAIL');
		}

		$this->setRedirect(JRoute::_('index.php?option=com_actionlogs&view=actionlogs', false), $message);
	}
}

The same content is in 2 releases, Joomla 3.9.0-alpha to 3.9.0-beta. See them all, or every version of this file.