• Welcome to Simple Machines Community Forum. Please login or sign up.

Adding noopener noreferrer in custom main menu links

Started by spiros, January 04, 2020, 06:51:46 AM

Previous topic - Next topic

spiros

I tried using 'rel' => 'noopener noreferrer' in Subs.php to increase security, is this supported and if not, is there any other way to do it?

       'search' => array(
'title' => $txt['search'],
'href' => $scripturl . '?action=search',
'show' => $context['allow_search'],
'sub_buttons' => array(
'fsearch' => array(
'title' => 'Forum Search',
'href' => $scripturl . '?action=search',
'show' => $context['allow_search'],
),
'tools' => array(
'title' => 'Search Tools',
'href' => 'https://www.translatum.gr/forum/side.html',
'target' => '_blank',
'rel' => 'noopener noreferrer',
'show' => true,
),

Antes

SMF does not auto-support those items, you have to add them by yourself... You already have rel in your Subs (menu array)... Just go over index.template (function template_menu) and use this

<a class="', $button['active_button'] ? 'active ' : '', 'firstlevel" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', !empty($button['rel']) ? 'rel="' . $button['rel'] . '"' : '' ,'>

spiros

Thanks! Not sure where that line must go or whether one (or more items) need to be edited in the theme (child items also needing editing perhaps?)

foreach ($context['menu_buttons'] as $act => $button)
{
if($act == "logout" || $act == "login" || $act == "register")
continue;

$icon = '';
if (!empty($settings[$act . '_icon']))
$icon = $settings[$act . '_icon'];

echo '
<li id="button_', $act, '">
<a
class="', $button['active_button'] ? 'active ' : '', 'firstlevel ', !empty($button['sub_buttons']) ? 'opener' : '', '"
href="', $button['href'], '"
', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '
>
', fontawesome($icon, !empty($menu_icons[$act]) ? $menu_icons[$act] : 'fas fa-chevron-circle-right'), '
<span class="', isset($button['is_last']) ? 'last ' : '', 'firstlevel">', $button['title'], '</span>
', !empty($button['sub_buttons']) ? '<div class="taphoOnlyInline floatright"><i class="fas fa-caret-down" style="padding:8px"></i></div>' : '', '
</a>';

if (!empty($button['sub_buttons']))
{
echo '
<ul>';

foreach ($button['sub_buttons'] as $childbutton)
{
echo '
<li>
<a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', '>
<span', isset($childbutton['is_last']) ? ' class="last"' : '', '>', $childbutton['title'], !empty($childbutton['sub_buttons']) ? '...' : '', '</span>
</a>';

// 3rd level menus :)
if (!empty($childbutton['sub_buttons']))
{
echo '
<ul>';

foreach ($childbutton['sub_buttons'] as $grandchildbutton)
echo '
<li>
<a href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', '>
<span', isset($grandchildbutton['is_last']) ? ' class="last"' : '', '>', $grandchildbutton['title'], '</span>
</a>
</li>';

echo '
</ul>';
}

Antes

You need to edit both if you want to support this "rel" in both... So like L436 & L448 (vanilla files), its easy to see that A element since its main of that element(s).

spiros


Advertisement: