Nofollow external plugin BUG Fix - marcus123 - 2013-12-03
Guys this plugin is awesome but for some reason it doesn't add nofollow to urls that are posted this way
My websites are http://google.com , http://google.com , http://google.com , http://google.com , http://google.com
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("parse_message_end", "nofollowexternal_changelink");
function nofollowexternal_info() {
return array(
"name" => "Nofollow external",
"description" => "A simple plugin that puts rel=\"nofollow\" in external links",
"website" => "",
"author" => "Matthew DeSantis",
"authorsite" => "http://www.anarchy46.net/",
"version" => "1.0",
"guid" => "2b874bd1e9ee6153673957629d68ef12",
"compatibility" => "*"
);
}
function nofollowexternal_changelink($message) {
global $mybb;
$message = preg_replace_callback("/<a href=\"(.+)\" (.+)>(.+)<\\/a>/", "replace_external", $message);
return $message;
}
function replace_external($groups) {
global $mybb;
$url = str_replace(array(".", "/"), array("\\.", "\\/"), $mybb->settings['bburl']);
$urls = preg_replace("/^http/","https", $url, 1);
if (preg_match("/$url/", $groups[1]) || preg_match("/$urls/", $groups[1])) {
return $groups[0];
}
else {
return "<a href=\"".$groups[1]."\" target=\"_blank\" rel=\"nofollow\">".$groups[3]."</a>";
}
}
?>
RE: Nofollow external plugin BUG Fix - .m. - 2013-12-03
you can try replacing
function nofollowexternal_changelink($message) with function nofollowexternal_changelink(&$message)
and function replace_external($groups) with function replace_external(&$groups)
(more details)
RE: Nofollow external plugin BUG Fix - marcus123 - 2013-12-03
Thanks .M. but it still doesn't add nofollow to all of them only to the last one!!
This plugin works great but I think it will also add nofollow to internal links!!
How to fix that?
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("parse_message_end", "nofollowlink_changelink");
function nofollowlink_info()
{
return array(
"name" => "Nofollow link",
"description" => "A simple plugin that puts nofollow in your links",
"website" => "http://community.mybboard.net/user-8198.html",
"author" => "TimB.",
"authorsite" => "http://community.mybboard.net/user-8198.html",
"version" => "1.0",
"guid" => "0fead3ffd1a376ceb5cef3388df5d39d",
"compatibility" => "*"
);
}
function nofollowlink_changelink($message){
$search = 'target="_blank"';
$replace = 'target="_blank" rel="nofollow"';
$message = str_replace($search , $replace , $message);
return $message;
}
?>
RE: Nofollow external plugin BUG Fix - Destroy666 - 2013-12-03
nvm...
RE: Nofollow external plugin BUG Fix - marcus123 - 2013-12-04
What do you mean Destroy666
RE: Nofollow external plugin BUG Fix - Dave H - 2013-12-07
The wildcard matches in this plugin are greedy:
$message = preg_replace_callback("/<a href=\"(.+)\" (.+)>(.+)<\\/a>/", "replace_external", $message);
Causing the first regex to start matching at the first URL and continue matching all the way to the last one as a single match.
They should be lazy like this:
$message = preg_replace_callback("/<a href=\"(.+?)\" (.+?)>(.+?)<\\/a>/", "replace_external", $message);
|