MyBB Hacks

Full Version: PHP in Templates / Complex Templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Variables are written in PHP code so, unfortunately, there's no general rule other than to look through the code itself.
In the EDITPOST template on a MyBB 1.8.12 board, I'm trying to create a condition where:

IF, the post being edited is the first post in the thread, the subject field can be edited

ELSE, (the post is not the first post,) the subject field cannot be edited

I've been playing around with mixed results, but not having any luck.

#################################################

This BELOW allows all posts in the thread to have the subject field edited. - the logic seems to flow down the IF path...

Code:
<if $thread['pid'] = 1 then>
<tr>
<td class="trow2" style="color:red; background-color: #fbe3e4"><strong>Edit Your Subject ?</strong></td>
<td class="trow2" style="background-color: #fbe3e4">{$prefixselect}<input type="text" class="textbox" name="subject" size="60" maxlength="85" value="{$subject}" tabindex="1" /></td>
</tr>

<else />
<tr>
<td class="trow2" style="color:red; background-color: #fbe3e4"><strong>Thread Subject:</strong></td>
<td class="trow2" style="background-color: #fbe3e4">{$subject}</td>
</tr>

</if>


This BELOW allows all posts in the thread to have subject field edited. - again, logic seems to follow the IF path...

Code:
<if $post['pid'] = 1 then>
<tr>
<td class="trow2" style="color:red; background-color: #fbe3e4"><strong>Edit Your Subject ?</strong></td>
<td class="trow2" style="background-color: #fbe3e4">{$prefixselect}<input type="text" class="textbox" name="subject" size="60" maxlength="85" value="{$subject}" tabindex="1" /></td>
</tr>

<else />
<tr>
<td class="trow2" style="color:red; background-color: #fbe3e4"><strong>Thread Subject:</strong></td>
<td class="trow2" style="background-color: #fbe3e4">{$subject}</td>
</tr>

</if>


This BELOW does not allow editing of the first or any subsequent posts. - the logic seems to follow the ELSE path...

Code:
<if $post['pid1'] then>
<tr>
<td class="trow2" style="color:red; background-color: #fbe3e4"><strong>Edit Your Subject ?</strong></td>
<td class="trow2" style="background-color: #fbe3e4">{$prefixselect}<input type="text" class="textbox" name="subject" size="60" maxlength="85" value="{$subject}" tabindex="1" /></td>
</tr>

<else />
<tr>
<td class="trow2" style="color:red; background-color: #fbe3e4"><strong>Thread Subject:</strong></td>
<td class="trow2" style="background-color: #fbe3e4">{$subject}</td>
</tr>

</if>


Lastly, same result here where the logic appears to follow the ELSE path...

Code:
<if $thread['pid1'] then>
<tr>
<td class="trow2" style="color:red; background-color: #fbe3e4"><strong>Edit Your Subject ?</strong></td>
<td class="trow2" style="background-color: #fbe3e4">{$prefixselect}<input type="text" class="textbox" name="subject" size="60" maxlength="85" value="{$subject}" tabindex="1" /></td>
</tr>

<else />
<tr>
<td class="trow2" style="color:red; background-color: #fbe3e4"><strong>Thread Subject:</strong></td>
<td class="trow2" style="background-color: #fbe3e4">{$subject}</td>
</tr>

</if>


Clearly, your plugin is functional as I can observe the logic flowing either down the IF or down the ELSE paths.

I'm just misapplying it.

Any help?

^ I updated my previous post so it's less vague. If anybody wants to take a second look, please do.

Thanks Smile
Bump Beg Tongue
Hi

If i wanted to run a script in headerinclude template, but wanted to exclude it from executing on say showthread.php, what would be the best / correct php syntax to use ?

<if !showthread.php then>
<script src="{$mybb->asset_url}/jscripts/somescript.js"></script>
</if>
(07-30-2017 03:51 AM)Ashley Wrote: [ -> ]Hi

If i wanted to run a script in headerinclude template, but wanted to exclude it from executing on say showthread.php, what would be the best / correct php syntax to use ?

<if !showthread.php then>
<script src="{$mybb->asset_url}/jscripts/somescript.js"></script>
</if>

Hi, I think it's:

Code:
<if THIS_SCRIPT != 'showthread.php' then><script src="{$mybb->asset_url}/jscripts/somescript.js"></script></if>

^^ Thanks.
I'm using "PHP and Template Conditionals" plugin but there is always an error where I add <if> conditional, for example:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /srv/users/serverpilot/apps/(appname)/public/forum/global.php(527) : eval()'d code on line 2

I'm using also PHP 7.0, maybe it isn't compatible with PHP 7.0? Frown

EDIT: nothing, sorry, I have uploaded from 2.0 to 2.1 and now it works without problems, I didn't see the update sorry Frown Frown Frown
(06-30-2017 05:16 AM)L Moody Wrote: [ -> ]In the EDITPOST template on a MyBB 1.8.12 board, I'm trying to create a condition where:

IF, the post being edited is the first post in the thread, the subject field can be edited

ELSE, (the post is not the first post,) the subject field cannot be edited
Unfortunately this plugin won't really enforce that.  At most, you could hide the inputs, but it won't actually stop someone editing a subject.  You'd need something more complex, like a plugin, for that.
If you don't actually care about post subjects though, you could just hide them in posts instead (or display the thread subject there instead).
Were is the download link to this?
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Reference URL's