Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

\defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;

/**
* Plugins master display controller.
Expand All @@ -27,4 +31,42 @@ class DisplayController extends BaseController
* @since 1.6
*/
protected $default_view = 'actionlogs';

/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached.
* @param mixed $urlparams An array of safe URL parameters and their variable types, for valid values see {@link \JFilterInput::clean()}.
*
* @return static|boolean This object to support chaining or false on failure.
*
* @since __DEPLOY_VERSION__
*/
public function display($cachable = false, $urlparams = false)
{
$view = $this->input->get('view', 'actionlogs');
$layout = $this->input->get('layout', 'default');
$id = $this->input->getInt('id');

if ($view === 'actionlogs')
{
$pluginEnabled = PluginHelper::isEnabled('actionlog', 'joomla');

// Show message if the plugin is not enabled
if (!$pluginEnabled)
{
$actionlogPluginId = ActionlogsHelper::getActionlogPluginId();
$link = HTMLHelper::_(
'link',
'#plugin' . $actionlogPluginId . 'Modal',
Text::_('COM_ACTIONLOGS_JOOMLA_PLUGIN'),
'class="alert-link" data-bs-toggle="modal" id="title-' . $actionlogPluginId . '"'
);
$this->app->enqueueMessage(Text::sprintf('COM_ACTIONLOGS_PLUGIN_MODAL_DISABLED', $link), 'error');
}
}

return parent::display();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,33 @@ protected static function escapeCsvFormula($value)

return $value;
}

/**
* Gets the actionlog plugin extension id.
*
* @return integer The actionlog plugin extension id.
*
* @since __DEPLOY_VERSION__
*/
public static function getActionlogPluginId()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method needs to be moved to the model as there you have the database object available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the exact same code used in multiple places in core then.

Really frustrating to copy paste code from one component to another and be told its wrong.

As you know core is wrong I now expect that you will fix it

