From bf17a010f56a3571805681ad4fee091f5f9abdce Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 17 Jan 2021 20:30:05 -0800 Subject: [PATCH] Fixes a bug in drop-down navigation containing HTML. --- .../batch/navigation_shortcodes.php | 7 ++-- e107_handlers/sitelinks_class.php | 2 +- .../tests/unit/e_parse_shortcodeTest.php | 41 ++++++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/e107_core/shortcodes/batch/navigation_shortcodes.php b/e107_core/shortcodes/batch/navigation_shortcodes.php index c31cb8b41..c89866a9b 100644 --- a/e107_core/shortcodes/batch/navigation_shortcodes.php +++ b/e107_core/shortcodes/batch/navigation_shortcodes.php @@ -15,6 +15,7 @@ require_once(__DIR__.'/navigation_shortcodes_legacy.php'); public $active; public $depth = 0; public $navClass; + private $activeSubFound = false; /** * As set by {NAVIGATION: class=xxxx} @@ -286,17 +287,17 @@ require_once(__DIR__.'/navigation_shortcodes_legacy.php'); if(is_string($this->var['link_sub'])) // html override option. { - // e107::getDebug()->log($this->var); return $this->var['link_sub']; } $this->depth++; + // Assume it's an array. - $startTemplate = !empty($this->var['link_sub'][0]['link_sub']) && isset($this->template['submenu_lowerstart']) ? $this->template['submenu_lowerstart'] : $this->template['submenu_start']; - $endTemplate = !empty($this->var['link_sub'][0]['link_sub']) && isset($this->template['submenu_lowerstart']) ? $this->template['submenu_lowerend'] : $this->template['submenu_end']; + $startTemplate = is_array($this->var['link_sub']) && !empty($this->var['link_sub'][0]['link_sub']) && isset($this->template['submenu_lowerstart']) ? $this->template['submenu_lowerstart'] : $this->template['submenu_start']; + $endTemplate = is_array($this->var['link_sub']) && !empty($this->var['link_sub'][0]['link_sub']) && isset($this->template['submenu_lowerstart']) ? $this->template['submenu_lowerend'] : $this->template['submenu_end']; diff --git a/e107_handlers/sitelinks_class.php b/e107_handlers/sitelinks_class.php index 86ae40db6..33f6a27ed 100644 --- a/e107_handlers/sitelinks_class.php +++ b/e107_handlers/sitelinks_class.php @@ -1660,7 +1660,7 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; } $active = ($this->isActive($_data, $this->activeMainFound)) ? "_active" : ""; $sc->setDepth(0); $sc->setVars($_data); // isActive is allowed to alter data - $itemTmpl = is_array($_data['link_sub']) && count($_data['link_sub']) > 0 ? $template['item_submenu'.$active] : $template['item'.$active]; + $itemTmpl = !empty($_data['link_sub']) ? $template['item_submenu'.$active] : $template['item'.$active]; $ret .= e107::getParser()->parseTemplate($itemTmpl, true, $sc); $sc->active = ($active) ? true : false; if($sc->active) diff --git a/e107_tests/tests/unit/e_parse_shortcodeTest.php b/e107_tests/tests/unit/e_parse_shortcodeTest.php index 50588e9d7..7bd40e0bb 100644 --- a/e107_tests/tests/unit/e_parse_shortcodeTest.php +++ b/e107_tests/tests/unit/e_parse_shortcodeTest.php @@ -316,7 +316,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit 'link_parent' => '0', 'link_open' => '0', 'link_class' => '0', - 'link_function' => 'news::last_ten', + 'link_function' => 'page::bookNav', 'link_sefurl' => 'index', 'link_owner' => 'news' ); @@ -325,6 +325,45 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit $this->processShortcodeMethods($sc); + + // Test sub links with deep level array. + $template = e107::getCoreTemplate('navigation', 'main'); + $sc->template = $template; + + $outArray = array(); + $data = array($vars); + + $ret = e107::getNav()->compile($data, $outArray); + + $sc->setVars($ret[0]); + $actual = e107::getParser()->parseTemplate('{LINK_SUB}', true, $sc); + $this->assertStringContainsString('General', $actual); + $this->assertStringContainsString('