View Single Post
  #175  
Old 11-22-2005, 03:55 PM
dc3dreamer dc3dreamer is offline
 
Join Date: Oct 2005
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Update #2 (final!): All is well now. Here is the code for dynamic_a() which implements nested conditionals:
Code:
function dynamic_a($logician_dfa_incoming1)
{
    extract ($GLOBALS);

    // Prevent successive conditionals on separate lines from generating
    // spurious <br /> after running thru BbCode parser. You might not
    // like this, it's optional.
    $logician_dfa_incoming1 = ereg_replace("\]\][\r\n\f \t]*\[\[", "]][[", $logician_dfa_incoming1);
    // Recursively process nested conditionals
    $logician_dfa_incoming1 = trim(dynamic_b($logician_dfa_incoming1));
    // Finish up by running result through BbCode parser
    if (trim($logician_dfa_incoming1)) 
    {
        $parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list()); 
        $logician_dfa_incoming1 = $parser->do_parse($logician_dfa_incoming1, 1, 1, 1, 1, 1, 1); 
    }
    return $logician_dfa_incoming1;
}

function dynamic_b($dc3dreamer_dfa_incoming1)
{
    extract ($GLOBALS);

    while (preg_match("/\[\[(.*)\]\](.*)\[\[(\/\\1)\]\]/siU", $dc3dreamer_dfa_incoming1, $matches14))
    {
        @eval ('if ('.stripslashes($matches14[1]).') { $eval_deger= "1"; } else { $eval_deger= "0"; }'); 
        if ($eval_deger == 1)           //if conditional applied, replace with inner text
        {
            $dc3dreamer_dfa_incoming1 = dynamic_b(str_replace($matches14[0], $matches14[2], $dc3dreamer_dfa_incoming1));
        }
        else                            // Conditional not applied, delete the whole chunk
        {
            $dc3dreamer_dfa_incoming1 = dynamic_b(str_replace($matches14[0], '', $dc3dreamer_dfa_incoming1));
        }
    }
    return $dc3dreamer_dfa_incoming1;
}
The recursion continues until there are no conditionals found, at which point the final result is passed through the BbCodeParser at the end of the first method. The trick was to remove line endings from conditionals that follow one another with just newlines between. They generated extra breaks and line spacing after going through the BbCode parser. You might want to remove the * in the regexp for the call to ereg_replace(). Er, do I really have to name my parameter variable like it might exist in the host page? I hope not, but I copied Logician's style. I would have used sumpin' like $src for the parameter var :nervous:

I'm slowly coming up to speed on PHP :nervous: I was killed by the $bbuserinfo[membergroupids] variable testing against values, till my ancient Perl tablets fell out on the ground. Yumba! It can be an array and it may not even exist! Well, rookie me! I got it now.

This is so nice! Nested conditionals open up a whole new world of possibilities, but ... Thank you Logician Thank you Logician Thank you Logician ...
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03324 seconds
  • Memory Usage 1,767KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete