Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: Implements a modal to edit the Redirect plugin settings when needed #16844

Merged
merged 12 commits into from
Jul 26, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
if (task == 'plugin.cancel' || document.formvalidator.isValid(document.getElementById('style-form'))) {
Joomla.submitform(task, document.getElementById('style-form'));
}

if (self !== top) {
window.top.setTimeout('window.parent.location.reload()', 1000);
window.parent.jQuery('#plugin" . $this->item->extension_id . "Modal').modal('hide');
}
};
");
?>
Expand Down
26 changes: 26 additions & 0 deletions administrator/components/com_plugins/views/plugin/tmpl/modal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

2017

* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

// This code is needed for proper check out in case of modal close
JFactory::getDocument()->addScriptDeclaration('
window.parent.jQuery(".modal").on("hidden", function () {
if (typeof window.parent.jQuery("#plugin' . $this->item->extension_id . 'Modal iframe").contents().find("#closeBtn") !== "undefined") {
window.parent.jQuery("#plugin' . $this->item->extension_id . 'Modal iframe").contents().find("#closeBtn").click();
}
});
');
?>
<button id="saveBtn" type="button" class="hidden" onclick="Joomla.submitbutton('plugin.save');"></button>
<button id="closeBtn" type="button" class="hidden" onclick="Joomla.submitbutton('plugin.cancel');"></button>

<?php
$this->setLayout('edit');
echo $this->loadTemplate();
29 changes: 0 additions & 29 deletions administrator/components/com_redirect/helpers/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,6 @@ public static function publishedOptions()
return $options;
}

/**
* Determines if the plugin for Redirect to work is enabled.
*
* @return boolean
*
* @since 1.6
*/
public static function isEnabled()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('enabled'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('redirect'));
$db->setQuery($query);

try
{
$result = (boolean) $db->loadResult();
}
catch (RuntimeException $e)
{
JError::raiseWarning(500, $e->getMessage());
}

return $result;
}

