Topic: Integrate punBB with php application

Hi,

I want to integrate punbb with my php application. That means the user registration and login should be handled by my own application.

If user clicks on register link then it'll redirect to my registration page and same as for login. There is a user table in my application with loginid, password and all other details. In punbb there is also a user table with forum specific details. So the synchronization of these two tables plus the navigation from home page to forum page with the credentials after login in my application.

In punbb the information stores in cookies where as I am using db session to store loginid and others. The difficult part is 'index.php' in punbb thats I am thinking.

Need help in this regards,

Thanks,
Faridi

Re: Integrate punBB with php application

with 1.2 you can rename index.php to forum.php and there are a few places that you need to update the redirects to index.php within the forum( breadcrumb trail.)

sorta example:
http://bunpai.com/

Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: Integrate punBB with php application

There is a special function in forum for checking the authorization of a user (cookie_login in "<FORUM_ROOT>/include/functions.php" line 1184). This function is used to determine whether the user is authorized or not at every forum page. Place the code with the authorization method in this function, which you use in your PHP application.

4

Re: Integrate punBB with php application

quaker wrote:

sorta example:
http://bunpai.com/

How can I list any posts from a category like there? I want news on a page which are posted in the forum.

Re: Integrate punBB with php application

Nigg, what i have done is created a html(php) page that pulls info from punbb1.2 and places it on the index.php in the main directory.

as follows

/index.php <-front end of site
/forum/index.php <-front end of punbb forum

this is easy to do but i'm using pun1.2 not pun1.3

Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

6

Re: Integrate punBB with php application

Hi and thanks for your answer. I'm also using pun 1.2 and I integrated it into my html/php pages. The structure is nearly the same:

/index.php
/cms/index.php (pun)


I just want to have something like a blog -> A page with the first posts (and headlines) of all threads in a category:


Headline (title of the thread in pun)
Post
....
Headline
Post
...
Headline
Post
...

Re: Integrate punBB with php application

ahh ok i will post my index.php here so that you can look at what i did.. my hacked up index for main site..lmao...

<?php
define('PUN_ROOT', './forum/');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'include/parser.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>home</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="http://bunpai.com/StyleSheet.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" media="screen" href="http://bunpai.com/forum/style/Oxygen.css" />
<style type="text/css">
/*<![CDATA[*/

.inform c4 {text-align:center}
h2, h2 a:active,h2 a:hover,h2 a:visited{color:#333333;
text-decoration:none;
font-size:12px;}
/* News Links on index page */

.news_subject {
    background-color: inherit;
    color: #999999;
    font: 1.6em/1.7em Georgia, "Times New Roman", serif;
    text-decoration:none;
    list-style-type: none;
}

a.news_subject:hover {
    background-color: inherit; 
    color: #ECA205;
    text-decoration: none;
    border-bottom:1px dotted #ECA205
}

.news_footer {
    background-color: #1D2435;
    color: inherit;
    border-top: 1px solid #313A50;
    border-left: 1px solid #313A50;
    border-bottom: 1px solid #313A50;
    border-right: 1px solid #313A50;
     text-decoration: none;
}

.byuser {
    font-weight: normal;
    color: #333333;
    background-color: inherit;
     text-decoration: none;
}

.user {
    font-weight: normal; 
    color: #6C695D; 
    background-color: inherit;
     text-decoration: none;
}

