Ok dann poste ich mal die Includeten Dateien:
Die wichtigsten Dateien sind wohl die common.php und die posts.php. Dort sind alle funktionen enthalten die zum anzeigen der Links notwendig sind.
Dank Dir auf jeden Fall im vorraus.
extension.inc
Code: Alles auswählen
<?php
if ( !defined('IN_PHPBB') )
{
die("Hacking attempt");
}
$phpEx = "php";
$starttime = 0;
?>
common.$phpEx
Code: Alles auswählen
<?php
$CFG['smilie_url'] = $phpbb_root_path . 'images/smiles';
//
// URL to your avatar directory without trailing slash.
//
// NOTE: THIS IS DEPRECATED SINCE VERSION 2.0.4 AND REMAINS HERE FOR
// BACKWARD COMPATIBILITY ONLY. YOU DO NOT NEED THIS OPTION ANY
// MORE SINCE IT WILL BE AUTOMATICALLY HANDLED BY
// phpbb_avatar_image()
//
$CFG['avatar_url'] = $phpbb_root_path . 'images/avatars';
//
// URL to your avatar gallery directory without trailing slash.
//
// NOTE: THIS IS DEPRECATED SINCE VERSION 2.0.4 AND REMAINS HERE FOR
// BACKWARD COMPATIBILITY ONLY. YOU DO NOT NEED THIS OPTION ANY
// MORE SINCE IT WILL BE AUTOMATICALLY HANDLED BY
// phpbb_avatar_image()
//
$CFG['avatar_gallery_url'] = $phpbb_root_path . 'images/avatars/gallery';
//
// When set to true the script will check postings and other
// things against the permissions of the user who views the
// script. If no permission for the particular action exists the
// script will not fetch and display the data.
//
// true = enabled (default)
// false = disabled
//
// IMPORTANT: Using auth check will require these two lines in
// your script to work properly:
//
// $userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length);
// init_userprefs($userdata);
//
$CFG['auth_check'] = true;
$CFG['time_zone'] = 0 * 3600;
$CFG['date_format'] = 'd.m.';
$CFG['time_format'] = 'H:i';
$CFG['on_error'] = 'die';
$CFG['redirect'] = '';
$CFG['debug'] = true;
$CFG['version'] = '2.0.10';
$CFG['auth_list'] = array();
$CFG['auth_called'] = false;
if (!defined('IN_PHPBB'))
{
die ('hacking attempt');
}
###############################################################################
## ##
## phpbb_raise_error() ##
## ------------------------------------------------------------------------- ##
## Produces an error message or redirects the browser to a given URL. You ##
## can use this function for your entire site to ensure that all scripts ##
## exits nicely on an error. The redirect option will forward the browser to ##
## another page which is very useful if (for example) the database is down ##
## and you want to show a 'site offline' page automatically. ##
## ##
## PARAMETER ##
## ##
## message ##
## ##
## The error message. ##
## ##
## file ##
## ##
## File name; use __FILE__ if you call this function from your own ##
## scripts. ##
## ##
## line ##
## ##
## Line number; use __LINE__ if you call this function from your own ##
## scripts. ##
## ##
## sql ##
## ##
## SQL query string which will be print if $CFG['debug'] is set to ##
## true ##
## ##
###############################################################################
function phpbb_raise_error($message = null, $file = null, $line = null,
$sql = null)
{
global $CFG;
if ($CFG['debug'] and $sql)
{
$message .= '<br /> <br />SQL: ' . $sql . '<br /> <br />';
}
switch ($CFG['on_error'])
{
//
// page redirect
//
case 'redirect':
if ($CFG['redirect'])
{
header ('Location: ' . $CFG['redirect']);
}
else
{
$CFG['on_error'] = 'die';
phpbb_raise_error($message, $file, $line, $sql);
}
break;
//
// phpBB's message_die()
//
case 'phpbb':
message_die(GENERAL_MESSAGE,
'<b>phpbb Fetch All error:</b> ' . $message, '',
__FILE__, __LINE__);
break;
//
// PHP's die()
//
default:
die('<tt><b>phpbb Fetch All error:</b> ' . $message . ' at '
. $file . ':' . $line . '</tt>');
}
exit;
} // end func phpbb_raise_error
###############################################################################
## ##
## phpbb_fetch_row() ##
## ------------------------------------------------------------------------- ##
## Performs a SQL database query and returns the result in a single array ##
## like this ##
## ##
## $result['field1'] ##
## $result['field2'] ##
## ##
## PARAMETER ##
## ##
## sql ##
## ##
## the SQL statement ##
## ##
###############################################################################
function phpbb_fetch_row($sql = null)
{
global $db;
if (!$sql)
{
return;
}
$query = phpbb_query($sql);
$result = $db->sql_fetchrow($query);
return $result;
} // end func phpbb_fetch_row
###############################################################################
## ##
## phpbb_fetch_rows() ##
## ------------------------------------------------------------------------- ##
## Performs a SQL database query and returns the result in a multi- ##
## dimensional array like this ##
## ##
## $result[0]['field1'] ##
## $result[0]['field2'] ##
## $result[1]['field1'] ##
## $result[1]['field2'] ##
## ##
## PARAMETER ##
## ##
## sql ##
## ##
## the SQL statement ##
## ##
###############################################################################
function phpbb_fetch_rows($sql = null)
{
global $db;
if (!$sql)
{
return;
}
$query = phpbb_query($sql);
$result = array();
while ($row = $db->sql_fetchrow($query))
{
$result[] = $row;
}
return $result;
} // end func phpbb_fetch_rows
###############################################################################
## ##
## phpbb_query() ##
## ------------------------------------------------------------------------- ##
## Executes a query through the phpBB DB API and returns the result. On an ##
## error phpbb_raise_error() will be called so you can make your own error ##
## handler with this. ##
## ##
## PARAMETER ##
## ##
## sql ##
## ##
## the SQL query statement ##
## ##
###############################################################################
function phpbb_query($sql = null)
{
global $db;
if (!$query = $db->sql_query($sql))
{
phpbb_raise_error('database query failed', __FILE__, __LINE__, $sql);
}
return $query;
} // end func phpbb_query
###############################################################################
## ##
## phpbb_numrows() ##
## ------------------------------------------------------------------------- ##
## Returns the number of rows in the result of a query. ##
## ##
## PARAMETER ##
## ##
## query ##
## ##
## the DB handle to the query ##
## ##
###############################################################################
function phpbb_numrows($query = null)
{
global $db;
return $db->sql_numrows($query);
} // end func phpbb_numrows
###############################################################################
## ##
## phpbb_disconnect() ##
## ------------------------------------------------------------------------- ##
## Disconnects from the database using the phpBB DB API. ##
## ##
###############################################################################
function phpbb_disconnect()
{
global $db;
$db->sql_close();
} // end func phpbb_disconnect
###############################################################################
## ##
## phpbb_parse_text() ##
## ------------------------------------------------------------------------- ##
## Parses text according to phpBB (BBCode, smilies, etc). ##
## ##
## PARAMETER ##
## ##
## text ##
## ##
## the text to be parsed ##
## ##
## bbcode_uid ##
## ##
## bbcode identifier ##
## ##
## enable_smilies ##
## ##
## If true all smilies will be parsed with their icon ##
## otherwise you will only see the smilie code. ##
## ##
## hide_images ##
## ##
## If false all images will be left untouched otherwise all ##
## images will be replaced with the text in the next ##
## parameter. ##
## ##
## replace_images ##
## ##
## text to replace images with ##
## ##
###############################################################################
function phpbb_parse_text($text = null,
$bbcode_uid = null,
$enable_smilies = true,
$hide_images = false,
$replace_images = '')
{
global $CFG;
if (!$text)
{
return;
}
//
// remove slashes
//
stripslashes($text);
//
// remove images if requested
//
if ($hide_images)
{
if ($replace_images)
{
$replacement = '[url=\\1]' . $replace_images . '[/url]';
}
else
{
$replacement = '';
}
$text =
preg_replace("#\[img:$bbcode_uid\](.*?)\[/img:$bbcode_uid\]#si",
$replacement, $text);
}
//
// parse bbcode
//
$text = bbencode_second_pass($text, $bbcode_uid);
//
// parse smilies if requested
//
if ($enable_smilies == 1)
{
$text = smilies_pass($text);
//
// need to overwrite the smilie path since we might not be within
// the phpBB directory
//
$text = preg_replace("/images\/smiles/", $CFG['smilie_url'], $text);
}
//
// parse url's
//
$text = make_clickable($text);
//
// change newlines to HTML
//
$text = str_replace("\n", "\n<br />\n", $text);
return $text;
} // end func phpbb_parse_text
###############################################################################
## ##
## phpbb_trim_text() ##
## ------------------------------------------------------------------------- ##
## This function can trim a text by number of characters or the first ##
## appearence of a character combination. ##
## ##
## PARAMETER ##
## ##
## text ##
## ##
## contains the text which should be trimmed ##
## ##
## is_trimmed ##
## ##
## will be false if no trimming has been done and true if the text ##
## has been trimmed ##
## ##
## character ##
## ##
## a character combination ('<br />') ##
## ##
## number ##
## ##
## a number of characters ('150') ##
## ##
## words ##
## ##
## a number of words ('5') ##
## ##
###############################################################################
function phpbb_trim_text(&$text,
&$is_trimmed,
$character = null,
$number = 0,
$words = 0)
{
//
// trim by character combination
//
if ($character != '' and eregi($character, $text))
{
$trimmed = explode($character, $text);
$text = $trimmed[0];
$is_trimmed = true;
}
//
// trim by number
//
if ($number != 0 and strlen($text) > $number)
{
$text = substr($text, 0, $number);
$is_trimmed = true;
}
//
// trim by words
//
if ($words != 0)
{
$exploded = explode(' ', $text);
if (count($exploded) > $words)
{
$text = '';
for ($i = 0; $i < $words; $i++)
{
$text .= $exploded[$i] . ' ';
}
$text = substr($text, 0, -1);
$is_trimmed = true;
}
}
return true;
} // end func phpbb_trim_text
###############################################################################
## ##
## phpbb_span_pages() ##
## ------------------------------------------------------------------------- ##
## Calculates the span pages. Returns a string with all available pages like ##
## ##
## Goto page 1,2,3 Next ##
## ##
## The 'goto page' is being set by your local language setup. The string is ##
## being formatted and contains a link on the calling script (PHP_SELF). ##
## ##
## PARAMETER ##
## ##
## numrows ##
## ##
## number of rows of the result query ##
## ##
## limit ##
## ##
## number of entries to show on one page ##
## ##
## offset ##
## ##
## number of entry from which the output starts ##
## ##
## add_prevnext_text ##
## ##
## true = adds the previous/next text ##
## false = do not add it ##
## ##
###############################################################################
function phpbb_span_pages($numrows = 0,
$limit = 0,
$offset = 0,
$add_prevnext_text = true)
{
global $PHP_SELF;
//
// avoid a division by zero error from phpBB
//
if ($limit == 0)
{
$limit = 100;
}
//
// do a little string replace to fix the original output of the phpBB
// pagination function (replace '&' with '?')
//
$result = eregi_replace('&start',
'start',
generate_pagination($PHP_SELF . '?',
$numrows,
$limit,
$offset,
$add_prevnext_text));
return $result;
} // end func phpbb_span_pages
###############################################################################
## ##
## phpbb_get_auth_list() ##
## ------------------------------------------------------------------------- ##
## This function will fetch the list of forums which the user is able to ##
## 'view'. The list will be saved within $CFG['auth_list'] so it is global ##
## available for every function. This function will run only once to reduce ##
## SQL queries. ##
## ##
###############################################################################
function phpbb_get_auth_list()
{
global $CFG, $userdata;
if (!$CFG['auth_called'] and $CFG['auth_check'])
{
$is_auth = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata);
while (list($k, $v) = each($is_auth))
{
if ($v['auth_view'])
{
$CFG['auth_list'][] = $k;
}
}
$CFG['auth_called'] = true;
}
return true;
} // end func phpbb_get_auth_list
###############################################################################
## ##
## phpbb_get_forum_list() ##
## ------------------------------------------------------------------------- ##
## This function will create a list of forums based on the forums passed as ##
## a parameter and the forums which are in $CFG['auth_list']. Basically it ##
## will filter the forums passed by against the allowed forums (if auth ##
## check is enabled). ##
## ##
## PARAMETER ##
## ##
## forum_id ##
## ##
## A single forums id or an array of multiple id's. ##
## ##
###############################################################################
function phpbb_get_forum_list($forum_id = null)
{
global $CFG;
$result = '';
if (!$forum_id and $CFG['auth_check'])
{
reset($CFG['auth_list']);
while (list($k, $v) = each($CFG['auth_list']))
{
$result .= $v . ',';
}
if ($result)
{
$result = substr($result, 0, strlen($result) -1);
}
}
if ($forum_id)
{
if (!is_array($forum_id))
{
if ($CFG['auth_check'])
{
if (in_array($forum_id, $CFG['auth_list']))
{
$result = $forum_id;
}
}
else
{
$result = $forum_id;
}
}
else
{
for ($i = 0; $i < count($forum_id); $i++)
{
if ($CFG['auth_check'])
{
if (in_array($forum_id[$i], $CFG['auth_list']))
{
$result .= $forum_id[$i] . ',';
}
}
else
{
$result .= $forum_id[$i] . ',';
}
}
if ($result)
{
$result = substr($result, 0, strlen($result) -1);
}
}
}
return $result;
} // end func phpbb_get_forum_list
###############################################################################
## ##
## phpbb_avatar_image() ##
## ------------------------------------------------------------------------- ##
## This function will return a valid image URL for the user avatar. ##
## ##
## PARAMETER ##
## ##
## avatar_type ##
## ##
## Type of the avatar: uploaded, remote or gallery. ##
## ##
## avatar ##
## ##
## user avatar ##
## ##
## EXAMPLE ##
## ##
## echo phpbb_avatar_image($userdata['user_avatar_type'], ##
## $userdata['user_avatar']); ##
## ##
###############################################################################
function phpbb_avatar_image($avatar_type = null, $avatar = null)
{
global $board_config, $phpbb_root_path;
$image = '';
switch($avatar_type)
{
case USER_AVATAR_UPLOAD:
$image = ($board_config['allow_avatar_upload'])
? '<img src="' . $phpbb_root_path
. $board_config['avatar_path'] . '/' . $avatar
. '" alt="" border="0" />'
: '';
break;
case USER_AVATAR_REMOTE:
$image = ($board_config['allow_avatar_remote'])
? '<img src="' . $avatar . '" alt="" border="0" />' : '';
break;
case USER_AVATAR_GALLERY:
$image = ($board_config['allow_avatar_local'])
? '<img src="' . $phpbb_root_path .
$board_config['avatar_gallery_path'] . '/' . $avatar
. '" alt="" border="0" />'
: '';
break;
}
return $image;
} // end func phpbb_avatar_image
###############################################################################
## ##
## phpbb_fetch_style() ##
## ------------------------------------------------------------------------- ##
## Fetches the template name from the user's settings. If board is set to ##
## only one style, it will use the default. ##
## ##
## This function returns the template name e.g. 'subSilver'. ##
## ##
## PARAMETER ##
## ##
## user_id ##
## ##
## the user's ID ##
## ##
## EXAMPLE ##
## ##
## $forum_style = phpbb_fetch_style($userdata['user_id']); ##
## echo 'The path to my templates is' . $phpbb_root_path; ##
## echo 'templates/' . $forum_style; ##
## ##
## AUTHOR ##
## ##
## RyanThaDude29 <ryan@ryansmadhouse.com> ##
## http://www.ryansmadhouse.com/ ##
## ##
###############################################################################
function phpbb_fetch_style($user_id = null)
{
global $userdata, $board_config, $phpbb_root_path;
if ($board_config['override_user_style'])
{
$style = $board_config['default_style'];
}
else
{
if ($userdata['session_logged_in'])
{
$style = $userdata['user_style'];
}
else
{
$style = $board_config['default_style'];
}
}
$sql = 'SELECT *
FROM ' . THEMES_TABLE . '
WHERE themes_id = ' . $style;
$row = phpbb_fetch_row($sql);
return $row['template_name'];
} // end func phpbb_fetch_style
?>
posts.$phpEx
Code: Alles auswählen
<?php
$CFG['posts_limit'] = 5;
$CFG['posts_order'] = 'p.post_time DESC';
$CFG['posts_hide_normal'] = false;
$CFG['posts_hide_sticky'] = false;
$CFG['posts_hide_announcements'] = false;
$CFG['posts_hide_locked'] = false;
$CFG['posts_hide_moved'] = false;
$CFG['posts_hide_polls'] = false;
$CFG['posts_hide_ranks'] = true;
$CFG['posts_hide_images'] = false;
$CFG['posts_replace_images'] = '[image]';
$CFG['posts_trim_text_character'] = '';
$CFG['posts_trim_text_number'] = 0;
$CFG['posts_trim_text_words'] = 0;
$CFG['posts_trim_title_number'] = 0;
$CFG['posts_date_offset_start'] = '';
$CFG['posts_date_offset_end'] = time();
$CFG['posts_search_string'] = '';
$CFG['posts_span_pages'] = false;
###############################################################################
## NO CHANGES NEEDED BELOW
###############################################################################
if (!defined('IN_PHPBB'))
{
die('hacking attempt');
}
define('POSTS_FETCH_FIRST', 0);
define('POSTS_FETCH_LAST', 1);
$CFG['posts_span_pages_offset'] = 0;
$CFG['posts_span_pages_numrows'] = 0;
$CFG['posts_offset'] = 0;
###############################################################################
## ##
## phpbb_fetch_posts() ##
## ------------------------------------------------------------------------- ##
## This function will fetch the first or the last posting from one or more ##
## topics. ##
## ##
## PARAMETER ##
## ##
## forum_id ##
## ##
## Can be left blank to fetch from all forums or set to a single ##
## forums id to fetch that specific forum. To fetch from multiple ##
## forums you can parse an array to it. ##
## ##
## fetch_mode ##
## ##
## Set it to POSTS_FETCH_FIRST to fetch the first postings of a ##
## topic (i.e. the posts which started the topic) or set it to ##
## POSTS_FETCH_LAST to fetch the last postings of a topic. ##
## ##
## EXAMPLE ##
## ##
## $news = phpbb_fetch_posts(); ##
## ##
## for ($i = 0; $i < count($news); $i++) ##
## { ##
## echo $news[$i]['topic_title'] . '<br>'; ##
## } ##
## ##
###############################################################################
function phpbb_fetch_posts($forum_id = null, $fetch_mode = POSTS_FETCH_FIRST)
{
global $CFG, $userdata;
//
// sanity check for dates
//
if ($CFG['posts_date_offset_start'] >= $CFG['posts_date_offset_end'])
{
phpbb_raise_error('\'posts_date_offset_start\' has to be smaller '
. 'than \'posts_date_offset_end\'');
}
//
// create a list of forums with read permission
// (only takes action when auth_check is enabled)
//
phpbb_get_auth_list();
//
// determine the forum list based on the user input
// and/or permissions (depends on auth check)
//
$forum_list = phpbb_get_forum_list($forum_id);
//
// if read permissions do not allow us to fetch anything
// we return nicely
//
if (!$forum_list and $CFG['auth_check'])
{
return;
}
$sql = 'SELECT f.*, p.*, pt.*, t.*, u.*';
if (!$CFG['posts_hide_ranks'])
{
$sql .= ', r.*';
}
$sql .= '
FROM ' . TOPICS_TABLE . ' AS t,
' . USERS_TABLE . ' AS u,
' . POSTS_TEXT_TABLE . ' AS pt,
' . POSTS_TABLE . ' AS p,
' . FORUMS_TABLE . ' AS f';
if (!$CFG['posts_hide_ranks'])
{
$sql .= ', ' . RANKS_TABLE . ' AS r';
}
$sql .= '
WHERE';
if ($forum_list)
{
$sql .= ' t.forum_id IN (' . $forum_list . ') AND';
}
if ($fetch_mode == POSTS_FETCH_FIRST)
{
$sql .= ' t.topic_first_post_id = pt.post_id
AND t.topic_first_post_id = p.post_id AND';
}
else
{
$sql .= ' t.topic_last_post_id = pt.post_id
AND t.topic_last_post_id = p.post_id AND';
}
if ($CFG['posts_date_offset_start'])
{
$sql .= ' p.post_time >= ' . $CFG['posts_date_offset_start'] . ' AND';
}
if ($CFG['posts_date_offset_end'])
{
$sql .= ' p.post_time <= ' . $CFG['posts_date_offset_end'] . ' AND';
}
if ($CFG['posts_hide_normal'])
{
$sql .= ' t.topic_type <> 0 AND';
}
if ($CFG['posts_hide_sticky'])
{
$sql .= ' t.topic_type <> 1 AND';
}
if ($CFG['posts_hide_announcement'])
{
$sql .= ' t.topic_type <> 2 AND';
}
if ($CFG['posts_hide_locked'])
{
$sql .= ' t.topic_status <> 1 AND';
}
if ($CFG['posts_hide_moved'])
{
$sql .= ' t.topic_status <> 2 AND';
}
if ($CFG['posts_hide_polls'])
{
$sql .= ' t.topic_vote <> 1 AND';
}
if ($CFG['posts_search_string'])
{
$sql .= ' (' . $CFG['posts_search_string'] . ') AND';
}
$sql .= ' t.forum_id = f.forum_id AND';
if (!$CFG['posts_hide_ranks'])
{
$sql .= ' r.rank_id = u.user_rank AND';
}
$sql .= ' u.user_id = p.poster_id';
$sql .= ' ORDER BY ' . $CFG['posts_order'];
if ($CFG['posts_span_pages'])
{
$CFG['posts_span_pages_numrows'] = phpbb_numrows(phpbb_query($sql));
if ($CFG['posts_span_pages_offset'] > $CFG['posts_span_pages_numrows'])
{
$CFG['posts_span_pages_offset'] =
$CFG['posts_span_pages_numrows'] - 1;
}
$CFG['posts_offset'] = $CFG['posts_span_pages_offset'];
}
else
{
$CFG['posts_offset'] = 0;
}
if ($CFG['posts_limit'] != 0)
{
$sql .= ' LIMIT ' . $CFG['posts_offset'] . ',' . $CFG['posts_limit'];
}
$result = phpbb_fetch_rows($sql);
if ($result)
{
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
for ($i = 0; $i < count($result); $i++)
{
$result[$i]['post_time'] =
$result[$i]['post_time'] + $CFG['time_zone'];
$result[$i]['topic_time'] =
$result[$i]['topic_time'] + $CFG['time_zone'];
$result[$i]['date'] =
date($CFG['date_format'], $result[$i]['post_time']);
$result[$i]['time'] =
date($CFG['time_format'], $result[$i]['post_time']);
$result[$i]['edit_date'] =
date($CFG['date_format'], $result[$i]['post_edit_time']);
$result[$i]['edit_time'] =
date($CFG['time_format'], $result[$i]['post_edit_time']);
$result[$i]['post_text'] = phpbb_parse_text(
$result[$i]['post_text'],
$result[$i]['bbcode_uid'],
$result[$i]['enable_smilies'],
$CFG['posts_hide_images'],
$CFG['posts_replace_images']);
if (count($orig_word))
{
$result[$i]['topic_title'] = preg_replace($orig_word,
$replacement_word,
$result[$i]['topic_title']);
$result[$i]['post_text'] = preg_replace($orig_word,
$replacement_word,
$result[$i]['post_text']);
}
$result[$i]['trimmed'] = false;
phpbb_trim_text($result[$i]['post_text'],
$result[$i]['trimmed'],
$CFG['posts_trim_text_character'],
$CFG['posts_trim_text_number'],
$CFG['posts_trim_text_words']);
$result[$i]['topic_trimmed'] = false;
phpbb_trim_text($result[$i]['topic_title'],
$result[$i]['topic_trimmed'],
'',
$CFG['posts_trim_topic_number'],
'');
}
}
return $result;
} // end func phpbb_fetch_posts
###############################################################################
## ##
## phpbb_fetch_topics() ##
## ------------------------------------------------------------------------- ##
## This function will fetch the first or the last posting from one or more ##
## topics specified by topic id. The only difference to phpbb_fetch_posts() ##
## is that this function will fetch by topic id instead of forum id. ##
## ##
## PARAMETER ##
## ##
## topic_id ##
## ##
## Can be left blank to fetch from all topicsor set to a single ##
## topic id to fetch that specific topic To fetch from multiple ##
## topics you can parse an array to it. ##
## ##
## fetch_mode ##
## ##
## Set it to POSTS_FETCH_FIRST to fetch the first postings of a ##
## topic (i.e. the posts which started the topic) or set it to ##
## POSTS_FETCH_LAST to fetch the last postings of a topic. ##
## ##
## EXAMPLE ##
## ##
## $news = phpbb_fetch_topics(); ##
## ##
## for ($i = 0; $i < count($news); $i++) ##
## { ##
## echo $news[$i]['topic_title'] . '<br>'; ##
## } ##
## ##
###############################################################################
function phpbb_fetch_topics($topic_id = null, $fetch_mode = FETCH_MODE_FIRST)
{
global $CFG, $userdata;
$topic_list = '';
if (!is_array($topic_id))
{
$topic_list = $topic_id;
}
else
{
for ($i = 0; $i < count($topic_id); $i++)
{
$topic_list .= $topic_id[$i] . ',';
}
if ($topic_list)
{
$topic_list = substr($topic_list, 0, strlen($topic_list) -1);
}
}
$sql = 'SELECT f.*, p.*, pt.*, t.*, u.*';
if (!$CFG['posts_hide_ranks'])
{
$sql .= ', r.*';
}
$sql .= '
FROM ' . TOPICS_TABLE . ' AS t,
' . USERS_TABLE . ' AS u,
' . POSTS_TEXT_TABLE . ' AS pt,
' . POSTS_TABLE . ' AS p,
' . FORUMS_TABLE . ' AS f';
if (!$CFG['posts_hide_ranks'])
{
$sql .= ', ' . RANKS_TABLE . ' AS r';
}
$sql .= '
WHERE u.user_id = p.poster_id AND';
if ($topic_list)
{
$sql .= ' t.topic_id IN (' . $topic_list . ') AND';
}
if ($fetch_mode == FETCH_MODE_FIRST)
{
$sql .= ' t.topic_first_post_id = pt.post_id
AND t.topic_first_post_id = p.post_id AND';
}
else
{
$sql .= ' t.topic_last_post_id = pt.post_id
AND t.topic_last_post_id = p.post_id AND';
}
$sql .= ' t.forum_id = f.forum_id';
if (!$CFG['posts_hide_ranks'])
{
$sql .= '
AND r.rank_id = u.user_rank';
}
$result = phpbb_fetch_rows($sql);
if ($result)
{
if ($CFG['auth_check'])
{
phpbb_get_auth_list();
$authed = array();
for ($i = 0; $i < count($result); $i++)
{
if (in_array($result[$i]['forum_id'], $CFG['auth_list']))
{
$authed[] = $result[$i];
}
}
$result = $authed;
}
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
for ($i = 0; $i < count($result); $i++)
{
$result[$i]['post_time'] =
$result[$i]['post_time'] + $CFG['time_zone'];
$result[$i]['topic_time'] =
$result[$i]['topic_time'] + $CFG['time_zone'];
$result[$i]['post_edit_time'] =
$result[$i]['post_edit_time'] + $CFG['time_zone'];
$result[$i]['date'] =
date($CFG['date_format'], $result[$i]['post_time']);
$result[$i]['time'] =
date($CFG['time_format'], $result[$i]['post_time']);
$result[$i]['edit_date'] =
date($CFG['date_format'], $result[$i]['post_edit_time']);
$result[$i]['edit_time'] =
date($CFG['time_format'], $result[$i]['post_edit_time']);
$result[$i]['post_text'] = phpbb_parse_text(
$result[$i]['post_text'],
$result[$i]['bbcode_uid'],
$result[$i]['enable_smilies'],
$CFG['posts_hide_images'],
$CFG['posts_replace_images']);
if (count($orig_word))
{
$result[$i]['topic_title'] = preg_replace($orig_word,
$replacement_word,
$result[$i]['topic_title']);
$result[$i]['post_text'] = preg_replace($orig_word,
$replacement_word,
$result[$i]['post_text']);
}
$result[$i]['trimmed'] = false;
phpbb_trim_text($result[$i]['post_text'],
$result[$i]['trimmed'],
$CFG['posts_trim_text_character'],
$CFG['posts_trim_text_number'],
$CFG['posts_trim_text_words']);
$result[$i]['topic_trimmed'] = false;
phpbb_trim_text($result[$i]['topic_title'],
$result[$i]['topic_trimmed'],
'',
$CFG['posts_trim_topic_number'],
'');
}
if (is_array($topic_id))
{
$sorted = array();
for ($i = 0; $i < count($topic_id); $i++)
{
for ($j = 0; $j < count($result); $j++)
{
if ($topic_id[$i] == $result[$j]['topic_id'])
{
$sorted[] = $result[$j];
}
}
}
$result = $sorted;
}
}
return $result;
} // end func phpbb_fetch_topics
###############################################################################
## ##
## phpbb_fetch_new_posts() ##
## ------------------------------------------------------------------------- ##
## Fetches the number of new posts since the last visit. ##
## ##
## EXAMPLE ##
## ##
## $new_posts = phpbb_fetch_new_posts(); ##
## ##
## echo 'There are ' . $new_posts . ' new posts for you.'; ##
## ##
###############################################################################
function phpbb_fetch_new_posts()
{
global $userdata;
$result['total'] = 0;
if ($userdata['session_logged_in'])
{
$sql = 'SELECT COUNT(post_id) AS total
FROM ' . POSTS_TABLE . '
WHERE post_time >= ' . $userdata['user_lastvisit'];
$result = phpbb_fetch_row($sql);
}
return $result;
}
###############################################################################
## ##
## phpbb_fetch_thread() ##
## ------------------------------------------------------------------------- ##
## This function will fetch an entire thread by topic id. ##
## ##
## PARAMETER ##
## ##
## topic_id ##
## ##
## Must be set to a single topic id. ##
## ##
## EXAMPLE ##
## ##
## $topic = phpbb_fetch_thread(1); ##
## ##
## for ($i = 0; $i < count($topic); $i++) ##
## { ##
## echo $topic[$i]['post_text'] . '<hr>'; ##
## } ##
## ##
###############################################################################
function phpbb_fetch_thread($topic_id = null)
{
global $CFG, $userdata;
if (!$topic_id)
{
phpbb_raise_error('no topic id specified', __FILE__, __LINE__);
}
$sql = 'SELECT p.*, pt.*, u.*';
if (!$CFG['posts_hide_ranks'])
{
$sql .= ', r.*';
}
$sql .= '
FROM ' . USERS_TABLE . ' AS u,
' . POSTS_TEXT_TABLE . ' AS pt,
' . POSTS_TABLE . ' AS p';
if (!$CFG['posts_hide_ranks'])
{
$sql .= ',
' . RANKS_TABLE . ' AS r';
}
$sql .= '
WHERE p.topic_id = ' . $topic_id . '
AND u.user_id = p.poster_id
AND pt.post_id = p.post_id
AND u.user_id = p.poster_id';
if (!$CFG['posts_hide_ranks'])
{
$sql .= '
AND r.rank_id = u.user_rank';
}
if ($CFG['posts_search_string'])
{
$sql .= '
AND (' . $CFG['posts_search_string'] . ')';
}
$sql .= '
ORDER BY ' . $CFG['posts_order'];
if ($CFG['posts_span_pages'])
{
$CFG['posts_span_pages_numrows'] = phpbb_numrows(phpbb_query($sql));
if ($CFG['posts_span_pages_offset'] > $CFG['posts_span_pages_numrows'])
{
$CFG['posts_span_pages_offset'] =
$CFG['posts_span_pages_numrows'] - 1;
}
$CFG['posts_offset'] = $CFG['posts_span_pages_offset'];
}
else
{
$CFG['posts_offset'] = 0;
}
if ($CFG['posts_limit'] != 0)
{
$sql .= ' LIMIT ' . $CFG['posts_offset'] . ',' . $CFG['posts_limit'];
}
$result = phpbb_fetch_rows($sql);
if ($result)
{
if ($CFG['auth_check'])
{
phpbb_get_auth_list();
$authed = array();
for ($i = 0; $i < count($result); $i++)
{
if (in_array($result[$i]['forum_id'], $CFG['auth_list']))
{
$authed[] = $result[$i];
}
}
$result = $authed;
}
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
for ($i = 0; $i < count($result); $i++)
{
$result[$i]['post_time'] =
$result[$i]['post_time'] + $CFG['time_zone'];
$result[$i]['topic_time'] =
$result[$i]['topic_time'] + $CFG['time_zone'];
$result[$i]['post_edit_time'] =
$result[$i]['post_edit_time'] + $CFG['time_zone'];
$result[$i]['date'] =
date($CFG['date_format'], $result[$i]['post_time']);
$result[$i]['time'] =
date($CFG['time_format'], $result[$i]['post_time']);
$result[$i]['edit_date'] =
date($CFG['date_format'], $result[$i]['post_edit_time']);
$result[$i]['edit_time'] =
date($CFG['time_format'], $result[$i]['post_edit_time']);
$result[$i]['post_text'] = phpbb_parse_text(
$result[$i]['post_text'],
$result[$i]['bbcode_uid'],
$result[$i]['enable_smilies'],
$CFG['posts_hide_images'],
$CFG['posts_replace_images']);
if (count($orig_word))
{
$result[$i]['topic_title'] = preg_replace($orig_word,
$replacement_word,
$result[$i]['topic_title']);
$result[$i]['post_text'] = preg_replace($orig_word,
$replacement_word,
$result[$i]['post_text']);
}
$result[$i]['trimmed'] = false;
phpbb_trim_text($result[$i]['post_text'],
$result[$i]['trimmed'],
$CFG['posts_trim_text_character'],
$CFG['posts_trim_text_number'],
$CFG['posts_trim_text_words']);
$result[$i]['topic_trimmed'] = false;
phpbb_trim_text($result[$i]['topic_title'],
$result[$i]['topic_trimmed'],
'',
$CFG['posts_trim_topic_number'],
'');
}
if (is_array($topic_id))
{
$sorted = array();
for ($i = 0; $i < count($topic_id); $i++)
{
for ($j = 0; $j < count($result); $j++)
{
if ($topic_id[$i] == $result[$j]['topic_id'])
{
$sorted[] = $result[$j];
}
}
}
$result = $sorted;
}
}
return $result;
} // end func phpbb_fetch_thread
###############################################################################
## ##
## phpbb_fetch_newposts() ##
## ------------------------------------------------------------------------- ##
## This function will fetch new postings based on the user session. It's has ##
## the same results as the search.php?search_id=newposts script. ##
## ##
## EXAMPLE ##
## ##
## $newposts = phpbb_fetch_newposts(); ##
## ##
## for ($i = 0; $i < count($newposts); $i++) ##
## { ##
## echo $newposts[$i]['post_text'] . '<br>'; ##
## } ##
## ##
###############################################################################
function phpbb_fetch_newposts()
{
global $CFG, $userdata;
if (!$userdata['session_logged_in'])
{
return;
}
$sql = 'SELECT post_id
FROM ' . POSTS_TABLE . '
WHERE post_time >= ' . $userdata['user_lastvisit'];
$result = phpbb_fetch_rows($sql);
if (!$result)
{
return;
}
$search_ids = array();
for ($i = 0; $i < count($result); $i++)
{
$search_ids[] = $result[$i]['post_id'];
}
$sql = 'SELECT topic_id
FROM ' . POSTS_TABLE . '
WHERE post_id IN (' . implode(', ', $search_ids) . ')
GROUP BY topic_id
ORDER BY post_time DESC';
$result = phpbb_fetch_rows($sql);
if (!$result)
{
return;
}
$topic_ids = array();
for ($i = 0; $i < count($result); $i++)
{
$topic_ids[] = $result[$i]['topic_id'];
}
$result = phpbb_fetch_topics($topic_ids, POSTS_FETCH_LAST);
return $result;
} // end func phpbb_fetch_newposts
?>