From 2473c4bbef02418874eb025891649c7209705ddd Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 17 Dec 2015 16:13:12 +0100 Subject: [PATCH 1/6] NavigationItemRenderer: provide more human-readable aliases for internal link targets refs #10330 --- .../Renderer/NavigationItemRenderer.php | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php index 3b739c320..b1a010ec5 100644 --- a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php @@ -54,7 +54,11 @@ class NavigationItemRenderer $this->setOptions($options); } - $this->internalLinkTargets = array('_main', '_self', '_next'); + $this->internalLinkTargets = array( + 'single_column' => '_main', + 'current_column' => '_self', + 'next_column' => '_next' + ); $this->init(); } @@ -185,7 +189,7 @@ class NavigationItemRenderer $url->overwriteParams($item->getUrlParameters()); $target = $item->getTarget(); - if ($url->isExternal() && (!$target || in_array($target, $this->internalLinkTargets, true))) { + if ($url->isExternal() && ! ($target && $this->actualLinkTarget($target) === null)) { $url = Url::fromPath('iframe', array('url' => $url)); } @@ -222,10 +226,28 @@ class NavigationItemRenderer return ''; } - if (! in_array($target, $this->internalLinkTargets, true)) { + $actualTarget = $this->actualLinkTarget($target); + if ($actualTarget === null) { return ' target="' . $this->view()->escape($target) . '"'; } - return ' data-base-target="' . $target . '"'; + return ' data-base-target="' . $actualTarget . '"'; + } + + /** + * If $target is an internal linktarget, return its HTML version. Otherwise, return null. + * + * @param string $target + * + * @return string|null + */ + protected function actualLinkTarget($target) + { + if (isset($this->internalLinkTargets[$target])) { + return $this->internalLinkTargets[$target]; + } + if (in_array($target, $this->internalLinkTargets, true)) { + return $target; + } } } From 5edd8df1b6246925aea62325719236035b539271 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 17 Dec 2015 16:13:12 +0100 Subject: [PATCH 2/6] NavigationItemRenderer: provide more human-readable aliases for native HTML link targets refs #10330 --- .../Renderer/NavigationItemRenderer.php | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php index b1a010ec5..1fcf5677e 100644 --- a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php @@ -36,6 +36,13 @@ class NavigationItemRenderer */ protected $internalLinkTargets; + /** + * Native HTML link targets + * + * @var array + */ + protected $htmlLinkTargets; + /** * Whether to escape the label * @@ -59,6 +66,10 @@ class NavigationItemRenderer 'current_column' => '_self', 'next_column' => '_next' ); + $this->htmlLinkTargets = array( + 'current_window' => '_self', + 'new_window' => '_blank' + ); $this->init(); } @@ -227,26 +238,29 @@ class NavigationItemRenderer } $actualTarget = $this->actualLinkTarget($target); - if ($actualTarget === null) { - return ' target="' . $this->view()->escape($target) . '"'; + if ($actualTarget !== null) { + return ' data-base-target="' . $actualTarget . '"'; } - return ' data-base-target="' . $actualTarget . '"'; + $actualTarget = $this->actualLinkTarget($target, false); + return ' target="' . ($actualTarget === null ? $this->view()->escape($target) : $actualTarget) . '"'; } /** - * If $target is an internal linktarget, return its HTML version. Otherwise, return null. + * If $target is a linktarget, return its HTML version. Otherwise, return null. * * @param string $target + * @param bool $internal Whether the target must or must not be provided by Icinga Web 2 * * @return string|null */ - protected function actualLinkTarget($target) + protected function actualLinkTarget($target, $internal = true) { - if (isset($this->internalLinkTargets[$target])) { - return $this->internalLinkTargets[$target]; + $linkTargets = $internal ? $this->internalLinkTargets : $this->htmlLinkTargets; + if (isset($linkTargets[$target])) { + return $linkTargets[$target]; } - if (in_array($target, $this->internalLinkTargets, true)) { + if (in_array($target, $linkTargets, true)) { return $target; } } From a9b818d52c1b75231a2cb5083fb962178f95c7f7 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 17 Dec 2015 16:13:12 +0100 Subject: [PATCH 3/6] NavigationItemRenderer: split actualLinkTarget() into getIcingaLinkTarget() and getHtmlLinkTarget() refs #10330 --- .../Renderer/NavigationItemRenderer.php | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php index 1fcf5677e..4c7cc0fa5 100644 --- a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php @@ -200,7 +200,7 @@ class NavigationItemRenderer $url->overwriteParams($item->getUrlParameters()); $target = $item->getTarget(); - if ($url->isExternal() && ! ($target && $this->actualLinkTarget($target) === null)) { + if ($url->isExternal() && ! ($target && $this->getIcingaLinkTarget($target) === null)) { $url = Url::fromPath('iframe', array('url' => $url)); } @@ -237,31 +237,43 @@ class NavigationItemRenderer return ''; } - $actualTarget = $this->actualLinkTarget($target); + $actualTarget = $this->getIcingaLinkTarget($target); if ($actualTarget !== null) { return ' data-base-target="' . $actualTarget . '"'; } - $actualTarget = $this->actualLinkTarget($target, false); + $actualTarget = $this->getHtmlLinkTarget($target); return ' target="' . ($actualTarget === null ? $this->view()->escape($target) : $actualTarget) . '"'; } /** - * If $target is a linktarget, return its HTML version. Otherwise, return null. + * If $targetName is an internal link target, return its HTML version. Otherwise, return null. * - * @param string $target - * @param bool $internal Whether the target must or must not be provided by Icinga Web 2 + * @param string $targetName * * @return string|null */ - protected function actualLinkTarget($target, $internal = true) + protected function getIcingaLinkTarget($targetName) { - $linkTargets = $internal ? $this->internalLinkTargets : $this->htmlLinkTargets; - if (isset($linkTargets[$target])) { - return $linkTargets[$target]; + if (isset($this->internalLinkTargets[$targetName])) { + return $this->internalLinkTargets[$targetName]; } - if (in_array($target, $linkTargets, true)) { - return $target; + if (in_array($targetName, $this->internalLinkTargets, true)) { + return $targetName; + } + } + + /** + * If $targetName is an HTML link target, return its HTML version. Otherwise, return null. + * + * @param string $targetName + * + * @return string|null + */ + protected function getHtmlLinkTarget($targetName) + { + if (isset($this->htmlLinkTargets[$targetName])) { + return $this->htmlLinkTargets[$targetName]; } } } From f6cd4794eedb989450f830bc4df892e42532170e Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 17 Dec 2015 16:13:12 +0100 Subject: [PATCH 4/6] NavigationItemRenderer::renderTargetAttribute(): don't use the same name for two different variables refs #10330 --- .../Web/Navigation/Renderer/NavigationItemRenderer.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php index 4c7cc0fa5..0f22de40b 100644 --- a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php @@ -237,13 +237,13 @@ class NavigationItemRenderer return ''; } - $actualTarget = $this->getIcingaLinkTarget($target); - if ($actualTarget !== null) { - return ' data-base-target="' . $actualTarget . '"'; + $icingaTarget = $this->getIcingaLinkTarget($target); + if ($icingaTarget !== null) { + return ' data-base-target="' . $icingaTarget . '"'; } - $actualTarget = $this->getHtmlLinkTarget($target); - return ' target="' . ($actualTarget === null ? $this->view()->escape($target) : $actualTarget) . '"'; + $htmlTarget = $this->getHtmlLinkTarget($target); + return ' target="' . ($htmlTarget === null ? $this->view()->escape($target) : $htmlTarget) . '"'; } /** From 9e2da07eb7ddeb6a0c8733e75408d56895c5fb13 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 17 Dec 2015 17:56:13 +0100 Subject: [PATCH 5/6] Menu: use target="_self" instead of data-base-target="_self" in logout link refs #10330 --- library/Icinga/Application/Web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 5bebde085..052e19412 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -361,7 +361,7 @@ class Web extends EmbeddedWeb 'logout' => array( 'label' => t('Logout'), 'priority' => 200, - 'target' => '_self', + 'target' => 'current_window', 'url' => 'authentication/logout' ) ) From 2059261eebebe15383d7175212b0cc9f5a25da33 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 17 Dec 2015 18:05:49 +0100 Subject: [PATCH 6/6] NavigationItemForm: use the new target names in createElements() refs #10330 --- application/forms/Navigation/NavigationItemForm.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/forms/Navigation/NavigationItemForm.php b/application/forms/Navigation/NavigationItemForm.php index cd6eca70d..4e63cab56 100644 --- a/application/forms/Navigation/NavigationItemForm.php +++ b/application/forms/Navigation/NavigationItemForm.php @@ -38,10 +38,10 @@ class NavigationItemForm extends Form 'label' => $this->translate('Target'), 'description' => $this->translate('The target where to open this navigation item\'s url'), 'multiOptions' => array( - '_blank' => $this->translate('New Window'), - '_next' => $this->translate('New Column'), - '_main' => $this->translate('Single Column'), - '_self' => $this->translate('Current Column') + 'new_window' => $this->translate('New Window'), + 'next_column' => $this->translate('New Column'), + 'single_column' => $this->translate('Single Column'), + 'current_column' => $this->translate('Current Column') ) ) );