From 3c7155f246bd28126d7a8a4579827c89ad481fca Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 21 Sep 2015 14:13:10 +0200 Subject: [PATCH] NavigationItemRenderer: Pass external urls through the iframe module refs #5600 --- .../Renderer/NavigationItemRenderer.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php index 2de90dae0..7e7a0fd55 100644 --- a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php @@ -7,6 +7,7 @@ use Icinga\Application\Icinga; use Icinga\Exception\ProgrammingError; use Icinga\Util\String; use Icinga\Web\Navigation\NavigationItem; +use Icinga\Web\Url; use Icinga\Web\View; /** @@ -28,6 +29,13 @@ class NavigationItemRenderer */ protected $item; + /** + * Internal link targets provided by Icinga Web 2 + * + * @var array + */ + protected $internalLinkTargets; + /** * Create a new NavigationItemRenderer * @@ -39,6 +47,7 @@ class NavigationItemRenderer $this->setOptions($options); } + $this->internalLinkTargets = array('_main', '_self', '_next'); $this->init(); } @@ -141,10 +150,17 @@ class NavigationItemRenderer } if (($url = $item->getUrl()) !== null) { + $url->overwriteParams($item->getUrlParameters()); + + $target = $item->getTarget(); + if ($url->isExternal() && (!$target || in_array($target, $this->internalLinkTargets, true))) { + $url = Url::fromPath('iframe', array('url' => $url)); + } + $content = sprintf( '%s', $this->view()->propertiesToString($item->getAttributes()), - $this->view()->url($url, $item->getUrlParameters()), + $url, $this->renderTargetAttribute(), $label ); @@ -172,7 +188,7 @@ class NavigationItemRenderer return ''; } - if (! in_array($target, array('_main', '_self', '_next'))) { + if (! in_array($target, $this->internalLinkTargets, true)) { return ' target="' . $this->view()->escape($target) . '"'; }