Log in

View Full Version : Parsing BBcodes in custom fields on member profile page.


Chris8
07-26-2011, 07:04 PM
People of vB perhaps you will be able to help me at least this time. I'm struggling with this problem since two days or so and I still cannot get it to work. I'm using vbulletin 3.8 series.

How the heck I will get bbcodes to work in custom fields in members profile. I'm trying to turn on smiles, urls and image parsing. I've digged various tutorials and plugins and and I've done a several mixes of them all and non of it works. I must be missing something obvious.

Here are some sample plugins I've tried.

<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="parse_member_bbcode" active="1">
<title>Parse BBCode in member profile fields</title>
<description><![CDATA[Parse bbcode for profile fields in members profiles.]]></description>
<version>1.0.0</version>
<codes>
</codes>
<templates>
</templates>
<plugins>
<plugin active="1">
<title>Parse BBCode in extra profile fields</title>
<hookname>member_complete</hookname>
<phpcode><![CDATA[$userinfo['field7'] = $parser->do_parse($userinfo['field7']);
$userinfo['field8'] = $parser->do_parse($userinfo['field8']);
$userinfo['field9'] = $parser->do_parse($userinfo['field9']);
$userinfo['field10'] = $parser->do_parse($userinfo['field10']);
$userinfo['field11'] = $parser->do_parse($userinfo['field11']);]]></phpcode>
</plugin>
<plugin active="1">
<title>Parse BBCode in custom profile fields</title>
<hookname>member_customfields</hookname>
<phpcode><![CDATA[$profilefield['value'] = $parser->do_parse($profilefield['value']);]]></phpcode>
</plugin>
<plugin active="1">
<title>Init BBCode-Parser</title>
<hookname>member_start</hookname>
<phpcode><![CDATA[require_once(DIR . '/includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());]]></phpcode>
</plugin>
</plugins>
<phrases>
</phrases>
<options>
</options>
</product>


not working
<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="bbcodes_style_profile" active="1">
<title>Parse BBCode in Custom Profile Fields</title>
<description>Give your users the full effect by letting them use BB Code in their profile.</description>
<version>1.1</version>
<codes>
</codes>
<templates>
</templates>
<plugins>
<plugin active="1">
<title>Parse BBCode for Custom Profile Fields</title>
<hookname>member_customfields</hookname>
<phpcode><![CDATA[if (!is_object($bbcode_parser))
{
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
}
$profilefield['value'] = $bbcode_parser->parse($userinfo["$profilefieldname"],0, true);]]></phpcode>
</plugin>
</plugins>
<phrases>
</phrases>
<options>
</options>
</product>


members page goes blank


in member_complete
if ($userinfo['field7'])
{
if (!is_object($bbcode_parser))
{
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
}
$userinfo['field7'] = $bbcode_parser->parse($userinfo['field7'],0, true);
}

not working

another one in member_complete
require_once(DIR . '/includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

$post[field7] = $parser->do_parse($post[field7], false, false, true, false, false, true);


Not working and so on... I've used of course a proper field number and bbcode parameters. So any help would be appreciated. I would be grateful if you could share a solution that will work in 100% percent.

Please, help me.

kh99
07-26-2011, 09:17 PM
This seems to work: use hook location member_customfields and this code:

if ($profilefield['profilefieldid'] == 7)
{
global $vbulletin;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$profilefield['value']= $bbcode_parser->parse(unhtmlspecialchars($profilefield['value']),0, true);
}


I tried it out but did not do much testing.

Chris8
07-28-2011, 04:14 PM
Awesome, this one works! Thank you very much kh99! Folks like you restore my faith in people. :)

GavoTrav
07-28-2011, 06:04 PM
Kh99 has already answered but this is another way!

NON-VB

Add it to the top of the template where it shows/pastes ;)



Just include the string
<?php include 'bb2html.php';?>
And to call it simply write
<?php $htmltext = bb2html($bbtext);?>
[/code]

Then upload this file:

Call it: bb2html.php

<?php

// A simple FAST parser to convert BBCode to HTML
// Trade-in more restrictive grammar for speed and simplicty
//
// Syntax Sample:
// --------------
// http://pvhax.com/images/star.gif
// PvHax (http://pvhax.com)
// Webmaster
// HUGE
// RED
// bold
// italic
// underline
// item item item
// [code]value="123";
// John said yadda yadda yadda
//
// Usage:
// ------
// <?php include 'bb2html.php'; ?>
// <?php $htmltext = bb2html($bbtext); ?>


function bb2html($text)
{
$bbcode = array("<", ">",
"", " ", "",
"", "",
"", "",
"", "",
"", "",
'[color="', "[/color]",
"[size=\"", "[/size]",
'[url="', "[/url]",
"[mail=\"", "[/mail]",
"", "",
"", "",
'"]');
$htmlcode = array("&lt;", "&gt;",
"<ul>", "<li>", "</ul>",
"<img src=\"", "\">",
"<b>", "</b>",
"<u>", "</u>",
"<i>", "</i>",
"<span style=\"color:", "</span>",
"<span style=\"font-size:", "</span>",
'<a href="', "</a>",
"<a href=\"mailto:", "</a>",
"<code>", "</code>",
"<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>",
'">');
$newtext = str_replace($bbcode, $htmlcode, $text);
$newtext = nl2br($newtext);//second pass
return $newtext;
}
?>