News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Advanced SSI FAQ

Started by Tomer, June 24, 2004, 05:47:39 PM

Previous topic - Next topic

Tomer

Advanced SSI FAQ

Hello and welcome to the Advanced SSI FAQ, in this FAQ you will learn the more advanced uses of SSI, this FAQ is written assuming you have already read the 'Basic 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 Edit Functions for my Needs?

A common question, if you can edit functions to fit your specific needs, and the answer is, EASILY!
Lets take an example to help us out:

Example:

You have a site, and also a forum, and on your main page you are using the ssi functions, 'ssi_boardNews' which displays the first post from threads in a ceratin board from your forum onto the page, you want to configure the function so that it only takes the first post of the thread from a certain board [Your announcements board], and that it wont display more then 5 threads so your page wont be too long, you also want that if the post is too long it will shorten it to save room, lets say, 250 characters long.

So most of would probaly think this is impossible to achieve and need [Unknown] to help you write this code, but no, you can do this in minutes very eaily, and I will explain how.

You are probaly used to displaying a function on a page like so: 'functionName();' but if you want to configure the function, you must send along some paramters along with the function.
This specific function, 'ssi_boardNews' takes the following parameters:


<?php

ssi_boardNews
($board null$limit null$start null$length null$output_method 'echo');

?>



All you need to do is to change these paramters to your needs, and in our case, change them like this:

Assuming board 5.0 is the board you want to take the posts from

<?php

ssi_boardNews
($board 5.0$limit 5$start null$length 250$output_method 'echo');

?>



    And that is the code you need to write in your page to get it working.


    • $board = 5.0 - It takes the first post of the thread from board with the ID of 5.0
    • $limit = 5 - Limits the number of posts to take to 5. [It will take the 5 newest ones]
    • $start = null -  You can leave this as is.
    • $length = 250 - Limits the number of characters per post to 250.
    • $output_method = 'echo' - You can leave this as is.

    Copy that code into your main page, and walla, you have exactly what you wanted.

    Most of the functions in 'SSI.php' work with paramters that can be easily modified as so.



How is a function built?

Please dont skip this part as in is vital knowing to answer the future questions.

The functions in 'SSI.php' are built like so:

Dont feel bad if you dont understand all of this.
1) The function is named and opened.
2) We connect to the MySQL databse.
3) We extract the information we need for the function.
4) We put the information extracted in variables and arrays.
5) We display the information.

This information will help us in the next question, 'How Can I Only Display a Certain Part of a Function?'.


How Can I Only Display a Certain Part of a Function?

Another common question, how do I only display a certain part of a function? This is very easily done without the need of editing 'SSI.php' at allLets take an example to help us out, I will use the same function as before, 'ssi_boardNews'

Example:

I have the function 'ssi_boardNews' displayed on my main page of my site using SSI, I only want to display the title of the thread and the body of the message, no fancy little icons and dates.

Now that we know how a function is built, modifying it for out needs is easy. This is part of the 'ssi_boardNews' function, the part that displays the information.



[/list]
foreach ($return as $news)
{
echo '
<table border="0" width="100%" align="center" class="ssi_table">
<tr>
<td>', $news['icon'], ' <b>', $news['subject'], '</b><span class="smaller"><br />', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '<br /><br /></span></td>
</tr>
<tr>
<td>', $news['body'], '<br /><br /></td>
</tr>
<tr>
<td>', $news['link'], ' | ', $news['new_comment'], '</td>
</tr>
</table>
<br />';

if (!$news['is_last'])
echo '
<hr width="100%" />
<br />';
}


The first section in this part says 'foreach ($return as $news)' meaning for every thread there is it will run the code in between the brackets.

So we need to take everything out exept for the topic name and topic body, this is the code needed to write on a page to display only the thread name and body and also limit the threads from coming only from a special board [board ID=5.0], limits the number to 5 posts, and makes sure every post is no more then 250 characters..[Note that the output method has changed.].

<?php

$array ssi_boardNews(5.05null250'array');

foreach ($array as $news)
{
echo '
<table border="0" width="100%" align="center" class="ssi_table">
<tr>
<td><b>'
$news['subject'], '</b></td>
</tr>
<tr>
<td>'
$news['body'], '<br /><br /></td>
</tr>
</table>
<br />'
;

if (!$news['is_last'])
echo '
<hr width="100%" />
<br />'
;
}

?>



That should display only the topic title and body, you can also remove or add some '<br />'s to make it fit! [<br /> makes a new line[/i].

Most of the functions work along this line, so I hope this helps.


Well this pretty much covers the advanced Guide, the next guide will be: 'Expert SSI FAQ'.

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

[Unknown]

I just skimmed, but everything mentioned here DOES NOT REQUIRE editing SSI.php, and that is BY FAR the very very WORST WAY of making these changes, especially because it makes upgrading more difficult when it DOESN'T HAVE TO.

-[Unknown]

Tomer

#2
How can you take out the icons, time, date, poster name and all that stuff and only leave the topic name and body without editing SSI.php? [ssi_boardNews]

I've heard something about how this is possible with a alternative output method, how does that work?
Is it somthing with gzip?

[Unknown]

> ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')

To get from a specific board and display it specially, CALL it like this:

$array = ssi_boardNews(5, null, null, null, 'array');

foreach ($array as $news)
{
echo '
<table border="0" width="100%" align="center" class="ssi_table">
<tr>
<td><b>', $news['subject'], '</b></td>
</tr>
<tr>
<td>', $news['body'], '<br /><br /></td>
</tr>
</table>
<br />';

if (!$news['is_last'])
echo '
<hr width="100%" />
<br />';
}


This requires zero modifications in SSI.php.

-[Unknown]

dracomiconia

Hi.

I have worked with both systems, and I prefer [Unknown] one, only cause you dont work on SSI.php. If u upgrade, u would have to re-do all the code in each upgrade...

One question. I have taken this [Unknown] code, but, how do u add a link to the post? It is because I only show some of the body...

[Unknown]

Change $news['subject'] to $news['link'].

-[Unknown]

dracomiconia

I think I didn't explained well...

I mean something like this:

<a href=[u]topic[/u]>$news['subject'] </a>

Elissen

echo '<a href="', $news['link'], '">', $news['subject'], '</a>';

This what you mean? (I assume $news['link'] only contains a url)

dracomiconia

No, $news['link'] has more than an URL, and I dont want to change SSI.php for updates....

I dont know if it is possible to make an SSImine.php, and call it as SSI.php

I could make this to change it.

Elissen

Sorry, my fault. I made an assumption ::)

