PDA

View Full Version : if conditional inside php file, how?


Chadi
10-01-2009, 08:59 PM
I'm trying to use an if conditional inside the skin file for my ipbpro arcade mode.

The problem is when I edit and reupload, I get a blank page due to the code I'm using but I'm not sure where I'm messing up.

In a regular vb template it looks like this.

<if condition="in_array($bbuserinfo['usergroupid'], array(2,6,7,35))">
<if condition="$bbuserinfo['posts'] > 4">
<a href="http://www.talkjesus.com/misc.php?do=page&template=Chat"><span><img src="/images/media-menu/chat.png" alt="Christian Live Chat" class="img-media-menu" />&nbsp;Live Chat</span></a><else /><a href="http://www.talkjesus.com/forum-rules-ten-commandments/53-talk-jesus-10-commandments-rule.html"><span><img src="/images/media-menu/chat.png" alt="Christian Live Chat" class="img-media-menu" />&nbsp;Live Chat: Disabled (?)</span></a></if></if>

In the arcade php file, I changed all the " to ' as I know the " does not work apparently.

It looks like this and results in a blank page

<if condition='in_array($bbuserinfo['usergroupid'], array(2,6,7,35))'>
<if condition='$bbuserinfo['posts'] > 4'>
<a href='http://www.talkjesus.com/misc.php?do=page&template=Chat'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;&nbsp;Live Chat</span></a>
<else /><a href='http://www.talkjesus.com/forum-rules-ten-commandments/53-talk-jesus-10-commandments-rule.html'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;Live Chat: Disabled (?)</span></a></if></if>

Any one know what I'm doing wrong?

Lynne
10-01-2009, 10:11 PM
If it's php, you can't use template conditions - you need to use actual php code. For instance:
if (in_array($vbulletin->userinfo['usergroupid'], array(2, 6, 7, 35)))
{
stuff
}

You can look in the vbulletin php files for other examples and in the manual also.

Chadi
10-01-2009, 10:24 PM
Thanks Lynne.

What about this one?

<if condition="$bbuserinfo['posts'] > 4">

Is this the correct replacement?

if (in_array($vbulletin->userinfo['bbuserinfo['posts'] > 4')

Tried this:

if (in_array($vbulletin->userinfo['usergroupid'], array(2, 6, 7, 35)))
{
<a href='http://www.talkjesus.com/misc.php?do=page&template=Chat'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;&nbsp;Live Chat</span></a>
}
if (in_array($vbulletin->userinfo['$bbuserinfo['posts'] > 4')
{
<a href='http://www.talkjesus.com/forum-rules-ten-commandments/53-talk-jesus-10-commandments-rule.html'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;Live Chat: Disabled (?)</span></a>
}
Results in screenshot

Chadi
10-01-2009, 10:51 PM
This is the entire portion of that file

function top_links_table($links,$width,$extra) {
global $ibforums;
return <<<EOF
<!-- Media Center Nav -->
<div class="mc_border_out">
<div class="mc_border_in">
<div id="middlebar">
<a href='http://www.talkjesus.com/arcade.php'><span><img src='/images/media-menu/games.png' alt='Arcade Games' class='img-media-menu' />&nbsp;Arcade</span></a>
<a href='http://www.talkjesus.com/journal.php'><span><img src='/images/media-menu/highlight.png' alt='Journals' class='img-media-menu' />&nbsp;Journals</span></a>

if (in_array($vbulletin->userinfo['usergroupid'], array(2, 6, 7, 35)))
{
<a href='http://www.talkjesus.com/misc.php?do=page&template=Chat'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;&nbsp;Live Chat</span></a>
}
if (in_array($vbulletin->userinfo['$bbuserinfo['posts'] > 4')
{
<a href='http://www.talkjesus.com/forum-rules...ents-rule.html (http://www.talkjesus.com/forum-rules-ten-commandments/53-talk-jesus-10-commandments-rule.html)'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;Live Chat: Disabled (?)</span></a>
}
<a href='http://www.talkjesus.com/album.php'><span><img src='/images/media-menu/folder.png' alt='Member Albums' class='img-media-menu' />&nbsp;Member Albums</span></a>
<a href='http://www.talkjesus.com/gallery/index.php'><span><img src='/images/media-menu/image.png' alt='Photo Gallery' class='img-media-menu' />&nbsp;Photo Gallery</span></a>
<a href='javascript:openRadioAndTV()'><span><img src='/images/media-menu/multimedia.png' alt='Radio Streaming' class='img-media-menu' />&nbsp;Radio</span></a>
</div>
</div>
</div>
<!-- /Media Center Nav -->
<br />
<table width='100%' border='0' cellspacing='1' cellpadding='4' class="tborder">
<tr>
<td class="tcat" align="center" width="{$width}">{$links}</td>
{$extra}
</tr>
</table>
EOF;
}

Lynne
10-01-2009, 11:21 PM
I think it will work with posts, but I'm not sure. You'll have to see if it's been formatted at the point that you go to use it.

You also cannot go in and out of html/php like you are doing. You may want to read up on using html in a php page and how to end your php and go into html and vice-versa.

Chadi
10-01-2009, 11:42 PM
Can anyone else help me please?

I'm not a coder, so I have no idea how to really go about this and I tried looking at other default vb files for hints, not picking up on how it works.

Digital Jedi
10-02-2009, 12:51 AM
I've not fooled around with it too much and I only understand a little about it, but I know you can't jumble your HTML and PHP together like you have. Take a look at the one of the skin files for ibProArcade and take note of where HTML is being placed and how. Take note of how only variables are being used within the HTML and how it stands out from the code structure of PHP. For instance, if conditions are not being used inside of return <<<EOF EOF;

HMBeaty
10-02-2009, 12:59 AM
Try something like this...
if (in_array($vbulletin->userinfo['usergroupid'], array(2, 6, 7, 35)) AND $vbulletin->userinfo[posts] > 4)
{
do something
}
else
{
do something else
}

Chadi
10-02-2009, 01:09 AM
I tried your method HM and got this

http://pingy.us/?v=box.png

The code
function top_links_table($links,$width,$extra) {
global $ibforums;
return <<<EOF
<!-- Media Center Nav -->
<div class="mc_border_out">
<div class="mc_border_in">
<div id="middlebar">
<a href='http://www.talkjesus.com/arcade.php'><span><img src='/images/media-menu/games.png' alt='Arcade Games' class='img-media-menu' />&nbsp;Arcade</span></a>
<a href='http://www.talkjesus.com/journal.php'><span><img src='/images/media-menu/highlight.png' alt='Journals' class='img-media-menu' />&nbsp;Journals</span></a>

if (in_array($vbulletin->userinfo['usergroupid'], array(2, 6, 7, 35)) AND $vbulletin->userinfo[posts] > 4)
{
<a href='http://www.talkjesus.com/misc.php?do=page&template=Chat'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;&nbsp;Live Chat</span></a>
}
else
{
<a href='http://www.talkjesus.com/forum-rules...ents-rule.html'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;Live Chat: Disabled (?)</span></a>
}

<a href='http://www.talkjesus.com/album.php'><span><img src='/images/media-menu/folder.png' alt='Member Albums' class='img-media-menu' />&nbsp;Member Albums</span></a>
<a href='http://www.talkjesus.com/gallery/index.php'><span><img src='/images/media-menu/image.png' alt='Photo Gallery' class='img-media-menu' />&nbsp;Photo Gallery</span></a>
<a href='javascript:openRadioAndTV()'><span><img src='/images/media-menu/multimedia.png' alt='Radio Streaming' class='img-media-menu' />&nbsp;Radio</span></a>
</div>
</div>
</div>
<!-- /Media Center Nav -->
<br />
<table width='100%' border='0' cellspacing='1' cellpadding='4' class="tborder">
<tr>
<td class="tcat" align="center" width="{$width}">{$links}</td>
{$extra}
</tr>
</table>
EOF;
}

This method below (the way I had it originally) works just fine, but I really want the if conditionals in place for enhanced security against trouble makers.


function top_links_table($links,$width,$extra) {
global $ibforums;
return <<<EOF
<!-- Media Center Nav -->
<div class="mc_border_out">
<div class="mc_border_in">
<div id="middlebar">
<a href='http://www.talkjesus.com/arcade.php'><span><img src='/images/media-menu/games.png' alt='Arcade Games' class='img-media-menu' />&nbsp;Arcade</span></a>
<a href='http://www.talkjesus.com/journal.php'><span><img src='/images/media-menu/highlight.png' alt='Journals' class='img-media-menu' />&nbsp;Journals</span></a>
<a href='http://www.talkjesus.com/misc.php?do=page&template=Chat'><span><img src='/images/media-menu/chat.png' alt='Christian Live Chat' class='img-media-menu' />&nbsp;&nbsp;Live Chat</span></a>
<a href='http://www.talkjesus.com/album.php'><span><img src='/images/media-menu/folder.png' alt='Member Albums' class='img-media-menu' />&nbsp;Member Albums</span></a>
<a href='http://www.talkjesus.com/gallery/index.php'><span><img src='/images/media-menu/image.png' alt='Photo Gallery' class='img-media-menu' />&nbsp;Photo Gallery</span></a>
<a href='javascript:openRadioAndTV()'><span><img src='/images/media-menu/multimedia.png' alt='Radio Streaming' class='img-media-menu' />&nbsp;Radio</span></a>
</div>
</div>
</div>
<!-- /Media Center Nav -->
<br />
<table width='100%' border='0' cellspacing='1' cellpadding='4' class="tborder">
<tr>
<td class="tcat" align="center" width="{$width}">{$links}</td>
{$extra}
</tr>
</table>
EOF;
}

Digital Jedi
10-02-2009, 01:16 AM
I'm not entirely sure what your trying to do, but why not just use the standard vBulletin conditionals in the ARCADE template? Then you can set up an <else> in the conditional with a message or whatever else you want those usergroups to see. Seems like that would be easier and closer to what your trying to accomplish.

Chadi
10-02-2009, 01:19 AM
Because the pink box is my "media menu" and the if conditionals is for the live chat link in that media box.

I do not want anyone to be able to enter live chat unless they have at least 5 forum posts.

There is no skin template for the arcade in the vb template area, only the php file.

Digital Jedi
10-02-2009, 01:28 AM
There is one template for ibProArcade. It's the ARCADE template. It looks like this:

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache" />
<!-- end no cache headers -->
$headinclude
<title><phrase 1=$vboptions[bbtitle]>$vbphrase[x_powered_by_vbulletin]</phrase></title>
</head>
<body>
$header
$navbar
<if condition="!$bbuserinfo[userid]">
$arcadeheader
<!-- small space -->
<span class="smallfont"><br />
</span></if>
$maincontent
</div>
$footer
</body>
</html>


It's the main and only template for all the arcade pages. You should be able to put your Media code anywhere in that template and block out anything form the arcade header to the main content while leaving the head and footer intact, or just doing the whole page. You should be able to do what your suggesting a lot more easily this way, and maybe even with a few more options.

Chadi
10-02-2009, 01:37 AM
I have a better idea.

How can I tell that php arcade file to fetch this vbulletin template called vbtpldw_01 ?

vbtpldw_01 is a custom vbulletin template I use but have no idea how to tell the php file to fetch the content.

I already tried editing the ARCADE template in vb but for some very odd reason, it just does not work.

I used:

$header
$navbar
$vbtpldw_01

I simply added that third line, and hard refreshed the main arcade page. That vbtpldw template does not show up at all. However, I have that same line in various other template areas such as album, live chat, photo gallery templates and that custom template pulls fine on those other templates/pages.

--------------- Added 1254451208 at 1254451208 ---------------

Ok, I got it working the manual way: using the actual code itself from that vbtpldw template instead of fetching it using the $ method.

Any idea why it wouldn't fetch the template?