forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from joomdonation/actionlog_plugin_group
3dp extensions support Introduce actionlogs plugin group thanks @joomdonation
- Loading branch information
Showing
22 changed files
with
1,157 additions
and
1,000 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
administrator/components/com_admin/sql/updates/mysql/3.9.0-2018-05-05.sql
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
3 changes: 2 additions & 1 deletion
3
administrator/components/com_admin/sql/updates/postgresql/3.9.0-2018-05-05.sql
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
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
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
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
46 changes: 46 additions & 0 deletions
46
administrator/components/com_userlogs/layouts/logstable.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,46 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_userlogs | ||
* | ||
* @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; | ||
|
||
JFactory::getLanguage()->load("com_userlogs", JPATH_ADMINISTRATOR, null, false, true); | ||
|
||
$messages = $displayData['messages']; | ||
?> | ||
<h1> | ||
<?php echo JText::_('COM_USERLOGS_EMAIL_SUBJECT'); ?> | ||
</h1> | ||
<h2> | ||
<?php echo JText::_('COM_USERLOGS_EMAIL_DESC'); ?> | ||
</h2> | ||
<table> | ||
<thead> | ||
<th><?php echo JText::_('COM_USERLOGS_MESSAGE'); ?></th> | ||
<th><?php echo JText::_('COM_USERLOGS_DATE'); ?></th> | ||
<th><?php echo JText::_('COM_USERLOGS_EXTENSION'); ?></th> | ||
<th><?php echo JText::_('COM_USERLOGS_NAME'); ?></th> | ||
<th><?php echo JText::_('COM_USERLOGS_IP_ADDRESS'); ?></th> | ||
</thead> | ||
<tbody> | ||
<?php | ||
foreach ($messages as $message) | ||
{ | ||
?> | ||
<tr> | ||
<td><?php echo $message->message; ?></td> | ||
<td><?php echo $message->log_date; ?></td> | ||
<td><?php echo $message->extension; ?></td> | ||
<td><?php echo $displayData['username']; ?></td> | ||
<td><?php echo $message->ip_address; ?></td> | ||
</tr> | ||
<?php | ||
} | ||
?> | ||
</tbody> | ||
</table> |
File renamed without changes.
155 changes: 155 additions & 0 deletions
155
administrator/components/com_userlogs/models/userlog.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,155 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_userlogs | ||
* | ||
* @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; | ||
|
||
/** | ||
* Methods supporting a list of article records. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class UserlogsModelUserlog extends JModelLegacy | ||
{ | ||
/** | ||
* Function to add logs to the database | ||
* This method adds a record to #__user_logs contains (message_language_key, message, date, context, user) | ||
* | ||
* @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 | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function addLogsToDb($messages, $messageLanguageKey, $context) | ||
{ | ||
$user = JFactory::getUser(); | ||
$db = $this->getDbo(); | ||
$date = JFactory::getDate(); | ||
$params = ComponentHelper::getComponent('com_userlogs')->getParams(); | ||
|
||
if ($params->get('ip_logging', 0)) | ||
{ | ||
$ip = JFactory::getApplication()->input->server->get('REMOTE_ADDR'); | ||
} | ||
else | ||
{ | ||
$ip = JText::_('COM_USERLOGS_DISABLED'); | ||
} | ||
|
||
$loggedMessages = array(); | ||
|
||
foreach ($messages as $message) | ||
{ | ||
$logMessage = new stdClass; | ||
$logMessage->message_language_key = $messageLanguageKey; | ||
$logMessage->message = json_encode($message); | ||
$logMessage->log_date = (string) $date; | ||
$logMessage->extension = $context; | ||
$logMessage->user_id = $user->id; | ||
$logMessage->ip_address = $ip; | ||
|
||
try | ||
{ | ||
$db->insertObject('#__user_logs', $logMessage); | ||
$loggedMessages[] = $logMessage; | ||
|
||
} | ||
catch (RuntimeException $e) | ||
{ | ||
// Ignore it | ||
} | ||
} | ||
|
||
// Send notification email to users who choose to be notified about the action logs | ||
$this->sendNotificationEmails($loggedMessages, $user->name, $context); | ||
} | ||
|
||
/** | ||
* Send notification emails about the action log | ||
* | ||
* @param array $messages The logged messages | ||
* @param string $username The username | ||
* @param string $context The Context | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected function sendNotificationEmails($messages, $username, $context) | ||
{ | ||
$db = $this->getDbo(); | ||
$query = $db->getQuery(true); | ||
|
||
$query->select($db->quoteName(array('email', 'params'))) | ||
->from($db->quoteName('#__users')) | ||
->where($db->quoteName('params') . ' LIKE ' . $db->quote('%"logs_notification_option":"1"%')); | ||
|
||
$db->setQuery($query); | ||
|
||
try | ||
{ | ||
$users = $db->loadObjectList(); | ||
} | ||
catch (RuntimeException $e) | ||
{ | ||
JError::raiseWarning(500, $e->getMessage()); | ||
|
||
return; | ||
} | ||
|
||
$recipients = array(); | ||
|
||
foreach ($users as $user) | ||
{ | ||
$userParams = json_decode($user->params, true); | ||
$extensions = $userParams['logs_notification_extensions']; | ||
|
||
if (in_array(strtok($context, '.'), $extensions)) | ||
{ | ||
$recipients[] = $user->email; | ||
} | ||
} | ||
|
||
if (empty($recipients)) | ||
{ | ||
return; | ||
} | ||
|
||
$layout = new JLayoutFile('components.com_userlogs.layouts.logstable', JPATH_ADMINISTRATOR); | ||
$extension = UserlogsHelper::translateExtensionName(strtoupper(strtok($context, '.'))); | ||
|
||
foreach ($messages as $message) | ||
{ | ||
$message->extension = $extension; | ||
$message->message = UserlogsHelper::getHumanReadableLogMessage($message); | ||
} | ||
|
||
$displayData = array( | ||
'messages' => $messages, | ||
'username' => $username, | ||
); | ||
|
||
$body = $layout->render($displayData); | ||
$mailer = JFactory::getMailer(); | ||
$mailer->addRecipient($recipients); | ||
$mailer->setSubject(JText::_('COM_USERLOGS_EMAIL_SUBJECT')); | ||
$mailer->isHTML(true); | ||
$mailer->Encoding = 'base64'; | ||
$mailer->setBody($body); | ||
|
||
if (!$mailer->Send()) | ||
{ | ||
JError::raiseWarning(500, JText::_('JERROR_SENDING_EMAIL')); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.