<?php
/**
 * MyBB 1.6
 * Copyright © 2006 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybboard.net
 * License: http://www.mybboard.net/eula.html
 *
 * 
 */

if(!defined("IN_MYBB")) {
    die("Non si pu&ograve; utilizzare questo file direttamente.<br /><br />assicurati che IN_MYBB sia definita.");
}

$plugins->add_hook("parse_message","Hide_links");

function Hide_links_info()
{
    return array(
        "name"        => "Nascondi Links",
        "description" => "Nascondi i links agli utenti non collegati",
        "website"     => "http://www.slimmer.it",
        "author"      => "Kaito",
        "authorsite"  => "http://www.slimmer.it",
        "version"     => "1.0",
    );
}

function Hide_links_activate() {
	global $db;   
	$Hide_links_group = array(
        "name" => "hl_group",
        "title" => "Impostazioni link nascosti",
        "description" => "Imposta la frase default per i link nascosti!",
        "disporder" => "4",
    );
	$db->insert_query("settinggroups", $Hide_links_group);
	$gid = $db->insert_id();
	$Hide_links_setting = array(
        "name"        => "frase_default",
        "title"            => "Frase sostituente i links",
        "description"    => "La frase che andrà a sostituire i links. <strong>Usa i BBCode se servono!</strong>",
        "optionscode" => "text",
        "value"          => "[i][url=member.php?action=register]Registrati[/url] o effettua il [url=member.php?action=login]Login[/url] per visualizzare il link![/i]",
        "disporder"    => "1",
        "gid"           => intval($gid),
    );
	$db->insert_query("settings", $Hide_links_setting);
}

function Hide_links_deactivate() {
	global $db;
	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='hl_group'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='frase_default'");
}

function Hide_links($message) {
	global $mybb;
	function madancode($var) { 
		$find = array( 
			'~\[b\](.*?)\[/b\]~s', 
			'~\[i\](.*?)\[/i\]~s', 
			'~\[u\](.*?)\[/u\]~s',
			'~\[s\](.*?)\[/s\]~s',
			'~\[size=(.*?)\](.*?)\[/size\]~s', 
			'~\[color=(.*?)\](.*?)\[/color\]~s',
			'~\[url=(.*?)\](.*?)\[/url\]~s'
		); 
		$replace = array( 
			'<strong>$1</strong>', 
			'<em>$1</em>',
			'<span style="text-decoration: underline;">$1</span>',
			'<span style="text-decoration: strike;">$1</span>',
			'<span style="font-size: $1px;">$2</span>', 
			'<span style="color: $1;">$2</span>',
			'<a href="$1">$2</a>'
		); 
		return preg_replace($find, $replace, $var); 
	}
	if(!$mybb->user['uid']) {
		$ltr = array();
		preg_match_all("#<a(.*?)</a>#s", $message, $m);
		foreach($m[1] as $value) {
			$ltr[] = "<a$value</a>";
		}
		$message = str_replace($ltr, madancode($mybb->settings['frase_default']), $message);
	}
	return $message;
}

?>
