MyBB Community Forums

Full Version: Quote Username
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
Try this:
            $r = '<span style="float: right; font-weight: normal;"> ('.$date.')</span>Originally posted by '.build_profile_link(htmlspecialchars_uni($post['username']), $post['uid']).$linkback;
        } 
You need to escape the "s in there. THis should work:

            $r = '<span style=\"float: right; font-weight: normal;\"> ('.$date.')</span>'
                .'Originally posted by '.build_profile_link(htmlspecialchars_uni($post['username']), $post['uid']).$linkback;
        } 
(2010-01-10, 07:46 PM)Mushu Wrote: [ -> ]Try this:
            $r = '<span style="float: right; font-weight: normal;"> ('.$date.')</span>Originally posted by '.build_profile_link(htmlspecialchars_uni($post['username']), $post['uid']).$linkback;
        } 

(2010-01-10, 08:57 PM)Scoutie44 Wrote: [ -> ]You need to escape the "s in there. THis should work:

            $r = '<span style=\"float: right; font-weight: normal;\"> ('.$date.')</span>'
                .'Originally posted by '.build_profile_link(htmlspecialchars_uni($post['username']), $post['uid']).$linkback;
        } 

I got a blank Plugins page with BOTH codes...
Oh, I forgot about 4 more. Does this work?
Wait never mind.
ÃÃÃ?
Yumi where are you! We need you!
Post up the whole plugin file.
(2010-01-10, 08:57 PM)Scoutie44 Wrote: [ -> ]You need to escape the "s in there. THis should work:

            $r = '<span style=\"float: right; font-weight: normal;\"> ('.$date.')</span>'
                .'Originally posted by '.build_profile_link(htmlspecialchars_uni($post['username']), $post['uid']).$linkback;
        } 

That code won't work. In that code you're using single quotes to encapsulate the string, so the double quotes do not need to be escaped. However, the single quotes around username and uid in the $post array would. So fix that and you're in business. This is generating a parse error and giving you the WoD
<?php

// KNOWN ISSUE: won't work on all setups (based on PHP version) with some AJAX features


// comment out this line if you want to save a (possible) query being run at the end of the page
//  This will disable the retrieval of post times and profile links.
define('VBQUOTE_USE_COMPLEX_QUOTES', 1);

if(!defined("IN_MYBB"))
	die("This file cannot be accessed directly.");

$plugins->add_hook('newreply_end', 'vbquote_newreply');
$plugins->add_hook('xmlhttp', 'vbquote_xmlhttp');
$plugins->add_hook('parse_message', 'vbquote_parse');
$plugins->add_hook('text_parse_message', 'vbquote_parse_text');

function vbquote_info()
{
	return array(
		'name'			=> 'vB Style Quotes',
		'description'	=> 'Causes quotes to use the simpler vB style syntax, eg, [quote=USERNAME;PID].',
		'website'		=> 'http://mybbhacks.zingaburga.com/',
		'author'		=> 'ZiNgA BuRgA',
		'authorsite'	=> 'http://zingaburga.com/',
		'version'		=> '1.0',
		'compatibility'	=> '14*',
		'guid'			=> ''
	);
}


function vbquote_newreply()
{
	global $mybb, $quoted_posts, $message;
	if(count($quoted_posts) < 1) return;
	
	// if we have quoted posts, then we'll have to reconstruct the message
	vbquote_convert_quotes($message);
}

function vbquote_xmlhttp()
{
	if(!defined('IN_XMLHTTP'))
		define('IN_XMLHTTP', 1);
	
	global $mybb;
	if($mybb->input['action'] != 'get_multiquoted') return;
	ob_start();
	
	function vbquote_xmlhttp_parse()
	{
		global $message;
		if(!$message)
		{
			ob_end_flush();
			return;
		}
		
		ob_end_clean();
		vbquote_convert_quotes($message);
		echo $message;
	}
	register_shutdown_function('vbquote_xmlhttp_parse');
}


