Skip to content

Commit

Permalink
Merge pull request #4 from joomla/4.0-dev
Browse files Browse the repository at this point in the history
4.0 dev
  • Loading branch information
Arpit-24 committed Mar 30, 2019
2 parents 03fc4a7 + 3bf41ce commit 13e1e3f
Show file tree
Hide file tree
Showing 133 changed files with 1,726 additions and 484 deletions.
2 changes: 1 addition & 1 deletion administrator/components/com_actionlogs/actionlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

$controller = JControllerLegacy::getInstance('Actionlogs');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();
$controller->redirect();
2 changes: 1 addition & 1 deletion administrator/components/com_actionlogs/actionlogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<folder>controllers</folder>
<folder>helpers</folder>
<folder>models</folder>
<folder>views</folder>
<folder>views</folder>
</files>
<languages folder="admin">
<language tag="en-GB">language/en-GB.com_actionlogs.ini</language>
Expand Down
1 change: 1 addition & 0 deletions administrator/components/com_actionlogs/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
description="COM_ACTIONLOGS_IP_LOGGING_DESC"
class="btn-group btn-group-yesno"
default="0"
filter="integer"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
Expand Down
14 changes: 0 additions & 14 deletions administrator/components/com_actionlogs/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,4 @@
*/
class ActionlogsController extends JControllerLegacy
{
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe URL parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return ActionlogsController This object to support chaining.
*
* @since __DEPLOY_VERSION__
*/
public function display($cachable = false, $urlparams = array())
{
return parent::display();
}
}
21 changes: 4 additions & 17 deletions administrator/components/com_actionlogs/controllers/actionlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
*/

defined('_JEXEC') or die;
JLoader::register('ActionlogsHelper', JPATH_COMPONENT . '/helpers/actionlogs.php');

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

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

/**
* Actionlogs list controller class.
*
Expand Down Expand Up @@ -45,10 +46,8 @@ public function __construct(array $config = array())
*
* @since __DEPLOY_VERSION__
*/
public function getModel($name = 'Actionlogs', $prefix = 'ActionlogsModel',
$config = array('ignore_request' => true))
public function getModel($name = 'Actionlogs', $prefix = 'ActionlogsModel', $config = array('ignore_request' => true))
{

// Return the model
return parent::getModel($name, $prefix, $config);
}
Expand All @@ -74,7 +73,7 @@ public function exportLogs()
if (count($data))
{
$rows = ActionlogsHelper::getCsvData($data);
$filename = "logs_" . JFactory::getDate();
$filename = 'logs_' . JFactory::getDate()->format('Y-m-d_His_T');
$csvDelimiter = ComponentHelper::getComponent('com_actionlogs')->getParams()->get('csv_delimiter', ',');

$app = JFactory::getApplication();
Expand All @@ -101,18 +100,6 @@ public function exportLogs()
}
}

/**
* Method to delete logs
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function delete()
{
parent::delete();
}

/**
* Clean out the logs
*
Expand Down
88 changes: 69 additions & 19 deletions administrator/components/com_actionlogs/helpers/actionlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
defined('_JEXEC') or die;

use Joomla\CMS\Filesystem\Path;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;

/**
* Actionlogs component helper.
Expand All @@ -36,11 +38,13 @@ public static function getCsvData($data)

foreach ($data as $log)
{
$extension = strtok($log->extension, '.');
static::loadTranslationFiles($extension);
$row = array();
$row['id'] = $log->id;
$row['message'] = strip_tags(self::getHumanReadableLogMessage($log));
$row['date'] = $log->log_date;
$row['extension'] = self::translateExtensionName(strtoupper(strtok($log->extension, '.')));
$row['message'] = strip_tags(static::getHumanReadableLogMessage($log));
$row['date'] = JHtml::_('date', $log->log_date, JText::_('DATE_FORMAT_LC6'));
$row['extension'] = JText::_($extension);
$row['name'] = $log->name;
$row['ip_address'] = JText::_($log->ip_address);

Expand All @@ -51,23 +55,55 @@ public static function getCsvData($data)
}

/**
* Change the retrieved extension name to more user friendly name
* Load the translation files for an extension
*
* @param string $extension Extension name
*
* @return string Translated extension name
* @return void
*
* @since __DEPLOY_VERSION__
*/
public static function translateExtensionName($extension)
public static function loadTranslationFiles($extension)
{
static $cache = array();

if (isset($cache[$extension]))
{
return;
}

$lang = JFactory::getLanguage();
$source = JPATH_ADMINISTRATOR . '/components/' . $extension;

switch (substr($extension, 0, 3))
{
case 'com':
default:
$source = JPATH_ADMINISTRATOR . '/components/' . $extension;
break;

case 'lib':
$source = JPATH_LIBRARIES . '/' . substr($extension, 4);
break;

case 'mod':
$source = JPATH_SITE . '/modules/' . $extension;
break;

case 'plg':
$parts = explode('_', $extension, 3);
$source = JPATH_PLUGINS . '/' . $parts[1] . '/' . $parts[2];
break;

case 'tpl':
$source = JPATH_BASE . '/templates/' . substr($extension, 4);
break;

}

$lang->load(strtolower($extension), JPATH_ADMINISTRATOR, null, false, true)
|| $lang->load(strtolower($extension), $source, null, false, true);

return JText::_($extension);
$cache[$extension] = true;
}

