- md5
- a4714371dd901c83f7f2817cc7f55320
- sha1
- bf60a8d6ee1facc626296e990cbc1d30714d5a6f
- sha256
- 47b0898eb88d6694e29d85c2d4c8e0ecbeba0cb32300134a91ef70d86362243d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
<?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_ADMINISTRATOR . '/components/com_actionlogs/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.
$this->checkToken();
$task = $this->getTask();
$pks = array();
if ($task == 'exportSelectedLogs')
{
// Get selected logs
$pks = ArrayHelper::toInteger(explode(',', $this->input->post->getString('cids')));
}
/** @var ActionlogsModelActionlogs $model */
$model = $this->getModel();
// Get the logs data
$data = $model->getLogDataAsIterator($pks);
if (count($data))
{
try
{
$rows = ActionlogsHelper::getCsvData($data);
}
catch (InvalidArgumentException $exception)
{
$this->setMessage(JText::_('COM_ACTIONLOGS_ERROR_COULD_NOT_EXPORT_DATA'), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_actionlogs&view=actionlogs', false));
return;
}
// Destroy the iterator now
unset($data);
$date = new JDate('now', new DateTimeZone('UTC'));
$filename = 'logs_' . $date->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()
{
// Check for request forgeries.
$this->checkToken();
$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 4 releases, Joomla 3.9.0-rc2 to 3.9.1. See them all, or every version of this file.