{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('extension_id'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('folder') . ' = ' . $db->quote('actionlog'))
->where($db->quoteName('element') . ' = ' . $db->quote('joomla'));
$db->setQuery($query);

try
{
$result = (int) $db->loadResult();
}
catch (\RuntimeException $e)
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Pagination\Pagination;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
Expand All @@ -38,6 +39,14 @@ class HtmlView extends BaseHtmlView
*/
protected $items;

/**
* The id of the actionlog plugin in the database
*
* @var integer
* @since __DEPLOY_VERSION__
*/
protected $actionlogPluginId = 0;

/**
* The model state
*
Expand Down Expand Up @@ -115,6 +124,11 @@ public function display($tpl = null)
throw new GenericDataException(implode("\n", $errors), 500);
}

if (!PluginHelper::isEnabled('actionlog', 'joomla'))
{
$this->actionlogPluginId = ActionlogsHelper::getActionlogPluginId();
}

$this->addToolbar();

// Load all actionlog plugins language files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@
<div id="j-main-container" class="j-main-container">
<?php // Search tools bar ?>
<?php echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
<?php if ($this->actionlogPluginId) : ?>
<?php $link = Route::_('index.php?option=com_plugins&client_id=0&task=plugin.edit&extension_id=' . $this->actionlogPluginId . '&tmpl=component&layout=modal'); ?>
<?php echo HTMLHelper::_(
'bootstrap.renderModal',
'plugin' . $this->actionlogPluginId . 'Modal',
array(
'url' => $link,
'title' => Text::_('COM_ACTIONLOGS_EDIT_PLUGIN_SETTINGS'),
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'closeButton' => false,
'backdrop' => 'static',
'keyboard' => false,
'footer' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"'
. ' onclick="Joomla.iframeButtonClick({iframeSelector: \'#plugin' . $this->actionlogPluginId . 'Modal\', buttonSelector: \'#closeBtn\'})">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>'
. '<button type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="Joomla.iframeButtonClick({iframeSelector: \'#plugin' . $this->actionlogPluginId . 'Modal\', buttonSelector: \'#saveBtn\'})">'
. Text::_('JSAVE') . '</button>'
. '<button type="button" class="btn btn-success" onclick="Joomla.iframeButtonClick({iframeSelector: \'#plugin' . $this->actionlogPluginId . 'Modal\', buttonSelector: \'#applyBtn\'}); return false;">'
. Text::_('JAPPLY') . '</button>'
)
); ?>
<?php endif; ?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
Expand Down
9 changes: 6 additions & 3 deletions administrator/language/en-GB/com_actionlogs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COM_ACTIONLOGS_CSV_DELIMITER_LABEL="CSV Delimiter"
COM_ACTIONLOGS_DATE="Date"
COM_ACTIONLOGS_DATE_RELATIVE_LABEL="Relative Date/Time"
COM_ACTIONLOGS_DISABLED="Disabled"
COM_ACTIONLOGS_EDIT_PLUGIN_SETTINGS="Edit Plugin Settings"
COM_ACTIONLOGS_EMAIL_BODY="Latest User Actions\n------\nThis is the latest action performed by a user on your website.\n\nAction | Date | Extension | Name\n{MESSAGES} {MESSAGE} | {DATE} | {EXTENSION} | {USERNAME} \n{/MESSAGES}"
COM_ACTIONLOGS_EMAIL_DESC="This is the latest action performed by a user on your website."
COM_ACTIONLOGS_EMAIL_HTMLBODY="<h1>Latest User Actions</h1>\n<h2>This is the latest action performed by a user on your website.</h2>\n<table>\n<thead>\n<th>Action</th>\n<th>Date</th>\n<th>Extension</th>\n<th>Name</th>\n</thead>\n<tbody>\n{MESSAGES}<tr>\n<td>{MESSAGE}</td>\n<td>{DATE}</td>\n<td>{EXTENSION}</td>\n<td>{USERNAME}</td>\n</tr>{/MESSAGES}\n</tbody>\n</table>"
Expand All @@ -38,16 +39,18 @@ COM_ACTIONLOGS_IP_ADDRESS_ASC="IP Address ascending"
COM_ACTIONLOGS_IP_ADDRESS_DESC="IP Address descending"
COM_ACTIONLOGS_IP_INVALID="Invalid IP"
COM_ACTIONLOGS_IP_LOGGING_LABEL="IP Logging"
COM_ACTIONLOGS_JOOMLA_PLUGIN="Action Log - Joomla Plugin"
COM_ACTIONLOGS_LOG_EXTENSIONS_LABEL="Events To Log"
COM_ACTIONLOGS_LOG_VERBS_LABEL="Request Methods To Log"
COM_ACTIONLOGS_MAIL_NOTIFICATION_DESC="Mail sent to administrators about new entries in the User Actions Log."
COM_ACTIONLOGS_MAIL_NOTIFICATION_TITLE="User Actions Log: Notification Mail"
COM_ACTIONLOGS_MANAGER_USERLOGS="User Actions Log"
COM_ACTIONLOGS_N_ITEMS_DELETED="%d logs deleted."
COM_ACTIONLOGS_N_ITEMS_DELETED_1="Log deleted."
COM_ACTIONLOGS_NAME="Name"
COM_ACTIONLOGS_NO_ITEM_SELECTED="Please first make a selection from the list."
COM_ACTIONLOGS_NO_LOGS_TO_EXPORT="There are no User Action logs to export."
COM_ACTIONLOGS_N_ITEMS_DELETED="%d logs deleted."
COM_ACTIONLOGS_N_ITEMS_DELETED_1="Log deleted."
COM_ACTIONLOGS_OPTIONS="Options"
COM_ACTIONLOGS_OPTION_FILTER_DATE="- Select Date -"
COM_ACTIONLOGS_OPTION_RANGE_NEVER="Never"
COM_ACTIONLOGS_OPTION_RANGE_PAST_1MONTH="In the last month"
Expand All @@ -57,7 +60,7 @@ COM_ACTIONLOGS_OPTION_RANGE_PAST_WEEK="In the last week"
COM_ACTIONLOGS_OPTION_RANGE_PAST_YEAR="In the last year"
COM_ACTIONLOGS_OPTION_RANGE_POST_YEAR="More than a year ago"
COM_ACTIONLOGS_OPTION_RANGE_TODAY="Today"
COM_ACTIONLOGS_OPTIONS="Options"
COM_ACTIONLOGS_PLUGIN_MODAL_DISABLED="The %s is disabled. It needs to be enabled for this component to work."
COM_ACTIONLOGS_POSTINSTALL_BODY="<p>With the release of Joomla 3.9.0 you can now log all administrative actions performed by your users in supported extensions. It is now easy to see who did what and when they did it.</p><p>The logs can be reviewed in Joomla or exported for external use.</p><p>For further information on this new feature read the <a href='https://docs.joomla.org/Special:MyLanguage/J3.x:User_Action_Logs' target='_blank' rel='noopener noreferrer'>User Action Logs documentation.</a></p>"
COM_ACTIONLOGS_POSTINSTALL_TITLE="User Actions Can Now Be Logged"
COM_ACTIONLOGS_PURGE_CONFIRM="Are you sure want to delete all User Action logs?"
Expand Down