News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Expert SSI FAQ

Started by Tomer, June 28, 2004, 07:31:34 PM

Previous topic - Next topic

Tomer

Expert SSI FAQ

Hello and welcome to the Expert SSI FAQ, in this FAQ you will learn expert stuff with SSI, this FAQ is written assuming you have already read the 'Basic SSI FAQ' and 'Advanced SSI FAQ'. This FAQ has commonly asked SSI questions as well as tips and tricks, you will also find a list of attached scripts to the end of this post that may help you with what you have learned in this FAQ. If at the end you still have questions or comments, please post them.
Your feedback if very imporant to me.

**PLEASE DO NOT EDIT YOUR 'SSI.PHP' FILE**
Everything done here is done without having to edit 'SSI.php'


How can I check if a user is part of a special membergroup?

We have already learned how to tell if a person is a guest, user or admin, but now we can also check if a user is part of a special membergorup, lets take an example to help us out:

Example:

You have a site, and a forum, and you have made a special membergroup where some users are part of, you want that membergroup to have access to a special page, and other users will see an error message.

This can be easily done, first, you need to know that special membergroup ID, go to 'Edit Membergroups', in your admin center, there you should see your membergroup, click on the 'Modify' link of your membergroup, then in the URL you should see something like this: 'action=membergroups;sa=edit;id=#'.
You should see a number istead of the blue '#' shown, that number is that membergroup ID.

Now that you got the membergroup ID, we can continue. This is the code we will be using:
We are assuming that id=9 is our special membergroup for our example!


<?php

if (in_array(9$user_info['groups']))
   {
       echo 
'Yay! Im in group 9!';
   }
else
   {
       echo 
'We are sorry, it seems you dont have access to this page.';
   }

?>



Well thats how you can do that, you guys know the rest!  :P


Is there anything else?

Glad you asked, because just so happens as there is some more, SSI has some advanced configuration that you can define with a simple code, here are the configurations that you can change.

$ssi_gzip = 'true/false';
$ssi_ban = 'true/false';
$ssi_theme = 'themeID#';
$ssi_layers = array('main');

Simple write these variables in your SSI page before the incude statment, here is a working example:

<?php

$ssi_gzip 
false;
$ssi_ban true;
$ssi_theme '2';
$ssi_layers = array('main');

ob_start();

require(
"/SSI.php");

?>



Lets explain the above code:

$ssi_gzip = false; means gzip is turned off.
$ssi_ban = true; means a banned forum user will be banned also in the SSI page.
$ssi_theme = '2'; uses the theme [images, buttons, colors] with ID=2, which usually is classic theme.
$ssi_layers = array('main'); uses the pair of main sub templates.
ob_start(); is needed not to get errors.
require("/SSI.php"); note its after the variables, but before any output.

Dont worry if it looks a bit hard, this is the expert faq. :) Just experiment with it and you will get the hang of it.




Well this pretty much covers the expert Guide, dont quote me on this, but maybe i'll write a Master SSI FAQ later on.

Attached to the end of this post are some sample scripts that may help you out.

None Yet
[/list]

If this FAQ has helped you in any way please post in this thread your opinions of it, what was unclear, confusing...etc
Your feedback is very important to me. :)

Thanks

-Lamper

Owdy

Good job dude ;)

Quote from: Lamper on June 28, 2004, 07:31:34 PM

Well this pretty much covers the expert Guide, dont quote me on this, but maybe i'll write a Master SSI FAQ later on.

[offtopic]
LOL, what comes after 'Master'? SuperHero SSI FAQ?  :P  ;D
[/offtopic]
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Tomer

#2
Quote from: Owdy on June 28, 2004, 07:38:17 PM
Good job dude ;)

[offtopic]
LOL, what comes after 'Master'? SuperHero SSI FAQ?  :P  ;D
[/offtopic]


Thanks!

No that will be the last one [if I make it] and if theres more SSI stuff added I will also make a Intermediate SSI FAQ so the order will be this:

