MyBB Community Forums

Full Version: Mybb 1.8 Nofollow plugins ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a nofollow plugin for mybb 1.8?
We need a plugin that shows all other site links as nofollow except for our own site links.
I tend to use a dirty hack to a corefile to achieve the goal with urls added by users (Mycode_url).

that means editing inc/class_parser.php by commenting out at around line: 1124:
 if(!empty($this->options['nofollow_on']))
 {
 $rel = " rel=\"noopener nofollow\"";
 }
 else
 {
 $rel = " rel=\"noopener\"";
 }
And placing below it:
/** haq
Added: For creating external reference in rel tags
**/
 $reltypes="noopener nofollow external ugc";
 $pos = stripos($url, "domain.tld");
 $pos1 = stripos($url, ".");
 if(($pos !== false) && ($pos1 <= $pos-1))
 {
 $reltypes="noopener";
 }
$rel = " rel=\"".$reltypes."\"";

This takes into account that the url includes a subdomain (www.domain.tld)
As the needles test that a first "."(pos1) exists before "domain.tld"(pos) (and that domain.tld exists) So it might not work in your case without tinkering.
It could be possible to write a variation for testing an array but that then adds more workload to the script.

Also note down the change you've made since any core update to the file will wipe out the edit.

Note: I negated options['nofollow_on'] since to be honest I couldn't work out how to set it to the parser. Maybe I'm blind or limited in knowledge on how it's applied but it's worked around.
What about replacing:
if(!empty($this->options['nofollow_on']))

With:
if(!empty($this->options['nofollow_on']) || my_strpos($url, 'domain.tld') === false)
Thanks for the addition Omar.
it's aided in making it a little smaller as well bringing to my attention my_strpos() exists Smile

$reltypes = "noopener ";
if(!empty($this->options['nofollow_on']) || my_strpos($url, 'domain.tld') === false)
$reltypes .= "nofollow external ugc";
$rel = " rel=\"".$reltypes."\"";
@stryderunknown: Pretty good solution.
This would really be good as a small plugin to prevent core files revert when MyBB upgrade package is released Smile
@WallBB
Indeed it would be good to have in a plugin, although it's a little beyond me (at the moment)

I'm just trying to figure out how I could extend the postParser Class in a plugin and duplicate just the mycode_parse_url function from inc/class_parser.php, and then have that Child function used instead of it's Parent function.

There doesn't seem to be much said on overriding functions in this manner within MyBB's documentation.
(I'd prefer to use that method, than search for the place to replace code in the Core file as it makes it a lot cleaner and allows reversion when necessary.)

Anyone with any clue on the rough jist of how to accomplish something like that would be extremely helpful (heck It needs a tutorial on it to be honest)
I suppose you could avoid core edits, if you use the Template Conditionals plugin, something like the following should work, replacing the mycode_url template.
<a href="{$url}" target="_blank" class="mycode_url" rel="noopener <if my_strpos($url, 'domain.tld') === false then>nofollow external ugc</if>">{$name}</a>

(2020-08-23, 09:32 AM)stryderunknown Wrote: [ -> ]I'm just trying to figure out how I could extend the postParser Class in a plugin and duplicate just the mycode_parse_url function from inc/class_parser.php, and then have that Child function used instead of it's Parent function.

There doesn't seem to be much said on overriding functions in this manner within MyBB's documentation.
(I'd prefer to use that method, than search for the place to replace code in the Core file as it makes it a lot cleaner and allows reversion when necessary.)

Take a look at Yumi's control_object(). Though hijacking the parser would be problematic because it is loaded in specific areas only. You could find issues supporting third-party plugins for example.

https://github.com/zingaburga/XThreads-M...#L857-L887
A readymade plugin, made for UGC, but can be modified easily ...
https://community.mybb.com/thread-224666...pid1336145