vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Parsing Conditions? Eval? (https://vborg.vbsupport.ru/showthread.php?t=94375)

Adrian Schneider 08-15-2005 06:27 PM

Parsing Conditions? Eval?
 
I have a standalone system where users enter HTML, and I want to have some conditions in it (such as hide left block if that option is enabled). Basically in the HTML they will have something like this:

HTML Code:

<table align="center" cellpadding="0" cellspacing="0" width="760">
        <tr valign="top">
                {IFSHOWLEFTBLOCK}
                <td width="{LEFTBLOCKWIDTH}" class="leftblock">
{LEFTBLOCKS}
                </td>
                <td width="{LEFTBLOCKSPACERWIDTH}"><img src="{SPACERIMAGE}" width="{LEFTBLOCKSPACERWIDTH}" alt="" /></td>
                {/IFSHOWLEFTBLOCK}


                <td class="content">
{BLOGPOSTBIT}
                </td>


                {IFSHOWRIGHTBLOCK}
                <td width="{RIGHTBLOCKSPACERWIDTH}"><img src="{SPACERIMAGE}" alt="" width="{RIGHTBLOCKSPACERWIDTH}"/></td>
                <td width="{RIGHTBLOCKWIDTH}" class="rightblock">
{RIGHTBLOCKS}
                </td>
                {/IFSHOWRIGHTBLOCK}


        </tr>
</table>

Right now I am just using preg_replace to replace the {variables} with the corresponding $variable (preset ones, they can't use anything), and I want the same for conditions.

I'm thinking eval (but I've never used much of it before), so how would I go about doing this with the IFs? Right now I am using preg replace, so if the condition they enter is false, it replaces the condtiions with <!-- and --> (very cheap solution) and if true, replaces with "".

I do not want this like vBulletins, where it runs any PHP they enter in the conditions, only presets.

Adrian Schneider 08-18-2005 06:09 PM

/me bumps this thread

Zero Tolerance 08-18-2005 08:15 PM

Let's say you had:
PHP Code:

eval('$userpage = "' fetch_template('YOUR_TEMPLATE') . '";'); 

Above that you would have:
PHP Code:

$vbulletin->templatecache['YOUR_TEMPLATE'] = str_replace(
                        array(
'{LEFTBLOCKSPACERWIDTH}'),
                        array(
$leftblockwidth),
                        
$vbulletin->templatecache['YOUR_TEMPLATE']
                        ); 

Not sure about your if macro's though, best to just use an if in php:
PHP Code:

$leftblock '';
if (
$show['leftblock'])
{
    
$leftblock "whatever...";


Hope that helps, be sure to change the array in the second code for the str_replace, and "YOUR_TEMPLATE" :)

- Zero Tolerance

Adrian Schneider 08-18-2005 08:27 PM

Hmm, I didn't know about the templatecache thing.. neat:)

Anyway I may have misunderstood, but I don't think that will help. The HTML that is being parsed is not powered by vBulletin (just stored in db).

$somevariable =
HTML Code:

<table align="center" cellpadding="0" cellspacing="0" width="760">
        <tr valign="top">
                <?php
                if ($userinfo['showleftblock'])
                {
?>

                <td width="{LEFTBLOCKWIDTH}" class="leftblock">
<?php print $leftblockbit; ?>
                </td>
                <td width="{LEFTBLOCKSPACERWIDTH}"><img src="{SPACERIMAGE}" width="{LEFTBLOCKSPACERWIDTH}" alt="" /></td>
<?                }?>

Well I edited it quickly, say if I replaced it like so from the old {if} how would I have it run the PHP while keeping the variable intact? I've never used much of eval before, and I think that's what I need to do. I'm not sure if this makes much sense... :ermm:

Zero Tolerance 08-18-2005 08:30 PM

Ah, not vb, i see, well lets say your variable for the template was "$mytemplate", you'd replace all instances of "$vbulletin->templatecache['YOUR_TEMPLATE']" with "$mytemplate", and instead of:
PHP Code:

eval('$userpage = "' fetch_template('YOUR_TEMPLATE') . '";'); 

You would have:
PHP Code:

eval('$mytemplate = "' .  $mytemplate'";'); 

Again as for the if statement, it would be much better for you to do it in php itself instead of the template.

- Zero Tolerance

Adrian Schneider 08-18-2005 08:40 PM

What would the difference between standard $var = val; and the eval?

The users are the ones inputing the conditions, how would I do it as you are suggesting?


All times are GMT. The time now is 03:03 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.01559 seconds
  • Memory Usage 1,739KB
  • 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_html_printable
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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