VI. Tutoriels communautaires

Ajouter des images sur les catégories du forum

Cet article a été mis à jour, vous consultez ici une archive de cet article!
Dernière mise à jour : 27/07/2014 à 01h40
En cours : Non finalisé et non testé



Ce Tutorial est réalisé pour la version V4.1



Ce tutorial a pour objectif d'ajouter une icône à chaque catégorie de votre forum.



Les numéros de lignes correspondent aux fichiers de la version V4.1.0



La base de donnée


Utiliser le script sql suivant pour ajouter le champ "icon" dans la table forum_cats

Code SQL :
ALTER TABLE `phpboost_forum_cats` ADD `icon` VARCHAR( 255 ) NOT NULL AFTER `url` ;




Les variables de langues


Ajouter dans les fichiers de langue, les deux éléments suivants :

Code PHP :
$LANG['icon_forum'] = 'Icône de la catégorie';
$LANG['icon_forum_explain'] = 'A placer dans le répertoire /forum';




Pour le french : forum\lang\french\forum_french.php





Modification php





admin_forum.php





Ajouter ligne 78 :

Code PHP :
$icon = retrieve(POST, 'icon', '');
$icon_path = retrieve(POST, 'icon_path', '');
if (!empty($icon_path))
$icon = $icon_path;




Remplacer la ligne 97 :

Code PHP :
        $Sql->query_inject("UPDATE " . PREFIX . "forum_cats SET name = '" . $name . "', subname = '" . $subname . "', url = '" . $url . "', status = '" . $status . "', aprob = '" . $aprob . "', auth = '" . addslashes(serialize($array_auth_all)) . "',icon = '" . $icon . "' WHERE id = '" . $id . "'", __LINE__, __FILE__);
 




Remplacer la ligne 265 :

Code PHP :
    $forum_info = $Sql->query_array(PREFIX . "forum_cats", "id_left", "id_right", "level", "name", "subname", "url", "status", "aprob", "auth", "WHERE id = '" . $id . "'", __LINE__, __FILE__);
 




Ajouter ligne 279 :

Code PHP :
    //Images disponibles
    $img_direct_path = (strpos($forum_info['icon'], '/') !== false);
    $rep = './';
    $image_list = '<option value=""' . ($img_direct_path ? ' selected="selected"' : '') . '>--</option>';
    if (is_dir($rep)) //Si le dossier existe
    {
        $img_array = array();
        $dh = @opendir( $rep);
        while (! is_bool($lang = readdir($dh)))
        {
            if (preg_match('`\.(gif|png|jpg|jpeg|tiff)+$`i', $lang))
                $img_array[] = $lang; //On crée un tableau, avec les different fichiers.
        }
        closedir($dh); //On ferme le dossier
 
        foreach ($img_array as $key => $img_path)
        {    
            $selected = $img_path == $forum_info['icon'] ? ' selected="selected"' : '';
            $image_list .= '<option value="' . $img_path . '"' . ($img_direct_path ? '' : $selected) . '>' . $img_path . '</option>';
        }
    }




Ajouter ligne 312 :

Code PHP :
        'IMG_ICON' => !empty($forum_info['icon']) ? '<img src="' . $forum_info['icon'] . '" alt="" class="valign_middle" />' : '',
        'IMG_LIST' => $image_list,
        'IMG_PATH' => $img_direct_path ? $forum_info['icon'] : '',




Ajoute rligne 325 :

Code PHP :
        'L_ICON' => $LANG['icon_forum'],
        'L_ICON_EXPLAIN' => $LANG['icon_forum_explain'],
        'L_OR_DIRECT_PATH' => $LANG['or_direct_path'],




Ajouter ligne 372 :

Code PHP :
        'L_ICON' => $LANG['icon_forum'],
        'L_ICON_EXPLAIN' => $LANG['icon_forum_explain'],
        'L_OR_DIRECT_PATH' => $LANG['or_direct_path'],








admin_forum_add.php





Ajouter ligne 78 :

Code PHP :
$icon = retrieve(POST, 'icon', '');




Remplacer ligne 127 :

Code PHP :
        $Sql->query_inject("INSERT INTO " . PREFIX . "forum_cats (id_left, id_right, level, name, subname, url, nbr_topic, nbr_msg, last_topic_id, status, aprob, auth) VALUES('" . $id_left . "', '" . ($id_left + 1) . "', '" . $level . "', '" . $name . "', '" . $subname . "', '" . $url . "', 0, 0, 0, '" . $status . "', '" . $aprob . "', '" . addslashes(serialize($array_auth_all)) . "')", __LINE__, __FILE__);
 




Ajouter ligne 154 :

Code PHP :
$rep = './';//Images disponibles
    $image_list = '';
    if (is_dir($rep)) //Si le dossier existe
    {
        $img_array = array();
        $dh = @opendir( $rep);
        while (! is_bool($lang = @readdir($dh)))
        {    
            if (preg_match('`\.(gif|png|jpg|jpeg|tiff)+$`i', $lang))
                $img_array[] = $lang; //On crée un tableau, avec les different fichiers.                
        }    
        @closedir($dh); //On ferme le dossier
 
        foreach ($img_array as $key => $img_path)
            $image_list .= '<option value="' . $img_path . '">' . $img_path . '</option>';
    }




Ajouter ligne 167 :

Code PHP :
'IMG_LIST' => $image_list,




Ajouter ligne 186 :

Code PHP :
'L_ICON' => $LANG['icon_forum'],/*Ajout ElenWii*/
        'L_ICON_EXPLAIN' => $LANG['icon_forum_explain'],/*Ajout ElenWii*/
        'L_OR_DIRECT_PATH' => $LANG['or_direct_path'],/*Ajout ElenWii*/






forum_interface.class.php





ajouter ligne 74 :

Code PHP :
$forum_cats .= '$CAT_FORUM[\'' . $row['id'] . '\'][\'icon\'] = ' . var_export($row['icon'], true) . ';' . "\n";




index.php





remplacer ligne 78 :

Code PHP :
$result = $Sql->query_while("SELECT c.id AS cid, c.level, c.name, c.subname, c.url, c.nbr_msg, c.nbr_topic, c.status, c.last_topic_id, t.id AS tid, 
t.idcat, t.title, t.last_timestamp, t.last_user_id, t.last_msg_id, t.nbr_msg AS t_nbr_msg, t.display_msg, m.user_id, m.login, m.user_avatar, v.last_view_id, c.icon
FROM " . PREFIX . "forum_cats c
LEFT JOIN " . PREFIX . "forum_topics t ON t.id = c.last_topic_id
LEFT JOIN " . PREFIX . "forum_view v ON v.user_id = '" . $User->get_attribute('user_id') . "' AND v.idtopic = t.id
LEFT JOIN " . DB_TABLE_MEMBER . " m ON m.user_id = t.last_user_id
WHERE c.aprob = 1 " . $display_sub_cat . " " . $unauth_cats . "
ORDER BY c.id_left", __LINE__, __FILE__);




Ajouter ligne 193 :

Code PHP :
            'ICON' => !empty($row['icon']) ? '<a href="forum' . url('.php?id=' . $row['cid'], '-' . $row['cid'] . '+' . url_encode_rewrite($row['name']) . '.php') . '"><img src="' . $row['icon'] . '" alt="" class="valign_middle" /></a><br />' : '' /*Ajout ElenWii */
 




Fichier TPL





admin_forum_add.tpl





Ajouter ligne 31 :

Code TPL :
        <!--
        function change_icon(img_path)
        {
            document.getElementById('icon_img').innerHTML = '<img src="' + img_path + '" alt="" class="valign_middle" />';
        }
        -->




Ajouter ligne 111 :

Code TPL :
                    <dl> <!--Debut Modif ElenWii-->
                        <dt><label for="icon">{L_ICON}</label><br /><span>{L_ICON_EXPLAIN}</span></dt>
                        <dd>
                            <label><select name="icon" id="icon" onchange="change_icon(this.options[this.selectedIndex].value)" onclick="change_icon(this.options[this.selectedIndex].value)">
                                {IMG_LIST}
                            </select></label>
                            <span id="icon_img">{IMG_ICON}</span>
                            <br />
                            <label><span class="text_small">{L_OR_DIRECT_PATH}</span> <input type="text" class="text" name="icon_path" value="{IMG_PATH}" onblur="if( this.value != '' )change_icon(this.value);" onclick="document.getElementById('img_default_select').selected = 'selected';" /></label>
                        </dd>
                    </dl> <!--Fin Modif ElenWii-->




admin_forum_cats_edit.tpl





Ajouter ligne 52 :

Code TPL :
        <!--
        function change_icon(img_path)
        {
            document.getElementById('icon_img').innerHTML = '<img src="' + img_path + '" alt="" class="valign_middle" />';
        }
        -->




Ajouter ligne 122 :

Code TPL :
                    <dl> <!--Debut Modif ElenWii-->
                        <dt><label for="icon">{L_ICON}</label><br /><span>{L_ICON_EXPLAIN}</span></dt>
                        <dd>
                            <label><select name="icon" id="icon" onchange="change_icon(this.options[this.selectedIndex].value)" onclick="change_icon(this.options[this.selectedIndex].value)">
                                {IMG_LIST}
                            </select></label>
                            <span id="icon_img">{IMG_ICON}</span>
                            <br />
                            <label><span class="text_small">{L_OR_DIRECT_PATH}</span> <input type="text" class="text" name="icon_path" value="{IMG_PATH}" onblur="if( this.value != '' )change_icon(this.value);" onclick="document.getElementById('img_default_select').selected = 'selected';" /></label>
                        </dd>
                    </dl> <!--Fin Modif ElenWii-->




forum_forum.tpl





Ajouter :
Code TPL :
{forums_list.subcats.ICON}




forum_index.tpl





Ajouter :
Code TPL :
{forums_list.subcats.ICON}