vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Unexpected T_VARIABLE in str_replace (https://vborg.vbsupport.ru/showthread.php?t=242737)

sheppardzwc 05-17-2010 09:44 PM

Unexpected T_VARIABLE in str_replace
 
Hey guys,

Ran into an issue earlier, I have debugged this as far as I can and I can't get why I'm having issues. Mind taking a look at it? I'm trying to replace the postbit template with <if condition="$post['noattachdisplay']"> and apparently I'm not doing something right.

Thanks in advance.

Parse error: syntax error, unexpected T_VARIABLE in /home/www/f/includes/class_postbit.php(304) : eval()'d code on line 108

PHP Code:

<?

// showthread_create_postbit

global $vbulletin;
if($vbulletin->options['hide_attach_enable']) {
    $find_begin = '<!-- attachments -->';
    $find_end = '<!-- / attachments -->';
    $replace_begin = '<!-- attachments -->
    <if condition="$post[' . "'" . 'noattachdisplay' . "'" . '">';
    $replace_end = '        <!-- / attachments -->
        </if>';
    $vbulletin->templatecache['postbit'] = str_replace($find_begin, $replace_begin, $vbulletin->templatecache['postbit']);
    $vbulletin->templatecache['postbit'] = str_replace($find_end, $replace_end, $vbulletin->templatecache['postbit']);
}


Lynne 05-17-2010 09:49 PM

Do the condition in the plugin then just spit out the output. Don't put the condition into the template like you are trying to do.

sheppardzwc 05-17-2010 10:06 PM

Quote:

Originally Posted by Lynne (Post 2038805)
Do the condition in the plugin then just spit out the output. Don't put the condition into the template like you are trying to do.

Ah, okay, what tripped me up originally (that's what I was trying to do at first) was that the part I'm trying to replace has several variables with apostrophes - do I just escape those in a str_replace?

i.e.

$find = '$var[\'key\']';
$replace = '$var[\'key\'] . $var2';
str_replace...

Lynne 05-17-2010 11:17 PM

If you are worried about apostophes in something, then try something like this before the str_replace:
PHP Code:

$find'$var[key]';
$find str_replace("'""&# 039;"$find); 

(Note: there are actually no spaces in &# 039; , but it won't print in here unless I put a space in it.)

But, if you are doing something like what you are saying in your post, then no need for a str_replace, just do something like:
PHP Code:

$var['key'] = $var['key'] . $var2


sheppardzwc 05-18-2010 10:29 PM

Quote:

Originally Posted by Lynne (Post 2038866)
If you are worried about apostophes in something, then try something like this before the str_replace:
PHP Code:

$find'$var[key]';
$find str_replace("'""&# 039;"$find); 

(Note: there are actually no spaces in &# 039; , but it won't print in here unless I put a space in it.)

But, if you are doing something like what you are saying in your post, then no need for a str_replace, just do something like:
PHP Code:

$var['key'] = $var['key'] . $var2


Thanks Lynne but it still doesn't seem to be working. Am I doing something wrong?

PHP Code:

if($noattach == 2) {
        
$find '    <!-- attachments -->
            <div style="padding:$stylevar[cellpadding]px">

            <if condition="$show[' 
"'" 'thumbnailattachment' "'" ']">
                <fieldset class="fieldset">
                    <legend>$vbphrase[attached_thumbnails]</legend>
                    <div style="padding:$stylevar[formspacer]px">
                    $post[thumbnailattachments]
                    </div>
                </fieldset>
            </if>

            <if condition="$show[' 
"'" 'imageattachment' "'" ']">
                <fieldset class="fieldset">
                    <legend>$vbphrase[attached_images]</legend>
                    <div style="padding:$stylevar[formspacer]px">
                    $post[imageattachments]
                    </div>
                </fieldset>
            </if>

            <if condition="$show[' 
"'" 'imageattachmentlink' "'" ']">
                <fieldset class="fieldset">
                    <legend>$vbphrase[attached_images]</legend>
                    <table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
                    $post[imageattachmentlinks]
                    </table>
                    </fieldset>
            </if>

            <if condition="$show[' 
"'" 'otherattachment' "'" ']">
                <fieldset class="fieldset">
                    <legend>$vbphrase[attached_files]</legend>
                    <table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
                    $post[otherattachments]
                    </table>
                </fieldset>
            </if>

            <if condition="$show[' 
"'" 'moderatedattachment' "'" ']">
                <fieldset class="fieldset">
                    <legend>$vbphrase[attachments_pending_approval]</legend>
                    <table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
                    $post[moderatedattachments]
                    </table>
                </fieldset>
            </if>

            </div>
        <!-- / attachments -->'
;
        
$find str_replace("'""&# 039;"$find); // without the space there
        
$replace '';
        
$vbulletin->templatecache['postbit'] = str_replace($find$replace$vbulletin->templatecache['postbit']);
    } 


Lynne 05-18-2010 10:55 PM

You can't have all those conditions and phrases in there and line breaks. Try taking a look at what the template cache looks like in the database. *That* is what you are trying to look at and it doesn't look like what you have above. Why don't you just remove that code from the postbit(_legacy)? What is wrong with that?

sheppardzwc 05-18-2010 11:13 PM

Quote:

Originally Posted by Lynne (Post 2039536)
You can't have all those conditions and phrases in there and line breaks. Try taking a look at what the template cache looks like in the database. *That* is what you are trying to look at and it doesn't look like what you have above. Why don't you just remove that code from the postbit(_legacy)? What is wrong with that?

Nothing - actually, just after I posted that I co. Could easily solve all that by just adding manually a simple if condition. Easy peasy.

Last question though... now I really don't understand. I'm replacing a small template with an extra line of HTML and it's giving me another error?

Parse error: syntax error, unexpected T_STRING in /home/www/f/includes/functions_editor.php(583) : eval()'d code on line 1

PHP Code:

global $vbulletin;
if(
$vbulletin->options['hide_attach_enable']) {
    
$find '</div>';
    
$replace '<label for="cb_hideattach"><input type="checkbox" name="hideattach" id="hideattach" /></label></div>';
    
$vbulletin->templatecache['newpost_disablesmiliesoption'] = str_replace($find$replace$vbulletin->templatecache['newpost_disablesmiliesoption']);



I'm trying to replace the last </div> with one more option, then end the div, and it's not seeming to work... I'm using the hook newreply_form_start. Do I need a different location?

Nevermind. Easy fix for this is escape all the double quotes. \" Oops. =p


All times are GMT. The time now is 05:14 PM.

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.01087 seconds
  • Memory Usage 1,766KB
  • 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
  • (7)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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