.poster {background-color: inherit; color: #8E94A3; }
a.poster {background-color: inherit; text-decoration: none; color: #8E94A3; }
a.poster:visited {background-color: inherit; text-decoration: none; color: #8E94A3; }
a.poster:hover {background-color: inherit; color: #FFFFFF; text-decoration: none; border-bottom: 1px solid #6C7283; }
/*]]>*/

</style>
</head>

<body>

    <div class="size">

        <div class="header">

            <div class="header01">

                <div class="logo">

                    <img src="image/img_15.jpg" alt="" />

                </div>

                <div class="hright">

                    <div class="hr01">

                        <div class="hr0101">

                            <a href="http://webjestic.net">Who is webJesitc</a></div>

                        <div class="hr0102">

                            <a href="#">My Account</a></div>

                        <div class="hr0102">

                            <a href="http://bunpai.com/forum/extern.php?action=active&amp;type=RSS">RSS</a></div>

                        <div class="hr0102">

                            <a href="#">Contact Us</a></div>

                    </div>

                    <div class="hr02">

                        <input id="Text1" type="text" value="Search..." />

                    </div>

                </div>

            </div>

            <div class="mnav">

                <img class="mnimgl" src="image/img_37.jpg" alt="" />

                <img class="mnimgr" src="image/img_50.jpg" alt="" />

                <div class="mnm">

                    <ul>

                        <li><a href="../">HOME</a></li>

                        <li><a href="#">ABOUT US</a></li>

                        <li><a href="/forum/gallery.php">GALLERY</a></li>

                        <li><a href="/forum">FORUM</a></li>

                        <li><a href="#">SERVICES</a></li>

                        <li><a href="/forum/contact.php">CONTACT</a></li>

                    </ul>

                </div>

            </div>

        </div>

        <div class="content">

            <div class="cmainimg">

                <img alt="" src="image/img_73.jpg" />

            </div>

            <div class="submenu" style="left: 0px; top: 0px">

                <img class="snimgl" src="image/img_96.jpg" alt="" />

                <img class="snimgr" src="image/img_107.jpg" alt="" />

                <div class="subtext">

                    You are here:Home

                </div>

                <div class="subimag" style="width: 41px; height: 51px">

                    <ul>

                        <li></li>

                        <li></li>

                        <li></li>

                        <li></li>

                    </ul>

                </div>

            </div>

            <div class="mcontent">

                <div class="mcleft">

                    <div class="mcbox01">

                        <div class="mc01t">

                            MAIN MENU

                        </div>

                        <div class="mc01c">

                            <ul>

                                <li><a href="./">Home</a></li>

                                <li><a href="#">About Us</a></li>

                                <li><a href="/forum/gallery.php">Gallery</a></li>

                                <li><a href="/forum">Forum</a></li>

                                <li><a href="#">Servies</a></li>

                                <li><a href="/forum/contact.php">Contact</a></li>

                            </ul>

                        </div>

                        <div class="mc01b">

                            <img src="image/img_272.jpg" alt="" />

                        </div>

                    </div>

                    <div class="mcbox01">

                        <div class="mc01t2">

                            LATEST NEWS

                        </div>

                        <div class="mc01cc">
<ul>
                           <?php
                           include('http://bunpai.com/forum/extern.php?action=active');
                           ?>
</ul>
                        </div>

                        <div class="mc01b">

                            <img src="image/img_272.jpg" alt="" />

                        </div>

                    </div>
<div class="mcbox01">

                        <div class="mc01t2">

                            Stats

                        </div>

                        <div class="mc01cc">
<ul>
                           <?php
                           include('http://bunpai.com/forum/extern.php?action=stats');
                           ?>
</ul>
                        </div>

                        <div class="mc01b">

                            <img src="image/img_272.jpg" alt="" />

                        </div>

                    </div>
                    <?php

// Show login if not logged in
if($pun_user['is_guest'])
{
    if(!isset($focus_element) || (isset($focus_element) && !in_array('login', $focus_element)))
    {

    // Load the language files
    require PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
    require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';

    // Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to index.php after login)
    $redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($pun_config['o_base_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'http://bunpai.com/index.php';

    $required_fields = array('req_username' => $lang_common['Username'], 'req_password' => $lang_common['Password']);

?>
<div class="mc01t2">Login</div>
<div class="mc01cc">
           <form id="login" name="qpost" method="post" action="forum/login.php?action=in" onsubmit="return process_form(this)">
<div style="text-align:center" >
<p><input type="hidden" name="form_sent" value="1" /> <input type="hidden" name="redirect_url" value="http://bunpai.com/index.php" /> Username<br />
<input type="text" name="req_username" size="16" maxlength="25" /><br />
<br />
 Password<br />
<input type="password" name="req_password" size="16" maxlength="16" onkeypress="if(event.keyCode==13) document.login.submit()" /><br />
<br />
<input type="submit" name="login" value="Login" tabindex="3" /><br />
<br />
<a href="forum/register.php">Register Now!</a></p>
</div>
</form>

         </div>

                        <div class="mc01b">

                            <img src="image/img_272.jpg" alt="" />

                        </div>
<?php
    }
}
?>

                </div>

                <div class="mcright">

                    <div class="mc01">

                        <div class="mc0101" style="left: 0px; top: 0px">

                            <img class="r0101" src="image/img_150.jpg" alt="" />

                            <img class="r0102" src="image/img_153.jpg" alt="" />

                            <img class="r0103" src="image/img_202.jpg" alt="" />

                            <img class="r0104" src="image/img_205.jpg" alt="" />

                            <div class="mcr">

                                <div class="mcr01">

                                    User Online

                                </div>

                                <div class="mcr02">
<?php
                                  include('http://Bunpai.com/forum/extern.php?action=online');
                                  ?>

                                </div>

                            </div>

                        </div>

                        <div class="mc0102">

                            <img class="r0101" src="image/img_155.jpg" alt="" />

                            <img class="r0102" src="image/img_157.jpg" alt="" />

                            <img class="r0103" src="image/img_207.jpg" alt="" />

                            <img class="r0104" src="image/img_209.jpg" alt="" />

                            <div class="mcl">

                                <div class="mcl01">

                                    Quotes

                                </div>

                                <div class="mcl02">
<script type="text/javascript" src="http://www.brainyquote.com/link/quotebr.js"></script>

                                </div>

                            </div>

                        </div>

                    </div>

                    <div class="mc02">

                        <div class="mc0201">

                            Welcome to Bunpai

                        </div>

                        <div class="mc0202" style="width: 18px; height: 15px">

                            &nbsp;

                        </div>

                        <div class="mc0203">

                            <div class="mc020301">
<?php
//----------------------------------------------------------------------//

//These are the forums from which the news is retrieved
$forumids = array(1,2,3);

//This is the overall limit for how many news items will be displayed
$master_limit = '5';

//This is the amount of characters above which truncation will occur
$trunc_chars = '550';

//----------------------------------------------------------------------//


//----------------------------------------------------------------------//

function close_tags($string)
{
    if (preg_match_all ('/<([a-z]+)[ >]/', $string, $start_tags))
    {
        $start_tags = $start_tags[1];

        if (preg_match_all ('/<\/([a-z]+)>/', $string, $end_tags))
        {
            $complete_tags = array();
            $end_tags = $end_tags[1];

            foreach ($start_tags as $key => $val)
            {
                $posb = array_search ($val, $end_tags);
                if (is_integer ($posb))
                {
                    unset ($end_tags[$posb]);
                }
                else
                {
                    $complete_tags[] = $val;
                }
            }
        }
        else
        {
            $complete_tags = $start_tags;
        }

        $complete_tags = array_reverse ($complete_tags);
        for ($i = 0; $i < count ($complete_tags); $i++)
        {
            $string .= '</' . $complete_tags[$i] . '>';
        }
    }

        // Removes irrelevant tags
    $xhtml_tags = array ('</img>', '</hr>', '</br>');
    $string = str_replace ($xhtml_tags, '', $string);
    return $string;
}

//----------------------------------------------------------------------//

function truncate($string)
{
global $pun_config;
$trunc_chars = '350';
$length = $trunc_chars;
$append = '...';

    if (strlen ($string) <= $length)
    {
        return $string;
    }
    else if ($length > 0)
    {
        preg_match ('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$length.',}\b#U', $string, $matches);
        $string = $matches[0];
        $string = close_tags (preg_replace ('#\s*<[^>]+>?\s*$#', '', $string).$append);
        return $string;
    }
}

//----------------------------------------------------------------------//

$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, u.use_avatar, u.num_posts, u.registered, u.title, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id IN ('.implode(',', $forumids).') AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$master_limit) or error('Unable to fetch announcements', __FILE__, __LINE__, $db->error());

if ($db->num_rows($result))
{
    while($cur_post = $db->fetch_assoc($result))
    {
        echo '<div class="block" style="border:none">';
        if ($pun_config['o_avatars'] == '1' && $cur_post['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
        {
            if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
            {
                $user_avatar = '<a href="forum/profile.php?id=' . $cur_post['poster_id'] . '"><img title="header=[<span class=\'box_username\'> '.pun_htmlspecialchars($cur_post['poster']).'] body=[<span class=\'box_info\'> Title: '.$cur_post['g_title'].'<br /> Total Post: '.$cur_post['num_posts'].'<br /> Registered Date: '. format_time($cur_post['registered'], true).']</span>" src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
            }
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
            {
                $user_avatar = '<a href="forum/profile.php?id=' . $cur_post['poster_id'] . '"><img title="header=[<span class=\'box_username\'> '.pun_htmlspecialchars($cur_post['poster']).'] body=[<span class=\'box_info\'> Title: '.$cur_post['g_title'].'<br /> Total Post: '.$cur_post['num_posts'].'<br /> Registered Date: '. format_time($cur_post['registered'], true).']</span>" src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
            }
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
            {
                $user_avatar = '<a href="forum/profile.php?id=' . $cur_post['poster_id'] . '"><img title="header=[<span class=\'box_username\'> '.pun_htmlspecialchars($cur_post['poster']).'] body=[<span class=\'box_info\'> Title: '.$cur_post['g_title'].'<br /> Total Post: '.$cur_post['num_posts'].'<br /> Registered Date: '. format_time($cur_post['registered'], true).']</span>" src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
            }
        }
        else
        {
            $user_avatar = '<a href="forum/profile.php?id=' . $cur_post['poster_id'] . '"><img src="forum/img/noimage.gif" alt=""/></a>';
        }

        $news_message = parse_message($cur_post['message'], $cur_post['hide_smilies']);

        if (pun_strlen($news_message) > $trunc_chars)
        {
            $news_message = truncate($news_message);
            $read_more = ' | <a href="'.$pun_config['o_base_url'].'forum/viewtopic.php?id='.$cur_post['id'].'">Read More</a> | ';
        }
        else
        {
            $read_more = ' | ';
        }

        if ($cur_post['num_replies'] != '0')
        {
            $replies = ' <a href="'.$pun_config['o_base_url'].'forum/viewtopic.php?id='.$cur_post['id'].'#p'.$cur_post['last_post_id'].'">Replies</a>: '.$cur_post['num_replies'].' ';
        }
        else
        {
            $replies = ' Replies: '.$cur_post['num_replies'].' ';
        }

        echo "\t\t\t\t\t\t\t".'<h2><strong><a href="forum/index.php">Forum</a> » <a href="forum/viewforum.php?id='.$cur_post['forum_id'].'">'.pun_htmlspecialchars($cur_post['forum_name']).'</a>'.'</strong></h2>'."\n";
?>
    <div class="box" style="border:none;list-style-type: none;">
                <div class="inbox" style="border:none">
<ul><li style="list-style-type:none">
       <div style="padding-bottom: 6px; list-style-type: none;" ><a class="news_subject" href="forum/viewtopic.php?id=<?php echo $cur_post['id']; ?>"><?php echo $cur_post['subject']; ?></a></div>
       <p><?php echo $news_message."\n" ?></p><br /><br />
<?php
    echo "\t\t\t\t\t\t\t".'<hr /><span class="byuser" style="float:left">Posted: '.format_time($cur_post['posted']).' by:<span class="byuser'.(isset($cur_post['g_title']) ? ' '.strtolower(str_replace(' ', '', $cur_post['g_title'])) : '').'"> <a href="forum/profile.php?id='.'2'.'" class="username">'.pun_htmlspecialchars($cur_post['poster']).'</a> |  Views: '. $cur_post['num_views'].' |  Replies: '. $cur_post['num_replies'].'</span></span>'."\n";
    
 
?>
                 
        </li></ul>
        </div>
    </div>
</div>
<br />
<?php
}
}
?>
<br />
<br />
</div>
   </div>


                    </div>

                </div>

            </div>

        </div>

        <div class="footer">

            <img class="mnimgl" src="image/img_275.jpg" alt="" />

            <img class="mnimgr" src="image/img_291.jpg" alt="" />

            <a href="../">HOME</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#">POLICYS</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a

                href="/forum">FORUM</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#">TERMS</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a

                    href="#">SERVICES</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="/forum/contact.php">CONTACT</a>

            <br/>

            <font color="#333333">Copyright 2007 - <?php echo date ('Y'); ?> Bunpai |

            <!-- By using this template you agree not to remove or edit the copyright & author links below -->

            Powered by <a style="color: #333333" href="http://punbb.org">Punbb</a> | Template by

            <a style="color: #333333" href="http://webjestic.net/">webjestic</a></font></div>

    </div>

</body>

</html>
My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

8

Re: Integrate punBB with php application

Thank you quaker! That helped me much, it works very great!