Try changing this:
PHP Code:
while ($row = mysql_fetch_array($sql_result2)) {
$pagetext = $row["pagetext"];
To this:
PHP Code:
require_once(DIR . '/includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
while ($row = mysql_fetch_array($sql_result2)) {
$pagetext = $parser->do_parse($row["pagetext"], false, true, true, true, true, false);
(you can change the do_parse()'s arguments depending on what you want to parse, if you use it as I posted it now, HTML wouldn't be parsed, and smilies, BB code and the img BB code would be parsed)
I didn't understand your problem including global.php, though since it's a plugin and not an entirely new .php file, global.php should have already been included/requested.