Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : options to remove "noreferral" and "noopener" #33

Open
aleclerc7 opened this issue Jul 11, 2020 · 0 comments
Open

Feature : options to remove "noreferral" and "noopener" #33

aleclerc7 opened this issue Jul 11, 2020 · 0 comments

Comments

@aleclerc7
Copy link

Hi,

In some cases, especially in specific twig cases, it would be useful to allow the referral mechanism. While at it, I would also give the same option for noopener, even if there are few chances it be used, but it could when not using the _blank target. (Only useful in that case.) But one could desire this behaviour.

So here is a proposal to add three config options. This is fully backward compatible because they are "opt in" options. It asks the plugin to actually "do referrer" and "do opener". There is an additionnal option to even control the "do referrer" while using _blank target which would be a very voluntary risk. Usually, it is better to add "noreferrer" when using _blank target.

Here is the code for ExternalLink.php

Starting at the actual code beginning with:

...
                    // Add no-follow.
                    $nofollow = $options->get('no_follow');
                    if ($nofollow) {
                        $rel = array_filter(explode(' ', $a->getAttribute('rel')));
                        if (!in_array('nofollow', $rel)) {
                            $rel[] = 'nofollow';
                            $a->setAttribute('rel', implode(' ', $rel));
                        }
                    }

But from that point, change/update the code for the following:

                    // Set rel="noopener"
                    $doopener = $options->get('do_opener');
                    if ($doopener == false) {
                        $rel = array_filter(explode(' ', $a->getAttribute('rel')));
                        if (!in_array('noopener', $rel)) {
                            $rel[] = 'noopener';
                            $a->setAttribute('rel', implode(' ', $rel));
                        }
                    }

                    // Add no-referrer.
                    $doreferrer = $options->get('do_referrer');
					$doreferrerevenonblanktarget = $options->get('do_referrer_even_on_blank_target');
                    if ($doreferrer == false || ($target == '_blank' and $doreferrerevenonblanktarget == false)) {
                        $rel = array_filter(explode(' ', $a->getAttribute('rel')));
                        if (!in_array('noreferrer', $rel)) {
                            $rel[] = 'noreferrer';
                            $a->setAttribute('rel', implode(' ', $rel));
                        }
                    }

                    // Add image class to <a> if it has at least one <img> child element
...

Thank you and best regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant