vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Parsing BBcodes in custom fields on member profile page. (https://vborg.vbsupport.ru/showthread.php?t=267468)

Chris8 07-26-2011 07:04 PM

Parsing BBcodes in custom fields on member profile page.
 
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.

PHP Code:

<?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
PHP Code:

<?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
PHP Code:

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


not working

another one in member_complete
PHP Code:

require_once(DIR '/includes/class_bbcode.php'); 
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());

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


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:

PHP Code:

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



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 ;)

PHP Code:


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
[code]
<?php

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


function bb2html($text)
{
  $bbcode = array("<", ">",
                "[list]", "[*]", "[/list]", 
                "[img]", "[/img]", 
                "[b]", "[/b]", 
                "[u]", "[/u]", 
                "[i]", "[/i]",
                '[color="', "[/color]",
                "[size=\"", "[/size]",
                '[url="', "[/url]",
                "[mail=\"", "[/mail]",
                "[code]", "[/code]",
                "[quote]", "[/quote]",
                '"]');
  $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;
}
?>



All times are GMT. The time now is 09:56 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02170 seconds
  • Memory Usage 1,760KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete