- md5
- cf9d0f3d3bde09f5b8f6afd4e1fa8024
- sha1
- a458851794d0bdf65770af2977811cea32e0be4b
- sha256
- 3e6d9667a4ae1b0843a30c2b7f07ef66832be837370d96d59a1b520ac9d0d312
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
<?php
/**
* @package Joomla.Plugin
* @subpackage System.actionlogs
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\User\User;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
use Joomla\Component\Actionlogs\Administrator\Plugin\ActionLogPlugin;
use Joomla\Utilities\ArrayHelper;
/**
* Joomla! Users Actions Logging Plugin.
*
* @since 3.9.0
*/
class PlgActionlogJoomla extends ActionLogPlugin
{
/**
* Array of loggable extensions.
*
* @var array
* @since 3.9.0
*/
protected $loggableExtensions = [];
/**
* Context aliases
*
* @var array
* @since 3.9.0
*/
protected $contextAliases = ['com_content.form' => 'com_content.article'];
/**
* Flag for loggable Api.
*
* @var boolean
* @since 4.0.0
*/
protected $loggableApi = false;
/**
* Array of loggable verbs.
*
* @var array
* @since 4.0.0
*/
protected $loggableVerbs = [];
/**
* Constructor.
*
* @param object &$subject The object to observe.
* @param array $config An optional associative array of configuration settings.
*
* @since 3.9.0
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
$params = ComponentHelper::getComponent('com_actionlogs')->getParams();
$this->loggableExtensions = $params->get('loggable_extensions', []);
$this->loggableApi = $params->get('loggable_api', 0);
$this->loggableVerbs = $params->get('loggable_verbs', []);
}
/**
* After save content logging method
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called right after the content is saved
*
* @param string $context The context of the content passed to the plugin
* @param object $article A JTableContent object
* @param boolean $isNew If the content is just about to be created
*
* @return void
*
* @since 3.9.0
*/
public function onContentAfterSave($context, $article, $isNew): void
{
if (isset($this->contextAliases[$context]))
{
$context = $this->contextAliases[$context];
}
$params = ActionlogsHelper::getLogContentTypeParams($context);
// Not found a valid content type, don't process further
if ($params === null)
{
return;
}
list($option, $contentType) = explode('.', $params->type_alias);
if (!$this->checkLoggable($option))
{
return;
}
if ($isNew)
{
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_ADDED';
$defaultLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_ADDED';
}
else
{
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_UPDATED';
$defaultLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_UPDATED';
}
// If the content type doesn't has it own language key, use default language key
if (!$this->app->getLanguage()->hasKey($messageLanguageKey))
{
$messageLanguageKey = $defaultLanguageKey;
}
$id = empty($params->id_holder) ? 0 : $article->get($params->id_holder);
$message = array(
'action' => $isNew ? 'add' : 'update',
'type' => $params->text_prefix . '_TYPE_' . $params->type_title,
'id' => $id,
'title' => $article->get($params->title_holder),
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $id, $params->id_holder, $article),
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* After delete content logging method
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called right after the content is deleted
*
* @param string $context The context of the content passed to the plugin
* @param object $article A JTableContent object
*
* @return void
*
* @since 3.9.0
*/
public function onContentAfterDelete($context, $article): void
{
$option = $this->app->input->get('option');
if (!$this->checkLoggable($option))
{
return;
}
$params = ActionlogsHelper::getLogContentTypeParams($context);
// Not found a valid content type, don't process further
if ($params === null)
{
return;
}
// If the content type has it own language key, use it, otherwise, use default language key
if ($this->app->getLanguage()->hasKey(strtoupper($params->text_prefix . '_' . $params->type_title . '_DELETED')))
{
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_DELETED';
}
else
{
$messageLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_DELETED';
}
$id = empty($params->id_holder) ? 0 : $article->get($params->id_holder);
$message = array(
'action' => 'delete',
'type' => $params->text_prefix . '_TYPE_' . $params->type_title,
'id' => $id,
'title' => $article->get($params->title_holder),
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* On content change status logging method
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called when the status of the article is changed
*
* @param string $context The context of the content passed to the plugin
* @param array $pks An array of primary key ids of the content that has changed state.
* @param integer $value The value of the state that the content has been changed to.
*
* @return void
*
* @since 3.9.0
*/
public function onContentChangeState($context, $pks, $value)
{
$option = $this->app->input->getCmd('option');
if (!$this->checkLoggable($option))
{
return;
}
$params = ActionlogsHelper::getLogContentTypeParams($context);
// Not found a valid content type, don't process further
if ($params === null)
{
return;
}
list(, $contentType) = explode('.', $params->type_alias);
switch ($value)
{
case 0:
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_UNPUBLISHED';
$defaultLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_UNPUBLISHED';
$action = 'unpublish';
break;
case 1:
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_PUBLISHED';
$defaultLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_PUBLISHED';
$action = 'publish';
break;
case 2:
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_ARCHIVED';
$defaultLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_ARCHIVED';
$action = 'archive';
break;
case -2:
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_TRASHED';
$defaultLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_TRASHED';
$action = 'trash';
break;
default:
$messageLanguageKey = '';
$defaultLanguageKey = '';
$action = '';
break;
}
// If the content type doesn't has it own language key, use default language key
if (!$this->app->getLanguage()->hasKey($messageLanguageKey))
{
$messageLanguageKey = $defaultLanguageKey;
}
$db = $this->db;
$query = $db->getQuery(true)
->select($db->quoteName([$params->title_holder, $params->id_holder]))
->from($db->quoteName($params->table_name))
->whereIn($db->quoteName($params->id_holder), ArrayHelper::toInteger($pks));
$db->setQuery($query);
try
{
$items = $db->loadObjectList($params->id_holder);
}
catch (RuntimeException $e)
{
$items = array();
}
$messages = array();
foreach ($pks as $pk)
{
$message = array(
'action' => $action,
'type' => $params->text_prefix . '_TYPE_' . $params->type_title,
'id' => $pk,
'title' => $items[$pk]->{$params->title_holder},
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $pk, $params->id_holder, null),
);
$messages[] = $message;
}
$this->addLog($messages, $messageLanguageKey, $context);
}
/**
* On Saving application configuration logging method
* Method is called when the application config is being saved
*
* @param JRegistry $config JRegistry object with the new config
*
* @return void
*
* @since 3.9.0
*/
public function onApplicationAfterSave($config): void
{
$option = $this->app->input->getCmd('option');
if (!$this->checkLoggable($option))
{
return;
}
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_APPLICATION_CONFIG_UPDATED';
$action = 'update';
$message = array(
'action' => $action,
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_APPLICATION_CONFIG',
'extension_name' => 'com_config.application',
'itemlink' => 'index.php?option=com_config',
);
$this->addLog(array($message), $messageLanguageKey, 'com_config.application');
}
/**
* On installing extensions logging method
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called when an extension is installed
*
* @param JInstaller $installer Installer object
* @param integer $eid Extension Identifier
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterInstall($installer, $eid)
{
$context = $this->app->input->get('option');
if (!$this->checkLoggable($context))
{
return;
}
$manifest = $installer->get('manifest');
if ($manifest === null)
{
return;
}
$extensionType = $manifest->attributes()->type;
// If the extension type has it own language key, use it, otherwise, use default language key
if ($this->app->getLanguage()->hasKey(strtoupper('PLG_ACTIONLOG_JOOMLA_' . $extensionType . '_INSTALLED')))
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_' . $extensionType . '_INSTALLED';
}
else
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_EXTENSION_INSTALLED';
}
$message = array(
'action' => 'install',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_' . $extensionType,
'id' => $eid,
'name' => (string) $manifest->name,
'extension_name' => (string) $manifest->name,
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* On uninstalling extensions logging method
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called when an extension is uninstalled
*
* @param JInstaller $installer Installer instance
* @param integer $eid Extension id
* @param integer $result Installation result
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterUninstall($installer, $eid, $result)
{
$context = $this->app->input->get('option');
if (!$this->checkLoggable($context))
{
return;
}
// If the process failed, we don't have manifest data, stop process to avoid fatal error
if ($result === false)
{
return;
}
$manifest = $installer->get('manifest');
if ($manifest === null)
{
return;
}
$extensionType = $manifest->attributes()->type;
// If the extension type has it own language key, use it, otherwise, use default language key
if ($this->app->getLanguage()->hasKey(strtoupper('PLG_ACTIONLOG_JOOMLA_' . $extensionType . '_UNINSTALLED')))
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_' . $extensionType . '_UNINSTALLED';
}
else
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_EXTENSION_UNINSTALLED';
}
$message = array(
'action' => 'install',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_' . $extensionType,
'id' => $eid,
'name' => (string) $manifest->name,
'extension_name' => (string) $manifest->name,
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* On updating extensions logging method
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called when an extension is updated
*
* @param JInstaller $installer Installer instance
* @param integer $eid Extension id
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterUpdate($installer, $eid)
{
$context = $this->app->input->get('option');
if (!$this->checkLoggable($context))
{
return;
}
$manifest = $installer->get('manifest');
if ($manifest === null)
{
return;
}
$extensionType = $manifest->attributes()->type;
// If the extension type has it own language key, use it, otherwise, use default language key
if ($this->app->getLanguage()->hasKey('PLG_ACTIONLOG_JOOMLA_' . $extensionType . '_UPDATED'))
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_' . $extensionType . '_UPDATED';
}
else
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_EXTENSION_UPDATED';
}
$message = array(
'action' => 'update',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_' . $extensionType,
'id' => $eid,
'name' => (string) $manifest->name,
'extension_name' => (string) $manifest->name,
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* On Saving extensions logging method
* Method is called when an extension is being saved
*
* @param string $context The extension
* @param JTable $table DataBase Table object
* @param boolean $isNew If the extension is new or not
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterSave($context, $table, $isNew): void
{
$option = $this->app->input->getCmd('option');
if ($table->get('module') != null)
{
$option = 'com_modules';
}
if (!$this->checkLoggable($option))
{
return;
}
$params = ActionlogsHelper::getLogContentTypeParams($context);
// Not found a valid content type, don't process further
if ($params === null)
{
return;
}
list(, $contentType) = explode('.', $params->type_alias);
if ($isNew)
{
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_ADDED';
$defaultLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_ADDED';
}
else
{
$messageLanguageKey = $params->text_prefix . '_' . $params->type_title . '_UPDATED';
$defaultLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_UPDATED';
}
// If the extension type doesn't have it own language key, use default language key
if (!$this->app->getLanguage()->hasKey($messageLanguageKey))
{
$messageLanguageKey = $defaultLanguageKey;
}
$message = array(
'action' => $isNew ? 'add' : 'update',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_' . $params->type_title,
'id' => $table->get($params->id_holder),
'title' => $table->get($params->title_holder),
'extension_name' => $table->get($params->title_holder),
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $table->get($params->id_holder), $params->id_holder),
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* On Deleting extensions logging method
* Method is called when an extension is being deleted
*
* @param string $context The extension
* @param JTable $table DataBase Table object
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterDelete($context, $table): void
{
if (!$this->checkLoggable($this->app->input->get('option')))
{
return;
}
$params = ActionlogsHelper::getLogContentTypeParams($context);
// Not found a valid content type, don't process further
if ($params === null)
{
return;
}
$messageLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_DELETED';
$message = array(
'action' => 'delete',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_' . $params->type_title,
'title' => $table->get($params->title_holder),
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* On saving user data logging method
*
* Method is called after user data is stored in the database.
* This method logs who created/edited any user's data
*
* @param array $user Holds the new user data.
* @param boolean $isnew True if a new user is stored.
* @param boolean $success True if user was successfully stored in the database.
* @param string $msg Message.
*
* @return void
*
* @since 3.9.0
*/
public function onUserAfterSave($user, $isnew, $success, $msg): void
{
$context = $this->app->input->get('option');
$task = $this->app->input->post->get('task');
if (!$this->checkLoggable($context))
{
return;
}
$jUser = Factory::getUser();
if (!$jUser->id)
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_REGISTERED';
$action = 'register';
// Reset request
if ($task === 'reset.request')
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_RESET_REQUEST';
$action = 'resetrequest';
}
// Reset complete
if ($task === 'reset.complete')
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_RESET_COMPLETE';
$action = 'resetcomplete';
}
// Registration Activation
if ($task === 'registration.activate')
{
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_REGISTRATION_ACTIVATE';
$action = 'activaterequest';
}
}
elseif ($isnew)
{
$messageLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_ADDED';
$action = 'add';
}
else
{
$messageLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_UPDATED';
$action = 'update';
}
$userId = $jUser->id ?: $user['id'];
$username = $jUser->username ?: $user['username'];
$message = array(
'action' => $action,
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER',
'id' => $user['id'],
'title' => $user['name'],
'itemlink' => 'index.php?option=com_users&task=user.edit&id=' . $user['id'],
'userid' => $userId,
'username' => $username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $userId,
);
$this->addLog(array($message), $messageLanguageKey, $context, $userId);
}
/**
* On deleting user data logging method
*
* Method is called after user data is deleted from the database
*
* @param array $user Holds the user data
* @param boolean $success True if user was successfully stored in the database
* @param string $msg Message
*
* @return void
*
* @since 3.9.0
*/
public function onUserAfterDelete($user, $success, $msg): void
{
$context = $this->app->input->get('option');
if (!$this->checkLoggable($context))
{
return;
}
$messageLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_DELETED';
$message = array(
'action' => 'delete',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER',
'id' => $user['id'],
'title' => $user['name'],
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* On after save user group data logging method
*
* Method is called after user group is stored into the database
*
* @param string $context The context
* @param JTable $table DataBase Table object
* @param boolean $isNew Is new or not
*
* @return void
*
* @since 3.9.0
*/
public function onUserAfterSaveGroup($context, $table, $isNew): void
{
// Override context (com_users.group) with the component context (com_users) to pass the checkLoggable
$context = $this->app->input->get('option');
if (!$this->checkLoggable($context))
{
return;
}
if ($isNew)
{
$messageLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_ADDED';
$action = 'add';
}
else
{
$messageLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_UPDATED';
$action = 'update';
}
$message = array(
'action' => $action,
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER_GROUP',
'id' => $table->id,
'title' => $table->title,
'itemlink' => 'index.php?option=com_users&task=group.edit&id=' . $table->id,
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* On deleting user group data logging method
*
* Method is called after user group is deleted from the database
*
* @param array $group Holds the group data
* @param boolean $success True if user was successfully stored in the database
* @param string $msg Message
*
* @return void
*
* @since 3.9.0
*/
public function onUserAfterDeleteGroup($group, $success, $msg): void
{
$context = $this->app->input->get('option');
if (!$this->checkLoggable($context))
{
return;
}
$messageLanguageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_DELETED';
$message = array(
'action' => 'delete',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER_GROUP',
'id' => $group['id'],
'title' => $group['title'],
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* Method to log user login success action
*
* @param array $options Array holding options (user, responseType)
*
* @return void
*
* @since 3.9.0
*/
public function onUserAfterLogin($options)
{
if ($options['action'] === 'core.login.api')
{
return;
}
$context = 'com_users';
if (!$this->checkLoggable($context))
{
return;
}
$loggedInUser = $options['user'];
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_LOGGED_IN';
$message = array(
'action' => 'login',
'userid' => $loggedInUser->id,
'username' => $loggedInUser->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $loggedInUser->id,
'app' => 'PLG_ACTIONLOG_JOOMLA_APPLICATION_' . $this->app->getName(),
);
$this->addLog(array($message), $messageLanguageKey, $context, $loggedInUser->id);
}
/**
* Method to log user login failed action
*
* @param array $response Array of response data.
*
* @return void
*
* @since 3.9.0
*/
public function onUserLoginFailure($response)
{
$context = 'com_users';
if (!$this->checkLoggable($context))
{
return;
}
// Get the user id for the given username
$query = $this->db->getQuery(true)
->select($this->db->quoteName(array('id', 'username')))
->from($this->db->quoteName('#__users'))
->where($this->db->quoteName('username') . ' = ' . $this->db->quote($response['username']));
$this->db->setQuery($query);
try
{
$loggedInUser = $this->db->loadObject();
}
catch (JDatabaseExceptionExecuting $e)
{
return;
}
// Not a valid user, return
if (!isset($loggedInUser->id))
{
return;
}
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_LOGIN_FAILED';
$message = array(
'action' => 'login',
'id' => $loggedInUser->id,
'userid' => $loggedInUser->id,
'username' => $loggedInUser->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $loggedInUser->id,
'app' => 'PLG_ACTIONLOG_JOOMLA_APPLICATION_' . $this->app->getName(),
);
$this->addLog(array($message), $messageLanguageKey, $context, $loggedInUser->id);
}
/**
* Method to log user's logout action
*
* @param array $user Holds the user data
* @param array $options Array holding options (remember, autoregister, group)
*
* @return void
*
* @since 3.9.0
*/
public function onUserLogout($user, $options = array())
{
$context = 'com_users';
if (!$this->checkLoggable($context))
{
return;
}
$loggedOutUser = User::getInstance($user['id']);
if ($loggedOutUser->block)
{
return;
}
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_LOGGED_OUT';
$message = array(
'action' => 'logout',
'id' => $loggedOutUser->id,
'userid' => $loggedOutUser->id,
'username' => $loggedOutUser->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $loggedOutUser->id,
'app' => 'PLG_ACTIONLOG_JOOMLA_APPLICATION_' . $this->app->getName(),
);
$this->addLog(array($message), $messageLanguageKey, $context);
}
/**
* Function to check if a component is loggable or not
*
* @param string $extension The extension that triggered the event
*
* @return boolean
*
* @since 3.9.0
*/
protected function checkLoggable($extension)
{
return in_array($extension, $this->loggableExtensions);
}
/**
* On after Remind username request
*
* Method is called after user request to remind their username.
*
* @param array $user Holds the user data.
*
* @return void
*
* @since 3.9.0
*/
public function onUserAfterRemind($user)
{
$context = $this->app->input->get('option');
if (!$this->checkLoggable($context))
{
return;
}
$message = array(
'action' => 'remind',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER',
'id' => $user->id,
'title' => $user->name,
'itemlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'userid' => $user->id,
'username' => $user->name,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
);
$this->addLog(array($message), 'PLG_ACTIONLOG_JOOMLA_USER_REMIND', $context, $user->id);
}
/**
* On after Check-in request
*
* Method is called after user request to check-in items.
*
* @param array $table Holds the table name.
*
* @return void
*
* @since 3.9.3
*/
public function onAfterCheckin($table)
{
$context = 'com_checkin';
$user = Factory::getUser();
if (!$this->checkLoggable($context))
{
return;
}
$message = array(
'action' => 'checkin',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER',
'id' => $user->id,
'title' => $user->username,
'itemlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'userid' => $user->id,
'username' => $user->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'table' => $table,
);
$this->addLog(array($message), 'PLG_ACTIONLOG_JOOMLA_USER_CHECKIN', $context, $user->id);
}
/**
* On after log action purge
*
* Method is called after user request to clean action log items.
*
* @param array $group Holds the group name.
*
* @return void
*
* @since 3.9.4
*/
public function onAfterLogPurge($group = '')
{
$context = $this->app->input->get('option');
$user = Factory::getUser();
$message = array(
'action' => 'actionlogs',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER',
'id' => $user->id,
'title' => $user->username,
'itemlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'userid' => $user->id,
'username' => $user->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
);
$this->addLog(array($message), 'PLG_ACTIONLOG_JOOMLA_USER_LOG', $context, $user->id);
}
/**
* On after log export
*
* Method is called after user request to export action log items.
*
* @param array $group Holds the group name.
*
* @return void
*
* @since 3.9.4
*/
public function onAfterLogExport($group = '')
{
$context = $this->app->input->get('option');
$user = Factory::getUser();
$message = array(
'action' => 'actionlogs',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER',
'id' => $user->id,
'title' => $user->username,
'itemlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'userid' => $user->id,
'username' => $user->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
);
$this->addLog(array($message), 'PLG_ACTIONLOG_JOOMLA_USER_LOGEXPORT', $context, $user->id);
}
/**
* On after Cache purge
*
* Method is called after user request to clean cached items.
*
* @param string $group Holds the group name.
*
* @return void
*
* @since 3.9.4
*/
public function onAfterPurge($group = 'all')
{
$context = $this->app->input->get('option');
$user = Factory::getUser();
if (!$this->checkLoggable($context))
{
return;
}
$message = array(
'action' => 'cache',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER',
'id' => $user->id,
'title' => $user->username,
'itemlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'userid' => $user->id,
'username' => $user->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'group' => $group,
);
$this->addLog(array($message), 'PLG_ACTIONLOG_JOOMLA_USER_CACHE', $context, $user->id);
}
/**
* On after Api dispatched
*
* Method is called after user perform an API request better on onAfterDispatch.
*
* @return void
*
* @since 4.0.0
*/
public function onAfterDispatch()
{
if (!$this->app->isClient('api'))
{
return;
}
if ($this->loggableApi === 0)
{
return;
}
$verb = $this->app->input->getMethod();
if (!in_array($verb, $this->loggableVerbs))
{
return;
}
$context = $this->app->input->get('option');
if (!$this->checkLoggable($context))
{
return;
}
$user = $this->app->getIdentity();
$message = array(
'action' => 'API',
'verb' => $verb,
'username' => $user->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'url' => htmlspecialchars(urldecode($this->app->get('uri.route')), ENT_QUOTES, 'UTF-8'),
);
$this->addLog(array($message), 'PLG_ACTIONLOG_JOOMLA_API', $context, $user->id);
}
/**
* On after CMS Update
*
* Method is called after user update the CMS.
*
* @param string $oldVersion The Joomla version before the update
*
* @return void
*
* @since 3.9.21
*/
public function onJoomlaAfterUpdate($oldVersion = null)
{
$context = $this->app->input->get('option');
$user = Factory::getUser();
if (empty($oldVersion))
{
$oldVersion = JText::_('JLIB_UNKNOWN');
}
$message = array(
'action' => 'joomlaupdate',
'type' => 'PLG_ACTIONLOG_JOOMLA_TYPE_USER',
'id' => $user->id,
'title' => $user->username,
'itemlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'userid' => $user->id,
'username' => $user->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'version' => JVERSION,
'oldversion' => $oldVersion,
);
$this->addLog(array($message), 'PLG_ACTIONLOG_JOOMLA_USER_UPDATE', $context, $user->id);
}
}
The same content is in 22 releases, Joomla 4.0.0-rc2 to 4.1.0-beta2. See them all, or every version of this file.