Created
December 29, 2017 15:01
-
-
Save tablatronix/d6217a67ca4e685e0113172cf749d734 to your computer and use it in GitHub Desktop.
mybb nofollow plugin fixed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This plugin is licensed under the GNU GPLv3 license | |
if(!defined("IN_MYBB")) | |
{ | |
die("Direct initialization of this file is not allowed."); | |
} | |
$plugins->add_hook("parse_message_end", "AddNoFollow_hook"); | |
function AddNoFollow_info() | |
{ | |
// Inspired by http://mods.mybb.com/view/nofollowexternal | |
return array( | |
"name" => "AddNoFollow", | |
"description" => "This is a simple plugin that puts rel=\"nofollow\" in external links", | |
"website" => "", | |
"author" => "Nixtren", | |
"authorsite" => "https://github.com/Nixtren", | |
"version" => "0.0.1", | |
"guid" => "", | |
"compatibility" => "18*" | |
); | |
} | |
function AddNoFollow_hook($message) | |
{ | |
global $mybb; | |
// Thanks to https://stackoverflow.com/questions/14573553/php-file-get-contents-replace-all-urls-in-all-a-href-links | |
$match = array(); | |
$links = array(); | |
preg_match_all('!https?://[\S]+!', $message, $match); | |
foreach ($match as $key => $value) foreach ($value as $key2 => $TheUrl) $links[] = $TheUrl; | |
for ($i = 0; $i < count($links); $i++) | |
{ | |
$linksurl = parse_url($links[$i]); | |
$bburl = $mybb->settings['bburl']; | |
if($linksurl['host'] != parse_url($bburl['host'])) | |
{ | |
$message = str_replace("<a href=\"{$links[$i]}", "<a rel=\"nofollow\" href=\"{$links[$i]}", $message); | |
} | |
} | |
return $message; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment