Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
BB Code Functions Details »»
BB Code Functions
Version: 1.00, by Velocd Velocd is offline
Developer Last Online: Nov 2023 Show Printable Version Email this Page

Version: 3.0.0 Rating:
Released: 03-28-2004 Last Update: Never Installs: 14
 
No support by the author.




As requested by mudpyr8:
https://vborg.vbsupport.ru/showthread.php?t=62933


Features
  • Manage BB Code functions from your AdminCP. These can be internal PHP functions, or custom (derived from a specified PHP file).
  • Apply a BB Code function to a custom BB Code tag, and you can use it (when the correct arguments are provided) in posts, etc.
  • You may choose for a function to be static, or update everytime upon page refresh. If it's static, the first time a function is called the value returned will be replaced with the tag in the post (hard-coded).

Known bugs
  • One must have posted in the WYSIWYG editor in order for function tags that are unchecked for "update upon page refresh" to work correctly. This is an annoying bug I discovered an hour from releasing this hack, and it will prevent functions tags from being replaced with their return values (hard-coded) in the post. It's only significant if you are using a function that returns a random/dynamic value, and wish not for the value to be updated upon page refresh, but stay unique. I will be looking into a solution when I have the time.
  • Know of another? Please PM me of it, or post it in the thread.

Notes
  • This script can only be maliciously taken advantage of if you provide functions that access your server. For example, don't create a custom function that queries your database and returns something. A user could place 100 of these tags into a post, and it would make 100 queries. Even worse, if the "update upon refresh" is enabled, it'll call 100 queries for every view of the page. Especially don't create functions that manipulate data on your server or in your database!

    Everything is at your risk, but I implore you to stick with simple functions.
  • More important notes inside install.html.

Screenshots
See attachments.

Enjoy. Remember to click install if you do use this hack.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #42  
Old 04-13-2005, 03:49 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just copy & paste the edited lines (with a few lines above and under).
Reply With Quote
  #43  
Old 04-13-2005, 11:43 AM
smju smju is offline
 
Join Date: Nov 2004
Location: Kent, U.K.
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, just to reiterate. The error received was a Parse error "Unexpected $ at line ... in functions_bbcodeparse.php" (where the line number corresponded to the last line of the php program = "?>".

Here be the areas of code I changed / inserted. As previously described I put comments in "// SMJU001 ..." to indicate what I had done.


Hack Steps 27/28
PHP Code:
    $bbcodes['custom']['recurse']['highlight'][0] = array('replace_html' => "<span class=\"highlight\">\\7</span>");

    return 
$bbcodes;
}

// ###################### Start bbcodeparse #######################
// SMJU001 {Step 27/28}
//     this line replaced by the following one - function parse_bbcode($bbcode, $forumid = 0, $allowsmilie = 1, $isimgcheck = 0, $parsedtext = '', $parsedhasimages = 0, $iswysiwyg = 0)
function parse_bbcode($bbcode$forumid 0$allowsmilie 1$isimgcheck 0$parsedtext ''$parsedhasimages 0$iswysiwyg 0$postid '')
{
    
// $parsedtext contains text that has already been turned into HTML and just needs images checking
    // $parsedhasimages specifies if the text has images in that need parsing

    
global $vboptions$parsed_postcache
Hack Steps 29/30
PHP Code:
    else
    {
        if (
$isimgcheck)
        { 
// do this since we're only checking for smilies and IMG code
            
$dobbcode 0;
        }
// SMJU001 {step 29/30}
//    this line replaced with the following one        return parse_bbcode2($bbcode, $dohtml, $dobbimagecode, $dosmilies, $dobbcode, $iswysiwyg, $donl2br);
        
return parse_bbcode2($bbcode$dohtml$dobbimagecode$dosmilies$dobbcode$iswysiwyg$donl2br$postid);
    }
}

// ###################### Start checkparam ####################### 
Hack Steps 31/32
PHP Code:
    $return preg_replace('#%(?!\d+\$s)#''%%'$return);
    return 
sprintf($return$param$option);
}

// ###################### Start bbcodeparse2 #######################
// SMJU001 {steps 31/32}
//    this line replaced with the following one function parse_bbcode2($bbcode, $dohtml, $dobbimagecode, $dosmilies, $dobbcode, $iswysiwyg = 0, $donl2br = 1)
function parse_bbcode2($bbcode$dohtml$dobbimagecode$dosmilies$dobbcode$iswysiwyg 0$donl2br 1$postid '')
{
// parses text for vB code, smilies and censoring

    
global $DB_site$vboptions$bbuserinfo$templatecache$smiliecache
Hack Steps 33/34
PHP Code:
            default:
                
$parsefunc 'parse_bbcode_regexrecurse';
        }
// SMJU001 {steps 33/34}
//                  this line replaced with the following one        $bbcode = $parsefunc($bbcode, $iswysiwyg);
      
$bbcode $parsefunc($bbcode$iswysiwyg$postid);

        if (
$wysiwygtype == 'ie'
Hack Steps 35/36/37/38
PHP Code:
    $replace = array("\n""\n""\n");
    
$innertext str_replace($find$replace$innertext);

    return 
'</p>' $prepend $innertext '[/list]<p style="margin:0px">';
// SMJU001 {step 35/36} This code inserted

// ###################### Start handle_bbcode_function #######################

function handle_bbcode_function($BBCODES$bbcode$post_bbcode$singleRegex$doubleRegex)
{
    if (
$bbcode['twoparams'])
    {
        
$regex sprintf($doubleRegex$bbcode['bbcodetag'], $bbcode['bbcodetag']);
        
$tagname "[$bbcode[bbcodetag]=";
        
        
$checkparam 5;
        
$option_param ",'\\7'";
    }
    else
    {
        
$regex sprintf($singleRegex$bbcode['bbcodetag'], $bbcode['bbcodetag']);
                    
        
$tagname "[$bbcode[bbcodetag]]";
        
$checkparam 4;
    }
    
    
$BBCODES['custom']['find']["$tagname"] = $regex;
    
    if (
$bbcode['bbcode_functionid'])
    {
        if (
$bbcode['include_file'])
        {
            
$BBCODES['custom']['include_file']["$tagname"] = $bbcode['include_file'];
        }
                
        
$BBCODES['custom']['replace']["$tagname"] = "@$bbcode[handle]('\\$checkparam'$option_param)";
                
        if (!
$bbcode['refresh'] && $post_bbcode)
        {
            if (
$bbcode['include_file'])
            {
                @include_once(
$bbcode['include_file']);
            }
                    
            if (
stristr($post_bbcode$tagname) !== false)
            {
                
$post_bbcode preg_replace($BBCODES['custom']['find']["$tagname"], $BBCODES['custom']['replace']["$tagname"], $post_bbcode);
                
$BBCODES['do_postupdate'] = 1;
            }
        }
    }
    else
    {
        
$BBCODES['custom']['replace']["$tagname"] = "handle_bbcode_parameter('\\$checkparam','" str_replace("'""\'"$bbcode['bbcodereplacement']) . "')";
    }
    
    unset(
$option_param);
    
    
    if (
$post_bbcode)
    {
        return 
$BBCODES;
    }
    else
    {
        
$BBCODE['replacement'] = $BBCODES['custom']['replace']["$tagname"];
        
$BBCODE['regex'] = $BBCODES['custom']['find']["$tagname"];
        
$BBCODE['include_file'] = $BBCODES['custom']['include_file']["$tagname"];
        
        return 
$BBCODE;
    }
}
// SMJU001 {step 36} End of inserted code


// ###################### Start bbcodeparse2_regexrecurse #######################
//SMJU001 {steps 37/38}
//                this line replaced by the following one - function parse_bbcode_regexrecurse($bbcode, $iswysiwyg)
function parse_bbcode_regexrecurse($bbcode$iswysiwyg$postid '')
{
    global 
$DB_site$vboptions$bbuserinfo$templatecache$datastore$wysiwygparse$session;
    static 
$BBCODES
Hack Steps 39/40/41/42/43/44
Note that I found the search text in step 43 twice in the file, therefore I inserted the code in step 44 twice. The duplicate area is further down the post.
PHP Code:
    $wysiwygparse $iswysiwyg;

    if (empty(
$BBCODES['standard']))
    {
        
$BBCODES fetch_bbcode_definitions();

        
$doubleRegex '/(\[)(%s)(=)(&quot;|"|\'|)([^"]*)(\\4)\](.*)(\[\/%s\])/esiU';
        
$singleRegex '/(\[)(%s)(\])(.*)(\[\/%s\])/esiU';
/* SMJU001 {step 39 / 41} This section of code replaced
        if (isset($datastore['bbcodecache'])) // get bbcodes from the datastore
        {
            $bbcodecache = unserialize($datastore['bbcodecache']);

            foreach ($bbcodecache AS $bbregex)
            {
                if ($bbregex['twoparams'])
                {
                    $regex = sprintf($doubleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
                    $bbregex['bbcodereplacement'] = str_replace(array('\\7', '\\5'), array('%1$s', '%2$s'), $bbregex['bbcodereplacement']);
                    $tagname = "[$bbregex[bbcodetag]=";
                    $checkparam = '\\7';
                    $checkoption = '\\5';
                }
                else
                {
                    $regex = sprintf($singleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
                    $bbregex['bbcodereplacement'] = str_replace('\\4', '%1$s', $bbregex['bbcodereplacement']);
                    $tagname = "[$bbregex[bbcodetag]]";
                    $checkparam = '\\4';
                    $checkoption = '';
                }
                $BBCODES['custom']['find']["$tagname"] = $regex;
                $BBCODES['custom']['replace']["$tagname"] = "handle_custom_bbcode('$checkparam', '$checkoption', '" . str_replace("'", "\'", $bbregex['bbcodereplacement']) . "')";
            }
        }
        else // query bbcodes out of the database
        {
            $bbcodes = $DB_site->query("
                SELECT bbcodetag, bbcodereplacement, twoparams
                FROM " . TABLE_PREFIX . "bbcode
            ");
            while ($bbregex = $DB_site->fetch_array($bbcodes))
            {
                if ($bbregex['twoparams'])
                {
                    $regex = sprintf($doubleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
                    $bbregex['bbcodereplacement'] = str_replace(array('\\7', '\\5'), array('%1$s', '%2$s'), $bbregex['bbcodereplacement']);
                    $tagname = "[$bbregex[bbcodetag]=";
                    $checkparam = '\\7';
                    $checkoption = '\\5';
                }
                else
                {
                    $regex = sprintf($singleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
                    $bbregex['bbcodereplacement'] = str_replace('\\4', '%1$s', $bbregex['bbcodereplacement']);
                    $tagname = "[$bbregex[bbcodetag]]";
                    $checkparam = '\\4';
                    $checkoption = '';
                }
                $BBCODES['custom']['find']["$tagname"] = $regex;
                $BBCODES['custom']['replace']["$tagname"] = "handle_custom_bbcode('$checkparam', '$checkoption', '" . str_replace("'", "\'", $bbregex['bbcodereplacement']) . "')";
            }
        }
// SMJU001 {step 39 / 41} end of code section to be replaced */
// SMJU001 {step 40 / 42} Replacement code - start
        
if (isset($datastore['bbcodecache'])) // get bbcodes from the datastore
        
{
            
$bbcodecache unserialize($datastore['bbcodecache']);
            
            foreach(
$bbcodecache AS $bbregex)
            {
                
$BBCODES handle_bbcode_function($BBCODES$bbregex, &$bbcode$singleRegex$doubleRegex);
            }
        }
        else 
// query bbcodes out of the database
        
{
            
$bbcodes $DB_site->query("
                SELECT bbcode.bbcodetag, bbcode.bbcodereplacement, bbcode.twoparams, 
                bbcode_function.handle, bbcode_function.include_file
                FROM " 
TABLE_PREFIX "bbcode
                LEFT JOIN " 
TABLE_PREFIX "bbcode_function 
                USING (bbcode_functionid)
            "
);
            
            while (
$bbregex $DB_site->fetch_array($bbcodes))
            {
                
$BBCODES handle_bbcode_function($BBCODES$bbregex$bbcode$singleRegex$doubleRegex);
            }
        }
// SMJU001 {step 40 / 42} Replacement code - end
    
}

// SMJU001 {step 43 / 44} Inserted Code - start
    
if ($BBCODES['do_postupdate'] && $postid// Hard code the retuned function value
    
{
        
$DB_site->query("
            UPDATE post 
            SET pagetext='"
.addslashes(str_replace('<br />'''html_entity_decode($bbcode)))."' 
            WHERE postid=
$postid");
    }
    
// SMJU001 {step 43 / 44} Inserted Code - End    
    
    
if ($iswysiwyg// text to show in the WYSIWYG editor box
    
{
        
$bbcode_find $BBCODES['standard']['find'];
        
$bbcode_replace $BBCODES['standard']['replace'];
    } 
Hack Steps 45/46
PHP Code:
    else // text to show everywhere else
    
{
        
//$bbcode_find = array_merge($BBCODES['standard']['find'], $BBCODES['custom']['find']);
        //$bbcode_replace = array_merge($BBCODES['standard']['replace'], $BBCODES['custom']['replace']);

        
$bbcode_find array_merge($BBCODES['custom']['find'], $BBCODES['standard']['find']);
        
$bbcode_replace array_merge($BBCODES['custom']['replace'], $BBCODES['standard']['replace']);

// SMJU001 {steps 45 / 46} Inserted code - start
        
if ($BBCODES['custom']['include_file'])
        {
            
$include_file $BBCODES['custom']['include_file'];
        }
// SMJU001 {steps 45 / 46} Inserted code - end
    
}

    foreach(
$bbcode_find AS $tag => $findregex)
    {
        
// if using option, $tag will be '[xxx='
        // if not using option, $tag will be '[xxx]'

        
while (stristr($bbcode$tag) !== false
Hack Steps 47/48
PHP Code:
        while (stristr($bbcode$tag) !== false)
        {
// SMJU001 {steps 47 / 48} Inserted code - start
            
if ($include_file["$tag"])
            {
                @include_once(
$include_file["$tag"]);
            }
// SMJU001 {steps 47 / 48} Inserted text - end
            // make a copy of the text pre-replacement for later comparison
            
$origtext $bbcode;

            
$bbcode preg_replace($findregex$bbcode_replace["$tag"], $bbcode); 
Hack Steps 43/44: In the hack instructions step 43 gave a search string. I therefore inserted the code twice, in both places.
PHP Code:
            while($bbregex $DB_site->fetch_array($bbcodes))
            {
                if (
$bbregex['twoparams'])
                {
                    
$regex sprintf($doubleRegex$bbregex['bbcodetag'], $bbregex['bbcodetag']);
                    
$checkparam 7;
                }
                else
                {
                    
$regex sprintf($singleRegex$bbregex['bbcodetag'], $bbregex['bbcodetag']);
                    
$checkparam 4;
                }
                for (
$i 0$i 3$i++)
                {
                    
$BBCODES['custom']['find'][] = $regex;
                    
$BBCODES['custom']['replace'][] = "handle_bbcode_parameter('\\$checkparam','" str_replace("'","\'",$bbregex['bbcodereplacement']) . "')";
                }
            }
        }
    }
    
// SMJU001 Step 43/44 Inserted Code - start
//     I found the search string twice, so I sinserted it twice.

    
if ($BBCODES['do_postupdate'] && $postid// Hard code the retuned function value
    
{
        
$DB_site->query("
            UPDATE post 
            SET pagetext='"
.addslashes(str_replace('<br />'''html_entity_decode($bbcode)))."' 
            WHERE postid=
$postid
        "
);
    }
// SMJU001 Inserted Code - End    

    
if ($iswysiwyg// text to show in the WYSIWYG editor box
    
{
        
$bbcode_find $BBCODES['standard']['find'];
        
$bbcode_replace $BBCODES['standard']['replace'];
    } 
Reply With Quote
  #44  
Old 04-16-2005, 08:07 AM
smju smju is offline
 
Join Date: Nov 2004
Location: Kent, U.K.
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

One bit of info I forgot to add, was that I got the error after selecting the "Custom BB Code" option off the "Admin CP" menu.
Reply With Quote
  #45  
Old 04-25-2005, 03:52 PM
smju smju is offline
 
Join Date: Nov 2004
Location: Kent, U.K.
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmmm.

I wonder if the lack of a response is due to me actually applying the changes correctly.

Hmmm.
Reply With Quote
  #46  
Old 04-25-2005, 08:52 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well i don't see anything wrong when quickly browsing through it.

What editor did you use?
Reply With Quote
  #47  
Old 04-28-2005, 08:45 AM
smju smju is offline
 
Join Date: Nov 2004
Location: Kent, U.K.
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

HTML-Kit.

I am wondering if the problem was in step 43 where the instructions only indicate 1 occurance of the search string and I found 2. Should I only have inserted the code once? and if so at which point.

It gratifies me someone else has looked and can't spot a problem, I was pulling my hair out looking for a accidentally erased / misplaced semi-colon.
Reply With Quote
  #48  
Old 07-05-2005, 11:53 AM
smju smju is offline
 
Join Date: Nov 2004
Location: Kent, U.K.
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bump
Reply With Quote
  #49  
Old 11-27-2005, 02:52 PM
smju smju is offline
 
Join Date: Nov 2004
Location: Kent, U.K.
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I never did get this implemented, however we are now on 3.5.1 sooooooooo

Any chance that this mod is going to get ported to 3.5?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:13 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.05785 seconds
  • Memory Usage 2,418KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (9)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (8)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete