Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 05-17-2010, 09:44 PM
sheppardzwc sheppardzwc is offline
 
Join Date: Dec 2008
Location: South Carolina
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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']);
}
Reply With Quote
  #2  
Old 05-17-2010, 09:49 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 05-17-2010, 10:06 PM
sheppardzwc sheppardzwc is offline
 
Join Date: Dec 2008
Location: South Carolina
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
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...
Reply With Quote
  #4  
Old 05-17-2010, 11:17 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #5  
Old 05-18-2010, 10:29 PM
sheppardzwc sheppardzwc is offline
 
Join Date: Dec 2008
Location: South Carolina
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
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']);
    } 
Reply With Quote
  #6  
Old 05-18-2010, 10:55 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #7  
Old 05-18-2010, 11:13 PM
sheppardzwc sheppardzwc is offline
 
Join Date: Dec 2008
Location: South Carolina
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
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
Reply With Quote
Reply

Thread Tools
Display Modes

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 03:21 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.04821 seconds
  • Memory Usage 2,256KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete