PDA

View Full Version : Please help. Need to parse bbcode in a user profile field and pass it to a template.


carcomp
03-28-2009, 05:39 PM
I posted a few days ago about this, but a member told me about user profile fields. Very helpful. I've managed to get the profile field to show in the template that I want (member info), however, when I add BBcode or html to the profile field, vbulletin just shows the code in the browser and doesn't parse it.

I know the dangers of html in vbulletin. I'm just trying things to see what works and what doesn't.

So what I need to do is this... I need to be able to show my profile field in the template but have it be parsed. I figure a plugin is needed, but I can't seem to get the code to work. I've read mod about parsing bbcode.

require_once(DIR . '/includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$parsed_text = $parser->do_parse($text, $do_html, $do_smilies, $do_bbcode, $do_imgcode, $do_nl2br, $cachable);

I just don't really know where that needs to go for the variable to get "back" to the template. I figure there is an eval() that needs to be there.

I know the template, plugin, and vbulletin "all become one" after the server works, but I can't grasp the concept well.

Please help.

Lynne
03-28-2009, 08:08 PM
I wrote a mod where I needed to process the bbcode (View all your social group messages (https://vborg.vbsupport.ru/showthread.php?t=205163)) and I copied/modified a function to parse the bbcode:

function process_message_preview($message)
{
global $vbulletin, $vbphrase, $stylevar, $show;

require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

$previewhtml = '';
if ($previewmessage = $bbcode_parser->parse($message['pagetext'], 'socialmessage', $message['disablesmilies'] ? 0 : 1))
{
$previewhtml = $previewmessage;
}

return $previewhtml;
}

The call in the code was something like:
query
then
while ($message = $vbulletin->db->fetch_array($messagelist))
{
.....

$message['pagetext'] = process_message_preview($message);
eval template that uses $message['pagetext'];
}

So, you look like you are on the right track. You would need to add the call to the function/code prior to the eval statement (like I show above).

carcomp
04-03-2009, 09:05 AM
Ok I tried to do what you said. I've got a new profile field (field65) that I've managed to display once on my page using an eval statement, but when I try the following code, I get nothing. I've got my variable $mypage inserted into the MEMBERINFO template. I've been playing with this for about an hour now. I must be off to work. Any ideas?

function process_message_preview($message)
{
global $vbulletin, $vbphrase, $stylevar, $show;

require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

$previewhtml = '';
if ($previewmessage = $bbcode_parser->parse($message['pagetext'], 'socialmessage', $message['disablesmilies'] ? 0 : 1))
{
$previewhtml = $previewmessage;
}

return $previewhtml;
}

process_message_preview($message);

$mypage = process_message_preview($vbulletin->userinfo['field65']);

eval MEMBERINFO;

Lynne
04-03-2009, 02:07 PM
That is not how you eval a template. Take a look in a page like member.php and you'll see these last lines:
eval('$navbar = "' . fetch_template('navbar') . '";');

$templatename = 'MEMBERINFO';

($hook = vBulletinHook::fetch_hook('member_complete')) ? eval($hook) : false;

eval('print_output("' . fetch_template($templatename) . '");');

carcomp
04-03-2009, 04:41 PM
I got it working! Awesome. Now all I have to do is create a bunch of bbcode tags for html elements like table td tr etc!

heres what I ended up with.

function process_message_preview($message)
{
global $vbulletin, $vbphrase, $stylevar, $show;

require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

$previewhtml = '';
if ($previewmessage = $bbcode_parser->parse($message, 'socialmessage', $message['disablesmilies'] ? 0 : 1))
{
$previewhtml = $previewmessage;
}

return $previewhtml;
}


$mypage = process_message_preview($vbulletin->userinfo['field65']);

eval('$mypage = "' . fetch_template('user_custompage') . '";');

I created a custom template called "user_custompage" and just dumped the $mypage variable in it and nothing else. Works great.

Lynne
04-03-2009, 04:55 PM
Great! :up:

carcomp
04-04-2009, 03:31 PM
I had posted something saying I was going to go look at class_bbcode.php. I did, and have changed my code to the following...

function process_message_preview($message)
{
global $vbulletin, $vbphrase, $stylevar, $show;

require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

$previewhtml = '';
if ($previewmessage = $bbcode_parser->do_parse($message, $do_html = true, $do_smilies = true, $do_bbcode = true, $do_imgcode = true, $do_nl2br = true, $cachable = false))
{
$previewhtml = $previewmessage;
}

$mypage = process_message_preview($vbulletin->userinfo['field65']);

eval('$mypage = "' . fetch_template('user_custompage') . '";');

Now what I don't understand is why its not allowing me to use <table> and </table> in my profile field.
Here is my profile field code.
<table>

Here is my test page
https://vborg.vbsupport.ru/external/2009/04/7.gif

</table>

On MEMBERINFO template, I'm able to show my bold text, the google image, but the <table> tags just show up like text, not html. Any Ideas?

Lynne
04-04-2009, 04:51 PM
<table> is html not bbcode. You would have to parse it for html otherwise it will treat the < and > as text characters and turn them into &lt; and $gt; in the page source.

carcomp
04-04-2009, 06:20 PM
Risking posting before googling, is there an HTML parse function in vbulletin?

Lynne
04-05-2009, 02:10 AM
Probably. You can look in the API for one (link under Quick Links)

carcomp
04-06-2009, 08:14 AM
Ok that was helpful. I've been looking for the msdn of vbulletin, but I have another question...

If I put some html in a php variable (like $myvar = "<TABLE> STUFF </TABLE>;), then ask it to show on a custom template, it still strips out the chars. Do I need to put a function of some sort on the template itself to allow it to be treated as code and not &lt $gt chars?

Here is a pseudo of what i'm doing...

PLUGIN in global_start:

$myvar = "<table> Stuff </table>";
eval $myvar on custom_template;


CUSTOM_TEMPLATE
$myvar


EDIT: Can I use

(taken from the api)
string unhtmlspecialchars (string $text, [boolean $doUniCode = false])

in a template?

Lynne
04-06-2009, 01:57 PM
You cannot use functions in a template. You may use them in a plugin and then use the result from the plugin in the template.

carcomp
04-06-2009, 02:51 PM
So how do I keep a template from stripping the html out of a php variable when I "eval" it into a template?

Lynne
04-06-2009, 03:06 PM
I don't know exactly cuz I've never looked into it. You can take a look at what vb does in the code when you allow html in a forum. It has to parse the message text differently when html is allowed, so go see how they do it with that option enabled.

carcomp
04-06-2009, 04:44 PM
And here it is, working just like it should. Profile fields as webpages!

function process_message_preview($message)
{
global $vbulletin, $vbphrase, $stylevar, $show;

require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

$previewhtml = '';
if ($previewmessage = $bbcode_parser->do_parse($message, $do_html = true, $do_smilies = true, $do_bbcode = true, $do_imgcode = true, $do_nl2br = true, $cachable = false))
{
$previewhtml = $previewmessage;

}

return $previewhtml;
}

$mypage = unhtmlspecialchars(process_message_preview($vbulle tin->userinfo['field65']));

eval('$mypage = "' . fetch_template('user_custompage') . '";');

grey_goose
12-11-2009, 07:51 PM
I'm trying to get certain custom user fields to parse, on postbit_legacy.

I did this plugin in member_complete, but it's still not working. what am I doing wrong?

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