Skip to content

Commit

Permalink
New Feature: Implements a modal to edit the Redirect plugin settings …
Browse files Browse the repository at this point in the history
…when needed (joomla#16844)

* Redo of joomla#7259 and implements a modal to edit the Redirect plugin settings when needed

* Fixed CSS class and copyright
Changed reload of parent page

* Removed label class

* Make location generic

* Changed amp usage

* Updated after feedback

* Updated the language constants and RTL issue

* Fixed invalid markup in Hathor

* Fixed the URLs for Hathor

* More Hathor massaging

* RTL support in Hathor joomla#16844 Redo
  • Loading branch information
roland-d authored and mbabker committed Jul 26, 2017
1 parent 3110af2 commit bc1e0a0
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 51 deletions.
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 = window.top.location.href', 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 - 2017 Open Source Matters, Inc. All rights reserved.
* @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
18 changes: 18 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,24 @@
<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) : ?>
<?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; ?>

<?php if (empty($this->items)) : ?>
<div class="alert alert-no-items">
<?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
Expand Down
51 changes: 40 additions & 11 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 @@ -56,22 +64,42 @@ public function display($tpl = null)
// Show messages about the enabled plugin and if the plugin should collect URLs
if ($this->enabled && $this->collect_urls_enabled)
{
$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');
$app->enqueueMessage(JText::sprintf('COM_REDIRECT_COLLECT_URLS_ENABLED', JText::_('COM_REDIRECT_PLUGIN_ENABLED')), '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();

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

// To be removed in Joomla 4
if (JFactory::getApplication()->getTemplate() === 'hathor')
{
$link = JHtml::_(
'link',
JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . RedirectHelper::getRedirectPluginId()),
JText::_('COM_REDIRECT_SYSTEM_PLUGIN')
);
}

if ($this->enabled && !$this->collect_urls_enabled)
{
$app->enqueueMessage(JText::sprintf('COM_REDIRECT_COLLECT_MODAL_URLS_DISABLED', JText::_('COM_REDIRECT_PLUGIN_ENABLED'), $link), 'notice');
}
else
{
$app->enqueueMessage(JText::sprintf('COM_REDIRECT_PLUGIN_MODAL_DISABLED', $link), 'error');
}
}

$this->addToolbar();

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

/**
Expand Down Expand Up @@ -129,6 +157,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 +185,5 @@ protected function addToolbar()
}

JToolbarHelper::help('JHELP_COMPONENTS_REDIRECT_MANAGER');

}
}
8 changes: 7 additions & 1 deletion administrator/language/en-GB/en-GB.com_redirect.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ COM_REDIRECT_BATCH_TIP="Enter expired URL (mandatory) with a new URL (optional)
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_MODAL_URLS_DISABLED="%1$s The 'Collect URLs' option in the %2$s is disabled. Error page URLs will not be collected by this component."
COM_REDIRECT_COLLECT_URLS_ENABLED="%1$s The option 'Collect URLs' is enabled."
; The following string is deprecated and will be removed with 4.0.
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_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 +82,14 @@ 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."
; The following string is deprecated and will be removed with 4.0.
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_ENABLED="The Redirect Plugin is enabled."
COM_REDIRECT_PLUGIN_MODAL_DISABLED="The %s is disabled. It needs to be enabled for this component to work."
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."
21 changes: 12 additions & 9 deletions administrator/templates/hathor/html/com_redirect/links/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,18 @@

<?php echo $this->pagination->getListFooter(); ?>
<p class="footer-tip">
<?php if ($this->enabled) : ?>
<span class="enabled"><?php echo JText::_('COM_REDIRECT_PLUGIN_ENABLED'); ?></span>
<?php if ($this->collect_urls_enabled) : ?>
<span class="enabled"><?php echo JText::_('COM_REDIRECT_COLLECT_URLS_ENABLED'); ?></span>
<?php else : ?>
<span class="enabled"><?php echo JText::_('COM_REDIRECT_COLLECT_URLS_DISABLED'); ?></span>
<?php endif; ?>
<?php else : ?>
<span class="disabled"><?php echo JText::_('COM_REDIRECT_PLUGIN_DISABLED'); ?></span>
<?php if ($this->enabled && $this->collect_urls_enabled) : ?>
<span class="enabled"><?php echo JText::sprintf('COM_REDIRECT_COLLECT_URLS_ENABLED', JText::_('COM_REDIRECT_PLUGIN_ENABLED')); ?></span>
<?php elseif ($this->enabled && !$this->collect_urls_enabled) : ?>
<?php $link = JHtml::_(
'link',
JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . RedirectHelper::getRedirectPluginId()),
JText::_('COM_REDIRECT_SYSTEM_PLUGIN')
);
?>
<span class="enabled"><?php echo JText::sprintf('COM_REDIRECT_COLLECT_MODAL_URLS_DISABLED', JText::_('COM_REDIRECT_PLUGIN_ENABLED'), $link); ?></span>
<?php elseif (!$this->enabled) : ?>
<span class="disabled"><?php echo JText::sprintf('COM_REDIRECT_PLUGIN_DISABLED', 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . RedirectHelper::getRedirectPluginId()); ?></span>
<?php endif; ?>
</p>
<div class="clr"></div>
Expand Down
17 changes: 16 additions & 1 deletion libraries/src/Joomla/CMS/Plugin/PluginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,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

0 comments on commit bc1e0a0

Please sign in to comment.