Viewing file: general_phpbb.php (14.5 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
/**
*
* @author Robert Johnston
*
* @package Forum Runner
* @version CVS/SVN: $Id: $
* @copyright (c) 2010 End of Time Studios, LLC
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
function
fr_msg_handler ($errno, $msg_text, $errfile, $errline)
{
global $cache, $db, $auth, $template, $config, $user;
global $phpEx, $phpbb_root_path, $msg_title, $msg_long_text;
// Do not display notices if we suppress them via @
if (error_reporting() == 0 && $errno != E_USER_ERROR && $errno != E_USER_WARNING && $errno != E_USER_NOTICE)
{
return;
}
// Message handler is stripping text. In case we need it, we are possible to define long text...
if (isset($msg_long_text) && $msg_long_text && !$msg_text)
{
$msg_text = $msg_long_text;
}
if (!defined('E_DEPRECATED'))
{
define('E_DEPRECATED', 8192);
}
switch ($errno)
{
case E_NOTICE:
case E_WARNING:
// Check the error reporting level and return if the error level does not match
// If DEBUG is defined the default level is E_ALL
if (($errno & ((defined('DEBUG')) ? E_ALL : error_reporting())) == 0)
{
return;
}
if (strpos($errfile, 'cache') === false && strpos($errfile, 'template.') === false)
{
// flush the content, else we get a white page if output buffering is on
if ((int) @ini_get('output_buffering') === 1 || strtolower(@ini_get('output_buffering')) === 'on')
{
@ob_flush();
}
// Another quick fix for those having gzip compression enabled, but do not flush if the coder wants to catch "something". ;)
if (!empty($config['gzip_compress']))
{
if (@extension_loaded('zlib') && !headers_sent() && !ob_get_level())
{
@ob_flush();
}
}
// remove complete path to installation, with the risk of changing backslashes meant to be there
$errfile = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $errfile);
$msg_text = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $msg_text);
json_error('[phpBB Debug] PHP Notice: in file ' . $errfile . ' on line ' . $errline . ':' . $msg_text);
}
return;
break;
case E_USER_ERROR:
$msg_text = (!empty($user->lang[$msg_text])) ? $user->lang[$msg_text] : $msg_text;
json_error(strip_tags($msg_text));
// On a fatal error (and E_USER_ERROR *is* fatal) we never want other scripts to continue and force an exit here.
exit;
break;
case E_USER_WARNING:
case E_USER_NOTICE:
$msg_text = (!empty($user->lang[$msg_text])) ? $user->lang[$msg_text] : $msg_text;
json_error(strip_tags($msg_text));
break;
// PHP4 compatibility
case E_DEPRECATED:
return true;
break;
}
// If we notice an error not handled here we pass this back to PHP by returning false
// This may not work for all php versions
return false;
}
define('FR_PREVIEW_POST', 0);
define('FR_PREVIEW_PM', 1);
function
fr_get_preview ($post_id, $len = FR_PREVIEW_LEN, $type = FR_PREVIEW_POST)
{
global $db;
$text = $uid = '';
switch ($type) {
case FR_PREVIEW_POST:
$result = $db->sql_query("
SELECT post_text, bbcode_uid
FROM " . POSTS_TABLE . "
WHERE post_id = " . $post_id . "
");
$text = $db->sql_fetchfield('post_text');
$uid = $db->sql_fetchfield('bbcode_uid');
break;
case FR_PREVIEW_PM:
$result = $db->sql_query("
SELECT message_text, bbcode_uid
FROM " . PRIVMSGS_TABLE . "
WHERE msg_id = " . $post_id . "
");
$text = $db->sql_fetchfield('message_text');
$uid = $db->sql_fetchfield('bbcode_uid');
break;
}
$t = remove_bbcode_uids_and_smilies(censor_text($text), $uid);
$db->sql_freeresult($result);
return preview_chop($t, $len);
}
function
fr_get_user_avatar ($avatar, $avatar_type)
{
global $config, $phpEx;
if (empty($avatar) || !$avatar_type) {
return '';
}
$avatar_img = '';
switch ($avatar_type) {
case AVATAR_UPLOAD:
if (!$config['allow_avatar_upload']) {
return '';
}
$avatar_img = "/download/file.$phpEx?avatar=";
break;
case AVATAR_GALLERY:
if (!$config['allow_avatar_local']) {
return '';
}
$avatar_img = $config['avatar_gallery_path'] . '/';
break;
case AVATAR_REMOTE:
if (!$config['allow_avatar_remote']) {
return '';
}
break;
}
$avatar_img .= $avatar;
return $avatar_img;
}
function
fr_get_phpbb_bburl ($host_only=false)
{
global $config;
$server_protocol = ($config['server_protocol']) ? $config['server_protocol'] : (($config['cookie_secure']) ? 'https://' : 'http://');
$server_port = (int) $config['server_port'];
$server_name = $config['server_name'];
$script_path = $config['script_path'];
if ($host_only) {
return $server_protocol . $server_name;
} else {
return $server_protocol . $server_name . $script_path;
}
}
function
fr_login_forum_box ($forum_data)
{
global $db, $config, $user, $template, $phpEx;
$password = request_var('password', '', true);
$sql = 'SELECT forum_id
FROM ' . FORUMS_ACCESS_TABLE . '
WHERE forum_id = ' . $forum_data['forum_id'] . '
AND user_id = ' . $user->data['user_id'] . "
AND session_id = '" . $db->sql_escape($user->session_id) . "'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row)
{
return true;
}
if ($password)
{
// Remove expired authorised sessions
$sql = 'SELECT f.session_id
FROM ' . FORUMS_ACCESS_TABLE . ' f
LEFT JOIN ' . SESSIONS_TABLE . ' s ON (f.session_id = s.session_id)
WHERE s.session_id IS NULL';
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
{
$sql_in = array();
do
{
$sql_in[] = (string) $row['session_id'];
}
while ($row = $db->sql_fetchrow($result));
// Remove expired sessions
$sql = 'DELETE FROM ' . FORUMS_ACCESS_TABLE . '
WHERE ' . $db->sql_in_set('session_id', $sql_in);
$db->sql_query($sql);
}
$db->sql_freeresult($result);
if (phpbb_check_hash($password, $forum_data['forum_password']))
{
$sql_ary = array(
'forum_id' => (int) $forum_data['forum_id'],
'user_id' => (int) $user->data['user_id'],
'session_id' => (string) $user->session_id,
);
$db->sql_query('INSERT INTO ' . FORUMS_ACCESS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
return true;
}
$template->assign_var('LOGIN_ERROR', $user->lang['WRONG_PASSWORD']);
}
return false;
}
function
fr_get_pm_unread ()
{
global $user, $phpbb_root_path, $phpEx;
include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
if ($user->data['user_id'] == ANONYMOUS) {
return 0;
}
update_pm_counts();
return $user->data['user_unread_privmsg'];
}
function
fr_get_sub_thread_updates ()
{
global $config, $user, $db;
$sql_array = array(
'SELECT' => 't.*, f.forum_name',
'FROM' => array(
TOPICS_WATCH_TABLE => 'tw',
TOPICS_TABLE => 't'
),
'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . '
AND t.topic_id = tw.topic_id
AND ' . $db->sql_in_set('t.forum_id', array(), true, true),
'ORDER_BY' => 't.topic_last_post_time DESC'
);
$sql_array['LEFT_JOIN'] = array();
$sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
if ($config['load_db_lastread'])
{
$sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
$sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
}
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
$topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
while ($row = $db->sql_fetchrow($result))
{
$topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
$topic_list[] = $topic_id;
$rowset[$topic_id] = $row;
$topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
$topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
if ($row['topic_type'] == POST_GLOBAL)
{
$global_announce_list[] = $topic_id;
}
}
$db->sql_freeresult($result);
$topic_tracking_info = array();
if ($config['load_db_lastread'])
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), ($f_id == 0) ? $global_announce_list : false);
}
}
else
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list);
}
}
$unread_topics = 0;
foreach ($topic_list as $topic_id)
{
$row = &$rowset[$topic_id];
$forum_id = $row['forum_id'];
$topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
if ($unread_topic) {
$unread_topics++;
}
}
return $unread_topics;
}
function
fr_update_push_user ($username = '', $fr_b = false)
{
global $db, $user, $table_prefix;
if ($username != '' && $user->data['is_registered']) {
$result = $db->sql_query("
SHOW TABLES LIKE '{$table_prefix}forumrunner_push_users'
");
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
// There can be only one FR user associated with this userid and fr_username
$result = $db->sql_query("
SELECT id FROM {$table_prefix}forumrunner_push_users
WHERE userid = {$user->data['user_id']}
");
$rowset = $db->sql_fetchrowset($result);
if (count($rowset) > 1) {
// Multiple userids. Nuke em.
$db->sql_query("
DELETE FROM {$table_prefix}forumrunner_push_users
WHERE userid = {$user->data['user_id']}
");
}
$db->sql_freeresult($result);
$result = $db->sql_query("
SELECT id FROM {$table_prefix}forumrunner_push_users
WHERE fr_username = '" . $db->sql_escape($username) . "'
");
$fr_user = (int)$db->sql_fetchfield('id');
$db->sql_freeresult($result);
if ($fr_user) {
$db->sql_query("
UPDATE {$table_prefix}forumrunner_push_users
SET userid = {$user->data['user_id']}, last_login = NOW(), b = " . ($fr_b ? 1 : 0) . "
WHERE id = $fr_user
");
} else {
$db->sql_query("
INSERT INTO {$table_prefix}forumrunner_push_users
(userid, fr_username, b, last_login)
VALUES ({$user->data['user_id']}, '" . $db->sql_escape($username) . "', " . ($fr_b ? 1 : 0) . ", NOW())
");
}
}
}
}
function
fr_update_subsent ($threadid, $threadread)
{
global $db, $table_prefix, $user;
$result = $db->sql_query("
SHOW TABLES LIKE '{$table_prefix}forumrunner_push_data'
");
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
$db->sql_query("
UPDATE {$table_prefix}forumrunner_push_data
SET subsent = 0, topicread = $threadread
WHERE userid = {$user->data['user_id']} AND topicid = $threadid
");
}
}
function
fr_show_ad ()
{
global $db, $user;
$groups = fr_get_config('fr_googleads_usergroups');
$js = fr_get_config('fr_googleads_javascript');
if (fr_get_config('fr_googleads') == 0 || !$groups || $groups == '' || !$js || $js == '') {
return 0;
}
if (!in_array($user->data['group_id'], explode(',', $groups))) {
return 0;
}
$ad = 0;
if (fr_get_config('fr_googleads_threadlist') == 1) {
$ad += FR_AD_THREADLIST;
}
if (fr_get_config('fr_googleads_topthread') == 1) {
$ad += FR_AD_TOPTHREAD;
}
if (fr_get_config('fr_googleads_bottomthread') == 1) {
$ad += FR_AD_BOTTOMTHREAD;
}
return $ad;
}
function
fr_get_config ($config_name)
{
global $table_prefix, $db;
$result = $db->sql_query("
SHOW TABLES LIKE '{$table_prefix}forumrunner_config'
");
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$row) {
return;
}
$result = $db->sql_query("
SELECT config_value
FROM {$table_prefix}forumrunner_config
WHERE config_name = '" . $db->sql_escape($config_name) . "'
");
$out = $db->sql_fetchfield('config_value');
$db->sql_freeresult($result);
if ($out) {
return trim($out);
}
}
function
fr_set_cookie ($name, $cookiedata, $cookietime)
{
global $config;
$name_data = rawurlencode($name) . '=' . rawurlencode($cookiedata);
$expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime);
$domain = (!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain'];
header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $config['cookie_path'] . $domain . ((!$config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false);
}
function
fr_smiley_text ($text, $force_option = false)
{
global $config, $user, $phpbb_root_path;
if ($force_option || !$config['allow_smilies'] || !$user->optionget('viewsmilies')) {
return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $text);
} else {
$root_path = fr_get_phpbb_bburl() . '/';
return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $root_path . $config['smilies_path'] . '/\2 />', $text);
}
}
function
remove_bbcode_uids_and_smilies ($text, $uid)
{
$message_parser = new parse_message();
$message_parser->message = $text;
$message_parser->bbcode_uid = $uid;
$message_parser->decode_message();
$text = html_entity_decode_utf8($message_parser->message, true);
return strip_tags($message_parser->message);
}
function
fr_set_debug ()
{
if (isset($_REQUEST['d'])) {
error_reporting(E_ALL);
} else {
error_reporting(0);
}
}
?>
|