$v)
{
if (is_array($v))
{
foreach ($v as $_k => $_v)
{
set_var($var[$k][$_k], $_v, $type, $multibyte);
}
}
else
{
set_var($var[$k], $v, $type, $multibyte);
}
}
}
else
{
set_var($var, $var, $type, $multibyte);
}
return $var;
}
}
/**
* Set config value. Creates missing config entry.
*/
function set_config($config_name, $config_value, $is_dynamic = false)
{
global $db, $cache, $config;
$sql = 'UPDATE ' . CONFIG_TABLE . "
SET config_value = '" . $db->sql_escape($config_value) . "'
WHERE config_name = '" . $db->sql_escape($config_name) . "'";
$db->sql_query($sql);
if (!$db->sql_affectedrows() && !isset($config[$config_name]))
{
$sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array(
'config_name' => $config_name,
'config_value' => $config_value,
'is_dynamic' => ($is_dynamic) ? 1 : 0));
$db->sql_query($sql);
}
$config[$config_name] = $config_value;
if (!$is_dynamic)
{
$cache->destroy('config');
$cache->save();
}
}
/**
* Generates an alphanumeric random string of given length
*/
function gen_rand_string($num_chars)
{
$chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9');
list($usec, $sec) = explode(' ', microtime());
mt_srand($sec * $usec);
$max_chars = count($chars) - 1;
$rand_str = '';
for ($i = 0; $i < $num_chars; $i++)
{
$rand_str .= $chars[mt_rand(0, $max_chars)];
}
return $rand_str;
}
/**
* Get userdata
* @param mixed $user user id or username
*/
function get_userdata($user)
{
global $db;
$sql = 'SELECT *
FROM ' . USERS_TABLE . '
WHERE ';
$sql .= ((is_integer($user)) ? "user_id = $user" : "username = '" . $db->sql_escape($user) . "'") . " AND user_id <> " . ANONYMOUS;
$result = $db->sql_query($sql);
return ($row = $db->sql_fetchrow($result)) ? $row : false;
}
/**
* Create forum rules for given forum
*/
function generate_forum_rules(&$forum_data)
{
if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
{
return;
}
global $template, $phpbb_root_path, $phpEx;
if ($forum_data['forum_rules'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($forum_data['forum_rules_bbcode_bitfield']);
$bbcode->bbcode_second_pass($forum_data['forum_rules'], $forum_data['forum_rules_bbcode_uid']);
$forum_data['forum_rules'] = smiley_text($forum_data['forum_rules'], !($forum_data['forum_rules_flags'] & 2));
$forum_data['forum_rules'] = str_replace("\n", '
', censor_text($forum_data['forum_rules']));
unset($bbcode);
}
$template->assign_vars(array(
'S_FORUM_RULES' => true,
'U_FORUM_RULES' => $forum_data['forum_rules_link'],
'FORUM_RULES' => $forum_data['forum_rules'])
);
}
/**
* Create forum navigation links for given forum, create parent
* list if currently null, assign basic forum info to template
*/
function generate_forum_nav(&$forum_data)
{
global $db, $user, $template, $phpEx, $SID, $phpbb_root_path;
// Get forum parents
$forum_parents = get_forum_parents($forum_data);
// Build navigation links
foreach ($forum_parents as $parent_forum_id => $parent_data)
{
list($parent_name, $parent_type) = array_values($parent_data);
$template->assign_block_vars('navlinks', array(
'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false,
'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false,
'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false,
'FORUM_NAME' => $parent_name,
'FORUM_ID' => $parent_forum_id,
'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$parent_forum_id")
);
}
$template->assign_block_vars('navlinks', array(
'S_IS_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
'S_IS_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
'S_IS_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
'FORUM_NAME' => $forum_data['forum_name'],
'FORUM_ID' => $forum_data['forum_id'],
'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=" . $forum_data['forum_id'])
);
$template->assign_vars(array(
'FORUM_ID' => $forum_data['forum_id'],
'FORUM_NAME' => $forum_data['forum_name'],
'FORUM_DESC' => strip_tags($forum_data['forum_desc']))
);
return;
}
/**
* Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
*/
function get_forum_parents(&$forum_data)
{
global $db;
$forum_parents = array();
if ($forum_data['parent_id'] > 0)
{
if ($forum_data['forum_parents'] == '')
{
$sql = 'SELECT forum_id, forum_name, forum_type
FROM ' . FORUMS_TABLE . '
WHERE left_id < ' . $forum_data['left_id'] . '
AND right_id > ' . $forum_data['right_id'] . '
ORDER BY left_id ASC';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
}
$db->sql_freeresult($result);
$forum_data['forum_parents'] = serialize($forum_parents);
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
WHERE parent_id = " . $forum_data['parent_id'];
$db->sql_query($sql);
}
else
{
$forum_parents = unserialize($forum_data['forum_parents']);
}
}
return $forum_parents;
}
/**
* Obtain list of moderators of each forum
*/
function get_moderators(&$forum_moderators, $forum_id = false)
{
global $config, $template, $db, $phpEx, $SID;
// Have we disabled the display of moderators? If so, then return
// from whence we came ...
if (empty($config['load_moderators']))
{
return;
}
if (!empty($forum_id) && is_array($forum_id))
{
$forum_sql = 'AND forum_id IN (' . implode(', ', $forum_id) . ')';
}
else
{
$forum_sql = ($forum_id) ? 'AND forum_id = ' . $forum_id : '';
}
$sql = 'SELECT *
FROM ' . MODERATOR_TABLE . "
WHERE display_on_index = 1
$forum_sql";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$forum_moderators[$row['forum_id']][] = (!empty($row['user_id'])) ? '' . $row['username'] . '' : '' . $row['groupname'] . '';
}
$db->sql_freeresult($result);
return;
}
/**
* User authorisation levels output
*/
function gen_forum_auth_level($mode, $forum_id)
{
global $SID, $template, $auth, $user;
$rules = array(
($auth->acl_get('f_post', $forum_id)) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
($auth->acl_get('f_reply', $forum_id)) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
($auth->acl_gets('f_edit', 'm_edit', $forum_id)) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
($auth->acl_gets('f_delete', 'm_delete', $forum_id)) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach', $forum_id)) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT']
);
foreach ($rules as $rule)
{
$template->assign_block_vars('rules', array('RULE' => $rule));
}
return;
}
/**
* Generate sort selection fields
*/
function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir, &$u_sort_param)
{
global $user;
$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
$s_limit_days = '';
$s_sort_key = '';
$s_sort_dir = '';
$u_sort_param = "st=$sort_days&sk=$sort_key&sd=$sort_dir";
return;
}
/**
* Generate Jumpbox
*/
function make_jumpbox($action, $forum_id = false, $select_all = false, $acl_list = false)
{
global $config, $auth, $template, $user, $db, $phpEx, $SID;
if (!$config['load_jumpbox'])
{
return;
}
$sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
FROM ' . FORUMS_TABLE . '
ORDER BY left_id ASC';
$result = $db->sql_query($sql, 600);
$right = $padding = 0;
$padding_store = array('0' => 0);
$display_jumpbox = false;
$iteration = 0;
// Sometimes it could happen that forums will be displayed here not be displayed within the index page
// This is the result of forums not displayed at index, having list permissions and a parent of a forum with no permissions.
// If this happens, the padding could be "broken"
while ($row = $db->sql_fetchrow($result))
{
if ($row['left_id'] < $right)
{
$padding++;
$padding_store[$row['parent_id']] = $padding;
}
else if ($row['left_id'] > $right + 1)
{
$padding = $padding_store[$row['parent_id']];
}
$right = $row['right_id'];
if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
{
// Non-postable forum with no subforums, don't display
continue;
}
if (!$auth->acl_get('f_list', $row['forum_id']))
{
// if the user does not have permissions to list this forum skip
continue;
}
if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
{
continue;
}
if (!$display_jumpbox)
{
$template->assign_block_vars('jumpbox_forums', array(
'FORUM_ID' => ($select_all) ? 0 : -1,
'FORUM_NAME' => ($select_all) ? $user->lang['ALL_FORUMS'] : $user->lang['SELECT_FORUM'],
'S_FORUM_COUNT' => $iteration)
);
$iteration++;
$display_jumpbox = true;
}
$template->assign_block_vars('jumpbox_forums', array(
'FORUM_ID' => $row['forum_id'],
'FORUM_NAME' => $row['forum_name'],
'SELECTED' => ($row['forum_id'] == $forum_id) ? ' selected="selected"' : '',
'S_FORUM_COUNT' => $iteration,
'S_IS_CAT' => ($row['forum_type'] == FORUM_CAT) ? true : false,
'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
'S_IS_POST' => ($row['forum_type'] == FORUM_POST) ? true : false)
);
for ($i = 0; $i < $padding; $i++)
{
$template->assign_block_vars('jumpbox_forums.level', array());
}
$iteration++;
}
$db->sql_freeresult($result);
unset($padding_store);
$template->assign_vars(array(
'S_DISPLAY_JUMPBOX' => $display_jumpbox,
'S_JUMPBOX_ACTION' => $action)
);
return;
}
/**
* Pick a language, any language ...
*/
function language_select($default = '')
{
global $db;
$sql = 'SELECT lang_iso, lang_local_name
FROM ' . LANG_TABLE . '
ORDER BY lang_english_name';
$result = $db->sql_query($sql);
$lang_options = '';
while ($row = $db->sql_fetchrow($result))
{
$selected = ($row['lang_iso'] == $default) ? ' selected="selected"' : '';
$lang_options .= '';
}
$db->sql_freeresult($result);
return $lang_options;
}
/**
* Pick a template/theme combo,
*/
function style_select($default = '', $all = false)
{
global $db;
$sql_where = (!$all) ? 'WHERE style_active = 1 ' : '';
$sql = 'SELECT style_id, style_name
FROM ' . STYLES_TABLE . "
$sql_where
ORDER BY style_name";
$result = $db->sql_query($sql);
$style_options = '';
while ($row = $db->sql_fetchrow($result))
{
$selected = ($row['style_id'] == $default) ? ' selected="selected"' : '';
$style_options .= '';
}
$db->sql_freeresult($result);
return $style_options;
}
/**
* Pick a timezone
*/
function tz_select($default = '')
{
global $sys_timezone, $user;
$tz_select = '';
foreach ($user->lang['tz'] as $offset => $zone)
{
if (is_numeric($offset))
{
$selected = ($offset == $default) ? ' selected="selected"' : '';
$tz_select .= '';
}
}
return $tz_select;
}
/**
* Topic and forum watching common code
*/
function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $match_id, $notify_status = 'unset', $start = 0)
{
global $template, $db, $user, $phpEx, $SID, $start, $phpbb_root_path;
$table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
$where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
$u_url = ($mode == 'forum') ? 'f' : 't';
// Is user watching this thread?
if ($user_id != ANONYMOUS)
{
$can_watch = TRUE;
if ($notify_status == 'unset')
{
$sql = "SELECT notify_status
FROM $table_sql
WHERE $where_sql = $match_id
AND user_id = $user_id";
$result = $db->sql_query($sql);
$notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
$db->sql_freeresult($result);
}
if (!is_null($notify_status))
{
if (isset($_GET['unwatch']))
{
if ($_GET['unwatch'] == $mode)
{
$is_watching = 0;
$sql = 'DELETE FROM ' . $table_sql . "
WHERE $where_sql = $match_id
AND user_id = $user_id";
$db->sql_query($sql);
}
meta_refresh(3, "view$mode.$phpEx$SID&$u_url=$match_id&start=$start");
$message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '
' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '', '');
trigger_error($message);
}
else
{
$is_watching = TRUE;
if ($notify_status)
{
$sql = 'UPDATE ' . $table_sql . "
SET notify_status = 0
WHERE $where_sql = $match_id
AND user_id = $user_id";
$db->sql_query($sql);
}
}
}
else
{
if (isset($_GET['watch']))
{
if ($_GET['watch'] == $mode)
{
$is_watching = TRUE;
$sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
VALUES ($user_id, $match_id, 0)";
$db->sql_query($sql);
}
meta_refresh(3, "view$mode.$phpEx$SID&$u_url=$match_id&start=$start");
$message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '
' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '', '');
trigger_error($message);
}
else
{
$is_watching = 0;
}
}
}
else
{
if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
{
login_box();
}
else
{
$can_watch = 0;
$is_watching = 0;
}
}
if ($can_watch)
{
$s_watching['link'] = "{$phpbb_root_path}view$mode.$phpEx$SID&$u_url=$match_id&" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&start=$start";
$s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
}
return;
}
/**
* Marks a topic or form as read
*/
function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
{
global $config, $db, $user;
if ($user->data['user_id'] == ANONYMOUS)
{
return;
}
if (!is_array($forum_id))
{
$forum_id = array($forum_id);
}
// Default tracking type
$type = TRACK_NORMAL;
$current_time = ($marktime) ? $marktime : time();
$topic_id = (int) $topic_id;
switch ($mode)
{
case 'mark':
if ($config['load_db_lastread'])
{
$sql = 'SELECT forum_id
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
AND forum_id IN (' . implode(', ', array_map('intval', $forum_id)) . ')';
$result = $db->sql_query($sql);
$sql_update = array();
while ($row = $db->sql_fetchrow($result))
{
$sql_update[] = $row['forum_id'];
}
$db->sql_freeresult($result);
if (sizeof($sql_update))
{
$sql = 'UPDATE ' . FORUMS_TRACK_TABLE . "
SET mark_time = $current_time
WHERE user_id = " . $user->data['user_id'] . '
AND forum_id IN (' . implode(', ', $sql_update) . ')';
$db->sql_query($sql);
}
if ($sql_insert = array_diff($forum_id, $sql_update))
{
foreach ($sql_insert as $forum_id)
{
$sql = '';
switch (SQL_LAYER)
{
case 'mysql':
$sql .= (($sql != '') ? ', ' : '') . '(' . $user->data['user_id'] . ", $forum_id, $current_time)";
$sql = 'VALUES ' . $sql;
break;
case 'mysql4':
case 'mssql':
case 'sqlite':
$sql .= (($sql != '') ? ' UNION ALL ' : '') . ' SELECT ' . $user->data['user_id'] . ", $forum_id, $current_time";
break;
default:
$sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . ' (user_id, forum_id, mark_time)
VALUES (' . $user->data['user_id'] . ", $forum_id, $current_time)";
$db->sql_query($sql);
$sql = '';
}
if ($sql)
{
$sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . " (user_id, forum_id, mark_time) $sql";
$db->sql_query($sql);
}
}
}
unset($sql_update);
unset($sql_insert);
}
else
{
$tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
foreach ($forum_id as $f_id)
{
unset($tracking[$f_id]);
$tracking[$f_id][0] = base_convert($current_time - $config['board_startdate'], 10, 36);
}
$user->set_cookie('track', serialize($tracking), time() + 31536000);
unset($tracking);
}
break;
case 'post':
// Mark a topic as read and mark it as a topic where the user has made a post.
$type = TRACK_POSTED;
case 'topic':
if (!isset($type))
{
$type = TRACK_NORMAL;
}
$forum_id = (int) $forum_id[0];
// Mark a topic as read
if ($config['load_db_lastread'] || ($config['load_db_track'] && $type == TRACK_POSTED))
{
$track_type = ($type == TRACK_POSTED ? ', mark_type = ' . $type : '');
$sql = 'UPDATE ' . TOPICS_TRACK_TABLE . "
SET mark_time = $current_time $track_type
WHERE topic_id = $topic_id
AND user_id = " . $user->data['user_id'] . "
AND mark_time < $current_time";
if (!$db->sql_query($sql) || !$db->sql_affectedrows())
{
$type = (!isset($type)) ? TRACK_NORMAL : $type;
$db->sql_return_on_error(true);
$sql = 'INSERT INTO ' . TOPICS_TRACK_TABLE . ' (user_id, topic_id, mark_type, mark_time)
VALUES (' . $user->data['user_id'] . ", $topic_id, $type, $current_time)";
$db->sql_query($sql);
$db->sql_return_on_error(false);
}
}
if (!$config['load_db_lastread'])
{
$tracking = array();
if (isset($_COOKIE[$config['cookie_name'] . '_track']))
{
$tracking = unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track']));
// If the cookie grows larger than 2000 characters we will remove
// the smallest value
if (strlen($_COOKIE[$config['cookie_name'] . '_track']) > 2000)
{
foreach ($tracking as $f => $t_ary)
{
if (!isset($m_value) || min($t_ary) < $m_value)
{
$m_value = min($t_ary);
$m_tkey = array_search($m_value, $t_ary);
$m_fkey = $f;
}
}
unset($tracking[$m_fkey][$m_tkey]);
}
}
if (isset($tracking[$forum_id]) && base_convert($tracking[$forum_id][0], 36, 10) < $current_time)
{
$tracking[$forum_id][base_convert($topic_id, 10, 36)] = base_convert($current_time - $config['board_startdate'], 10, 36);
$user->set_cookie('track', serialize($tracking), time() + 31536000);
}
else if (!isset($tracking[$forum_id]))
{
$tracking[$forum_id][0] = base_convert($current_time - $config['board_startdate'], 10, 36);
$user->set_cookie('track', serialize($tracking), time() + 31536000);
}
unset($tracking);
}
break;
}
}
/**
* Pagination routine, generates page number sequence
* tpl_prefix is for using different pagination blocks at one page
*/
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = '')
{
global $template, $user;
$seperator = $user->theme['primary']['pagination_sep'];
$total_pages = ceil($num_items/$per_page);
if ($total_pages == 1 || !$num_items)
{
return false;
}
$on_page = floor($start_item / $per_page) + 1;
$page_string = ($on_page == 1) ? '1' : '1';
if ($total_pages > 5)
{
$start_cnt = min(max(1, $on_page - 4), $total_pages - 5);
$end_cnt = max(min($total_pages, $on_page + 4), 6);
$page_string .= ($start_cnt > 1) ? ' ... ' : $seperator;
for($i = $start_cnt + 1; $i < $end_cnt; $i++)
{
$page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . '';
if ($i < $end_cnt - 1)
{
$page_string .= $seperator;
}
}
$page_string .= ($end_cnt < $total_pages) ? ' ... ' : $seperator;
}
else
{
$page_string .= $seperator;
for($i = 2; $i < $total_pages; $i++)
{
$page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . '';
if ($i < $total_pages)
{
$page_string .= $seperator;
}
}
}
$page_string .= ($on_page == $total_pages) ? '' . $total_pages . '' : '' . $total_pages . '';
if ($add_prevnext_text)
{
if ($on_page != 1)
{
$page_string = '' . $user->lang['PREVIOUS'] . ' ' . $page_string;
}
if ($on_page != $total_pages)
{
$page_string .= ' ' . $user->lang['NEXT'] . '';
}
}
$template->assign_vars(array(
$tpl_prefix . 'BASE_URL' => $base_url,
$tpl_prefix . 'PER_PAGE' => $per_page,
$tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . '&start=' . (($on_page - 2) * $per_page),
$tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . '&start=' . ($on_page * $per_page))
);
return $page_string;
}
/**
* Return current page (pagination)
*/
function on_page($num_items, $per_page, $start)
{
global $template, $user;
$on_page = floor($start / $per_page) + 1;
$template->assign_var('ON_PAGE', $on_page);
return sprintf($user->lang['PAGE_OF'], $on_page, max(ceil($num_items / $per_page), 1));
}
/**
* Obtain list of naughty words and build preg style replacement arrays for use by the
* calling script
*/
function obtain_word_list(&$censors)
{
global $db, $cache, $user;
if (!$user->optionget('viewcensors') && $config['allow_nocensors'])
{
return;
}
if ($cache->exists('word_censors'))
{
$censors = $cache->get('word_censors');
}
else
{
$sql = 'SELECT word, replacement
FROM ' . WORDS_TABLE;
$result = $db->sql_query($sql);
$censors = array();
while ($row = $db->sql_fetchrow($result))
{
$censors['match'][] = '#\b(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')\b#i';
$censors['replace'][] = $row['replacement'];
}
$db->sql_freeresult($result);
$cache->put('word_censors', $censors);
}
return true;
}
/**
* Obtain currently listed icons
*/
function obtain_icons(&$icons)
{
global $db, $cache;
if ($cache->exists('icons'))
{
$icons = $cache->get('icons');
}
else
{
// Topic icons
$sql = 'SELECT *
FROM ' . ICONS_TABLE . '
ORDER BY icons_order';
$result = $db->sql_query($sql);
$icons = array();
while ($row = $db->sql_fetchrow($result))
{
$icons[$row['icons_id']]['img'] = $row['icons_url'];
$icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
$icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
$icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
}
$db->sql_freeresult($result);
$cache->put('icons', $icons);
}
return;
}
/**
* Obtain ranks
*/
function obtain_ranks(&$ranks)
{
global $db, $cache;
if ($cache->exists('ranks'))
{
$ranks = $cache->get('ranks');
}
else
{
$sql = 'SELECT *
FROM ' . RANKS_TABLE . '
ORDER BY rank_min DESC';
$result = $db->sql_query($sql);
$ranks = array();
while ($row = $db->sql_fetchrow($result))
{
if ($row['rank_special'])
{
$ranks['special'][$row['rank_id']] = array(
'rank_title' => $row['rank_title'],
'rank_image' => $row['rank_image']
);
}
else
{
$ranks['normal'][] = array(
'rank_title' => $row['rank_title'],
'rank_min' => $row['rank_min'],
'rank_image' => $row['rank_image']
);
}
}
$db->sql_freeresult($result);
$cache->put('ranks', $ranks);
}
}
/**
* Obtain allowed extensions
*/
function obtain_attach_extensions(&$extensions, $forum_id = false)
{
global $db, $cache;
if ($cache->exists('extensions'))
{
$extensions = $cache->get('extensions');
}
else
{
// The rule is to only allow those extensions defined. ;)
$sql = 'SELECT e.extension, g.*
FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
WHERE e.group_id = g.group_id
AND g.allow_group = 1';
$result = $db->sql_query($sql);
$extensions = array();
while ($row = $db->sql_fetchrow($result))
{
$extension = strtolower(trim($row['extension']));
$extensions[$extension]['display_cat'] = (int) $row['cat_id'];
$extensions[$extension]['download_mode'] = (int) $row['download_mode'];
$extensions[$extension]['upload_icon'] = trim($row['upload_icon']);
$extensions[$extension]['max_filesize'] = (int) $row['max_filesize'];
$allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
if ($row['allow_in_pm'])
{
$allowed_forums = array_merge($allowed_forums, array(0));
}
// Store allowed extensions forum wise
$extensions['_allowed_'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
}
$db->sql_freeresult($result);
$cache->put('extensions', $extensions);
}
if ($forum_id !== false)
{
$return = array();
foreach ($extensions['_allowed_'] as $extension => $check)
{
$allowed = false;
if (is_array($check))
{
// Check for private messaging
if (sizeof($check) == 1 && $check[0] == 0)
{
$allowed = true;
continue;
}
$allowed = (!in_array($forum_id, $check)) ? false : true;
}
else
{
$allowed = ($forum_id == 0) ? false : true;
}
if ($allowed)
{
$return['_allowed_'][$extension] = 0;
$return[$extension] = $extensions[$extension];
}
}
$extensions = $return;
}
return;
}
/**
* Generate board url
*/
function generate_board_url()
{
global $config;
$path = preg_replace('#^/?(.*?)/?$#', '\1', trim($config['script_path']));
return (($config['cookie_secure']) ? 'https://' : 'http://') . preg_replace('#^/?(.*?)/?$#', '\1', trim($config['server_name'])) . (($config['server_port'] <> 80) ? ':' . trim($config['server_port']) : '') . (($path) ? '/' . $path : '');
}
/**
* Redirects the user to another page then exits the script nicely
*/
function redirect($url)
{
global $db, $cache, $config, $user;
if (isset($db))
{
$db->sql_close();
}
if (isset($cache))
{
$cache->unload();
}
// Make sure no &'s are in, this will break the redirect
$url = str_replace('&', '&', $url);
// If relative path, prepend board url
if (strpos($url, '://') === false && $url{0} != '/')
{
$url = generate_board_url() . preg_replace('#^/?(.*?)/?$#', '/\1', trim($url));
}
// Redirect via an HTML form for PITA webservers
if (@preg_match('#Microsoft|WebSTAR|Xitami#', getenv('SERVER_SOFTWARE')))
{
header('Refresh: 0; URL=' . $url);
echo '
![]() | General Error |
' . $msg_text . ' Please notify the board administrator or webmaster : ' . $config['board_contact'] . ' |