Basic >>> Intermediate >>> Advanced >>> Expert >>> Master.

Like on Pogo.com  8)

Cerberus

Best Regards, Cerberus
YaBB Gold -> YaBB 1.1 -> YaBB SE (YaPP -> PfaBB) -> SMF
Pocket PC Russia

Tomer


LaurieC

Thank you, thank you, thank you! I have read all of the SSI FAQS and I think I am finally getting the hang of it! Can't wait for more  :)
Make someone smile today...

Tomer

Dont think that will happen... :(

Nothing more the explain.

Elissen

Quote from: Tomer Dean on August 09, 2004, 05:26:01 PM
Dont think that will happen... :(

Nothing more the explain.
You sure? You can do some funky stuff with the template system and SSI ;)

Tomer

You talking about the ssi_layers?

Elissen

Nope, creating your own "sub"-templates (like BoardIndex.template.php) and load those. The template system that SMF uses is very flexible and you split your logic from the apperance (template/theme). Being able to use that system on your SSI-powered pages is very nice to work with.

Also, more (internal) functions would be nice (like db_query, is_admin, is_loggedin). A lot can be learned from reading SSI.php, but still, explanations on what, why and how are always good.

Your FAQ's are excellent. I find them very thorough. This just might be an interesting addition.

Elissen

Example of what I mean.

regions.php
<?php
$ssi_gzip 
1;
$ssi_ban 1;

ob_start();

include_once 
'../forum/SSI.php';
include_once 
'customhelper.php';

global 
$context;

loadTemplate('eli_map_regions');
$context['linktree'][] = array(
        'url' => '/map',
        'name' => "Map"
        );

$context['page_title'] = "Regions";
$context['factions'] = loadFactions();

$res db_query("SELECT *
                FROM map_regions
                ORDER BY regionName"
__FILE____LINE__);
$context['regions'] = array();
while (
$row mysql_fetch_assoc($res))
        $context['regions'][] = array(
                'name' => $row['regionName'],
                'faction' => $row['factionID'],
                'id' => $row['regionID']
                );
mysql_free_result($res);

obExit();
?>

loadFactions() loads another table. It is used in more files so hence the function.
loadTemplate('eli_map_regions'); loads a custom (sub-)template. I prefix mine with eli_ so I won't run into problems with mods or future additions to SMF.

Themes/default/eli_map_regions.template.php
<?php

function template_main()
{
        global $context$settings$options$scripturl$txt;

        // Show the link tree.
        echo '
                <table width="100%" cellpadding="3" cellspacing="0">
                        <tr>
                                <td>'
theme_linktree(), '</td>
                        </tr>
                </table>'
;
        // Tha content
        echo '<table width="100%" cellpadding="6" cellspacing="0" border="0" class="tborder" style="margin-bottom: 1ex;">
                <tr>
                        <td align="left" class="catbg" width="100%" height="24">Regions</td>
                </tr>
        </table>
        <table border="0" cellspacing="1" cellpadding="4" align="center" width="100%" class="bordercolor">
                <tr class="titlebg">
                        <td>Region</td>
                        <td>Faction</td>
                </tr>'
;
        foreach ($context['regions'] as $r) {
                echo '<tr class="windowbg2">
                        <td><a href="constellations.php?regionID=' 
$r['id'] . '">' htmlentities($r['name']) . '</a></td>
                        <td>'
;
                if (!empty($r['faction']))
                        echo htmlentities($context['factions'][$r['faction']]);
                echo '</td></tr>';
        }
        echo '</table>';

}

?>


result: www.ascend-ind.com/map

About the forum: it is a clan/guild forum of the corporation I am in in EVE Online (clans are called corporations in EVE). The template system will be very important for me in the future. The next major patch, called Shiva will have a decent ingame browser, but it will NOT support javascript. I have done some testing with the alpha/beta version of the client and with a modified theme I can log into the forum. It requires some work, but I will be able to get the whole forum and everything attached, except coppermine maybe, to work in it. Thanks to the template system.
I use the subtemplates in preparation for this since I can just make a new subtemplate in the folder of the special theme for the ingame browser if the "normal" one doesn't work or looks ugly.

Long read maybe, but I hope this is usefull for somebody

Totally off-topic, if you want a 7-day trail send me a PM with your e-mail address :P Every player can give out those trials

LaurieC

#11
I have managed to get a page working with the great information here in the ssi faq and now I am hooked.

I have a question. The page is for our charter members and I used this
<?php

if (in_array(9$user_info['groups']))
   {
       echo 'Yay! Im in group 9!';
   }
else
   {
       echo 'We are sorry, it seems you dont have access to this page.';
   }

?>


my question is how or what do you add so that the admin will also be able to access the page?

Lace


woops Link to page
Make someone smile today...

Metho

<?php

if (in_array(9$user_info['groups']) || $context['user']['is_admin'])
   {
       echo 
'Yay! Im in group 9!';
   }
else
   {
       echo 
'We are sorry, it seems you dont have access to this page.';
   }

?>


Believe that should work.

- Methonis
Joshua "Methonis" Frazer
Support Specialist
The Simple Machines Team

LaurieC

Like a charm  ;)

Thank you Metho.....

Lace
Make someone smile today...

Superboy

Hi everyone,
I have tiried to get this:
<?php
require("/Library/WebServer/Documents/goosesoft/forum/SSI.php"); 

if (
$context['user']['is_guest'])
{
   echo 
   
'<h5>Access Denied</h5>
   We are sorry guest, it seems you dont have premission to view these downloads.'
;
}
else
{
   echo
   
'<h5>Welcome '$context['user']['name'], '!</h5>
   Here are your downloads:'
;
}



?>



to work with my forum. All of the other tags like <?php ssi_recentPosts(); ?> work fine. Also, if I do get this working, is there a way to list downloads after the "Here are your downloads:" bit or redirect them to another page?

Thanks! :)
Windows (n): 32 bit extension and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company that can't stand 1 bit of competition.

Tomer

Quote from: Superboy on November 02, 2004, 03:33:24 PM
Hi everyone,
I have tiried to get this:
<?php
require("/Library/WebServer/Documents/goosesoft/forum/SSI.php"); 

if (
$context['user']['is_guest'])
{
   echo 
   
'<h5>Access Denied</h5>
   We are sorry guest, it seems you dont have premission to view these downloads.'
;
}
else
{
   echo
   
'<h5>Welcome '$context['user']['name'], '!</h5>
   Here are your downloads:'
;
}



?>



to work with my forum. All of the other tags like <?php ssi_recentPosts(); ?> work fine. Also, if I do get this working, is there a way to list downloads after the "Here are your downloads:" bit or redirect them to another page?

Thanks! :)

Does it work for you?

The part about the downloads was an example, you can change the download part to anything you want, remember, everything inside the "else" will be done if user is logged in.

If you want logged in users to be redirected to another page, use this:


<?php
require("/Library/WebServer/Documents/goosesoft/forum/SSI.php");

if (!
$context['user']['is_guest'])
{
   
header("Location: www.your-page.com");
}



?>


Superboy

Thanks for your reply :)

Sorry, for some reason i seemed to miss out the part that actually said that it wouldn't work...  :-\

I have tried the code you have written but I only get a blank page.

Here is the URL to the page: http://brazil2005.dyndns.org/goosesoft/test.php

Thanks for the help! :)
Windows (n): 32 bit extension and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company that can't stand 1 bit of competition.

[Unknown]

Don't do that... use:

if ($context['user']['is_guest'])
   redirectexit('http://www.google.com/';, false);

Or similar...

-[Unknown]

Superboy

Windows (n): 32 bit extension and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company that can't stand 1 bit of competition.

Superboy

Anyone have any suggestions...? Please...? :)
Windows (n): 32 bit extension and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company that can't stand 1 bit of competition.

Advertisement: