3.1  Tutorial: Create a personalized homepage

The SDK comes with a function called md_get_forum_cat_infos which retrieves the necessary information when creating a personalized homepage for the forum

This function requires certain variables that we will detail

md_get_forum_cat_infos( string $current_forum, int $cat, bool $registered, bool $use_current_db, resource $dbhr, resource $dbhw, [$add_field = ''])

The function returns a MySQl object that contains a certain number of variables that we will progressively study

(locked, cat_number, name, name_supercat, url_name, password, visible, link, target_cat, target_forum_id, use_current_forum, auto_redirect, allow_anonymous_posting, apriori_cat, orderby_creation)

At first, we will only retrieve the name

In our example we will create an original layout displaying the categories

<?php

include('include/initialize.php');
include('include/common_func.php');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Original presentation</title>
<style type="text/css">
html * {
    margin:0;
    padding:0;    
}
body {
    background-color:#333;
    padding-top:20px;
}
#listingcategorie {
    position:absolute;
    display:block;
    text-align:center;
    width:650px;
    left:50%;
    margin-left:-325px;
    background-color:#f00;    
    border:2px solid #fff;
}
#listingcategorie li {
    display:block;
    font-family:"Trebushet MS",Verdana,Arial;
    width:200px;
    height:50px;
    background-color:#000;
    color:#fff;
    border:3px solid #555;    
    float:left;    
    margin:5px;
}
</style>
</head>
<body>
<?php

$get_cat_infos= md_get_forum_cat_infos($md_db_extension,NULL,1,1,$dbhr,$dbhw);
    
echo '<ul id="listingcategorie">';    
    
while (list(,,$nom)=md_mysqlw_fetch_row($get_cat_infos)) {
    echo '<li>',$nom,'</li>';
}

echo '</ul>';
?>
</body>
</html>

On the screen, it should look like:

Now we want the names to be replaced by link in order to access those categories

In order to do so, we use the function md_get_url_forum1 by which we get the url to access a particular category

This function requires a certain number of parameters but a lot of them are optional and since we want to show you a quick example, we will not describe those over here. For more details , please refer to the complete SDK guide.

The function (without its optional parameters) : md_get_url_forum1( bool $modrewrite, string $forum_rewritten_name, bool $default, int $cat, string $cat_nom);

Now, we are going to modify our program according to those changes. We will first edit the CSS part to attribute values to textual elements that will become links

#listingcategorie a {
    color:#bbf;
    text-decoration:none;    
}
#listingcategorie a:hover {
    color:#fff;
    text-decoration:underline;    
}

Then we modify the category fetching process for

while (list(,$numero,$nom,,$url_nom,)=md_mysqlw_fetch_row($get_cat_infos)) {
    echo '<li><a href="',md_get_url_forum1(md_modrewrite,$md_db_extension,0,$numero,$url_nom),'">',$nom,'</a></li>';
}

We should come up with something like this. The names of the categories have been transformed into links. Clicking on a link will redirect you to the associated category topic list.

Now we want to display the author and the date of the last posted message in each category

In order to do so, we will use the SDK function md_get_forum_post_infos which provides information about categories last messages.

md_get_forum_post_infos( string $current_forum, int $cat, bool $use_current_db, resource $dbhr, resource $dbhw)

This function requires a certain number of parameters.

This function will return a 2-dimension table containing the pseudo of the last author, the ID of the last reply, the date of the last message and the total number of messages for this category.

We will start by modifying the CSS. We will slightly enlarge the height of the blocs and then define a layout for the HTML tag p (paragraph)

#listingcategorie li {
    display:block;
    font-family:"Trebushet MS",Verdana,Arial;
    width:200px;
    height:70px;
    background-color:#000;
    color:#fff;
    border:3px solid #555;    
    float:left;    
    margin:5px;
}
#listingcategorie p {
    font-size:10px;
    padding-bottom:5px;    
}

Then we add the calling function and we modify our loop to display the our infos.

$get_infos_last_message= md_get_forum_post_infos($md_db_extension,NULL,md_one_database, $dbhr, $dbhw);

$get_cat_infos= md_get_forum_cat_infos($md_db_extension,NULL,1,1,$dbhr,$dbhw);
    
echo '<ul id="listingcategorie">';    
    
while (list(,$numero,$nom,,$url_nom,)=md_mysqlw_fetch_row($get_cat_infos)) {
    echo '<li><a href="',md_get_url_forum1(md_modrewrite,$md_db_extension,0,$numero,$url_nom),'">',$nom,'</a>';
    
    list($lastPosteur,$numreponse,$datelast,$total)= $get_infos_last_message[$numero];
    echo '<p>',$total,' messages</p><p>',$lastPosteur,'<br />',$datelast,'</p>';
    echo '</li>';
}

echo '</ul>';

You should get something that looks like:

Now let's put some useful pieces of information:

First, we add a bloc around our list of categories, and then we will display the total number of messages on the forum. This is actually quite simple and no SDK function is needed. Simply memorize each category total number of messages and display the result.

while (list(,$numero,$nom,,$url_nom,)=md_mysqlw_fetch_row($get_cat_infos)) {
    echo '<li><a href="',md_get_url_forum1(md_modrewrite,$md_db_extension,0,$numero,$url_nom),'">',$nom,'</a>';
    
    list($lastPosteur,$numreponse,$datelast,$total)= $get_infos_last_message[$numero];
    $totalmessages+= $total;
    echo '<p>',$total,' messages</p><p>',$lastPosteur,'<br />',$datelast,'</p>';
    echo '</li>';
}
echo '</ul>';
echo '<p style="color:#fff">Nombre total de message : ',$totalmessages,'</p>';

Also, we want to display the pseudo of the current member. For this purpose, Initialize provides the variable $user, if $user is empty, we know that the user is not logged in. We can therefore suggest him to log in.

echo '<p>';
if (empty($md_user)) {
    echo '<a href="login.php?config=',$config,'">Identification</a>';    
} else {
    echo 'Bonjour ',$md_user;    
}
echo '</p>';

We edit our CSS to wrap the whole thing and we get something like this:

Here we are! This is our personalized homepage. Though the design might be tasteless, at least, it shows you the possibilities. Here is the final code by which we obtain what is shown above

<?php

include('include/initialize.php');
include('include/common_func.php');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Original presentation</title>
<style type="text/css">
html * {
    margin:0;
    padding:0;
    font-family:Verdana,Arial;
    font-size:12px;    
}
body {
    background-color:#333;
    padding-top:20px;
}
#listingcategorie {
    position:absolute;
    display:block;
    text-align:center;
    width:650px;
    left:50%;
    margin-left:-325px;
    background-color:#f00;    
    border:2px solid #fff;
}
#listingcategorie li {
    display:block;
    font-family:"Trebushet MS",Verdana,Arial;
    width:200px;
    height:70px;
    background-color:#000;
    color:#fff;
    border:3px solid #555;    
    float:left;    
    margin:5px;
}
#listingcategorie p {
    font-size:10px;
    padding-bottom:5px;    
}
#listingcategorie a {
    color:#bbf;
    text-decoration:none;    
}
#listingcategorie a:hover {
    color:#fff;
    text-decoration:underline;    
}
#forum {
    position:absolute;
    display:block;
    width:680px;
    background-color:#8279ff;
    left:50%;
    margin-left:-350px;
    padding:10px;
}
#forum p {
    clear:both;
    color:#fff;
    padding-bottom:5px;    
}
</style>
</head>
<body>
<?php

$get_infos_last_message= md_get_forum_post_infos($md_db_extension,NULL,md_one_database, $dbhr, $dbhw);

$get_cat_infos= md_get_forum_cat_infos($md_db_extension,NULL,1,1,$dbhr,$dbhw);

echo '<div id="forum">';
echo '<p>';
if (empty($md_user)) {
    echo '<a href="login.php?config=',$config,'">Identification</a>';    
} else {
    echo 'Bonjour ',$md_user;    
}
echo '</p>';
echo '<ul id="listingcategorie">';    
$totalmessages= 0;    
while (list(,$numero,$nom,,$url_nom,)=md_mysqlw_fetch_row($get_cat_infos)) {
    echo '<li><a href="',md_get_url_forum1(md_modrewrite,$md_db_extension,0,$numero,$url_nom),'">',$nom,'</a>';
    
    list($lastPosteur,$numreponse,$datelast,$total)= $get_infos_last_message[$numero];
    $totalmessages+= $total;
    echo '<p>',$total,' messages</p><p>',$lastPosteur,'<br />',$datelast,'</p>';
    echo '</li>';
}
echo '</ul>';
echo '<p style="float:right; padding-top:190px">Nombre total de message : ',$totalmessages,'</p>';
echo '</div>';
?>
</body>
</html>

3 SDK Tutorial4 Webservices