/**
Expand All @@ -83,9 +119,9 @@ public static function getLogContentTypeParams($context)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.*')
->from($db->quoteName('#__action_logs_tables_data', 'a'))
->where($db->quoteName('a.type_alias') . ' = ' .$db->quote($context));
->select('a.*')
->from($db->quoteName('#__action_log_config', 'a'))
->where($db->quoteName('a.type_alias') . ' = ' . $db->quote($context));

$db->setQuery($query);

Expand All @@ -110,7 +146,7 @@ public static function getDataByPks($pks, $field, $idField, $table)
$query = $db->getQuery(true)
->select($db->quoteName(array($idField, $field)))
->from($db->quoteName($table))
->where($db->quoteName($idField) . ' IN (' . implode(',', $pks) . ')');
->where($db->quoteName($idField) . ' IN (' . implode(',', ArrayHelper::toInteger($pks)) . ')');
$db->setQuery($query);

try
Expand Down Expand Up @@ -140,11 +176,20 @@ public static function getHumanReadableLogMessage($log)
// Special handling for translation extension name
if (isset($messageData['extension_name']))
{
$messageData['extension_name'] = self::translateExtensionName($messageData['extension_name']);
static::loadTranslationFiles($messageData['extension_name']);
$messageData['extension_name'] = JText::_($messageData['extension_name']);
}

$linkMode = JFactory::getApplication()->get('force_ssl', 0) >= 1 ? 1 : -1;

foreach ($messageData as $key => $value)
{
// Convert relative url to absolute url so that it is clickable in action logs notification email
if (StringHelper::strpos($value, 'index.php?') === 0)
{
$value = JRoute::link('administrator', $value, false, $linkMode);
}

$message = str_replace('{' . $key . '}', JText::_($value), $message);
}

Expand All @@ -154,12 +199,13 @@ public static function getHumanReadableLogMessage($log)
/**
* Get link to an item of given content type
*
* @param string $component
* @param string $contentType
* @param int $id
* @param string $urlVar
* @param string $component
* @param string $contentType
* @param integer $id
* @param string $urlVar
*
* @return string Link to the content item
*
* @since __DEPLOY_VERSION__
*/
public static function getContentTypeLink($component, $contentType, $id, $urlVar = 'id')
Expand Down Expand Up @@ -191,8 +237,9 @@ public static function getContentTypeLink($component, $contentType, $id, $urlVar
}