if you put this in you can see what is actually IN the news-array:
print_r($news);

So, what you want is this:
echo '<a href="', $news['href'], '">', $news['subject'], '</a><br />';

dracomiconia


Tomer

Quote from: [Unknown] on June 24, 2004, 06:58:26 PM
> ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')

To get from a specific board and display it specially, CALL it like this:

$array = ssi_boardNews(5, null, null, null, 'array');

foreach ($array as $news)
{
echo '
<table border="0" width="100%" align="center" class="ssi_table">
<tr>
<td><b>', $news['subject'], '</b></td>
</tr>
<tr>
<td>', $news['body'], '<br /><br /></td>
</tr>
</table>
<br />';

if (!$news['is_last'])
echo '
<hr width="100%" />
<br />';
}


This requires zero modifications in SSI.php.

-[Unknown]

Thanks for that, didint know you can do that.

I updated the FAQ.

mcdougrs

Magnifico!!! BRAVO!!! I can't WAIT for the Expert installment.

Tomer


bojzi

great faq!

I program in php for about a year now and understand the ssi file pretty good and could do an alteration but, here's my question: would it be possible to display the user's avatar who posted the news? i could do it easily by adding one more element to the array in the ssi.php file, but is there a way since the news array doesn't contain the avatar part?

thx!
The mind is like a parachute, it only works if it's open.

Tomer

No, the news array doesnt include a members avatar. :)

If you like this FAQ, try also the Basic and Expert SSI FAQ's.

bojzi

seen them all, they all rule! ;)

maybe we should point out to the development team that they should put in  the option of displaying the member's avatar in the news postings because it was very popular way back in 2000 when me and my friends tried to install it on Grant Willams' News Publisher and did it... I think that that would be a really nice thing to do since I don't see it on other forum/portal solutions that much...

One more question to you (if it's not to much :) )
Is it possible to make a board which contains polls posted by mods and admins (that part is already done) and then post only the latest poll in that board with SSI?
The mind is like a parachute, it only works if it's open.

Elijah Bliss

before I start designing my portal, I would like to know if the following is possible:

Separate from the message board, I want to have a page with current events. I want to have it so that the latest 5-10 threads from a specific poster show up on the page instead of the latest threads of a board.

Is that possible?

bojzi

yep, it's possible... just use the knowledge gained in this faq:

make a $array variable like this and declare the variable with the posters name or id:

$posts = ssi_recentPosts($num_recent = 8, $exclude_boards = array(), $output_method = 'array');
$name = bert;
$id = 15;


then use that array to loop from it:

foreach ($posts as $post) {

the values of the posts array contain a member_id that is used as $post['id'] or you can use $post['name'] to test and print if the post is from that exact user:

if ($post['poster']['name'] == $name) {

or

if ($post['poster']['id'] == $id) {


and after that, just add the post something like this (but, of course, use your layout and use tables):

$post['subject'];?> written by <?php $row['poster']['link'];
    //close the if statement

//close the foreach statement


The list of values that you can use what to display of the post is in the SSI.php file lines 233-254. And you can use the ssi_recentTopics() function in SSI the same way. :) hope i helped :)
The mind is like a parachute, it only works if it's open.

Elijah Bliss

Quote from: bojzi on June 30, 2004, 04:22:27 AM
yep, it's possible... just use the knowledge gained in this faq:

make a $array variable like this and declare the variable with the posters name or id:

$posts = ssi_recentPosts($num_recent = 8, $exclude_boards = array(), $output_method = 'array');
$name = bert;
$id = 15;


then use that array to loop from it:

foreach ($posts as $post) {

the values of the posts array contain a member_id that is used as $post['id'] or you can use $post['name'] to test and print if the post is from that exact user:

if ($post['poster']['name'] == $name) {

or

if ($post['poster']['id'] == $id) {


and after that, just add the post something like this (but, of course, use your layout and use tables):

$post['subject'];?> written by <?php $row['poster']['link'];
    //close the if statement

//close the foreach statement


The list of values that you can use what to display of the post is in the SSI.php file lines 233-254. And you can use the ssi_recentTopics() function in SSI the same way. :) hope i helped :)

Can't get it to work. The poster's name is not showing up and neither are her topics alone. Here's my code so far:

$posts = ssi_recentPosts($num_recent = 25, $exclude_boards = array(), $output_method = 'array');
$name = MsHoney;


  foreach ($posts as $post)
     {
                echo '
                       <table border="0" width="100%" align="center" class="ssi_table">
                            <tr>
                                        <td><b>', $post['name'], '</b></td>
                              </tr>
                                <tr>
                                        <td>', $post['subject'], '<br /><br /></td>
                                       
                            </tr>
                        </table>
                        <br />';

               if ($post['poster']['name'] == $name) {
                      $row['poster']['link'];
       }
}

Advertisement: