[phpBB3] Fonction create_forum()

Vous trouverez ici des morceaux de codes qui peuvent être utiles à votre site.
Verrouillé
Avatar du membre
Dakin Quelia
Webmaster
Webmaster
Messages : 565
Enregistré le : ven. 27 nov. 2009 05:47
Localisation : Belgique
Contact :

[phpBB3] Fonction create_forum()

Message par Dakin Quelia »

» Fonction create_forum()

Cette fonction vous permet, par exemple, de créer un forum par utilisateur ou groupe en remplissant un formulaire.

Code : Tout sélectionner

<?php

/**
* Create a forum
*
* inspiration: http://www.phpbb.com/community/viewtopic.php?f=71&t=758985
*/
function create_forum($forum_perm_from = false)
{
    $forum_data = array(
        'parent_id'                        => 0,
        'left_id'                       => 0,
        'right_id'                      => 0,
        'forum_parents'                 => '',
        'forum_name'                       => 'test',
        'forum_desc'                    => '',
        'forum_desc_bitfield'           => '',
        'forum_desc_options'            => 7,
        'forum_desc_uid'                => '',
        'forum_link'                    => '',
        'forum_password'                 => '',
        'forum_style'                    => 0,
        'forum_image'                    => '',
        'forum_rules'                    => '',
        'forum_rules_link'                 => '',
        'forum_rules_bitfield'          => '',
        'forum_rules_options'              => 7,
        'forum_rules_uid'                 => '',
        'forum_topics_per_page'          => 0,
        'forum_type'                    => 1,
        'forum_status'                    => 0,
        'forum_posts'                   => 0,
        'forum_topics'                    => 0,
        'forum_topics_real'             => 0,
        'forum_last_post_id'              => 0,
        'forum_last_poster_id'          => 0,
        'forum_last_post_subject'       => '',
        'forum_last_post_time'          => 0,
        'forum_last_poster_name'           => '',
        'forum_last_poster_colour'       => '',
        'forum_flags'                    => 32,
        'display_on_index'                 => false,
        'enable_indexing'                 => true,
        'enable_icons'                    => false,
        'enable_prune'                    => false,
        'prune_next'                    => 0,
        'prune_days'                    => 7,
        'prune_viewed'                    => 7,
        'prune_freq'                    => 1,
    );

    // Check class acp_forums
    if (!class_exists('acp_forums'))
    {
        global $phpbb_root_path, $phpEx;
        include($phpbb_root_path . 'includes/acp/acp_forums.' . $phpEx);
    }

    $forums_admin = new acp_forums();
    $forums_admin->update_forum_data($forum_data);

    if ($forum_perm_from)
    {
        global $auth;

        $auth->acl_clear_prefetch();
        $users_sql_ary = $groups_sql_ary = array();

        // Copy permisisons from/to the acl users table (only forum_id gets changed)
        $sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
                FROM ' . ACL_USERS_TABLE . '
                WHERE forum_id = ' . $forum_perm_from;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result))
        {
             $users_sql_ary[] = array(
                'user_id'         => (int) $row['user_id'],
                'forum_id'         => (int) $forum_data['forum_id'],
                'auth_option_id'   => (int) $row['auth_option_id'],
                'auth_role_id'      => (int) $row['auth_role_id'],
                'auth_setting'      => (int) $row['auth_setting'],
             );
        }
        $db->sql_freeresult($result);

        // Copy permisisons from/to the acl groups table (only forum_id gets changed)
        $sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
                FROM ' . ACL_GROUPS_TABLE . '
                WHERE forum_id = ' . $forum_perm_from;
        $result = $db->sql_query($sql);
        
        while ($row = $db->sql_fetchrow($result))
        {
             $groups_sql_ary[] = array(
                'group_id'             => (int) $row['group_id'],
                'forum_id'             => (int) $forum_data['forum_id'],
                'auth_option_id'       => (int) $row['auth_option_id'],
                'auth_role_id'      => (int) $row['auth_role_id'],
                'auth_setting'      => (int) $row['auth_setting']
             );
        }
        
        $db->sql_freeresult($result);

        // Now insert the data
        $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
        $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
        cache_moderators();
    }
}

?>
Source: igorw de phpBB.com

Verrouillé

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 15 invités