<?php
/*
* This plugin depends on User CSS plugin
* User CSS plugin is coded by:
*
*	Yumi/ZiNgA BuRgA
*	@ http://mybbhacks.zingaburga.com
*
* Official released thread for User CSS:
*	http://mybbhacks.zingaburga.com/showthread.php?tid=1300
*/

defined('IN_MYBB') or die('This file cannot be accessed directly.');

function profile_usercss_info() {
	return array(
		'name'			=> 'User CSS on Member Profile',
		'description'	=> '<strong style="color: red"><em><a href="http://mybbhacks.zingaburga.com/showthread.php?tid=1300">User CSS</a> is required for this plugin</em></strong><br />Set the style of members profile page based on the profile owner\'s User CSS setting.',
		'website'		=> 'http://mybbhacks.zingaburga.com/',
		'author'		=> 'XThreads Mania',
		'authorsite'	=> 'http://mybbhacks.zingaburga.com/',
		'version'		=> '1.0',
		'compatibility'	=> '14*,15*,16*',
		'guid'			=> ''
	);
}

$plugins->add_hook('global_start','profile_usercss_global');
function profile_usercss_global() {
	if(THIS_SCRIPT == 'member.php' && $GLOBALS['mybb']->input['action'] == 'profile') unset($GLOBALS['usercss']);
}

$plugins->add_hook('member_profile_end','profile_usercss_memprofile');
function profile_usercss_memprofile(){
	global $mybb,$memprofile;
	if($memprofile['usergroup'] != 4){
		$user = $mybb->user;
	}else{
		$user = $memprofile;
	}
	if(!$user['usercss'] || $mybb->input['nousercss']) return;
	$user['usercss'] = preg_replace_callback("~(\n|^)/\*@- *([a-z0-9\-_]+\.php)(, *[a-z0-9\-_]+\.php)* *\*/\r?\n.*?\n/\*@-\*/(?=\r?\n|$)~si", 'usercss_global_preg', $user['usercss']);
	$GLOBALS['headerinclude'] .= '<style type="text/css"><!-- '.$user['usercss'].' --></style>';
}
?>