Welcome Guest, Not a member yet? Register   Sign In
phpBB3 library
#41

[eluser]Maglok[/eluser]
It would still be handy to know what you mean by 'chokes me' is it a error? If so what?

Anyway I have had issues with including those myself once in a while. It can very possibly have to do with you sending http headers first and then including. If you echo you display, thus you send http headers, yet the file wants to send them later. Something like that. For more, I'd have to see some error.
#42

[eluser]tobefound[/eluser]
Just hopping in; curious to find out why you guys chose procedural phpBB when at the same time working with object oriented and MVC-patterned CI? Surely there must be a better (OO) forum package out there? I'm looking for one myself right now and stumbled upon phpBB as being the largest (although not the cleanest).

For instance, having a function "redirect()" really warrants name clashing problems.

Any input on this would be appreciated,

/T
#43

[eluser]Maglok[/eluser]
Phpbb3 is one of the best supported forums out there. That is usually a huge reason. I have used several forums and in the end phpbb3's community is just the most active. Try SMF, it has a API, but it is out of date badly.

CI also works with databases which are hardly object oriented. Converting is the magic word.
#44

[eluser]Maglok[/eluser]
For those interested. You can log someone out by making a url like this:

Code:
<a href="http://forumlocation/ucp.php?mode=logout&sid;=&lt;?php echo $session_id;?&gt;">

Now it won't redirect back to your page yet. You can go into the common.php from phpbb3 and make it meta_refresh() (a function they have) to $_SERVER['HTTP_REFERRER'] and it will redirect.

I also added some stuff to the library in my personal copy to display the last five post titles, authors and forums. It is very rough, since CI doesn't like you naming variables 'db' or 'auth'. It also outputs the html in the library, instead of in the view, but it will make you understand the concept since I have had issues with getting it to work in CI before.

Code:
Add to the constructor:
$this->db3 = $db;
$this->auth2 = $auth;

Add these functions to the library:

/* create_where_clauses( int[] gen_id, String type )
* This function outputs an SQL WHERE statement for use when grabbing
* posts and topics */

function create_where_clauses($gen_id, $type)
{
global $db, $auth;

    $size_gen_id = sizeof($gen_id);

        switch($type)
        {
            case 'forum':
                $type = 'forum_id';
                break;
            case 'topic':
                $type = 'topic_id';
                break;
            default:
                trigger_error('No type defined');
        }

    // Set $out_where to nothing, this will be used of the gen_id
    // size is empty, in other words "grab from anywhere" with
    // no restrictions
    $out_where = '';

    if( $size_gen_id > 0 )
    {
    // Get a list of all forums the user has permissions to read
    $auth_f_read = array_keys($auth->acl_getf('f_read', true));

        if( $type == 'topic_id' )
        {
            $sql     = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
                        WHERE ' .  $db->sql_in_set('topic_id', $gen_id) . '
                        AND ' .  $db->sql_in_set('forum_id', $auth_f_read);

            $result     = $db->sql_query($sql);

                while( $row = $db->sql_fetchrow($result) )
                {
                        // Create an array with all acceptable topic ids
                        $topic_id_list[] = $row['topic_id'];
                }

            unset($gen_id);

            $gen_id = $topic_id_list;
            $size_gen_id = sizeof($gen_id);
        }

    $j = 0;    

        for( $i = 0; $i < $size_gen_id; $i++ )
        {
        $id_check = (int) $gen_id[$i];

            // If the type is topic, all checks have been made and the query can start to be built
            if( $type == 'topic_id' )
            {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }

            // If the type is forum, do the check to make sure the user has read permissions
            else if( $type == 'forum_id' && $auth->acl_get('f_read', $id_check) )
            {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }    

        $j++;
        }
    }

    if( $out_where == '' && $size_gen_id > 0 )
    {
        trigger_error('A list of topics/forums has not been created');
    }

    return $out_where;
}

    public function forumzaken() {
        $search_limit = 5;

        $forum_id = array(2, 5);
        $forum_id_where = $this->create_where_clauses($forum_id, 'forum');

        $topic_id = array(20, 50);
        $topic_id_where = $this->create_where_clauses($topic_id, 'topic');

        $posts_ary = array(
            'SELECT'    => 'p.*, t.*, f.*, u.username, u.user_colour',
    
            'FROM'      => array(POSTS_TABLE     => 'p',
                ),
    
            'LEFT_JOIN' => array(
                array(
                    'FROM'  => array(USERS_TABLE => 'u'),
                    'ON'    => 'u.user_id = p.poster_id'
                    ),
                array(
                    'FROM'  => array(TOPICS_TABLE => 't'),
                    'ON'    => 'p.topic_id = t.topic_id'
                    ),
                array(
                    'FROM'    => array(FORUMS_TABLE => 'f'),
                    'ON'    => 't.forum_id = f.forum_id'
                    )
            ),
    
            'WHERE'     => $this->db3->sql_in_set('t.forum_id', array_keys($this->auth2->acl_getf('f_read', true))) . '
                        AND t.topic_status <> ' . ITEM_MOVED . '
                         AND t.topic_approved = 1',
    
            'ORDER_BY'  => 'p.post_id DESC',
        );
    
        $posts = $this->db3->sql_build_query('SELECT', $posts_ary);

        $posts_result = $this->db3->sql_query_limit($posts, $search_limit);

        $forumzaken = '';

        while( $posts_row = $this->db3->sql_fetchrow($posts_result) ) {
            $topic_title = $posts_row['topic_title'];
            $post_link       = append_sid("http://forumlocation/viewtopic.php", 'f=' . $posts_row['forum_id'] . '&amp;t=' . $posts_row['topic_id'] . '&amp;p=' . $posts_row['post_id']) . '#p' . $posts_row['post_id'];
            $post_forum        = $posts_row['forum_name'];
            $forumzaken .= "<li><strong><a href='" . $post_link . "'>" . $topic_title . "</a></strong><br/>";
            $forumzaken .= "Door: <b><a href='http://forum.lore-ley.nl/memberlist.php?mode=viewprofile&amp;u=" . $posts_row[' style='color: #" . $posts_row['>" . $posts_row['username'] . "</a></b> - " . $post_forum . "</li>";
        }

        return $forumzaken;
    }

This is thus a specific implementation for my app. The main catch is that you need to redefine the db connection from phpbb3. ($this->dbname = $db)
#45

[eluser]gr0uch0mars[/eluser]
Thank you very much!

It works for me, and it's what I was looking for.

By the way, Maglok, I tried to log sb out like you said, and it didn't work ($session_id doesn't appear). I tried to retrieve session_id from db, but there is no way!!! (It may be VEEEERY easy, but today I'm not seccessful). If what you do works, explain it to me, please, because it seems easier than my method. If it doesn't work anyway, here is my code:
Code:
public function getUserSession()
{
        global $table_prefix;

        $userId = $this->_user->data['user_id'];

        $this->forum_db->select('session_id');
        $this->forum_db->from($table_prefix . 'sessions');
        $this->forum_db->where('session_user_id', $userId);
        $this->forum_db->limit(1);

        $query = $this->forum_db->get();

        if ($query->num_rows() == 1)
        {
            $row = $query->row();
            return $row->session_id;
        }
        else
        {
            return FALSE;
}

I don't know why, but it returns no results.

And in my view:
Code:
<a href="http://forumlocation/ucp.php?mode=logout&sid;=&lt;?php echo $this-&gt;phpbb_library-&gt;getUserSession();?&gt;">




:red: EDIT: My method works perfectly. It was just a minor mistake I made, but now it works.
#46

[eluser]Maglok[/eluser]
It's all rather tricky really. Nice though. Smile
#47

[eluser]JavaJunky[/eluser]
[quote author="Maglok" date="1264533718"]It would still be handy to know what you mean by 'chokes me' is it a error? If so what?

Anyway I have had issues with including those myself once in a while. It can very possibly have to do with you sending http headers first and then including. If you echo you display, thus you send http headers, yet the file wants to send them later. Something like that. For more, I'd have to see some error.[/quote]

Sorry for the lack of response. My project was shelved for a month, but I'm just getting back into it. When I said choke, I meant, it basically breaks and spit out a blank page without any actual errors. I did figure out the issue was as I originally suspected that it was a php redeclaration error in the includes. I found a simple solution that I really should of thought of in the first place, but I never really worked with libraries before. Basically, the phpBB register functions require most of the same files as the login functions in the library file. So I just put the code into phpbb_library.php. The only extra thing I had to do was write a few extra validation functions though most of the built in phpBB validation functions worked.

So for everyone, you can register phpBB users externally!
#48

[eluser]Maglok[/eluser]
That's neat. I might eventually do that. At the moment I just redirect them to the forum. Tongue
#49

[eluser]JavaJunky[/eluser]
The only reason why I'm going the external route is because the client wants a scenario where a new user can register an account and register to attend an event (managed in a different db system) in one form.
#50

[eluser]Maglok[/eluser]
That makes sense. I try to combine forms where I can as well. I have this signup system where I automatically let the user see his personal info again so he can change anything he needs to about his info, but doesn't have to. Basically confront him/her with the 'Dont forget to update'.

Besides registering outside of the forum is awefully neat. Smile




Theme © iAndrew 2016 - Forum software by © MyBB