PDA

View Full Version : Unexpected T_VARIABLE in str_replace


sheppardzwc
05-17-2010, 09:44 PM
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

<?

// 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
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:
$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:
$var['key'] = $var['key'] . $var2;

sheppardzwc
05-18-2010, 10:29 PM
If you are worried about apostophes in something, then try something like this before the str_replace:
$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:
$var['key'] = $var['key'] . $var2;
Thanks Lynne but it still doesn't seem to be working. Am I doing something wrong?

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
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

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