MyBB Community Forums

Full Version: PHP help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to make this work sorry have like 0 experience with PHP

function nofollowlink_changelink($message){

		$search = '<a';
		$replace = '<a rel="nofollow"';
	 $message = str_replace($search  , $replace  , $message);
	 return $message;
		}
		function nofollowlink_changelink_internal($message){

		$search = '<a rel="nofollow" href="http://letsforum.com';
		$replace = '<a href="http://letsforum.com';
	 $message = str_replace($search  , $replace  , $message);
	 return $message;
		}
Both are correct php functions? Or did your question was to integrate it in MyBB ?
I want to create a plugin that will add nofollow to all the links except letsforum.com

If url is mybb>url then do nothing else add nofollow

Please anybody help me to create a plugin that will add nofollow to all the outgoing links but not internal
(2013-12-04, 01:13 AM)marcus123 Wrote: [ -> ]Please anybody help me to create a plugin that will add nofollow to all the outgoing links but not internal

For example, this is a basic plugin to add 'no follow' in posts for all links (except a certain website):
<?php
// access denied
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.");
}

// add hook
$plugins->add_hook("postbit", "nofollowlink_postbit");

// _info
function nofollowlink_info()
{
	return array(
		"name"			=> "No follow link",
		"description"	=> "Add 'no follow' to all extern links in posts.",
		"website"		=> "http://mybb.com",
		"author"		=> "Flavius Popa",
		"authorsite"	=> "http://community.mybb.com/user-39767.html",
		"version"		=> "0.1",
		"guid" 			=> "",
		"compatibility" => "16*"
	);
}

// _postbit
function nofollowlink_postbit(&$post)
{
	// web address (without 'http')
	$my_site = "www.mysite.com";
	
	// add 'no follow' for all links from posts (except '$my_site')
	$search_1 = '<a href="http://';
	$replace_1 = '<a rel="nofollow" href="http://';
	$post['message'] = str_replace($search_1, $replace_1, $post['message']);
	
	// remove 'no follow' for '$my_site'
	$search_2 = '<a rel="nofollow" href="http://'.$my_site.'';
	$replace_2 = '<a href="http://'.$my_site.'';
	$post['message'] = str_replace($search_2, $replace_2, $post['message']);
}
?>

Copy this code in a blank file, adjust value of '$my_site' and save it in 'inc/plugins/' folder with 'nofollowlink.php' name.
Go in AdminCP and activate it.
@Flavius Popa I love you man you have just saved the day thanks bro I very appreciate this and not just me many will find your post useful
I'm glad to help you.
Btw... to use '$my_site' with default forum web address, replace:
	// web address (without 'http')
	$my_site = "www.mysite.com";
with:
	global $mybb;
	// default board address (without 'http')
	$my_site = $mybb->settings['bburl'];
	$search = '#^https?://#';
	$my_site = preg_replace($search, '', $my_site);  

In this way, is not need to specify a certain web address.
Now its perfect