function vbquote_parse(&$message, $text_only=false)
{
	// TODO: push regex into parser cache
	global $parser, $lang;
	if(is_object($parser))
	{
		// check if MyCode is being parsed
		if($parser->options['allow_mycode'] == 0)
			return;
	}
	
	// parse our quotes
	//$pattern = '#\[quote=(&quot;|["\'])?(.*?);([0-9]+)\\1\](.*?)\[\/quote\](\r\n?|\n?)#si';
	
	if($text_only) // a little dodgey, but, well...
		$pattern = "#(\n)([^<\n]*?);([0-9]+) ".preg_quote($lang->wrote,'#')."(\n--\n)#s";
	else
		$pattern = '#(\<cite\>)([^<]*?);([0-9]+) '.preg_quote($lang->wrote,'#').'(\</cite\>)#s'; // no case insenstive flag cause I feel like it
	
	// can we do much for text-only parsing???
	do {
		$message = preg_replace($pattern.'e', '\'$1\'.vbquote_parse_quote(str_replace(\'\\"\', \'"\', \'$2\'), \'$3\', '.($text_only?'true':'false').').\'$4\'', $message);
	} while(preg_match($pattern, $message));
	
	return $message;
}

function vbquote_parse_text(&$msg) { return vbquote_parse($msg, true); }


function vbquote_parse_quote($user, $pid, $text_only=false)
{
	global $lang, $templates, $mybb, $theme;
	
	// if we're processing complex quotes
	if(defined('VBQUOTE_USE_COMPLEX_QUOTES') && !$text_only && !defined('IN_ARCHIVE'))
	{
		global $vbquote_quotedpids, $plugins;
		$vbquote_quotedpids[$pid] = $user;
		
		$plugins->add_hook('pre_output_page', 'vbquote_parse_complex');
		if(defined('IN_XMLHTTP') || $mybb->input['ajax']==1)
		{
			static $ajax_done;
			if(!$ajax_done)
			{
				ob_start();
				function vbquote_xmlhttp_preoutput()
				{
					run_shutdown();	// reconstruct objects if destroyed (urgh, won't fix $lang, $templates and $theme)
					$page = ob_get_clean();
					echo vbquote_parse_complex($page);
				}
				register_shutdown_function('vbquote_xmlhttp_preoutput');
				$ajax_done = true;
			}
		}
		
		return '<!-- VBQUOTE_COMPLEX_QUOTE_'.$pid.' -->';
	}
	
	return vbquote_parse_quote_user($user, $pid, $text_only);
}

function vbquote_parse_quote_user($user, $pid, $text_only=false)
{
	global $lang, $templates, $mybb, $theme;
	if($text_only)
		return 'Originally posted by '.$user; 
	
	$url = $mybb->settings['bburl'].'/'.get_post_link($pid).'#pid'.$pid;
	if(defined('IN_ARCHIVE'))
		$linkback = ' <a href="'.$url.'">[ -> ]</a>';
	else
		eval('$linkback = " '.$templates->get('postbit_gotopost', 1, 0).'";');
	
	//return "<p>\n<blockquote><cite>".htmlspecialchars_uni($user)." $lang->wrote{$linkback}</cite>{$msg}</blockquote></p>\n";
	return $user.' '.$lang->wrote.$linkback;
}



function vbquote_parse_complex(&$page)
{
	global $vbquote_quotedpids;
	if(empty($vbquote_quotedpids)) return $page;
	static $done;
	if($done) return $page;
	$done = true;
	
	global $db, $lang, $mybb, $templates, $theme;
	$posts = array();
	$query = $db->simple_select('posts', '*', 'pid IN ('.implode(',',array_keys($vbquote_quotedpids)).')');
	while($post = $db->fetch_array($query))
		$posts[$post['pid']] = $post;
	
	$replaces = array();
	foreach($vbquote_quotedpids as $pid => $uname)
	{
		$post = &$posts[$pid];
		// posts doesn't exist anymore...?
		if(!$post)
		{
			$r = vbquote_parse_quote_user(htmlspecialchars_uni($uname), $pid);
		}
		else
		{
			$url = $mybb->settings['bburl'].'/'.get_post_link($pid).'#pid'.$pid;
			eval('$linkback = " '.$templates->get('postbit_gotopost', 1, 0).'";');
			
			$date = my_date($mybb->settings['dateformat'], $post['dateline']).' '.my_date($mybb->settings['timeformat'], $post['dateline']);
			
			$r = '<span style="float: right; font-weight: normal;"> ('.$date.')</span>
			Originally posted by '.build_profile_link(htmlspecialchars_uni($post['username']), $post['uid']).$linkback;
        }
        }
		$replaces['<!-- VBQUOTE_COMPLEX_QUOTE_'.$pid.' -->'] = $r;
	}
	
	return strtr($page, $replaces);
}


