vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Parse BBCode (in 3.5) (https://vborg.vbsupport.ru/showthread.php?t=82693)

Andreas 06-07-2005 10:00 PM

Parse BBCode (in 3.5)
 
If you want to parse BBCodes somewhere in your hacks/scripts (assuming that global.php is already required):

PHP Code:

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

The parameters for method do_parse() are:
  • $text = Text to be parsed
  • $do_html = Whether to allow HTML or not (Default = false)
  • $do_smilies = Whether to parse smilies or not (Default = true)
  • $do_bbcode = Whether to parse BB code (Default = true)
  • $do_imgcode = Whether to parse the [img] BB code or not, independant of $do_bbcode (Default = true)
  • $do_nl2br = Whether to automatically replace new lines with HTML line breaks or not (Default = true)
    This should be set to false if you allow HTML.
  • $cachable = Whether the post text is cachable or not (Default = false)

All parameters except $text can be omitted and will use the defaults then.

VBCoder 06-16-2005 02:40 AM

Can this only be used to go from BBCode --> HTML? Or can it also go from HTML --> BBCode?

Andreas 06-16-2005 02:43 AM

Yes, Class vB_CodeParser can only be userd for BBCode -> HTML.

For limited HTML -> BBCode use convert_wysiwyg_html_to_bbcode() in functions_wysiwyg.php

VBCoder 06-16-2005 12:44 PM

Kirby,

Thanks. I've noticed that convert_ can handle &lt and &gt properly, but leaves &quot as &quot - not " . Any ideas?

Kirk Y 08-03-2005 02:57 AM

How can I do this in vB 3.0.7?

Boofo 08-03-2005 04:08 AM

Could this be used to fix the /me problem in quotes for 3.5 RC 1?

safiel 08-09-2005 02:22 AM

Search is my friend.

Thanks for posting this, was looking for a hint and this saved me lots of time.

chanzero 08-11-2005 03:32 AM

help for a noob please :) if i have the following...

PHP Code:

<?php
chdir
('./forums');
require_once(
'./global.php');
require_once(
'./includes/class_bbcode.php');

// test parse bb
$text "[url=http://www.mysite.com/reviews.php?id=4661][b]My Review![/b][/url]";

$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());
$parsed_text $parser->do_parse($text$do_html$do_smilies$do_bbcode$do_imgcode$do_nl2br$cachable);  

print 
"parsed text = " $parsed_text;
?>

if i understand what this code does, i should get back something like this:

parsed text = My Review!

but i just get

HTML Code:

[url=http://www.mysite.com/reviews.php?id=4661][b]My Review![/b][/url]

Ky Kiske 08-11-2005 04:57 AM

How do you do this if it's like forum.yoursite.com? And that directory has a password?

chanzero 08-30-2005 04:44 PM

Quote:

Originally Posted by chanzero
help for a noob please :) if i have the following...

PHP Code:

<?php
chdir
('./forums');
require_once(
'./global.php');
require_once(
'./includes/class_bbcode.php');

// test parse bb
$text "[url=http://www.mysite.com/reviews.php?id=4661][b]My Review![/b][/url]";

$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());
$parsed_text $parser->do_parse($text$do_html$do_smilies$do_bbcode$do_imgcode$do_nl2br$cachable);  

print 
"parsed text = " $parsed_text;
?>

if i understand what this code does, i should get back something like this:

parsed text = My Review!

but i just get

HTML Code:

[url=http://www.mysite.com/reviews.php?id=4661][b]My Review![/b][/url]

i should note that kirby helped me figure this out by pointing out that i did not definie $do_html, $do_smilies, $do_bbcode, $do_imgcode, etc

thanks kirby!

Boofo 09-13-2005 09:07 PM

And how do you define them? ;)

KingSpade 09-14-2005 04:11 AM

Quote:

Originally Posted by Boofo
And how do you define them? ;)

I must be missing something because I've yet to get this to work for me :). I've got the following and I've tried just about all that I can and nothing is working for me. If anyone could help, I'd appreciate it very much.

PHP Code:

        while ($news $db->fetch_array($getnews))
        {

            
$parser =& new vB_BbcodeParser($vbulletinfetch_tag_list(), true);
            
$news['pagetext'] = $parser->parse($news['pagetext'], falsefalsetruefalsetruefalse);

            eval(
'$blogbit .= "' fetch_template('zoom_blogbits') . '";');
        } 


Brinnie 09-19-2005 05:05 PM

Kirby, how would one go about adding this to the FAQ manager?

CapinPete 10-01-2005 01:14 AM

In my case I had to use the following code:
Code:

GLOBAL $parser;
I am pretty much a php noob and it took me a good hour to figure this out. I guess its because I declared the parser as an object at the beginning of the script. I am using a function that gets the last 10 posts in a forum and displays it as HTML for use on the homepage. As we all SHOULD know, php requires that you declare a variable "global" if its outside your function.

Man1c M0g 10-10-2005 08:52 PM

Well, I've fiddled with all the suggestions here for the last 2 hours and I still can't get anything to work! Here's the errors I get:

Fatal error: Call to a member function on a non-object in /home/httpd/vhosts/biorust.com/subdomains/forums/httpdocs/includes/class_bbcode.php on line 181

Fatal error: Call to a member function on a non-object in /home/httpd/vhosts/biorust.com/subdomains/forums/httpdocs/includes/functions.php on line 4308

Andreas 10-10-2005 09:00 PM

Wrong Thread.
Please post a new Thread in vB 3.5 Modification Questions and attach the Code you are using.
These errors mean that the vBulletin Registry Object ($vbulletin) does not have a valid reference for the database object.

Man1c M0g 10-10-2005 09:09 PM

Quote:

Originally Posted by KirbyDE
Wrong Thread.
Please post a new Thread in vB 3.5 Modification Questions and attach the Code you are using.
These errors mean the the vBulletin Registry Object ($vbulletin) does not have a valid reference for the database object.

Actually... what you just said goes a long way towards solving the problem! Thanks! :D

CommuneZoom 10-19-2005 04:57 PM

Quote:

Originally Posted by Man1c M0g
Actually... what you just said goes a long way towards solving the problem! Thanks! :D

Something small I noticed, which is probably more than obvious for those more experienced, although unless I specifically define true or false in the parse line, it will not convert the BBCode.

It will not parse simply by including the variables.

MetalAges 10-20-2005 05:28 PM

I'm trying to get an index page (www.ultimatemetal.com) to work with the same code I used to have. It worked fine in 3.0.7 . The only issue is the bbcode stuff (which is why I am in this thread :) ). I exchanged the code I had:

require_once('includes/functions_bbcodeparse.php');

with the code at the beginning of this post:

require_once('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 get this same error message with both:

Quote:

Fatal error: Call to undefined function: parse_bbcode() in /home/mahke/public_html/index-test.php on line 32
Line 32 is: $articlelength1 = parse_bbcode($articles['pagetext']);

Am I brainfarting on something here?

Quote:

Originally Posted by chanzero
i should note that kirby helped me figure this out by pointing out that i did not definie $do_html, $do_smilies, $do_bbcode, $do_imgcode, etc

thanks kirby!

Maybe this is my issue? Chanzero or anyone else, can you elaborate on how to define this properly?

Andreas 10-20-2005 07:30 PM

Well, the parse_bbcode() call needs to be $parser->do_parse() instead :)

MetalAges 10-20-2005 07:32 PM

Excellent! works....still in the middle of learning all this code so, I thank you for the help! :)

donBLACK 10-21-2005 02:18 AM

can this be used to allow bb code in custom titles?

nvm i got it

SilverDawn 10-23-2005 01:42 AM

nm I got it! Thanks so much!

Oreamnos 11-06-2005 01:50 AM

What do i need to do to make it turn non-bbcoded url's into links (like what vb does when you just type a url into the post without using bbcode)?

noonespecial 11-11-2005 08:04 PM

I've been trying to get this to work in the member.php file so that bbcode will be parsed for user profiles --

PHP Code:

require_once('./includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());
$profilefield['value'] = $parser->do_parse($profilefield['value']); 

Just isn't working though.

noonespecial 11-21-2005 12:35 AM

Help???

Oreamnos 11-21-2005 12:47 AM

Quote:

Originally Posted by noonespecial
Help???

are you getting any errors?
are you sure the profile fields have things to be parsed?
are the things you are trying to parse being excluded by a 'false' default setting of the function?

noonespecial 11-21-2005 05:21 AM

Quote:

Originally Posted by Oreamnos
are you getting any errors?
are you sure the profile fields have things to be parsed?
are the things you are trying to parse being excluded by a 'false' default setting of the function?

No errors.
Yah, it just comes out as the text with bbcode showing.
Not that I know of... the code above is what I'm using and all I want is for BBcode to work for a custom profile field.

Oreamnos 11-21-2005 06:08 AM

Try this:
PHP Code:

require_once('./includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());
$profilefield['value'] = $parser->do_parse($profilefield['value'], falsetruetruefalsetruefalse); 

if this doesn't work, then i have to imagine you are passing the wrong value to the function, ie. $profilefield['value']

noonespecial 11-21-2005 06:48 AM

Quote:

Originally Posted by Oreamnos
Try this:
PHP Code:

require_once('./includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());
$profilefield['value'] = $parser->do_parse($profilefield['value'], falsetruetruefalsetruefalse); 

if this doesn't work, then i have to imagine you are passing the wrong value to the function, ie. $profilefield['value']

Nope, didn't work. I assumed it was that value because of this thread: https://vborg.vbsupport.ru/showthrea...bbcode+profile

I know that's 3.0, so maybe it's changed? Does anyone know the correct syntax for me? I just need BBcode to be parsed in custom profile field 27.

noonespecial 11-26-2005 06:01 AM

Someone, anyone, PLEASE help ....

Andreas 11-26-2005 11:32 PM

Quote:

Originally Posted by noonespecial
I've been trying to get this to work in the member.php file so that bbcode will be parsed for user profiles --

PHP Code:

require_once('./includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());
$profilefield['value'] = $parser->do_parse($profilefield['value']); 

Just isn't working though.

Works fine. Though, for performance reasons I would split it into 2 Plugins.

Kristoph 11-27-2005 12:35 PM

just a quick one... got this working great for including posts on my front page, but it is trying to find the smilies in /images/smilies, when infact they're in /community/images/smilies....

is there a quick fix around this built into the vbcodeparser class? or should I just use str_replace on the outputted string?

cheers!

noonespecial 12-08-2005 05:07 AM

Anyone know any way to parse $thread[preview] - I can't figure out where or how to do it for the life of me. It's in functions_forumdisplay.php ..

Found it. Much easier then I thought.

Ratchet 12-14-2005 06:45 PM

Quote:

Originally Posted by Kristoph
just a quick one... got this working great for including posts on my front page, but it is trying to find the smilies in /images/smilies, when infact they're in /community/images/smilies....

is there a quick fix around this built into the vbcodeparser class? or should I just use str_replace on the outputted string?


cheers!

I just used str_replace as you mentioned. Seemed easy. Something like this should work:
Code:

$parsed_text = str_replace("images/smilies","community/images/smilies",$parsed_text);
As an aside, I couldn't get this code working either until I replaced do_parse() with parse(). Dunno what the difference is.

ericgtr 12-15-2005 04:49 PM

I have a custom bbcode [mp3] [/mp3] which shows an inline media player. I have struggled with this for hours but cannot come up with a solution to make it so only registered members can see it. All I really need is to prevent guest from viewing it.

SHANE-D-PAIN 01-07-2006 07:17 AM

This is so frustrating. I am trying to create a plugin that will parse html in certain userinfo fields.

So far I have this as a plugin in member_complete:
PHP Code:

if ($userinfo['field1']) 

if (!
is_object($bbcode_parser)) 



 require_once(
'./includes/class_bbcode.php'); 
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list()); 
$userinfo['field1'] = $bbcode_parser->do_parse($userinfo['field1'], truetruetruetruetruetrue); 


Any ideas?

Oreamnos 01-08-2006 07:59 AM

Quote:

Originally Posted by SHANE-D-PAIN
This is so frustrating. I am trying to create a plugin that will parse html in certain userinfo fields.

So far I have this as a plugin in member_complete:

Any ideas?

this might help: https://vborg.vbsupport.ru/showthread.php?t=103460

bigtime 01-17-2006 07:10 PM

Hi,

The following code will display posts on a non forum page in the home directory. However, when I try to parse the bbcode it doesn't work.

Any ideas?

PHP Code:

<?
chdir('./deluxeforums'); 
require("./global.php"); 
require_once("./includes/class_bbcode.php"); 
require_once("./includes/config.php");


    $num_active = 5;
    $num_topicchars  = 110;

     $db=mysql_connect("$host","$user","$pass");
    mysql_select_db("$dbname");

    $querylatest="select * from thread where forumid='1' or forumid='2' or forumid='3' or forumid='4' or forumid='5' or forumid='6' or forumid='7' or forumid='10' or forumid='11' or forumid='12' or forumid='13' or forumid='14' or forumid='15' or forumid='16' or forumid='17' or forumid='18' or forumid='19' or forumid='20' or forumid='22' or forumid='23' or forumid='25' or forumid='26' or forumid='27' or forumid='28' or forumid='29' or forumid='30' or forumid='31' or forumid='32' or forumid='34' or forumid='35' or forumid='36' or forumid='37' or forumid='38' order by lastpost desc limit $num_active";

    $resultlatest = mysql_query($querylatest,$db);

?>
<style type="text/css">
<!--
.style2 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
}
-->
</style>
<table width="100%" align="center" cellpadding="2" cellspacing="0">
  <?

    while ($latest_array = mysql_fetch_array($resultlatest)) {

    // Get Forum Infomation
    $query_forum = "select * from forum where forumid='$latest_array[forumid]'";
    
    $result_forum = mysql_query($query_forum,$db);
    $forum_info_array = mysql_fetch_array($result_forum);

        // split the date up a bit
        $datestr1 = substr($latest_array["dateline"],0,10);
    $datetime = substr($latest_array["dateline"],11,8);


?>
  <tr>
    <td align="left"><b><font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#335980"><? echo $forum_info_array["title"]; ?></font>:<br>
            <font size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $latest_array["title"]; ?></font></b></td>
  </tr>
  <?
    $querythread="select * from post where threadid='$latest_array[threadid]' order by dateline desc limit 1";

    $result_thread_text= mysql_query($querythread,$db);

    $result_thread_array = mysql_fetch_array($result_thread_text);


    $pagetext = substr(strip_tags($result_thread_array[pagetext]),0,$num_topicchars);



//parse bbcode...
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list()); 
$pagetext = $parser->do_parse($pagetext);  



    ?>
  <td width="100%"><p align="left"><img src="/deluxeforums/images/statusicon/forum_new.gif"> <span class="style2"><? echo "$pagetext"; ?>... <a href="/deluxeforums/showthread.php?threadid=<? echo "$latest_array[threadid]"; ?>">(more)</a></span></p>
          <p align="left"><span class="style2">Started By: <? echo "$latest_array[postusername]"; ?> <br>
        Last Post By: <? echo "$latest_array[lastposter]"; ?> </span></p><hr align="center" width="80%">
      </td></tr>
 <?
}
?>
</table>


DrewM 03-13-2006 09:48 PM

Why won't this work I'm trying to make it parse my page stuff it's loading it form the db and it just won't parse my php code is:
PHP Code:

<?php
error_reporting
(E_ALL & ~E_NOTICE);
define('THIS_SCRIPT''News'); 
$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array(
        
'site_page',
        
'News_view',
);
$actiontemplates = array();
 
chdir('/home/rdsx667/public_html/forum/');
require_once(
'./global.php');
require_once(
DIR '/includes/class_bbcode.php'); 

$headinclude str_replace('clientscript'$vbulletin->options['bburl'] . '/clientscript'$headinclude);
$navbits = array(); 
$navbits[$parent] = '';
$navbits construct_navbits($navbits);


    

    
if (
$_REQUEST['do'])
{
$call $_REQUEST['do'];
$Feed $db->query_first("select * from " TABLE_PREFIX "page where page_id = " intval($call));
$pagename $Feed['page_name'];
$text $Feed['page_contents'];
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list()); 
$pagecontents $parser->do_parse($text$do_html$do_smilies$do_bbcode$do_imgcode$do_nl2br$cachable);
eval(
'print_output("' fetch_template('site_page') . '");');
}


eval(
'$navbar = "' fetch_template('navbar') . '";');    


?>



All times are GMT. The time now is 10:56 PM.

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

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02996 seconds
  • Memory Usage 1,890KB
  • 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
  • (2)bbcode_code_printable
  • (2)bbcode_html_printable
  • (11)bbcode_php_printable
  • (12)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete