[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_actionlogs 6 * 7 * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Actionlogs\Administrator\Controller; 12 13 use DateTimeZone; 14 use Exception; 15 use InvalidArgumentException; 16 use Joomla\CMS\Application\CMSApplication; 17 use Joomla\CMS\Component\ComponentHelper; 18 use Joomla\CMS\Date\Date; 19 use Joomla\CMS\Input\Input; 20 use Joomla\CMS\Language\Text; 21 use Joomla\CMS\MVC\Controller\AdminController; 22 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 23 use Joomla\CMS\Router\Route; 24 use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper; 25 use Joomla\Component\Actionlogs\Administrator\Model\ActionlogsModel; 26 use Joomla\Utilities\ArrayHelper; 27 28 // phpcs:disable PSR1.Files.SideEffects 29 \defined('_JEXEC') or die; 30 // phpcs:enable PSR1.Files.SideEffects 31 32 /** 33 * Actionlogs list controller class. 34 * 35 * @since 3.9.0 36 */ 37 class ActionlogsController extends AdminController 38 { 39 /** 40 * Constructor. 41 * 42 * @param array $config An optional associative array of configuration settings. 43 * Recognized key values include 'name', 'default_task', 'model_path', and 44 * 'view_path' (this list is not meant to be comprehensive). 45 * @param MVCFactoryInterface $factory The factory. 46 * @param CMSApplication $app The Application for the dispatcher 47 * @param Input $input Input 48 * 49 * @since 3.9.0 50 * 51 * @throws Exception 52 */ 53 public function __construct($config = [], MVCFactoryInterface $factory = null, $app = null, $input = null) 54 { 55 parent::__construct($config, $factory, $app, $input); 56 57 $this->registerTask('exportSelectedLogs', 'exportLogs'); 58 } 59 60 /** 61 * Method to export logs 62 * 63 * @return void 64 * 65 * @since 3.9.0 66 * 67 * @throws Exception 68 */ 69 public function exportLogs() 70 { 71 // Check for request forgeries. 72 $this->checkToken(); 73 74 $task = $this->getTask(); 75 76 $pks = array(); 77 78 if ($task == 'exportSelectedLogs') { 79 // Get selected logs 80 $pks = ArrayHelper::toInteger(explode(',', $this->input->post->getString('cids'))); 81 } 82 83 /** @var ActionlogsModel $model */ 84 $model = $this->getModel(); 85 86 // Get the logs data 87 $data = $model->getLogDataAsIterator($pks); 88 89 if (\count($data)) { 90 try { 91 $rows = ActionlogsHelper::getCsvData($data); 92 } catch (InvalidArgumentException $exception) { 93 $this->setMessage(Text::_('COM_ACTIONLOGS_ERROR_COULD_NOT_EXPORT_DATA'), 'error'); 94 $this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false)); 95 96 return; 97 } 98 99 // Destroy the iterator now 100 unset($data); 101 102 $date = new Date('now', new DateTimeZone('UTC')); 103 $filename = 'logs_' . $date->format('Y-m-d_His_T'); 104 105 $csvDelimiter = ComponentHelper::getComponent('com_actionlogs')->getParams()->get('csv_delimiter', ','); 106 107 $this->app->setHeader('Content-Type', 'application/csv', true) 108 ->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '.csv"', true) 109 ->setHeader('Cache-Control', 'must-revalidate', true) 110 ->sendHeaders(); 111 112 $output = fopen("php://output", "w"); 113 114 foreach ($rows as $row) { 115 fputcsv($output, $row, $csvDelimiter); 116 } 117 118 fclose($output); 119 $this->app->triggerEvent('onAfterLogExport', array()); 120 $this->app->close(); 121 } else { 122 $this->setMessage(Text::_('COM_ACTIONLOGS_NO_LOGS_TO_EXPORT')); 123 $this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false)); 124 } 125 } 126 127 /** 128 * Method to get a model object, loading it if required. 129 * 130 * @param string $name The model name. Optional. 131 * @param string $prefix The class prefix. Optional. 132 * @param array $config Configuration array for model. Optional. 133 * 134 * @return object The model. 135 * 136 * @since 3.9.0 137 */ 138 public function getModel($name = 'Actionlogs', $prefix = 'Administrator', $config = ['ignore_request' => true]) 139 { 140 // Return the model 141 return parent::getModel($name, $prefix, $config); 142 } 143 144 /** 145 * Clean out the logs 146 * 147 * @return void 148 * 149 * @since 3.9.0 150 */ 151 public function purge() 152 { 153 // Check for request forgeries. 154 $this->checkToken(); 155 156 $model = $this->getModel(); 157 158 if ($model->purge()) { 159 $message = Text::_('COM_ACTIONLOGS_PURGE_SUCCESS'); 160 } else { 161 $message = Text::_('COM_ACTIONLOGS_PURGE_FAIL'); 162 } 163 164 $this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false), $message); 165 } 166 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |