Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
straytalk
New Member
New Member


Joined: Aug 13, 2006
Posts: 14

PostPosted: Sun Aug 13, 2006 11:42 pm Reply with quote

Ok im trying to make a simple block for navigation. The not so simple part is I want it to change based apon your status. So if you not logged in you see a navigation block, if your registered you see a different and if you in a group you see a different. And I don't want people too see each others. I tried using the admin panel but if i do it that way people in group A also see the registered navigation as well as their own.

Does anyone know of some script that has a functionality simlar to this i can model my block after? Or a work around or somthing?

thanks in advance
Straytalk
 
View user's profile Send private message
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Mon Aug 14, 2006 12:42 am Reply with quote

You can use NSN Groups to set visibility per group. But perhaps it would be easier for one block to just use some code to do this

Code:


if (is_user($user)) {

.. show block..

} elseif (in_group($user)) {

.. show block 2...

} else {

.. show block 3 ..

}


That's some pseudo-code, may not actually work like that exactly. But hope it gives you the general idea

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
straytalk
PostPosted: Tue Aug 15, 2006 4:54 pm Reply with quote

Alright, know I recall you have to have set blocks up differently if your going to use php in them as opposed to plain text or HTML, this would be the first block I've done in php. Anyone have a link or some basic instructions on going about this?
 
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9456
Location: Arizona

PostPosted: Wed Aug 16, 2006 6:27 am Reply with quote

Not sure any more what documentation to recommend. Personally, I would take one of the blocks in the blocks folder and model after that. The absolutely most critical thing to "take-away" from reviewing those block scripts is that you should do this at the beginning:

$content = '';

And then you continue to add your HTML into the $content string. You do NOT echo the HTML out to the browser. PHP-Nuke will take care of echoing the contents of the $content string after your script ends.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
straytalk
PostPosted: Wed Aug 16, 2006 2:56 pm Reply with quote

well i guess my php is far more rusty then I thought that or I still need to figure out how to make my scripts properly work in nuke. I poked around the block files I have and using evaders99 code i really quickly wiped up this little test block to see if it works before I go and do the rest of the work

the code looks like this
Code:
<?php

if ( !defined('BLOCK_FILE') ) {
    Header("Location: ../index.php");
    die();
}

global $user;

if (is_user($user)) {

$content = <b>1</b>

} elseif (in_group($user)) {

$content .= <i>2</i>

} else {

$content .= <p>3</p>

}
?>


and rather then getting some error message of some sort it screws up the site so that all the blocks on the left got pushed over to the right and all pages were blank. Had to delete the block file to use the site again. I used to do php a few years back nothing serious stopped and now picking it back up it appears i really have forgotten almost all of it.
 
montego
PostPosted: Thu Aug 17, 2006 6:12 am Reply with quote

Does the following work?

Code:


<?php
if ( !defined('BLOCK_FILE') ) {
    Header("Location: ../index.php");
    die();
}

global $user;

if (is_user($user)) {

$content = '<b>1</b>';

} elseif (in_group($user)) {

$content = '<i>2</i>';

} else {

$content = '<p>3</p>';

}
?>


Wink

NOTE: I edited this just now as I forgot to remove the "." in front of the assignment on two of the lines.
 
montego
PostPosted: Thu Aug 17, 2006 6:14 am Reply with quote

By the way, remember what I said about first initializing the $content variable to ''? When you finalize this block, I would do that right after your global statement and before any other code.
 
straytalk
PostPosted: Thu Aug 17, 2006 12:39 pm Reply with quote

Everything works now, see i was so rusty i forgot quotes and semicolons Razz I had to re order it so it would check to see if your in a group first otherwise it would just give you the registered user one instead of a group one. I threw in some comments so if there are any other users who either have forgotten all their php or never learned here they can use this because I think it is a useful little scripit at least for what im doing.
Code:
<?php

if ( !defined('BLOCK_FILE') ) {
    Header("Location: ../index.php");
    die();
}

global $user;

if (in_group($user)) {
//content here will be seen only by those in a group.
$content = '<b>group content here</b>';

} elseif (is_user($user)) {
//content here will only be seen by registered users not in a group.
$content = '<i>registered content here</i>';

} else {
//unregistred users can only see this.
$content = '<p>unregistered content here</p>';

}
?>

thanks for the help montego
 
montego
PostPosted: Fri Aug 18, 2006 6:45 am Reply with quote

Anytime. Glad to help.
 
straytalk
PostPosted: Mon Sep 04, 2006 2:13 am Reply with quote

I have one more request. I have since added and additional section I guess you'd call it. What would be the line of code to also have a seperate navigation bar for users that are subscribed?
 
evaders99
PostPosted: Wed Sep 06, 2006 12:37 pm Reply with quote

I believe the function to check for subscribed users is paid()
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©