/**
* Gets the redirect system plugin extension id.
*
Expand Down
21 changes: 21 additions & 0 deletions administrator/components/com_redirect/views/links/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@
<form action="<?php echo JRoute::_('index.php?option=com_redirect&view=links'); ?>" method="post" name="adminForm" id="adminForm">
<div id="j-main-container">
<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
<?php
if ($this->redirectPluginId)
Copy link
Contributor

Choose a reason for hiding this comment

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

please use opening and closing <?php ?> for everyline of PHP in layout files ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is just insane. It's a complete block of code, why would you want to open and close tags for every single line?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just copy:

			<?php if ($this->redirectPluginId) : ?>
				<?php $link = JRoute::_('index.php?option=com_plugins&client_id=0&task=plugin.edit&extension_id=' . $this->redirectPluginId . '&tmpl=component&layout=modal'); ?>
				<?php echo JHtml::_(
					'bootstrap.renderModal',
					'plugin' . $this->redirectPluginId . 'Modal',
					array(
						'url'        => $link,
						'title'      => JText::_('COM_REDIRECT_EDIT_PLUGIN_SETTINGS'),
						'height'     => '400px',
						'modalWidth' => '60',
						'footer'     => '<button class="btn" data-dismiss="modal" aria-hidden="true">'
							. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</button>'
							. '<button class="btn btn-success" data-dismiss="modal" aria-hidden="true" onclick="jQuery(\'#plugin' . $this->redirectPluginId . 'Modal iframe\').contents().find(\'#saveBtn\').click();">'
							. JText::_("JSAVE") . '</button>'
					)
				); ?>
			<?php endif; ?>

{
$link = JRoute::_('index.php?option=com_plugins&amp;client_id=0&amp;task=plugin.edit&amp;extension_id=' . $this->redirectPluginId . '&amp;tmpl=component&amp;layout=modal');
Copy link
Contributor

Choose a reason for hiding this comment

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

why use &amp; in JRoute::_()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason, just copy and paste :)


echo JHtml::_(
'bootstrap.renderModal',
'plugin' . $this->redirectPluginId . 'Modal',
array(
'url' => $link,
'title' => JText::_('COM_REDIRECT_EDIT_PLUGIN_SETTINGS'),
'height' => '400px',
'modalWidth' => '60',
'footer' => '<button class="btn" data-dismiss="modal" aria-hidden="true">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</button>'
. '<button class="btn btn-success" data-dismiss="modal" aria-hidden="true" onclick="jQuery(\'#plugin' . $this->redirectPluginId . 'Modal iframe\').contents().find(\'#saveBtn\').click();">'
. JText::_("JSAVE") . '</button>'
)
);
}
?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-no-items">
<?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
Expand Down
39 changes: 29 additions & 10 deletions administrator/components/com_redirect/views/links/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ class RedirectViewLinks extends JViewLegacy

protected $collect_urls_enabled;

protected $redirectPluginId = 0;

protected $items;

protected $pagination;

protected $state;

public $filterForm;

public $activeFilters;

/**
* Display the view.
*
Expand All @@ -34,12 +40,14 @@ class RedirectViewLinks extends JViewLegacy
* @return mixed False if unsuccessful, otherwise void.
*
* @since 1.6
*
* @throws Exception
*/
public function display($tpl = null)
{
// Set variables
$app = JFactory::getApplication();
$this->enabled = RedirectHelper::isEnabled();
$this->enabled = JPluginHelper::isEnabled('system', 'redirect');
$this->collect_urls_enabled = RedirectHelper::collectUrlsEnabled();
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
Expand All @@ -58,20 +66,30 @@ public function display($tpl = null)
{
$app->enqueueMessage(JText::_('COM_REDIRECT_PLUGIN_ENABLED') . ' ' . JText::_('COM_REDIRECT_COLLECT_URLS_ENABLED'), 'notice');
}
elseif ($this->enabled && !$this->collect_urls_enabled)
{
$link = JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . RedirectHelper::getRedirectPluginId());
$app->enqueueMessage(JText::_('COM_REDIRECT_PLUGIN_ENABLED') . JText::sprintf('COM_REDIRECT_COLLECT_URLS_DISABLED', $link), 'notice');
}
else
{
$link = JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . RedirectHelper::getRedirectPluginId());
$app->enqueueMessage(JText::sprintf('COM_REDIRECT_PLUGIN_DISABLED', $link), 'error');
$this->redirectPluginId = RedirectHelper::getRedirectPluginId();
Copy link
Contributor

@andrepereiradasilva andrepereiradasilva Jun 25, 2017

Choose a reason for hiding this comment

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

since you already added the id to JPluginHelper db query return data, can't you just use JPluginHelper::getPlugin('system', 'redirect')->id and remove/deprecate RedirectHelper::getRedirectPluginId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You cannot do that because when the plugin is disabled the function will return an empty array.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right! Forget that


$link = JHtml::_(
'link',
'#plugin' . $this->redirectPluginId . 'Modal',
JText::_('COM_REDIRECT_SYSTEM_PLUGIN'),
'role="button" class="btn label" data-toggle="modal" title="' . JText::_('COM_REDIRECT_SYSTEM_PLUGIN') . '" id="title-' . $this->redirectPluginId . '"'
);

if ($this->enabled && !$this->collect_urls_enabled)
{
$app->enqueueMessage(JText::_('COM_REDIRECT_PLUGIN_ENABLED') . JText::sprintf('COM_REDIRECT_COLLECT_URLS_DISABLED', $link), 'notice');
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a space between sentences.

}
else
{
$app->enqueueMessage(JText::sprintf('COM_REDIRECT_PLUGIN_DISABLED', $link), 'error');
}
}

$this->addToolbar();

parent::display($tpl);
return parent::display($tpl);
}

