Differences

This shows you the differences between the selected revision and the current version of the page.

punbb13:integration 2009/02/06 04:26 punbb13:integration 2020/02/06 11:04 current
Line 1: Line 1:
====== PunBB 1.3 integration ====== ====== PunBB 1.3 integration ======
 +Forum integration is very useful when you want to use the same database for your website as the forum one or if you want to execute some tasks that require the user to be a part of a certain usergroup. Below you will find some integration possibilities.
===== General ===== ===== General =====
 +In order to use PunBB user authentication within your scripts or to have access to the logged in user's information you have to include common.php which can be found in the include/ folder. You have also to define the FORUM_ROOT global variable in your script. For example, if your website front page is located in /home/user/public_html/ and your forums are located in /home/user/public_html/forums/, your FORUM_ROOT should be './forums/'. It can be done like this:
 +<code php>
 +<?php
 +
 +// Add these lines in the very top of your code
 +define('FORUM_ROOT', './forum/');
 +require FORUM_ROOT.'include/common.php';
 +
 +?>
 +</code>
 +
 +===== URL schemes =====
 +PunBB 1.3 natively supports URL rewriting, including SEF URLs.
 +
 +How to enable URL rewriting:\\
 +  - Rename file ''.htaccess.dist'' in the root of your forum to ''.htaccess''.
 +  - Go to Administration => Settings (''/admin/settings.php?section=setup''), find ''URL Scheme'' section there.
 +  - Choose the URL scheme you like and save changes.
 +
 +
 +===== Template customization =====
 +==== How to include my file into *.tpl? ====
 +Use the ''forum_include "file.ext"'' substitute to include the file ''<FORUM_ROOT>/include/user/file.ext'':
 +<code php><!-- forum_include "file.ext" --></code>
===== Common tasks ===== ===== Common tasks =====
Line 9: Line 34:
<code php> <code php>
<?php <?php
 +
 +header('Content-type: text/html; charset=utf-8');
define('RECENT_POSTS_SHOW_POST', true); // Set to false to show topic subject only define('RECENT_POSTS_SHOW_POST', true); // Set to false to show topic subject only
Line 52: Line 79:
{ {
if (utf8_strlen($cur_post['message']) > RECENT_POSTS_MAX_POST_LENGTH) if (utf8_strlen($cur_post['message']) > RECENT_POSTS_MAX_POST_LENGTH)
- $cur_post['message'] = utf8_substr($cur_post['message'], 0, RECENT_POSTS_MAX_POST_LENGTH).'…';+ $cur_post['message'] = utf8_substr($cur_post['message'], 0, RECENT_POSTS_MAX_POST_LENGTH).'...';
echo '<br />', "\n", $cur_post['message']; echo '<br />', "\n", $cur_post['message'];
Line 70: Line 97:
<code php> <code php>
<?php <?php
 +
 +header('Content-type: text/html; charset=utf-8');
if (!defined('FORUM_ROOT')) if (!defined('FORUM_ROOT'))
Line 116: Line 145:
</ul> </ul>
</code> </code>
 +
==== Showing active topics ==== ==== Showing active topics ====
-<code php>$topics_count = 5;+<code php><?php 
 + 
 +header('Content-type: text/html; charset=utf-8'); 
 + 
 +define('FORUM_ROOT', './'); 
 +require FORUM_ROOT.'include/common.php'; 
 + 
 +require FORUM_ROOT.'lang/'.$forum_user['language'].'/index.php'; 
 +require FORUM_ROOT.'lang/'.$forum_user['language'].'/forum.php'; 
 + 
 +$topics_count = 5;
$query_active_topics= array( $query_active_topics= array(
    'SELECT'    => 't.id AS tid, t.poster, t.subject, t.posted AS has_posted, t.last_post, t.last_post_id, t.num_replies, t.num_views, t.closed, t.sticky,     'SELECT'    => 't.id AS tid, t.poster, t.subject, t.posted AS has_posted, t.last_post, t.last_post_id, t.num_replies, t.num_views, t.closed, t.sticky,
Line 227: Line 267:
} }
 +</code>
 +
 +==== Login form outside the forum ====
 +
 +<code php><?php
 +
 +// Define the path to the forum root
 +define('FORUM_ROOT', './forum/');
 +require FORUM_ROOT.'include/common.php';
 +
 +// Where will we go after login?
 +$forum_page['redirect_url'] = 'http://your_site.com/forum/';
 +
 +$forum_page['form_action'] = forum_link($forum_url['login']);
 +
 +$forum_page['hidden_fields'] = array(
 + 'form_sent' => '<input type="hidden" name="form_sent" value="1" />',
 + 'redirect_url' => '<input type="hidden" name="redirect_url" value="'.forum_htmlencode($forum_page['redirect_url']).'" />',
 + 'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
 +);
 +
 +?>
 +<form method="post" action="<?php echo $forum_page['form_action'] ?>">
 + <?php echo implode("\n\t\t", $forum_page['hidden_fields'])."\n" ?>
 +
 + Username:
 + <input type="text" id="fld1" name="req_username" value="" />
 + <br />
 +
 + Password:
 + <input type="password" id="fld2" name="req_password" value="" />
 + <br />
 +
 + <input type="checkbox" id="fld3" name="save_pass" value="1" />
 + <label for="fld3">Log me in automatically each time I visit.</label>
 + <br />
 +
 + <input type="submit" name="login" value="Login" />
 +</form>
 +</code>
 +
 +==== Using parser ====
 +
 +<code php>
 +<?php
 +
 +define('FORUM_ROOT', './');
 +require FORUM_ROOT.'include/common.php';
 +require FORUM_ROOT.'include/parser.php';
 +
 +$s = 'test [b]test[/b]';
 +
 +echo $s, parse_message($s, false);
</code> </code>

Personal Tools