mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
I hope nothing broke!
- Added a query builder, it is currently only used for complex queries that involve a FROM clause with two tables and a left join - Changed some function calls in the DBAL - Made the viewtopic queries nicer git-svn-id: file:///svn/phpbb/trunk@5885 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -344,14 +344,29 @@ class acp_permissions
|
||||
$sql_forum_id = ($permission_scope == 'global') ? 'AND a.forum_id = 0' : ((sizeof($forum_id)) ? 'AND a.forum_id IN (' . implode(', ', $forum_id) . ')' : 'AND a.forum_id <> 0');
|
||||
$sql_permission_option = "AND o.auth_option LIKE '" . $db->sql_escape($permission_type) . "%'";
|
||||
|
||||
$sql = 'SELECT DISTINCT u.username, u.user_regdate, u.user_id
|
||||
FROM (' . USERS_TABLE . ' u, ' . ACL_OPTIONS_TABLE . ' o, ' . ACL_USERS_TABLE . ' a)
|
||||
LEFT JOIN ' . ACL_ROLES_DATA_TABLE . " r ON (a.auth_role_id = r.role_id)
|
||||
WHERE (a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
|
||||
$sql_permission_option
|
||||
$sql_forum_id
|
||||
AND u.user_id = a.user_id
|
||||
ORDER BY u.username, u.user_regdate ASC";
|
||||
$sql = $db->sql_build_query('SELECT_DISTINCT', array(
|
||||
'SELECT' => 'u.username, u.user_regdate, u.user_id',
|
||||
|
||||
'FROM' => array(
|
||||
USERS_TABLE => 'u',
|
||||
ACL_OPTIONS_TABLE => 'o',
|
||||
ACL_USERS_TABLE => 'a'
|
||||
),
|
||||
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
|
||||
'ON' => 'a.auth_role_id = r.role_id'
|
||||
)
|
||||
),
|
||||
|
||||
'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
|
||||
$sql_permission_option
|
||||
$sql_forum_id
|
||||
AND u.user_id = a.user_id",
|
||||
|
||||
'ORDER_BY' => 'u.username, u.user_regdate ASC'
|
||||
));
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$s_defined_user_options = '';
|
||||
@@ -363,14 +378,29 @@ class acp_permissions
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql = 'SELECT DISTINCT g.group_type, g.group_name, g.group_id
|
||||
FROM (' . GROUPS_TABLE . ' g, ' . ACL_OPTIONS_TABLE . ' o, ' . ACL_GROUPS_TABLE . ' a)
|
||||
LEFT JOIN ' . ACL_ROLES_DATA_TABLE . " r ON (a.auth_role_id = r.role_id)
|
||||
WHERE (a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
|
||||
$sql_permission_option
|
||||
$sql_forum_id
|
||||
AND g.group_id = a.group_id
|
||||
ORDER BY g.group_type DESC, g.group_name ASC";
|
||||
$sql = $db->sql_build_query('SELECT_DISTINCT', array(
|
||||
'SELECT' => 'g.group_type, g.group_name, g.group_id',
|
||||
|
||||
'FROM' => array(
|
||||
GROUPS_TABLE => 'g',
|
||||
ACL_OPTIONS_TABLE => 'o',
|
||||
ACL_USERS_TABLE => 'a'
|
||||
),
|
||||
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
|
||||
'ON' => 'a.auth_role_id = r.role_id'
|
||||
)
|
||||
),
|
||||
|
||||
'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
|
||||
$sql_permission_option
|
||||
$sql_forum_id
|
||||
AND g.group_id = a.group_id",
|
||||
|
||||
'ORDER_BY' => 'g.group_type DESC, g.group_name ASC'
|
||||
));
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$s_defined_group_options = '';
|
||||
|
@@ -486,14 +486,29 @@ class auth
|
||||
|
||||
// First grab user settings ... each user has only one setting for each
|
||||
// option ... so we shouldn't need any ACL_NO checks ... he says ...
|
||||
$sql = 'SELECT ao.auth_option, a.auth_role_id, r.auth_setting as role_auth_setting, a.user_id, a.forum_id, a.auth_setting
|
||||
FROM (' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_USERS_TABLE . ' a)
|
||||
LEFT JOIN ' . ACL_ROLES_DATA_TABLE . ' r ON (a.auth_role_id = r.role_id)
|
||||
WHERE (ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
|
||||
' . (($sql_user) ? 'AND a.' . $sql_user : '') . "
|
||||
$sql_forum
|
||||
$sql_opts
|
||||
ORDER BY a.forum_id, ao.auth_option";
|
||||
// Grab assigned roles...
|
||||
$sql = $db->sql_build_query('SELECT', array(
|
||||
'SELECT' => 'ao.auth_option, a.auth_role_id, r.auth_setting as role_auth_setting, a.user_id, a.forum_id, a.auth_setting',
|
||||
|
||||
'FROM' => array(
|
||||
ACL_OPTIONS_TABLE => 'ao',
|
||||
ACL_USERS_TABLE => 'a'
|
||||
),
|
||||
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
|
||||
'ON' => 'a.auth_role_id = r.role_id'
|
||||
)
|
||||
),
|
||||
|
||||
'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
|
||||
' . (($sql_user) ? 'AND a.' . $sql_user : '') . "
|
||||
$sql_forum
|
||||
$sql_opts",
|
||||
|
||||
'ORDER_BY' => 'a.forum_id, ao.auth_option'
|
||||
));
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
@@ -504,15 +519,30 @@ class auth
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
// Now grab group settings ... ACL_NO overrides ACL_YES so act appropriatley
|
||||
$sql = 'SELECT ug.user_id, ao.auth_option, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting
|
||||
FROM (' . USER_GROUP_TABLE . ' ug, ' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_GROUPS_TABLE . ' a)
|
||||
LEFT JOIN ' . ACL_ROLES_DATA_TABLE . ' r ON (a.auth_role_id = r.role_id)
|
||||
WHERE (ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
|
||||
AND a.group_id = ug.group_id
|
||||
' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
|
||||
$sql_forum
|
||||
$sql_opts
|
||||
ORDER BY a.forum_id, ao.auth_option";
|
||||
$sql = $db->sql_build_query('SELECT', array(
|
||||
'SELECT' => 'ug.user_id, ao.auth_option, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting',
|
||||
|
||||
'FROM' => array(
|
||||
USER_GROUP_TABLE => 'ug',
|
||||
ACL_OPTIONS_TABLE => 'ao',
|
||||
ACL_GROUPS_TABLE => 'a'
|
||||
),
|
||||
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
|
||||
'ON' => 'a.auth_role_id = r.role_id'
|
||||
)
|
||||
),
|
||||
|
||||
'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
|
||||
AND a.group_id = ug.group_id
|
||||
' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
|
||||
$sql_forum
|
||||
$sql_opts",
|
||||
|
||||
'ORDER_BY' => 'a.forum_id, ao.auth_option'
|
||||
));
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
@@ -571,14 +601,28 @@ class auth
|
||||
$hold_ary = array();
|
||||
|
||||
// Grab user settings...
|
||||
$sql = 'SELECT ao.auth_option, a.auth_role_id, r.auth_setting as role_auth_setting, a.user_id, a.forum_id, a.auth_setting
|
||||
FROM (' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_USERS_TABLE . ' a)
|
||||
LEFT JOIN ' . ACL_ROLES_DATA_TABLE . ' r ON (a.auth_role_id = r.role_id)
|
||||
WHERE (ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
|
||||
' . (($sql_user) ? 'AND a.' . $sql_user : '') . "
|
||||
$sql_forum
|
||||
$sql_opts
|
||||
ORDER BY a.forum_id, ao.auth_option";
|
||||
$sql = $db->sql_build_query('SELECT', array(
|
||||
'SELECT' => 'ao.auth_option, a.auth_role_id, r.auth_setting as role_auth_setting, a.user_id, a.forum_id, a.auth_setting',
|
||||
|
||||
'FROM' => array(
|
||||
ACL_OPTIONS_TABLE => 'ao',
|
||||
ACL_USERS_TABLE => 'a'
|
||||
),
|
||||
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
|
||||
'ON' => 'a.auth_role_id = r.role_id'
|
||||
),
|
||||
),
|
||||
|
||||
'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
|
||||
' . (($sql_user) ? 'AND a.' . $sql_user : '') . "
|
||||
$sql_forum
|
||||
$sql_opts",
|
||||
|
||||
'ORDER_BY' => 'a.forum_id, ao.auth_option'
|
||||
));
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
@@ -616,14 +660,28 @@ class auth
|
||||
$hold_ary = array();
|
||||
|
||||
// Grab group settings...
|
||||
$sql = 'SELECT a.group_id, ao.auth_option, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting
|
||||
FROM (' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_GROUPS_TABLE . ' a)
|
||||
LEFT JOIN ' . ACL_ROLES_DATA_TABLE . ' r ON (a.auth_role_id = r.role_id)
|
||||
WHERE (ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
|
||||
' . (($sql_group) ? 'AND a.' . $sql_group : '') . "
|
||||
$sql_forum
|
||||
$sql_opts
|
||||
ORDER BY a.forum_id, ao.auth_option";
|
||||
$sql = $db->sql_build_query('SELECT', array(
|
||||
'SELECT' => 'a.group_id, ao.auth_option, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting',
|
||||
|
||||
'FROM' => array(
|
||||
ACL_OPTIONS_TABLE => 'ao',
|
||||
ACL_USERS_TABLE => 'a'
|
||||
),
|
||||
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
|
||||
'ON' => 'a.auth_role_id = r.role_id'
|
||||
),
|
||||
),
|
||||
|
||||
'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
|
||||
' . (($sql_group) ? 'AND a.' . $sql_group : '') . "
|
||||
$sql_forum
|
||||
$sql_opts",
|
||||
|
||||
'ORDER_BY' => 'a.forum_id, ao.auth_option'
|
||||
));
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
|
@@ -191,6 +191,67 @@ class dbal
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build sql statement from array for select and select distinct statements
|
||||
*
|
||||
* Possible query values: SELECT, SELECT_DISTINCT
|
||||
*/
|
||||
function sql_build_query($query, $array)
|
||||
{
|
||||
$sql = '';
|
||||
switch ($query)
|
||||
{
|
||||
case 'SELECT':
|
||||
case 'SELECT_DISTINCT';
|
||||
|
||||
if ($query == 'SELECT_DISTINCT')
|
||||
{
|
||||
$sql .= 'SELECT DISTINCT';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql .= 'SELECT';
|
||||
}
|
||||
|
||||
$sql .= ' ' . $array['SELECT'];
|
||||
$sql .= ' FROM ';
|
||||
|
||||
$table_array = array();
|
||||
foreach ($array['FROM'] as $table_name => $alias)
|
||||
{
|
||||
$table_array[] = $table_name . ' ' . $alias;
|
||||
}
|
||||
|
||||
$sql .= $this->_sql_custom_build('FROM', implode(', ', $table_array));
|
||||
|
||||
if (!empty($array['LEFT_JOIN']))
|
||||
{
|
||||
foreach ($array['LEFT_JOIN'] as $join)
|
||||
{
|
||||
$sql .= ' LEFT JOIN ' . key($join['FROM']) . ' ' . current($join['FROM']) . ' ON (' . $join['ON'] . ')';
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($array['WHERE']))
|
||||
{
|
||||
$sql .= ' WHERE ' . $this->_sql_custom_build('WHERE', $array['WHERE']);
|
||||
}
|
||||
|
||||
if (!empty($array['GROUP_BY']))
|
||||
{
|
||||
$sql .= ' GROUP BY ' . $array['GROUP_BY'];
|
||||
}
|
||||
|
||||
if (!empty($array['ORDER_BY']))
|
||||
{
|
||||
$sql .= ' ORDER BY ' . $array['ORDER_BY'];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* display sql error page
|
||||
*/
|
||||
|
@@ -56,6 +56,7 @@ class dbal_firebird extends dbal
|
||||
switch ($status)
|
||||
{
|
||||
case 'begin':
|
||||
$result = true;
|
||||
$this->transaction = true;
|
||||
break;
|
||||
|
||||
@@ -90,7 +91,6 @@ class dbal_firebird extends dbal
|
||||
{
|
||||
global $cache;
|
||||
|
||||
$query = preg_replace('#FROM \(([^)]*)\)(,|[\n\r\t ]+(?:WHERE|LEFT JOIN)) #', 'FROM \1\2 ', $query);
|
||||
|
||||
$this->last_query_text = $query;
|
||||
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
|
||||
@@ -319,6 +319,15 @@ class dbal_firebird extends dbal
|
||||
return (@ini_get('magic_quotes_sybase') || strtolower(@ini_get('magic_quotes_sybase')) == 'on') ? str_replace('\\\'', '\'', addslashes($msg)) : str_replace('\'', '\'\'', stripslashes($msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @private
|
||||
@@ -360,7 +369,7 @@ class dbal_firebird extends dbal
|
||||
{
|
||||
// Take the time spent on parsing rows into account
|
||||
}
|
||||
@ibase_freeresult($result);
|
||||
@ibase_free_result($result);
|
||||
|
||||
$splittime = explode(' ', microtime());
|
||||
$splittime = $splittime[0] + $splittime[1];
|
||||
|
@@ -98,7 +98,6 @@ class dbal_mssql extends dbal
|
||||
{
|
||||
global $cache;
|
||||
|
||||
$query = preg_replace('#FROM \(([^)]*)\)(,|[\n\r\t ]+(?:WHERE|LEFT JOIN)) #', 'FROM \1\2 ', $query);
|
||||
|
||||
// EXPLAIN only in extra debug mode
|
||||
if (defined('DEBUG_EXTRA'))
|
||||
@@ -333,6 +332,15 @@ class dbal_mssql extends dbal
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
* @private
|
||||
|
@@ -101,7 +101,6 @@ class dbal_mssql_odbc extends dbal
|
||||
$this->sql_report('start', $query);
|
||||
}
|
||||
|
||||
$query = preg_replace('#FROM \(([^)]*)\)(,|[\n\r\t ]+(?:WHERE|LEFT JOIN)) #', 'FROM \1\2 ', $query);
|
||||
|
||||
$this->last_query_text = $query;
|
||||
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
|
||||
@@ -317,6 +316,15 @@ class dbal_mssql_odbc extends dbal
|
||||
return str_replace("'", "''", str_replace('\\', '\\\\', $msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @private
|
||||
|
@@ -290,6 +290,21 @@ class dbal_mysql extends dbal
|
||||
|
||||
return @mysql_real_escape_string($msg, $this->db_connect_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
switch ($stage)
|
||||
{
|
||||
case 'FROM':
|
||||
$data = '(' . $data . ')';
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
|
@@ -293,6 +293,21 @@ class dbal_mysql4 extends dbal
|
||||
|
||||
return @mysql_real_escape_string($msg, $this->db_connect_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
switch ($stage)
|
||||
{
|
||||
case 'FROM':
|
||||
$data = '(' . $data . ')';
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
|
@@ -284,6 +284,21 @@ class dbal_mysqli extends dbal
|
||||
{
|
||||
return @mysqli_real_escape_string($this->db_connect_id, $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
switch ($stage)
|
||||
{
|
||||
case 'FROM':
|
||||
$data = '(' . $data . ')';
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
|
@@ -90,7 +90,6 @@ class dbal_oracle extends dbal
|
||||
{
|
||||
global $cache;
|
||||
|
||||
$query = preg_replace('#FROM \(([^)]*)\)(,|[\n\r\t ]+(?:WHERE|LEFT JOIN)) #', 'FROM \1\2 ', $query);
|
||||
|
||||
// EXPLAIN only in extra debug mode
|
||||
if (defined('DEBUG_EXTRA'))
|
||||
@@ -361,6 +360,11 @@ class dbal_oracle extends dbal
|
||||
return str_replace("'", "''", str_replace('\\', '\\\\', $msg));
|
||||
}
|
||||
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @private
|
||||
|
@@ -127,10 +127,6 @@ class dbal_postgres extends dbal
|
||||
{
|
||||
global $cache;
|
||||
|
||||
if (strpos($query, 'SELECT') === 0 && strpos($query, 'FROM (') !== false)
|
||||
{
|
||||
$query = preg_replace('#FROM \(([^)]+)\)\s#', 'FROM \1 ', $query);
|
||||
}
|
||||
|
||||
// EXPLAIN only in extra debug mode
|
||||
if (defined('DEBUG_EXTRA'))
|
||||
@@ -145,7 +141,7 @@ class dbal_postgres extends dbal
|
||||
{
|
||||
$this->num_queries++;
|
||||
|
||||
if (($this->query_result = @pg_exec($this->db_connect_id, $query)) === false)
|
||||
if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false)
|
||||
{
|
||||
$this->sql_error($query);
|
||||
}
|
||||
@@ -178,6 +174,15 @@ class dbal_postgres extends dbal
|
||||
return ($this->query_result) ? $this->query_result : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build LIMIT query
|
||||
*/
|
||||
|
@@ -94,7 +94,6 @@ class dbal_sqlite extends dbal
|
||||
{
|
||||
global $cache;
|
||||
|
||||
$query = preg_replace('#FROM \(([^)]*)\)(,|[\n\r\t ]+(?:WHERE|LEFT JOIN)) #', 'FROM \1\2 ', $query);
|
||||
|
||||
// EXPLAIN only in extra debug mode
|
||||
if (defined('DEBUG_EXTRA'))
|
||||
@@ -285,6 +284,15 @@ class dbal_sqlite extends dbal
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @private
|
||||
*/
|
||||
function _sql_custom_build($stage, $data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sql connection
|
||||
* @private
|
||||
|
@@ -1733,15 +1733,29 @@ function cache_moderators()
|
||||
$ug_id_ary = array_keys($hold_ary);
|
||||
|
||||
// Remove users who have group memberships with DENY moderator permissions
|
||||
$sql = 'SELECT a.forum_id, ug.user_id
|
||||
FROM (' . ACL_OPTIONS_TABLE . ' o, ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug)
|
||||
LEFT JOIN ' . ACL_ROLES_DATA_TABLE . ' r ON (a.auth_role_id = r.role_id)
|
||||
WHERE (o.auth_option_id = a.auth_option_id OR o.auth_option_id = r.auth_option_id)
|
||||
AND ((a.auth_setting = ' . ACL_NO . ' AND r.auth_setting IS NULL)
|
||||
OR r.auth_setting = ' . ACL_NO . ')
|
||||
AND a.group_id = ug.group_id
|
||||
AND ug.user_id IN (' . implode(', ', $ug_id_ary) . ")
|
||||
AND o.auth_option LIKE 'm\_%'";
|
||||
$sql = $db->sql_build_query('SELECT', array(
|
||||
'SELECT' => 'a.forum_id, ug.user_id',
|
||||
|
||||
'FROM' => array(
|
||||
ACL_OPTIONS_TABLE => 'o',
|
||||
USER_GROUP_TABLE => 'ug',
|
||||
ACL_GROUPS_TABLE => 'a'
|
||||
),
|
||||
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
|
||||
'ON' => 'a.auth_role_id = r.role_id'
|
||||
)
|
||||
),
|
||||
|
||||
'WHERE' => '(o.auth_option_id = a.auth_option_id OR o.auth_option_id = r.auth_option_id)
|
||||
AND ((a.auth_setting = ' . ACL_NO . ' AND r.auth_setting IS NULL)
|
||||
OR r.auth_setting = ' . ACL_NO . ')
|
||||
AND a.group_id = ug.group_id
|
||||
AND ug.user_id IN (' . implode(', ', $ug_id_ary) . ")
|
||||
AND o.auth_option LIKE 'm\_%'",
|
||||
));
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
|
@@ -123,16 +123,34 @@ function mcp_front_view($id, $mode, $action)
|
||||
|
||||
if ($total)
|
||||
{
|
||||
$sql = 'SELECT r.*, p.post_id, p.post_subject, u.username, t.topic_id, t.topic_title, f.forum_id, f.forum_name
|
||||
FROM (' . REPORTS_TABLE . ' r, ' . REASONS_TABLE . ' rr,' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u)
|
||||
LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = p.forum_id)
|
||||
WHERE r.post_id = p.post_id
|
||||
AND r.report_closed = 0
|
||||
AND r.reason_id = rr.reason_id
|
||||
AND p.topic_id = t.topic_id
|
||||
AND r.user_id = u.user_id
|
||||
AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')
|
||||
ORDER BY p.post_id DESC';
|
||||
$sql = $db->sql_build_query('SELECT', array(
|
||||
'SELECT' => 'r.*, p.post_id, p.post_subject, u.username, t.topic_id, t.topic_title, f.forum_id, f.forum_name',
|
||||
|
||||
'FROM' => array(
|
||||
REPORTS_TABLE => 'r',
|
||||
REASONS_TABLE => 'rr',
|
||||
TOPICS_TABLE => 't',
|
||||
USERS_TABLE => 'u',
|
||||
POSTS_TABLE => 'p'
|
||||
|
||||
),
|
||||
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(FORUMS_TABLE => 'f'),
|
||||
'ON' => 'f.forum_id = p.forum_id'
|
||||
)
|
||||
),
|
||||
|
||||
'WHERE' => 'r.post_id = p.post_id
|
||||
AND r.report_closed = 0
|
||||
AND r.reason_id = rr.reason_id
|
||||
AND p.topic_id = t.topic_id
|
||||
AND r.user_id = u.user_id
|
||||
AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')',
|
||||
|
||||
'ORDER_BY' => 'p.post_id DESC'
|
||||
));
|
||||
$result = $db->sql_query_limit($sql, 5);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
|
@@ -216,25 +216,36 @@ class ucp_main
|
||||
}
|
||||
}
|
||||
|
||||
$sql_array = array(
|
||||
'SELECT' => 'f.*',
|
||||
|
||||
'FROM' => array(
|
||||
FORUMS_WATCH_TABLE => 'fw',
|
||||
FORUMS_TABLE => 'f'
|
||||
),
|
||||
|
||||
'WHERE' => "fw.user_id = " . $user->data['user_id'] . '
|
||||
AND f.forum_id = fw.forum_id',
|
||||
|
||||
'ORDER_BY' => 'left_id'
|
||||
);
|
||||
|
||||
if ($config['load_db_lastread'])
|
||||
{
|
||||
$sql_join = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id)';
|
||||
$lastread_select = ', ft.mark_time ';
|
||||
$sql_array['LEFT_JOIN'] = array(
|
||||
array(
|
||||
'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
|
||||
'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
|
||||
)
|
||||
);
|
||||
$sql_array['SELECT'] .= ', ft.mark_time ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql_join = '';
|
||||
$lastread_select = '';
|
||||
|
||||
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
|
||||
}
|
||||
|
||||
$sql = "SELECT f.*$lastread_select
|
||||
FROM (" . FORUMS_TABLE . ' f, ' . FORUMS_WATCH_TABLE . " fw)
|
||||
$sql_join
|
||||
WHERE fw.user_id = " . $user->data['user_id'] . '
|
||||
AND f.forum_id = fw.forum_id
|
||||
ORDER BY left_id';
|
||||
$sql = $db->sql_build_query('SELECT', $sql_array);
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
@@ -315,31 +326,34 @@ class ucp_main
|
||||
);
|
||||
}
|
||||
|
||||
$sql_join = ($config['load_db_lastread']) ? ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id'] . ')' : '';
|
||||
$sql_f_select = ($config['load_db_lastread']) ? ', ft.mark_time AS forum_mark_time' : '';
|
||||
$sql_t_select = '';
|
||||
$sql_array = array(
|
||||
'SELECT' => 't.*',
|
||||
|
||||
if ($config['load_db_track'])
|
||||
{
|
||||
$sql_join .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
|
||||
AND tp.user_id = ' . $user->data['user_id'] . ')';
|
||||
$sql_t_select .= ', tp.topic_posted';
|
||||
}
|
||||
'FROM' => array(
|
||||
TOPICS_WATCH_TABLE => 'tw',
|
||||
TOPICS_TABLE => 't'
|
||||
),
|
||||
|
||||
'WHERE' => "tw.user_id = " . $user->data['user_id'] . '
|
||||
AND t.topic_id = tw.topic_id',
|
||||
|
||||
'ORDER_BY' => 't.topic_last_post_time DESC'
|
||||
);
|
||||
|
||||
if ($config['load_db_lastread'])
|
||||
{
|
||||
$sql_join .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
|
||||
AND tt.user_id = ' . $user->data['user_id'] . ')';
|
||||
$sql_t_select .= ', tt.mark_time';
|
||||
$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';
|
||||
}
|
||||
|
||||
if ($config['load_db_track'])
|
||||
{
|
||||
$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
|
||||
$sql_array['SELECT'] .= ', tp.topic_posted';
|
||||
}
|
||||
|
||||
$sql = "SELECT t.* $sql_f_select $sql_t_select
|
||||
FROM (" . TOPICS_WATCH_TABLE . ' tw, ' . TOPICS_TABLE . " t)
|
||||
$sql_join
|
||||
WHERE tw.user_id = " . $user->data['user_id'] . '
|
||||
AND t.topic_id = tw.topic_id
|
||||
ORDER BY t.topic_last_post_time DESC';
|
||||
$sql = $db->sql_build_query('SELECT', $sql_array);
|
||||
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
|
||||
|
||||
$topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
|
||||
|
Reference in New Issue
Block a user