/**
* Load both enabled and disabled actionlog plugins language file. It is used to make sure actions log is
* displayed properly instead of only language items displayed when a plugin is disabled
* Load both enabled and disabled actionlog plugins language file.
*
* It is used to make sure actions log is displayed properly instead of only language items displayed when a plugin is disabled.
*
* @return void
*
Expand Down Expand Up @@ -258,5 +305,8 @@ public static function loadActionLogPluginsLanguage()
$lang->load($extension, JPATH_ADMINISTRATOR, null, false, true)
|| $lang->load($extension, JPATH_PLUGINS . '/' . $type . '/' . $name, null, false, true);
}

// Load com_privacy too.
$lang->load('com_privacy', JPATH_ADMINISTRATOR, null, false, true);
}
}
4 changes: 2 additions & 2 deletions administrator/components/com_actionlogs/layouts/logstable.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* @package Joomla.Administrator
* @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
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;
Expand Down
20 changes: 13 additions & 7 deletions administrator/components/com_actionlogs/models/actionlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ class ActionlogsModelActionlog extends JModelLegacy
* @param array $messages The contents of the messages to be logged
* @param string $messageLanguageKey The language key of the message
* @param string $context The context of the content passed to the plugin
* @param int $userId ID of user perform the action, usually ID of current logged in user
* @param integer $userId ID of user perform the action, usually ID of current logged in user
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function addLogsToDb($messages, $messageLanguageKey, $context, $userId = null)
public function addLog($messages, $messageLanguageKey, $context, $userId = null)
{
$user = JFactory::getUser($userId);
$db = $this->getDbo();
Expand All @@ -41,7 +42,12 @@ public function addLogsToDb($messages, $messageLanguageKey, $context, $userId =

if ($params->get('ip_logging', 0))
{
$ip = JFactory::getApplication()->input->server->get('REMOTE_ADDR');
$ip = JFactory::getApplication()->input->server->get('REMOTE_ADDR', null, 'raw');

if (!filter_var($ip, FILTER_VALIDATE_IP))
{
$ip = 'COM_ACTIONLOGS_IP_INVALID';
}
}
else
{
Expand All @@ -65,7 +71,6 @@ public function addLogsToDb($messages, $messageLanguageKey, $context, $userId =
{
$db->insertObject('#__action_logs', $logMessage);
$loggedMessages[] = $logMessage;

}
catch (RuntimeException $e)
{
Expand Down Expand Up @@ -97,7 +102,7 @@ protected function sendNotificationEmails($messages, $username, $context)

$query->select($db->quoteName(array('email', 'params')))
->from($db->quoteName('#__users'))
->where($db->quoteName('params') . ' LIKE ' . $db->quote('%"logs_notification_option":"1"%'));
->where($db->quoteName('params') . ' LIKE ' . $db->quote('%"logs_notification_option":1%'));

$db->setQuery($query);

Expand Down Expand Up @@ -131,11 +136,12 @@ protected function sendNotificationEmails($messages, $username, $context)
}

$layout = new JLayoutFile('components.com_actionlogs.layouts.logstable', JPATH_ADMINISTRATOR);
$extension = ActionlogsHelper::translateExtensionName(strtoupper(strtok($context, '.')));
$extension = strtok($context, '.');
ActionlogsHelper::loadTranslationFiles($extension);

foreach ($messages as $message)
{
$message->extension = $extension;
$message->extension = JText::_($extension);
$message->message = ActionlogsHelper::getHumanReadableLogMessage($message);
}

Expand Down
15 changes: 11 additions & 4 deletions administrator/components/com_actionlogs/models/actionlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;

/**
* Methods supporting a list of article records.
*
* @since __DEPLOY_VERSION__
*/
class ActionlogsModelActionlogs extends JModelList
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @since __DEPLOY_VERSION__
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
Expand Down Expand Up @@ -195,7 +204,6 @@ private function buildDateRange($range)
$tz = new DateTimeZone('GMT');
$dStart->setTimezone($tz);
break;

}

return array('dNow' => $dNow, 'dStart' => $dStart);
Expand Down Expand Up @@ -238,7 +246,6 @@ public function getLogsForItem($extension, $itemId)
/**
* Get logs data into JTable object
*
*
* @return array All logs in the table
*
* @since __DEPLOY_VERSION__
Expand All @@ -253,7 +260,7 @@ public function getLogsData($pks = null)

if (is_array($pks) && count($pks) > 0)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $pks) . ')');
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', ArrayHelper::toInteger($pks)) . ')');
}

$db->setQuery($query);
Expand All @@ -275,7 +282,7 @@ public function delete(&$pks)
$db = $this->getDbo();
$query = $db->getQuery(true)
->delete($db->quoteName('#__action_logs'))
->where($db->quoteName('id') . ' IN (' . implode(',', $pks) . ')');
->where($db->quoteName('id') . ' IN (' . implode(',', ArrayHelper::toInteger($pks)) . ')');
$db->setQuery($query);

try
Expand Down

0 comments on commit 13e1e3f

Please sign in to comment.