Differences
This shows you the differences between the selected revision and the current version of the page.
punbb13:integration 2009/04/09 09:31 | punbb13:integration 2020/02/06 11:04 current | ||
---|---|---|---|
Line 4: | Line 4: | ||
===== 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. It can be done like this: | + | 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> | <code php> | ||
<?php | <?php | ||
// Add these lines in the very top of your code | // Add these lines in the very top of your code | ||
- | define('FORUM_ROOT', 'forum/'); | + | define('FORUM_ROOT', './forum/'); |
require FORUM_ROOT.'include/common.php'; | require FORUM_ROOT.'include/common.php'; | ||
Line 18: | Line 18: | ||
PunBB 1.3 natively supports URL rewriting, including SEF URLs. | PunBB 1.3 natively supports URL rewriting, including SEF URLs. | ||
- | ==== How to enable URL rewriting ==== | + | How to enable URL rewriting:\\ |
- Rename file ''.htaccess.dist'' in the root of your forum to ''.htaccess''. | - 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. | - Go to Administration => Settings (''/admin/settings.php?section=setup''), find ''URL Scheme'' section there. | ||
- Choose the URL scheme you like and save changes. | - Choose the URL scheme you like and save changes. | ||
- | ===== Database helpers ===== | ||
- | On ''include/common.php'' inclusion, the proper implementation of [[database layer]] class is being also included according to forum configuration. | ||
- | An instance of this database layer named ''$forum_db'' is being created in global scope to provide [[database helpers]]. | ||
- | |||
- | ==== How to perform a query ==== | ||
- | * Direct query. You can simply write an SQL-statement and execute it. | ||
- | <code php> $result = $forum_db->query('SELECT * FROM topics WHERE id = 10');</code> | ||
- | Be sure, that your SQL code is cross-compatible with all database engines supported by PunBB. | ||
- | * Using [[query builder]]. You may transparently build database queries. All the specific of database engines and database structure will automatically be taken in account. Example of usage (FIXME make it more informative): | ||
- | <code php>$query = array( | ||
- | 'SELECT' => '*', | ||
- | 'FROM' => 'topics', | ||
- | 'WHERE' => 'id = 10' | ||
- | ); | ||
- | $result = $forum_db->query_build($query); | ||
- | </code> | ||
- | See [[query builder]] page for details. | ||
- | ==== How to work with query results ==== | ||
- | For example, we have this query: | ||
- | <code php> | ||
- | $query = array( | ||
- | 'SELECT' => 't.id, t.poster, t.subject, t.posted', | ||
- | 'FROM' => 'topics AS t', | ||
- | 'WHERE' => 't.forum_id = 1' | ||
- | ); | ||
- | $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); | ||
- | </code> | ||
- | * To know how many rows this query returns, use this: | ||
- | <code php> | ||
- | $forum_db->num_rows($result); | ||
- | </code> | ||
- | * To fetch the current row to associative array: | ||
- | <code php> | ||
- | $data = $forum_db->fetch_assoc($result); | ||
- | //An example of getting topic_id | ||
- | $topic_id = $data['id']; | ||
- | </code> | ||
- | * To fetch the current row to numeric array: | ||
- | <code php> | ||
- | $data = $forum_db->fetch_row($result); | ||
- | //An example of getting topic_id | ||
- | $topic_id = $data[0]; | ||
- | </code> | ||
- | * To fetch only some values from the current row: | ||
- | <code php> | ||
- | //This code will fetch only the topic id and the topic subject | ||
- | list($id,, $subject,) = $forum_db->fetch_row($result); | ||
- | </code> | ||
- | * To process all rows in a set you can use this code: | ||
- | <code php> | ||
- | while ($cur_row = $forum_db->fetch_assoc($result)) | ||
- | { | ||
- | //Actions with $cur_row | ||
- | } | ||
- | </code> | ||
===== Template customization ===== | ===== Template customization ===== | ||
Line 134: | 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 322: | 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> |