aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acp/acp_permissions.php62
-rw-r--r--phpBB/includes/auth.php124
-rw-r--r--phpBB/includes/db/dbal.php61
-rw-r--r--phpBB/includes/db/firebird.php13
-rw-r--r--phpBB/includes/db/mssql.php10
-rw-r--r--phpBB/includes/db/mssql_odbc.php10
-rw-r--r--phpBB/includes/db/mysql.php15
-rw-r--r--phpBB/includes/db/mysql4.php15
-rw-r--r--phpBB/includes/db/mysqli.php15
-rw-r--r--phpBB/includes/db/oracle.php6
-rw-r--r--phpBB/includes/db/postgres.php15
-rw-r--r--phpBB/includes/db/sqlite.php10
-rw-r--r--phpBB/includes/functions_admin.php32
-rw-r--r--phpBB/includes/mcp/mcp_front.php38
-rw-r--r--phpBB/includes/ucp/ucp_main.php72
15 files changed, 390 insertions, 108 deletions
diff --git a/phpBB/includes/acp/acp_permissions.php b/phpBB/includes/acp/acp_permissions.php
index f42a03ba15..1059629863 100644
--- a/phpBB/includes/acp/acp_permissions.php
+++ b/phpBB/includes/acp/acp_permissions.php
@@ -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 = '';
diff --git a/phpBB/includes/auth.php b/phpBB/includes/auth.php
index d32cb0a945..c31a45bc7f 100644
--- a/phpBB/includes/auth.php
+++ b/phpBB/includes/auth.php
@@ -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))
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index acc64da799..1a8b8a4ddf 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -192,6 +192,67 @@ class dbal
}
/**
+ * 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
*/
function sql_error($sql = '')
diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php
index c94fd00882..e4eca60772 100644
--- a/phpBB/includes/db/firebird.php
+++ b/phpBB/includes/db/firebird.php
@@ -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;
@@ -320,6 +320,15 @@ class dbal_firebird extends dbal
}
/**
+ * 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];
diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index 0e7ee89196..e1082d282c 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -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'))
@@ -334,6 +333,15 @@ class dbal_mssql extends dbal
}
/**
+ * Build db-specific query data
+ * @private
+ */
+ function _sql_custom_build($stage, $data)
+ {
+ return $data;
+ }
+
+ /**
* Close sql connection
* @private
*/
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index 1e219f985e..a31c6074bc 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -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;
@@ -318,6 +317,15 @@ class dbal_mssql_odbc extends dbal
}
/**
+ * Build db-specific query data
+ * @private
+ */
+ function _sql_custom_build($stage, $data)
+ {
+ return $data;
+ }
+
+ /**
* return sql error array
* @private
*/
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index 625c6876ee..d9369f3a75 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -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
diff --git a/phpBB/includes/db/mysql4.php b/phpBB/includes/db/mysql4.php
index c388987e40..47c1ebc41f 100644
--- a/phpBB/includes/db/mysql4.php
+++ b/phpBB/includes/db/mysql4.php
@@ -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
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index 137ca39591..0233c7092f 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -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
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index 2a4898ca0d..72732d2a50 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -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
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php
index d9e8bc2bfa..eb5f2d17e8 100644
--- a/phpBB/includes/db/postgres.php
+++ b/phpBB/includes/db/postgres.php
@@ -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);
}
@@ -179,6 +175,15 @@ class dbal_postgres extends dbal
}
/**
+ * Build db-specific query data
+ * @private
+ */
+ function _sql_custom_build($stage, $data)
+ {
+ return $data;
+ }
+
+ /**
* Build LIMIT query
*/
function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index 16319aec83..f2f3ceb1f1 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -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'))
@@ -286,6 +285,15 @@ class dbal_sqlite extends dbal
}
/**
+ * Build db-specific query data
+ * @private
+ */
+ function _sql_custom_build($stage, $data)
+ {
+ return $data;
+ }
+
+ /**
* Close sql connection
* @private
*/
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 7b3c7e68f1..2df3c37f9b 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -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))
diff --git a/phpBB/includes/mcp/mcp_front.php b/phpBB/includes/mcp/mcp_front.php
index 653af87a45..f227dec9a6 100644
--- a/phpBB/includes/mcp/mcp_front.php
+++ b/phpBB/includes/mcp/mcp_front.php
@@ -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))
diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php
index 7959e656de..2577e1e781 100644
--- a/phpBB/includes/ucp/ucp_main.php
+++ b/phpBB/includes/ucp/ucp_main.php
@@ -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();