/**
Expand Down Expand Up @@ -129,6 +147,8 @@ protected function addToolbar()

$title = JText::_('JTOOLBAR_BULK_IMPORT');

JHtml::_('bootstrap.modal', 'collapseModal');

// Instantiate a new JLayoutFile instance and render the batch button
$layout = new JLayoutFile('toolbar.batch');

Expand All @@ -155,6 +175,5 @@ protected function addToolbar()
}

JToolbarHelper::help('JHELP_COMPONENTS_REDIRECT_MANAGER');

}
}
6 changes: 4 additions & 2 deletions administrator/language/en-GB/en-GB.com_redirect.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ COM_REDIRECT_BUTTON_UPDATE_LINKS="Update Links"
COM_REDIRECT_CLEAR_FAIL="Failed to delete unpublished links."
COM_REDIRECT_CLEAR_SUCCESS="All unpublished links have been deleted."
COM_REDIRECT_COLLECT_URLS_ENABLED="The option 'Collect URLs' is enabled."
COM_REDIRECT_COLLECT_URLS_DISABLED="The 'Collect URLs' option in the <a href="_QQ_"%s"_QQ_">Redirect System Plugin</a> is disabled. Error page URLs will not be collected by this component."
COM_REDIRECT_COLLECT_URLS_DISABLED="The 'Collect URLs' option in the %s is disabled. Error page URLs will not be collected by this component."
COM_REDIRECT_CONFIGURATION="Redirect: Options"
COM_REDIRECT_DISABLE_LINK="Disable Link"
COM_REDIRECT_EDIT_LINK="Edit Link #%d"
COM_REDIRECT_EDIT_PLUGIN_SETTINGS="Edit Plugin Settings"
COM_REDIRECT_ENABLE_LINK="Enable Link"
COM_REDIRECT_ERROR_DESTINATION_URL_REQUIRED="The redirect must have a destination URL"
COM_REDIRECT_ERROR_DUPLICATE_OLD_URL="The source URL must be unique."
Expand Down Expand Up @@ -79,11 +80,12 @@ COM_REDIRECT_N_LINKS_UPDATED_1="1 link has been updated."
COM_REDIRECT_NEW_LINK="New Link"
COM_REDIRECT_NO_ITEM_ADDED="No links added."
COM_REDIRECT_NO_ITEM_SELECTED="No links selected."
COM_REDIRECT_PLUGIN_DISABLED="The <a href="_QQ_"%s"_QQ_">Redirect System Plugin</a> is disabled. It needs to be enabled for this component to work."
COM_REDIRECT_PLUGIN_DISABLED="The %s is disabled. It needs to be enabled for this component to work."
COM_REDIRECT_PLUGIN_ENABLED="The Redirect Plugin is enabled."
COM_REDIRECT_REDIRECTED_ON="Redirected on: %s."
COM_REDIRECT_SAVE_SUCCESS="Link saved."
COM_REDIRECT_SEARCH_LINKS="Search in link fields."
COM_REDIRECT_SYSTEM_PLUGIN="Redirect System Plugin"
COM_REDIRECT_TOOLBAR_PURGE="Purge Unpublished"
COM_REDIRECT_XML_DESCRIPTION="This component implements link redirection."
JLIB_RULES_SETTING_NOTES="Changes apply to this component only.<br /><em><strong>Inherited</strong></em> - a Global Configuration setting or higher level setting is applied.<br /><em><strong>Denied</strong></em> always wins - whatever is set at the Global or higher level and applies to all child elements.<br /><em><strong>Allowed</strong></em> will enable the action for this component unless it is overruled by a Global Configuration setting."
17 changes: 16 additions & 1 deletion libraries/cms/plugin/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,22 @@ protected static function load()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select(array($db->quoteName('folder', 'type'), $db->quoteName('element', 'name'), $db->quoteName('params')))
->select(
$db->quoteName(
array(
'folder',
'element',
'params',
'extension_id'
),
array(
'type',
'name',
'params',
'id'
)
)
)
->from('#__extensions')
->where('enabled = 1')
->where('type = ' . $db->quote('plugin'))
Expand Down