Differences

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

punbb13:integration 2009/07/08 02:18 punbb13:integration 2020/02/06 11:04 current
Line 23: Line 23:
  - 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 338: Line 283:
$forum_page['hidden_fields'] = array( $forum_page['hidden_fields'] = array(
- 'form_sent' => '<input type="hidden" name="form_sent" value="1" />',+ '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']).'" />', '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']).'" />' 'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
Line 361: Line 306:
<input type="submit" name="login" value="Login" /> <input type="submit" name="login" value="Login" />
</form> </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