We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

PHP hack if statement for Discussion Module

Development and Programming

Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

Hello, I need to check which member_group a person is then display appropriate hard coded forum, link and description.

I have created my own index.php file for the discussion forum so I can have discussion forums display a description and the job posting boards to just have single line titles (because there are so many.)

On the last box of Discussion forums I want to only show the chat forum for there specific group (which I will hard code the forum title, link and description.)

{if member_group == "1"} 
<a href="#">Admins chat board</a>
description
{if:else member_group == "2"} 
<a href="#">Graphic Artist chat board</a>
description
{if:else member_group == "3"} 
<a href="#">Programmers chat board</a>
description
{/if}

but in php

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

Is no one commenting on this because it’s one of those “wicked” easy ones I’ve boggled my self on, or because it’s to tough?

I’m looking at hacking the actual module for the forums for this? Correct?

If () statements aren’t parsing simple commands at all?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

1) Why are you using a modified index.php file for the discussion forums? This sounds like something you can accomplish in your themes, as the index.php file is not one you want to modify.

2) You are correct that conditionals are not parsed in the forum themes, except for the conditionals that there are specific handlers for (like those that you see in the default themes). You have some options that don’t require a hack. One is to run the forums through the regular template engine, which will allow for conditionals you have above. Another is to enable PHP in the discussion forums, and use $SESS->userdata[‘group_id’] in PHP conditionals.

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

Hello Mr. Jones, Thank you for responding;

Why are you using a modified index.php file for the discussion forums? This sounds like something you can accomplish in your themes, as the index.php file is not one you want to modify.

Well, there are several reasons and I’ll attempt to explain the major ones. a) The emulation look of the “All” forum Categories and there groups looks just like that of individual Categories and there groups, so I thought I would utilize the forums landing page (index.php [“all” showing]) for more content. b) Utilization of the landing page for better SEO stepping, leading not just to categories but also other areas of the website (which I have not utilized just yet [will be building this off of what the freelancers would like on the landing.]) c) Their are (and will be more) a large number of boards for employers/sub-contractors to post gigs/projects in, so having just single line titles helps with making a little more room for future content and to save users from having to scroll way down to get to their corresponding board. d) I don’t use EXP: (template embeding) for the forums for several reasons which need not be explained here. e) Sense the next version will be 2.0 I see no reason to not hack up the 1.6+ version lol. (I’ll utilize the 2.+ version for the next ver. of fjf a few years down the line.)

You are correct that conditionals are not parsed in the forum themes, except for the conditionals that there are specific handlers for (like those that you see in the default themes). You have some options that don’t require a hack. One is to run the forums through the regular template engine, which will allow for conditionals you have above. Another is to enable PHP in the discussion forums, and use $SESS->userdata[’group_id’] in PHP conditionals.

Ahh! that may be the answer.. I did hard code a function utilizing the $SESS, and of course did not work, but from what you’ve mentioned above may work by enable php?.. is this in reference to EXP in templates? or is this as it stands alone?

Thank you in advance.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Corvaire, I still see absolutely nothing about what you are saying that would require or even make it a good idea to modify your index.php file. You should be building all of your content in your themes and/or templates.

Yes, you must enable PHP parsing for the forums in the board preferences.

<?php
global $SESS;

if ($SESS->userdata['group_id'] == 1):?>
    You are a Super Admin
<?php elseif($SESS->userdata['group_id'] == 5): ?>
   You are a member
<?php endif; ?>
       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

Thank you Mr. Jones, I will give this a go.

I am using the index.php file in the forums theme folder. Is that what your referring to?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Do you mean your theme_index.php file? That’s fine, as that is a forum template. It sounded like you were referring to your ExpressionEngine index.php file.

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

Yes, the theme one, sorry for the confusion.

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

embeding the function with in my td tags:

{include:chat_forums}

and creating a function with your suggestion:



when I saw it was wrapped with the php I realized this probably wouldn’t work because it’s with in a php tag already. I tested and of course have an error for each php wrap. Where should I go from now?

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

I get three “Undefined variable: SESS” errors

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

Well, gave a shot at throwing this into the mod file and declaring the function for the index_theme class name.. then realized (once I got the errors) can’t use the html in the mod file.

How do I keep the html from not parcing until it’s reached the theme_index file?

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

can I use this:

$LANG->line('group 1 html');

then add corresponding language calls with html included?

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

Well, that didn’t work.. How about this? adjustments I should make? Comes back no errors, but displays nothing:

//-------------------------------------
//  Chat Forums
//-------------------------------------

function chat_forums()
{
   global $SESS;

if ($SESS->userdata['group_id'] == 1)
{
    $line = 'Group ONE';
    }
elseif($SESS->userdata['group_id'] == 2)
{
    $line = 'Group TWO';
}
    
}
/* END */

I put this in the mod.forums file and included the function in the cell I need it in.

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

I GOT IT WOOT!!

//-------------------------------------
//  Chat Forums
//-------------------------------------

function chat_forums()
{
   global $SESS;
   
        $str = '';

if ($SESS->userdata['group_id'] == 1)
{
    $str .= 'Group ONE';
    }
elseif($SESS->userdata['group_id'] == 2)
{
    $str .= 'Group TWO';
}

        
        return $str;
    
}
/* END */

Yes, it does hold html!! Don’t forget to define the function as shown below; “into the mod file and declaring the function for the index_theme class name”

       
Corvaire Wind's avatar
Corvaire Wind
60 posts
17 years ago
Corvaire Wind's avatar Corvaire Wind

Thank you very much Derek for setting me on the right path.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.