1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-06 16:56:44 +02:00

- added updated coding guidelines

- introduced is_registered and is_bot flags for correct determinition of guest/registered/bot users
- changed bot code to act on useragent || ip


git-svn-id: file:///svn/phpbb/trunk@5117 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen
2005-04-10 18:07:12 +00:00
parent c947835317
commit 557d09bb72
30 changed files with 1233 additions and 483 deletions

View File

@@ -87,13 +87,14 @@ class acm
}
$this->var_expires = array();
if (count($delete))
if (sizeof($delete))
{
$sql = 'DELETE FROM ' . CACHE_TABLE . "
WHERE var_name IN ('" . implode("', '", $delete) . "')";
$db->sql_query($sql);
}
if (count($insert))
if (sizeof($insert))
{
switch (SQL_LAYER)
{

View File

@@ -236,7 +236,7 @@ class acm
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
$query_id = 'Cache id #' . count($this->sql_rowset);
$query_id = 'Cache id #' . sizeof($this->sql_rowset);
if (!file_exists($this->cache_dir . 'sql_' . md5($query) . ".$phpEx"))
{

View File

@@ -39,7 +39,7 @@ function login_ldap(&$username, &$password)
$search = @ldap_search($ldap, $config['ldap_base_dn'], $config['ldap_uid'] . '=' . $username, array($config['ldap_uid']));
$result = @ldap_get_entries($ldap, $search);
if (is_array($result) && count($result) > 1)
if (is_array($result) && sizeof($result) > 1)
{
if (@ldap_bind($ldap, $result[0]['dn'], $password))
{

View File

@@ -558,7 +558,7 @@ class sql_db
{
while ($row = $this->sql_fetchrow($result))
{
if (!$html_table && count($row))
if (!$html_table && sizeof($row))
{
$html_table = TRUE;
$html_hold .= '<table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center"><tr>';

View File

@@ -454,7 +454,7 @@ class sql_db
{
while ($row = mysql_fetch_assoc($result))
{
if (!$html_table && count($row))
if (!$html_table && sizeof($row))
{
$html_table = TRUE;
$html_hold .= '<table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center"><tr>';

View File

@@ -148,7 +148,7 @@ class sql_db
{
while ($row = @sqlite_fetch_array($result, @sqlite_ASSOC))
{
if (!$html_table && count($row))
if (!$html_table && sizeof($row))
{
$html_table = TRUE;
$this->sql_report .= "<table width=100% border=1 cellpadding=2 cellspacing=1>\n";

View File

@@ -110,7 +110,7 @@ function gen_rand_string($num_chars)
list($usec, $sec) = explode(' ', microtime());
mt_srand($sec * $usec);
$max_chars = count($chars) - 1;
$max_chars = sizeof($chars) - 1;
$rand_str = '';
for ($i = 0; $i < $num_chars; $i++)
{
@@ -505,7 +505,7 @@ function tz_select($default = '')
global $sys_timezone, $user;
$tz_select = '';
foreach ($user->lang['tz'] as $offset => $zone)
foreach ($user->lang['tz']['zones'] as $offset => $zone)
{
if (is_numeric($offset))
{
@@ -631,7 +631,7 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
{
global $config, $db, $user;
if ($user->data['user_id'] == ANONYMOUS)
if (!$user->data['is_registered'])
{
return;
}
@@ -1804,7 +1804,7 @@ function page_header($page_title = '')
$s_privmsg_new = false;
// Obtain number of new private messages if user is logged in
if ($user->data['user_id'] != ANONYMOUS)
if ($user->data['is_registered'])
{
if ($user->data['user_new_privmsg'])
{
@@ -1842,7 +1842,7 @@ function page_header($page_title = '')
// Which timezone?
$tz = ($user->data['user_id'] != ANONYMOUS) ? strval(doubleval($user->data['user_timezone'])) : strval(doubleval($config['board_timezone']));
// The following assigns all _common_ variables that may be used at any point
// in a template.
$template->assign_vars(array(
@@ -1889,10 +1889,10 @@ function page_header($page_title = '')
'S_CONTENT_ENCODING' => $user->lang['ENCODING'],
'S_CONTENT_DIR_LEFT' => $user->lang['LEFT'],
'S_CONTENT_DIR_RIGHT' => $user->lang['RIGHT'],
'S_TIMEZONE' => ($user->data['user_dst'] || ($user->data['user_id'] == ANONYMOUS && $config['board_dst'])) ? sprintf($user->lang['ALL_TIMES'], (($tz >= 0) ? '+' . $tz : $tz), $user->lang['tz']['dst']) : sprintf($user->lang['ALL_TIMES'], (($tz >= 0) ? '+' . $tz : $tz), ''),
'S_DISPLAY_ONLINE_LIST' => (!empty($config['load_online'])) ? 1 : 0,
'S_DISPLAY_SEARCH' => (!empty($config['load_search'])) ? 1 : 0,
'S_DISPLAY_PM' => (!empty($config['allow_privmsg'])) ? 1 : 0,
'S_TIMEZONE' => ($user->data['user_dst'] || ($user->data['user_id'] == ANONYMOUS && $config['board_dst'])) ? sprintf($user->lang['ALL_TIMES'], $user->lang['tz'][$tz], $user->lang['tz']['dst']) : sprintf($user->lang['ALL_TIMES'], $user->lang['tz'][$tz], ''),
'S_DISPLAY_ONLINE_LIST' => ($config['load_online']) ? 1 : 0,
'S_DISPLAY_SEARCH' => ($config['load_search']) ? 1 : 0,
'S_DISPLAY_PM' => ($config['allow_privmsg'] && $user->data['is_registered']) ? 1 : 0,
'S_DISPLAY_MEMBERLIST' => (isset($auth)) ? $auth->acl_get('u_viewprofile') : 0,
'S_NEW_PM' => ($s_privmsg_new) ? 1 : 0,
@@ -1957,7 +1957,7 @@ function page_footer()
$template->assign_vars(array(
'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '',
'U_ACP' => ($auth->acl_get('a_') && $user->data['user_id'] != ANONYMOUS) ? "adm/index.$phpEx?sid=" . $user->data['session_id'] : '')
'U_ACP' => ($auth->acl_get('a_') && $user->data['is_registered']) ? "adm/index.$phpEx?sid=" . $user->data['session_id'] : '')
);
$template->display('body');

View File

@@ -34,7 +34,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
// Display list of active topics for this category?
$show_active = (isset($root_data['forum_flags']) && $root_data['forum_flags'] & 16) ? true : false;
if ($config['load_db_lastread'] && $user->data['user_id'] != ANONYMOUS)
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
switch (SQL_LAYER)
{
@@ -65,7 +65,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$forum_ids = array($root_data['forum_id']);
while ($row = $db->sql_fetchrow($result))
{
if ($mark_read == 'forums' && $user->data['user_id'] != ANONYMOUS)
if ($mark_read == 'forums' && $user->data['is_registered'])
{
if ($auth->acl_get('f_list', $row['forum_id']))
{
@@ -157,7 +157,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$mark_time_forum = ($config['load_db_lastread']) ? $row['mark_time'] : ((isset($tracking_topics[$forum_id][0])) ? base_convert($tracking_topics[$forum_id][0], 36, 10) + $config['board_startdate'] : 0);
if ($mark_time_forum < $row['forum_last_post_time'] && $user->data['user_id'] != ANONYMOUS)
if ($mark_time_forum < $row['forum_last_post_time'] && $user->data['is_registered'])
{
$forum_unread[$parent_id] = true;
}
@@ -240,7 +240,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
}
$subforums_list = implode(', ', $links);
$l_subforums = (count($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
$l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
}
}
@@ -290,7 +290,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$l_moderator = $moderators_list = '';
if ($display_moderators && !empty($forum_moderators[$forum_id]))
{
$l_moderator = (count($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
$l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
$moderators_list = implode(', ', $forum_moderators[$forum_id]);
}
@@ -440,7 +440,7 @@ function topic_status(&$topic_row, $replies, $mark_time_topic, $mark_time_forum,
$folder_new = 'folder_locked_new';
}
if ($user->data['user_id'] != ANONYMOUS)
if ($user->data['is_registered'])
{
$unread_topic = $new_votes = true;

View File

@@ -389,7 +389,7 @@ class jabber
{
$temp = $this->_split_incoming($incoming);
for ($a = 0; $a < count($temp); $a++)
for ($a = 0, $size = sizeof($temp); $a < $size; $a++)
{
$this->packet_queue[] = $this->xmlize($temp[$a]);
}
@@ -957,7 +957,7 @@ class make_xml extends jabber
$temp = @explode('/', $string);
for ($a = 0; $a < count($temp); $a++)
for ($a = 0, $size = sizeof($temp); $a < $size; $a++)
{
$temp[$a] = preg_replace('#^[@]{1}([a-z0-9_]*)$#i', '["@"]["\1"]', $temp[$a]);
$temp[$a] = preg_replace('#^([a-z0-9_]*)\(([0-9]*)\)$/i', '["\1"][\2]', $temp[$a]);
@@ -1001,7 +1001,7 @@ class make_xml extends jabber
}
elseif (is_array($value))
{
for ($a = 0; $a < count($value); $a++)
for ($a = 0, $size = sizeof($value); $a < $size; $a++)
{
$text .= "<$key";

View File

@@ -473,7 +473,7 @@ class queue
@set_time_limit(60);
$package_size = $data_ary['package_size'];
$num_items = (count($data_ary['data']) < $package_size) ? count($data_ary['data']) : $package_size;
$num_items = (sizeof($data_ary['data']) < $package_size) ? sizeof($data_ary['data']) : $package_size;
switch ($object)
{
@@ -552,7 +552,7 @@ class queue
}
// No more data for this object? Unset it
if (!count($this->queue_data[$object]['data']))
if (!sizeof($this->queue_data[$object]['data']))
{
unset($this->queue_data[$object]);
}
@@ -602,10 +602,14 @@ class queue
foreach ($this->queue_data as $object => $data_ary)
{
if (count($this->data[$object]))
if (isset($this->data[$object]) && sizeof($this->data[$object]))
{
$this->data[$object]['data'] = array_merge($data_ary['data'], $this->data[$object]['data']);
}
else
{
$this->data[$object]['data'] = $data_ary['data'];
}
}
}

View File

@@ -868,7 +868,8 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id
WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . "
AND w.user_id NOT IN ($sql_ignore_users)
AND w.notify_status = 0
AND u.user_id = w.user_id";
AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')
AND u.user_id = w.user_id';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -900,7 +901,8 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id
WHERE fw.forum_id = $forum_id
AND fw.user_id NOT IN ($sql_ignore_users)
AND fw.notify_status = 0
AND u.user_id = fw.user_id";
AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')
AND u.user_id = fw.user_id';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))

View File

@@ -133,7 +133,7 @@ function mcp_topic_view($id, $mode, $action, $url)
'MESSAGE' => $message,
'POST_ID' => $row['post_id'],
'POST_ICON_IMG' => ($row['post_time'] > $user->data['user_lastvisit'] && $user->data['user_id'] != ANONYMOUS) ? $user->img('icon_post_new', $user->lang['NEW_POST']) : $user->img('icon_post', $user->lang['POST']),
'POST_ICON_IMG' => ($row['post_time'] > $user->data['user_lastvisit'] && $user->data['is_registered']) ? $user->img('icon_post_new', $user->lang['NEW_POST']) : $user->img('icon_post', $user->lang['POST']),
'S_CHECKBOX' => $s_checkbox,
'S_POST_REPORTED' => ($row['post_reported']) ? true : false,

View File

@@ -110,6 +110,9 @@ class session
WHERE session_id = '" . $db->sql_escape($this->session_id) . "'";
$db->sql_query($sql);
}
$this->data['is_registered'] = ($this->data['user_id'] != ANONYMOUS && ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER)) ? true : false;
$this->data['is_bot'] = (!$this->data['is_registered'] && $this->data['user_id'] != ANONYMOUS) ? true : false;
return true;
}
@@ -135,7 +138,7 @@ class session
$bot = false;
// Pull bot information from DB and loop through it
$sql = 'SELECT user_id, bot_agent, bot_ip
$sql = 'SELECT user_id, bot_agent, bot_ip
FROM ' . BOTS_TABLE . '
WHERE bot_active = 1';
$result = $db->sql_query($sql);
@@ -146,8 +149,8 @@ class session
{
$bot = $row['user_id'];
}
if ($row['bot_ip'] && (!$row['bot_agent'] || $bot))
if ($row['bot_ip'] && (!$row['bot_agent'] || !$bot))
{
foreach (explode(',', $row['bot_ip']) as $bot_ip)
{
@@ -276,6 +279,8 @@ class session
// Is there an existing session? If so, grab last visit time from that
$this->data['session_last_visit'] = ($this->data['session_time']) ? $this->data['session_time'] : (($this->data['user_lastvisit']) ? $this->data['user_lastvisit'] : time());
$this->data['is_registered'] = (!$bot && $user_id != ANONYMOUS) ? true : false;
$this->data['is_bot'] = ($bot) ? true : false;
// Create or update the session
$db->sql_return_on_error(true);
@@ -358,9 +363,18 @@ class session
$db->sql_query($sql);
// Reset some basic data immediately
$this->session_id = $this->data['username'] = $this->data['user_permissions'] = '';
$this->data['user_id'] = ANONYMOUS;
$this->data['session_admin'] = 0;
$sql = 'SELECT *
FROM ' . USERS_TABLE . '
WHERE user_id = ' . ANONYMOUS;
$result = $db->sql_query($sql);
$this->data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$this->session_id = $this->data['session_id'] = '';
$this->data['session_time'] = $this->data['session_admin'] = 0;
// Trigger EVENT_END_SESSION

View File

@@ -763,7 +763,7 @@ class template
$new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1));
array_splice($tokens, $is_arg_start, count($tokens), $new_tokens);
array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens);
$i = $is_arg_start;

View File

@@ -441,7 +441,7 @@ class ucp_main extends module
if ($config['load_db_lastread'])
{
$mark_time_topic = ($user->data['user_id'] != ANONYMOUS) ? $row['mark_time'] : 0;
$mark_time_topic = ($user->data['is_registered']) ? $row['mark_time'] : 0;
$mark_time_forum = $row['forum_mark_time'];
}
else

View File

@@ -45,7 +45,7 @@ class ucp_pm extends module
{
global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $SID, $config;
if ($user->data['user_id'] == ANONYMOUS)
if (!$user->data['is_registered'])
{
trigger_error('NO_MESSAGE');
}
@@ -89,7 +89,7 @@ class ucp_pm extends module
case 'popup':
$l_new_message = '';
if ($user->data['user_id'] != ANONYMOUS)
if ($user->data['is_registered'])
{
if ($user->data['user_new_privmsg'])
{