-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dos2unix i hope
- Loading branch information
Showing
25 changed files
with
1,998 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<access component="com_userlogs"> | ||
<section name="component"> | ||
<action name="core.viewlogs" title="COM_USERLOGS_ACTION_VIEWLOGS" description="COM_USERLOGS_ACTION_VIEWLOGS_DESC" /> | ||
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" /> | ||
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" /> | ||
<action name="core.options" title="JACTION_OPTIONS" description="JACTION_OPTIONS_COMPONENT_DESC" /> | ||
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" /> | ||
</section> | ||
</access> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<config> | ||
<fieldset | ||
name="permissions" | ||
label="JCONFIG_PERMISSIONS_LABEL" | ||
description="JCONFIG_PERMISSIONS_DESC" | ||
> | ||
<field | ||
name="rules" | ||
type="rules" | ||
label="JCONFIG_PERMISSIONS_LABEL" | ||
class="inputbox" | ||
validate="rules" | ||
filter="rules" | ||
component="com_userlogs" | ||
section="component" | ||
/> | ||
</fieldset> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_userlogs | ||
* | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
/** | ||
* Userlogs Controller | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class UserlogsController extends JControllerLegacy | ||
{ | ||
} |
115 changes: 115 additions & 0 deletions
115
administrator/components/com_userlogs/controllers/userlogs.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_userlogs | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
JLoader::register('UserlogsHelper', JPATH_COMPONENT . '/helpers/userlogs.php'); | ||
|
||
use Joomla\Utilities\ArrayHelper; | ||
|
||
/** | ||
* Userlogs list controller class. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class UserlogsControllerUserlogs extends JControllerAdmin | ||
{ | ||
/** | ||
* 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 __DEPLOY_VERSION__ | ||
*/ | ||
public function getModel($name = 'Userlogs', $prefix = 'UserlogsModel', | ||
$config = array('ignore_request' => true)) | ||
{ | ||
|
||
// Return the model | ||
return parent::getModel($name, $prefix, $config); | ||
} | ||
|
||
/** | ||
* Method to export logs | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function exportLogs() | ||
{ | ||
// Check for request forgeries. | ||
JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); | ||
|
||
// Get the logs data | ||
$data = $this->getModel('userlogs')->getLogsData(); | ||
|
||
// Export data to CSV file | ||
UserlogsHelper::dataToCsv($data); | ||
} | ||
|
||
/** | ||
* Method to delete logs | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function delete() | ||
{ | ||
// Check for request forgeries. | ||
JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); | ||
|
||
// Get the input | ||
$app = JFactory::getApplication(); | ||
|
||
// Sanitize the input | ||
$pks = ArrayHelper::toInteger($app->input->post->get('cid', array(), 'array')); | ||
|
||
// Get the logs data | ||
$data = $this->getModel('userlogs')->delete($pks); | ||
|
||
if ($data) | ||
{ | ||
$app->enqueueMessage(JText::_('COM_USERLOGS_DELETE_SUCCESS'), 'message'); | ||
} | ||
else | ||
{ | ||
$app->enqueueMessage(JText::_('COM_USERLOGS_DELETE_FAIL'), 'error'); | ||
} | ||
|
||
// Redirect to the list screen. | ||
$this->setRedirect(JRoute::_('index.php?option=com_userlogs&view=userlogs', false)); | ||
} | ||
|
||
/** | ||
* Method to export selected logs | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function exportSelectedLogs() | ||
{ | ||
// Check for request forgeries. | ||
JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); | ||
|
||
// Get selected logs | ||
$pks = ArrayHelper::toInteger(JFactory::getApplication()->input->post->get('cid', array(), 'array')); | ||
|
||
// Get the logs data | ||
$data = $this->getModel('userlogs')->getLogsData($pks); | ||
|
||
// Export data to CSV file | ||
UserlogsHelper::dataToCsv($data); | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
administrator/components/com_userlogs/helpers/userlogs.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_userlogs | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
/** | ||
* Userlogs component helper. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class UserlogsHelper | ||
{ | ||
/** | ||
* Method to extract data array of objects into CSV file | ||
* | ||
* @param array $data Has the data to be exported | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public static function dataToCsv($data) | ||
{ | ||
$date = JFactory::getDate(); | ||
$filename = "Logs_" . $date; | ||
$data = json_decode(json_encode($data), true); | ||
$dispatcher = JEventDispatcher::getInstance(); | ||
|
||
$app = JFactory::getApplication(); | ||
$app->setHeader('Content-Type', 'application/csv', true) | ||
->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '.csv"', true) | ||
->setHeader('Cache-Control', 'must-revalidate', true); | ||
|
||
$app->sendHeaders(); | ||
|
||
$fp = fopen('php://temp', 'r+'); | ||
ob_end_clean(); | ||
|
||
foreach ($data as $log) | ||
{ | ||
$dispatcher->trigger('onLogMessagePrepare', array (&$log['message'], $log['extension'])); | ||
$log['ip_address'] = JText::_($log['ip_address']); | ||
$log['extension'] = self::translateExtensionName(strtoupper(strtok($log['extension'], '.'))); | ||
|
||
fputcsv($fp, $log, ','); | ||
} | ||
|
||
rewind($fp); | ||
$content = stream_get_contents($fp); | ||
echo $content; | ||
fclose($fp); | ||
|
||
$app->close(); | ||
} | ||
|
||
/** | ||
* Change the retrived extension name to more user friendly name | ||
* | ||
* @param string $extension Extension name | ||
* | ||
* @return string Translated extension name | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public static function translateExtensionName($extension) | ||
{ | ||
$lang = JFactory::getLanguage(); | ||
$source = JPATH_ADMINISTRATOR . '/components/' . $extension; | ||
|
||
$lang->load(strtolower($extension), JPATH_ADMINISTRATOR, null, false, true) | ||
|| $lang->load(strtolower($extension), $source, null, false, true); | ||
|
||
return JText::_($extension); | ||
} | ||
|
||
/** | ||
* Get parameters to be | ||
* | ||
* @param string $context The context of the content | ||
* | ||
* @return mixed An array of parameters, or false on error. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public static function getLogMessageParams($context) | ||
{ | ||
$db = JFactory::getDbo(); | ||
$query = $db->getQuery(true) | ||
->select('a.*') | ||
->from($db->quoteName('#__user_logs_tables_data', 'a')) | ||
->where($db->quoteName('a.type_alias') . ' = "' . $context . '"'); | ||
|
||
$db->setQuery($query); | ||
|
||
$items = $db->loadObjectList(); | ||
|
||
if (empty($items)) | ||
{ | ||
return false; | ||
} | ||
|
||
return $items[0]; | ||
} | ||
|
||
/** | ||
* Method to retrive data by primary keys from a table | ||
* | ||
* @param array $pks An array of primary key ids of the content that has changed state. | ||
* @param string $field The field to get from the table | ||
* @param string $tableType The type (name) of the JTable class to get an instance of. | ||
* @param string $tablePrefix An optional prefix for the table class name. | ||
* | ||
* @return array | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public static function getDataByPks($pks, $field, $tableType, $tablePrefix = 'JTable') | ||
{ | ||
$items = array(); | ||
$table = JTable::getInstance($tableType, $tablePrefix); | ||
|
||
foreach ($pks as $pk) | ||
{ | ||
$table->load($pk); | ||
$items[] = $table->get($field); | ||
} | ||
|
||
return $items; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
administrator/components/com_userlogs/models/fields/extension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_userlogs | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
JFormHelper::loadFieldClass('list'); | ||
JLoader::register('UserlogsHelper', JPATH_COMPONENT . '/helpers/userlogs.php'); | ||
|
||
/** | ||
* Field to load a list of all users that have logged actions | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class JFormFieldExtension extends JFormFieldList | ||
{ | ||
/** | ||
* The form field type. | ||
* | ||
* @var string | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $type = 'extension'; | ||
|
||
/** | ||
* Method to get the options to populate list | ||
* | ||
* @return array The field option objects. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function getOptions() | ||
{ | ||
$db = JFactory::getDbo(); | ||
$query = $db->getQuery(true) | ||
->select('DISTINCT b.extension') | ||
->from($db->quoteName('#__user_logs', 'b')); | ||
|
||
$db->setQuery($query); | ||
$extensions = $db->loadObjectList(); | ||
|
||
$options = array(); | ||
|
||
foreach ($extensions as $extension) | ||
{ | ||
$text = UserlogsHelper::translateExtensionName(strtoupper(strtok($extension->extension, '.'))); | ||
$options[] = JHtml::_('select.option', $extension->extension, $text); | ||
} | ||
|
||
return array_merge(parent::getOptions(), $options); | ||
} | ||
} |
Oops, something went wrong.