//  * has issues if quoted message already contains old MyBB 1.4 style quotes
function vbquote_convert_quotes(&$message)
{
	$pattern = '#\[quote=(["\'])?([^[\]"]*?)\\1 (?:[^[\]]*?)?pid=(["\'])?([0-9]+)\\3(?:[^\]].*?)?\](.*?)\[/quote\]#si';
	while($message != ($new_message = preg_replace($pattern, '[quote=$2;$4]$5[/quote]', $message)))
		$message = $new_message;
}


?>
Try this:
<?php

// KNOWN ISSUE: won't work on all setups (based on PHP version) with some AJAX features


// comment out this line if you want to save a (possible) query being run at the end of the page
//  This will disable the retrieval of post times and profile links.
define('VBQUOTE_USE_COMPLEX_QUOTES', 1);

if(!defined("IN_MYBB"))
	die("This file cannot be accessed directly.");

$plugins->add_hook('newreply_end', 'vbquote_newreply');
$plugins->add_hook('xmlhttp', 'vbquote_xmlhttp');
$plugins->add_hook('parse_message', 'vbquote_parse');
$plugins->add_hook('text_parse_message', 'vbquote_parse_text');

function vbquote_info()
{
	return array(
		'name'			=> 'vB Style Quotes',
		'description'	=> 'Causes quotes to use the simpler vB style syntax, eg, [quote=USERNAME;PID].',
		'website'		=> 'http://mybbhacks.zingaburga.com/',
		'author'		=> 'ZiNgA BuRgA',
		'authorsite'	=> 'http://zingaburga.com/',
		'version'		=> '1.0',
		'compatibility'	=> '14*',
		'guid'			=> ''
	);
}


function vbquote_newreply()
{
	global $mybb, $quoted_posts, $message;
	if(count($quoted_posts) < 1) return;
	
	// if we have quoted posts, then we'll have to reconstruct the message
	vbquote_convert_quotes($message);
}

function vbquote_xmlhttp()
{
	if(!defined('IN_XMLHTTP'))
		define('IN_XMLHTTP', 1);
	
	global $mybb;
	if($mybb->input['action'] != 'get_multiquoted') return;
	ob_start();
	
	function vbquote_xmlhttp_parse()
	{
		global $message;
		if(!$message)
		{
			ob_end_flush();
			return;
		}
		
		ob_end_clean();
		vbquote_convert_quotes($message);
		echo $message;
	}
	register_shutdown_function('vbquote_xmlhttp_parse');
}


function vbquote_parse(&$message, $text_only=false)
{
	// TODO: push regex into parser cache
	global $parser, $lang;
	if(is_object($parser))
	{
		// check if MyCode is being parsed
		if($parser->options['allow_mycode'] == 0)
			return;
	}
	
	// parse our quotes
	//$pattern = '#\[quote=(&quot;|["\'])?(.*?);([0-9]+)\\1\](.*?)\[\/quote\](\r\n?|\n?)#si';
	
	if($text_only) // a little dodgey, but, well...
		$pattern = "#(\n)([^<\n]*?);([0-9]+) ".preg_quote($lang->wrote,'#')."(\n--\n)#s";
	else
		$pattern = '#(\<cite\>)([^<]*?);([0-9]+) '.preg_quote($lang->wrote,'#').'(\</cite\>)#s'; // no case insenstive flag cause I feel like it
	
	// can we do much for text-only parsing???
	do {
		$message = preg_replace($pattern.'e', '\'$1\'.vbquote_parse_quote(str_replace(\'\\"\', \'"\', \'$2\'), \'$3\', '.($text_only?'true':'false').').\'$4\'', $message);
	} while(preg_match($pattern, $message));
	
	return $message;
}

function vbquote_parse_text(&$msg) { return vbquote_parse($msg, true); }


function vbquote_parse_quote($user, $pid, $text_only=false)
{
	global $lang, $templates, $mybb, $theme;
	
	// if we're processing complex quotes
	if(defined('VBQUOTE_USE_COMPLEX_QUOTES') && !$text_only && !defined('IN_ARCHIVE'))
	{
		global $vbquote_quotedpids, $plugins;
		$vbquote_quotedpids[$pid] = $user;
		
		$plugins->add_hook('pre_output_page', 'vbquote_parse_complex');
		if(defined('IN_XMLHTTP') || $mybb->input['ajax']==1)
		{
			static $ajax_done;
			if(!$ajax_done)
			{
				ob_start();
				function vbquote_xmlhttp_preoutput()
				{
					run_shutdown();	// reconstruct objects if destroyed (urgh, won't fix $lang, $templates and $theme)
					$page = ob_get_clean();
					echo vbquote_parse_complex($page);
				}
				register_shutdown_function('vbquote_xmlhttp_preoutput');
				$ajax_done = true;
			}
		}
		
		return '<!-- VBQUOTE_COMPLEX_QUOTE_'.$pid.' -->';
	}
	
	return vbquote_parse_quote_user($user, $pid, $text_only);
}

function vbquote_parse_quote_user($user, $pid, $text_only=false)
{
	global $lang, $templates, $mybb, $theme;
	if($text_only)
		return 'Originally posted by '.$user; 
	
	$url = $mybb->settings['bburl'].'/'.get_post_link($pid).'#pid'.$pid;
	if(defined('IN_ARCHIVE'))
		$linkback = ' <a href="'.$url.'">[ -> ]</a>';
	else
		eval('$linkback = " '.$templates->get('postbit_gotopost', 1, 0).'";');
	
	//return "<p>\n<blockquote><cite>".htmlspecialchars_uni($user)." $lang->wrote{$linkback}</cite>{$msg}</blockquote></p>\n";
	return $user.' '.$lang->wrote.$linkback;
}



function vbquote_parse_complex(&$page)
{
	global $vbquote_quotedpids;
	if(empty($vbquote_quotedpids)) return $page;
	static $done;
	if($done) return $page;
	$done = true;
	
	global $db, $lang, $mybb, $templates, $theme;
	$posts = array();
	$query = $db->simple_select('posts', '*', 'pid IN ('.implode(',',array_keys($vbquote_quotedpids)).')');
	while($post = $db->fetch_array($query))
		$posts[$post['pid']] = $post;
	
	$replaces = array();
	foreach($vbquote_quotedpids as $pid => $uname)
	{
		$post = &$posts[$pid];
		// posts doesn't exist anymore...?
		if(!$post)
		{
			$r = vbquote_parse_quote_user(htmlspecialchars_uni($uname), $pid);
		}
		else
		{
			$url = $mybb->settings['bburl'].'/'.get_post_link($pid).'#pid'.$pid;
			eval('$linkback = " '.$templates->get('postbit_gotopost', 1, 0).'";');
			
			$date = my_date($mybb->settings['dateformat'], $post['dateline']).' '.my_date($mybb->settings['timeformat'], $post['dateline']);
			
			$r = '<span style="float: right; font-weight: normal;"> ('.$date.')</span>
			Originally posted by '.build_profile_link(htmlspecialchars_uni($post['username']), $post['uid']).$linkback;
		}
		$replaces['<!-- VBQUOTE_COMPLEX_QUOTE_'.$pid.' -->'] = $r;
	}
	
	return strtr($page, $replaces);
}


//  * has issues if quoted message already contains old MyBB 1.4 style quotes
function vbquote_convert_quotes(&$message)
{
	$pattern = '#\[quote=(["\'])?([^[\]"]*?)\\1 (?:[^[\]]*?)?pid=(["\'])?([0-9]+)\\3(?:[^\]].*?)?\](.*?)\[/quote\]#si';
	while($message != ($new_message = preg_replace($pattern, '[quote=$2;$4]$5[/quote]', $message)))
		$message = $new_message;
}


?>
Didn't appear in the Plugins List.
Pages: 1 2 3 4 5