diff --git a/phpBB/common.php b/phpBB/common.php
index e1dac7f511..4428337f0c 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -98,8 +98,8 @@ define('POST_STICKY', 1);
define('POST_ANNOUNCE', 2);
// Lastread types
-define('LASTREAD_NORMAL', 0); // not used at the moment
-define('LASTREAD_POSTED', 1);
+define('TRACK_NORMAL', 0); // not used at the moment
+define('TRACK_POSTED', 1);
// Private messaging
define('PRIVMSGS_READ_MAIL', 0);
@@ -136,11 +136,11 @@ define('DISALLOW_TABLE', $table_prefix.'disallow'); //
define('EXTENSIONS_TABLE', $table_prefix.'extensions');
define('EXTENSION_GROUPS_TABLE', $table_prefix.'extension_groups');
define('FORUMS_TABLE', $table_prefix.'forums');
+define('FORUMS_TRACK_TABLE', $table_prefix.'forums_marking');
define('FORUMS_WATCH_TABLE', $table_prefix.'forums_watch');
define('GROUPS_TABLE', $table_prefix.'groups');
define('GROUPS_MODERATOR_TABLE', $table_prefix.'groups_moderator');
define('ICONS_TABLE', $table_prefix.'icons');
-define('TOPICS_TRACK_TABLE', $table_prefix.'topics_marking');
define('LOG_ADMIN_TABLE', $table_prefix.'log_admin');
define('LOG_MOD_TABLE', $table_prefix.'log_moderator');
define('MODERATOR_TABLE', $table_prefix.'moderator_cache');
@@ -162,7 +162,7 @@ define('STYLES_TPL_TABLE', $table_prefix.'styles_template');
define('STYLES_CSS_TABLE', $table_prefix.'styles_theme');
define('STYLES_IMAGE_TABLE', $table_prefix.'styles_imageset');
define('TOPICS_TABLE', $table_prefix.'topics');
-define('TOPICS_PREFETCH_TABLE', $table_prefix.'topics_prefetch');
+define('TOPICS_TRACK_TABLE', $table_prefix.'topics_marking');
define('TOPICS_WATCH_TABLE', $table_prefix.'topics_watch');
define('UCP_MODULES_TABLE', $table_prefix.'ucp_modules');
define('USER_GROUP_TABLE', $table_prefix.'user_group');
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php
index 96a90fbb1a..644fba48b0 100644
--- a/phpBB/includes/db/postgres.php
+++ b/phpBB/includes/db/postgres.php
@@ -19,7 +19,7 @@
*
***************************************************************************/
-if(!defined("SQL_LAYER"))
+if (!defined("SQL_LAYER"))
{
define("SQL_LAYER","postgresql");
@@ -42,33 +42,33 @@ class sql_db
{
$this->connect_string = "";
- if( $sqluser )
+ if ($sqluser)
{
$this->connect_string .= "user=$sqluser ";
}
- if( $sqlpassword )
+ if ($sqlpassword)
{
$this->connect_string .= "password=$sqlpassword ";
}
- if( $sqlserver )
+ if ($sqlserver)
{
- if( ereg(":", $sqlserver) )
+ if (ereg(":", $sqlserver))
{
list($sqlserver, $sqlport) = split(":", $sqlserver);
$this->connect_string .= "host=$sqlserver port=$sqlport ";
}
else
{
- if( $sqlserver != "localhost" )
+ if ($sqlserver != "localhost")
{
$this->connect_string .= "host=$sqlserver ";
}
}
}
- if( $database )
+ if ($database)
{
$this->dbname = $database;
$this->connect_string .= "dbname=$database";
@@ -76,9 +76,9 @@ class sql_db
$this->persistency = $persistency;
- $this->db_connect_id = ( $this->persistency ) ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string);
+ $this->db_connect_id = ($this->persistency) ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string);
- return ( $this->db_connect_id ) ? $this->db_connect_id : false;
+ return ($this->db_connect_id) ? $this->db_connect_id : false;
}
//
@@ -86,17 +86,17 @@ class sql_db
//
function sql_close()
{
- if( $this->db_connect_id )
+ if ($this->db_connect_id)
{
//
// Commit any remaining transactions
//
- if( $this->in_transaction )
+ if ($this->in_transaction)
{
@pg_exec($this->db_connect_id, "COMMIT");
}
- if( $this->query_result )
+ if ($this->query_result)
{
@pg_freeresult($this->query_result);
}
@@ -118,30 +118,30 @@ class sql_db
// Remove any pre-existing queries
//
unset($this->query_result);
- if( $query != "" )
+ if ($query != "")
{
$this->num_queries++;
$query = preg_replace("/LIMIT ([0-9]+),([ 0-9]+)/", "LIMIT \\2 OFFSET \\1", $query);
- if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
+ if ($transaction == BEGIN_TRANSACTION && !$this->in_transaction)
{
$this->in_transaction = TRUE;
- if( !@pg_exec($this->db_connect_id, "BEGIN") )
+ if (!@pg_exec($this->db_connect_id, "BEGIN"))
{
return false;
}
}
$this->query_result = @pg_exec($this->db_connect_id, $query);
- if( $this->query_result )
+ if ($this->query_result)
{
- if( $transaction == END_TRANSACTION )
+ if ($transaction == END_TRANSACTION)
{
$this->in_transaction = FALSE;
- if( !@pg_exec($this->db_connect_id, "COMMIT") )
+ if (!@pg_exec($this->db_connect_id, "COMMIT"))
{
@pg_exec($this->db_connect_id, "ROLLBACK");
return false;
@@ -158,7 +158,7 @@ class sql_db
}
else
{
- if( $this->in_transaction )
+ if ($this->in_transaction)
{
@pg_exec($this->db_connect_id, "ROLLBACK");
}
@@ -169,11 +169,11 @@ class sql_db
}
else
{
- if( $transaction == END_TRANSACTION && $this->in_transaction )
+ if ($transaction == END_TRANSACTION && $this->in_transaction)
{
$this->in_transaction = FALSE;
- if( !@pg_exec($this->db_connect_id, "COMMIT") )
+ if (!@pg_exec($this->db_connect_id, "COMMIT"))
{
@pg_exec($this->db_connect_id, "ROLLBACK");
return false;
@@ -189,56 +189,56 @@ class sql_db
//
function sql_numrows($query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- return ( $query_id ) ? @pg_numrows($query_id) : false;
+ return ($query_id) ? @pg_numrows($query_id) : false;
}
function sql_numfields($query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- return ( $query_id ) ? @pg_numfields($query_id) : false;
+ return ($query_id) ? @pg_numfields($query_id) : false;
}
function sql_fieldname($offset, $query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- return ( $query_id ) ? @pg_fieldname($query_id, $offset) : false;
+ return ($query_id) ? @pg_fieldname($query_id, $offset) : false;
}
function sql_fieldtype($offset, $query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- return ( $query_id ) ? @pg_fieldtype($query_id, $offset) : false;
+ return ($query_id) ? @pg_fieldtype($query_id, $offset) : false;
}
function sql_fetchrow($query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- if($query_id)
+ if ($query_id)
{
$this->row = @pg_fetch_array($query_id, $this->rownum[$query_id]);
- if( $this->row )
+ if ($this->row)
{
$this->rownum[$query_id]++;
return $this->row;
@@ -250,18 +250,18 @@ class sql_db
function sql_fetchrowset($query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- if( $query_id )
+ if ($query_id)
{
unset($this->rowset[$query_id]);
unset($this->row[$query_id]);
$this->rownum[$query_id] = 0;
- while( $this->rowset = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC) )
+ while($this->rowset = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC))
{
$result[] = $this->rowset;
$this->rownum[$query_id]++;
@@ -275,51 +275,25 @@ class sql_db
function sql_fetchfield($field, $row_offset=-1, $query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- if( $query_id )
- {
- if( $row_offset != -1 )
- {
- $this->row = @pg_fetch_array($query_id, $row_offset, PGSQL_ASSOC);
- }
- else
- {
- if( $this->rownum[$query_id] )
- {
- $this->row = @pg_fetch_array($query_id, $this->rownum[$query_id]-1, PGSQL_ASSOC);
- }
- else
- {
- $this->row = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC);
-
- if( $this->row )
- {
- $this->rownum[$query_id]++;
- }
- }
- }
-
- return $this->row[$field];
- }
-
return false;
}
function sql_rowseek($offset, $query_id = 0)
{
- if(!$query_id)
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- if( $query_id )
+ if ($query_id)
{
- if( $offset > -1 )
+ if ($offset > -1)
{
$this->rownum[$query_id] = $offset;
return true;
@@ -337,20 +311,20 @@ class sql_db
{
$query_id = $this->query_result;
- if($query_id && $this->last_query_text[$query_id] != "")
+ if ($query_id && $this->last_query_text[$query_id] != "")
{
- if( preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text[$query_id], $tablename) )
+ if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text[$query_id], $tablename))
{
$query = "SELECT currval('" . $tablename[1] . "_id_seq') AS last_value";
$temp_q_id = @pg_exec($this->db_connect_id, $query);
- if( !$temp_q_id )
+ if (!$temp_q_id)
{
return false;
}
$temp_result = @pg_fetch_array($temp_q_id, 0, PGSQL_ASSOC);
- return ( $temp_result ) ? $temp_result['last_value'] : false;
+ return ($temp_result) ? $temp_result['last_value'] : false;
}
}
@@ -359,27 +333,27 @@ class sql_db
function sql_affectedrows($query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- return ( $query_id ) ? @pg_cmdtuples($query_id) : false;
+ return ($query_id) ? @pg_cmdtuples($query_id) : false;
}
function sql_freeresult($query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
- return ( $query_id ) ? @pg_freeresult($query_id) : false;
+ return ($query_id) ? @pg_freeresult($query_id) : false;
}
function sql_error($query_id = 0)
{
- if( !$query_id )
+ if (!$query_id)
{
$query_id = $this->query_result;
}
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 966b253466..8adc170b1f 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -528,122 +528,158 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $post_id = 0)
return;
}
+ // Default tracking type
+ $type = TRACK_NORMAL;
+ $current_time = time();
+
switch ($mode)
{
case 'mark':
- // Mark one forum as read.
- // Do this by inserting a record with -$forum_id in the 'forum_id' field.
- $sql = "SELECT forum_id
- FROM " . TOPICS_TRACK_TABLE . "
- WHERE user_id = " . $user->data['user_id'] . "
- AND forum_id = -$forum_id";
- $result = $db->sql_query($sql);
-
- if ($db->sql_fetchrow($result))
+ if ($config['load_db_lastread'])
{
+ // Mark one forum as read.
+ // Do this by inserting a record with -$forum_id in the 'forum_id' field.
// User has marked this topic as read before: Update the record
- $sql = "UPDATE " . TOPICS_TRACK_TABLE . "
- SET mark_time = " . time() . "
+ $db->sql_return_on_error = true;
+
+ $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . "
+ SET mark_time = $current_time
WHERE user_id = " . $user->data['user_id'] . "
- AND forum_id = -$forum_id";
- $db->sql_query($sql);
+ AND forum_id = $forum_id";
+ if (!$db->sql_query($sql) || !$db->sql_affectedrows())
+ {
+ // User is marking this forum for the first time.
+ // Insert dummy topic_id to satisfy PRIMARY KEY (user_id, topic_id)
+ // dummy id = -forum_id
+ $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);
+ }
+
+ $db->sql_return_on_error = false;
}
else
{
- // User is marking this forum for the first time.
- // Insert dummy topic_id to satisfy PRIMARY KEY (user_id, topic_id)
- // dummy id = -forum_id
- $sql = "INSERT INTO " . TOPICS_TRACK_TABLE . "
- (user_id, forum_id, topic_id, mark_time)
- VALUES
- (" . $user->data['user_id'] . ", -$forum_id, -$forum_id, " . time() . ")";
- $db->sql_query($sql);
+ $tracking_forums = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_f']) : array();
+ $tracking_forums[$forum_id] = time();
+
+ setcookie($config['cookie_name'] . '_f', serialize($tracking_forums), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']);
+ unset($tracking_forums);
}
break;
case 'markall':
- // Mark all forums as read.
- // Select all forum_id's that are not yet in the lastread table
- $sql = "SELECT f.forum_id
- FROM " . FORUMS_TABLE . " f
- LEFT JOIN (" . TOPICS_TRACK_TABLE . " lr ON (
- lr.user_id = " . $user->data['user_id'] . "
- AND f.forum_id = -lr.forum_id))
- WHERE lr.forum_id IS NULL";
- $result = $db->sql_query($sql);
+ // Mark all forums as read
- if ($row = $db->sql_fetchrow($result))
+ if ($config['load_db_lastread'])
{
- // Some forum_id's are missing. We are not taking into account
- // the auth data, even forums the user can't see are marked as read.
- $sql = "INSERT INTO " . TOPICS_TRACK_TABLE . "
- (user_id, forum_id, topic_id, lastread_time)
- VALUES";
- $forum_insert = array();
-
- do
- {
- // Insert dummy topic_id to satisfy PRIMARY KEY
- // dummy id = -forum_id
- $forum_insert[] = "(" . $user->data['user_id'] . ", -".$row['forum_id'].", -".$row['forum_id'].", " . time() . ")";
- }
- while ($row = $db->sql_fetchrow($result));
-
- $forum_insert = implode(",\n", $forum_insert);
- $sql .= $forum_insert;
-
+ $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . '
+ SET mark_time = ' . $current_time . '
+ WHERE user_id = ' . $user->data['user_id'];
$db->sql_query($sql);
}
+ else
+ {
+ $tracking_forums = array();
+ }
- // Mark all forums as read
- $sql = "UPDATE " . TOPICS_TRACK_TABLE . "
- SET mark_time = " . time() . "
- WHERE user_id = " . $user->data['user_id'] . "
- AND forum_id < 0";
- $db->sql_query($sql);
+ // Select all forum_id's that are not yet in the lastread table
+ switch (SQL_LAYER)
+ {
+ case 'oracle':
+ break;
+
+ default:
+ $sql = ($config['load_db_lastread']) ? 'SELECT f.forum_id FROM (' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id)) WHERE ft.forum_id IS NULL' : 'SELECT forum_id FROM ' . FORUMS_TABLE;
+ }
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error = true;
+ if ($row = $db->sql_fetchrow($result))
+ {
+ do
+ {
+ if ($config['load_db_lastread'])
+ {
+ $sql = '';
+ // Some forum_id's are missing. We are not taking into account
+ // the auth data, even forums the user can't see are marked as read.
+ switch (SQL_LAYER)
+ {
+ case 'mysql':
+ case 'mysql4':
+ $sql .= (($sql != '') ? ', ' : '') . '(' . $user->data['user_id'] . ', ' . $row['forum_id'] . ", $current_time)";
+ break;
+
+ case 'mssql':
+ $sql = (($sql != '') ? ' UNION ALL ' : '') . ' SELECT ' . $user->data['user_id'] . ', ' . $row['forum_id'] . ", $current_time";
+ break;
+
+ default:
+ $sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . ' (user_id, forum_id, mark_time)
+ VALUES (' . $user->data['user_id'] . ', ' . $row['forum_id'] . ", $current_time)";
+ $db->sql_query($sql);
+ $sql = '';
+ }
+
+ if ($sql != '')
+ {
+ $sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . ' (user_id, forum_id, mark_time)
+ VALUES ' . $sql;
+ $db->sql_query($sql);
+ }
+ }
+ else
+ {
+ $tracking_forums[$row['forum_id']] = $current_time;
+ }
+ }
+ while ($row = $db->sql_fetchrow($result));
+ $db->sql_freeresult($result);
+
+ $db->sql_return_on_error = false;
+
+ if (!$config['load_db_lastread'])
+ {
+ setcookie($config['cookie_name'] . '_f', serialize($tracking_forums), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']);
+ unset($tracking_forums);
+ }
+ }
break;
case 'post':
// Mark a topic as read and mark it as a topic where the user has made a post.
- $type = 1;
+ $type = TRACK_POSTED;
case 'topic':
- // Mark a topic as read.
-
- // Type:
- // 0 = Normal topic
- // 1 = user made a post in this topic
- $type_update = (isset($type) && $type = 1) ? 'mark_type = 1,' : '';
- $sql = "UPDATE " . TOPICS_TRACK_TABLE . "
- SET $type_update forum_id = $forum_id, mark_time = " . time() . "
- WHERE topic_id = $topic_id
- AND user_id = " . $user->data['user_id'];
- $result = $db->sql_query($sql);
-
- if (!$db->sql_affectedrows($result))
+ // Mark a topic as read
+ if ($config['load_db_lastread'] || ($config['load_db_track'] && $type == TRACK_POSTED))
{
- // Couldn't update. Row probably doesn't exist. Insert one.
- if(isset($type) && $type = 1)
+ $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . "
+ SET mark_type = $type, mark_time = " . time() . "
+ WHERE topic_id = $topic_id
+ AND user_id = " . $user->data['user_id'];
+ if (!$db->sql_query($sql) || !$db->sql_affectedrows())
{
- $type_name = 'mark_type, ';
- $type_value = '1, ';
- }
- else
- {
- $type_name = '';
- $type_value = '';
+ $sql = 'INSERT INTO ' . TOPICS_TRACK_TABLE . ' (user_id, topic_id, mark_type, mark_time)
+ VALUES (' . $user->data['user_id'] . ", $topic_id, $type, " . time() . ")";
+ $db->sql_query($sql);
}
+ }
- $sql = "INSERT INTO " . TOPICS_TRACK_TABLE . "
- (user_id, topic_id, forum_id, $type_name mark_time)
- VALUES
- (" . $user->data['user_id'] . ", $topic_id, $forum_id, $type_value " . time() . ")";
- $db->sql_query($sql);
+ if (!$config['load_db_lastread'])
+ {
+ $tracking = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_t']) : array();
+ $tracking[$topic_id] = $current_time;
+
+ setcookie($config['cookie_name'] . '_t', serialize($tracking), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']);
+ unset($tracking);
}
break;
}
}
+
// Pagination routine, generates page number sequence
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE)
{
@@ -848,6 +884,16 @@ function redirect($url)
exit;
}
+// Meta refresh assignment
+function meta_refresh($time, $url)
+{
+ global $template;
+
+ $template->assign_vars(array(
+ 'META' => '')
+ );
+}
+
// Generate login box or verify password
function login_box($s_action, $s_hidden_fields = '', $login_explain = '')
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index 6fa6a7375c..563728f7b6 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -21,8 +21,8 @@
function display_forums($root_data = '', $display_moderators = TRUE)
{
- global $db, $template, $auth, $user;
- global $config, $phpEx, $SID, $forum_moderators;
+ global $config, $db, $template, $auth, $user;
+ global $phpEx, $SID, $forum_moderators;
$visible_forums = 0;
@@ -38,20 +38,25 @@ function display_forums($root_data = '', $display_moderators = TRUE)
if ($config['load_db_lastread'] && $user->data['user_id'] != ANONYMOUS)
{
- $lastread_select = ", lr.lastread_time ";
-/* $sql_lastread = 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
- AND ft.forum_id = f.forum_id)';*/
- $sql_lastread = 'LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . '
- AND tt.forum_id IN (f.forum_id, -f.forum_id)
- AND tt.lastread_time >= f.forum_last_post_time)';
- $sql_where .= ' GROUP BY f.forum_id';
+ switch (SQL_LAYER)
+ {
+ case 'oracle':
+ break;
+
+ default:
+ $sql_lastread = 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
+ AND ft.forum_id = f.forum_id)';
+ break;
+ }
+ $lastread_select = ', ft.mark_time ';
}
else
{
$lastread_select = '';
$sql_lastread = '';
- // Cookie based tracking
+ $tracking_forums = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_f']) : array();
+ $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_t']) : array();
}
$sql = "SELECT f.* $lastread_select
@@ -82,57 +87,101 @@ function display_forums($root_data = '', $display_moderators = TRUE)
continue;
}
- if (!$auth->acl_get('f_list', $row['forum_id']))
+ $forum_id = $row['forum_id'];
+
+ if (!$auth->acl_get('f_list', $forum_id))
{
// if the user does not have permissions to list this forum, skip everything until next branch
-
$right_id = $row['right_id'];
continue;
}
- if ($row['parent_id'] == $root_data['forum_id'])
+ if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
{
// Direct child
- $forum_rows[] = $row;
- $parent_id = $row['forum_id'];
- $forum_ids[] = $row['forum_id'];
+ $parent_id = $forum_id;
+ $forum_rows[$forum_id] = $row;
+ $forum_ids[] = $forum_id;
- if (!$row['forum_postable'])
+ if (!$row['forum_postable'] && $row['parent_id'] == $root_data['forum_id'])
{
- $branch_root_id = $row['forum_id'];
+ $branch_root_id = $forum_id;
}
}
- elseif ($row['parent_id'] == $branch_root_id)
- {
- // Forum directly under a category
- $forum_rows[] = $row;
- $parent_id = $row['forum_id'];
- $forum_ids[] = $row['forum_id'];
- }
elseif ($row['forum_postable'])
{
if ($row['display_on_index'])
{
- $subforums[$parent_id][$row['forum_id']]['forum_name'] = $row['forum_name'];
+ $subforums[$parent_id][$forum_id] = $row['forum_name'];
}
+ }
+/*
+ if (!empty($forum_unread[$forum_id]))
+ {
+ $forum_unread[$parent_id] = true;
+ }
+*/
- $subforums[$parent_id][$row['forum_id']]['unread_count'] = $row['unread_count'];
- $subforums[$parent_id][$row['forum_id']]['forum_last_post_time'] = $row['forum_last_post_time'];
+ if (!isset($forum_unread[$parent_id]))
+ {
+ $forum_unread[$parent_id] = false;
+ }
- $subforums[$parent_id][$row['forum_id']]['forum_id'] = $row['forum_id'];
- $subforums[$parent_id][$row['forum_id']]['forum_last_post_id'] = $row['forum_last_post_id'];
- $subforums[$parent_id][$row['forum_id']]['forum_last_post_time'] = $row['forum_last_post_time'];
- $subforums[$parent_id][$row['forum_id']]['forum_last_poster_name'] = $row['forum_last_poster_name'];
- $subforums[$parent_id][$row['forum_id']]['forum_last_poster_id'] = $row['forum_last_poster_id'];
+ $check_time = (!$config['load_db_lastread']) ? $tracking_forums[$forum_id] : $row['mark_time'];
+ if ($check_time < $row['forum_last_post_time'] && $user->data['user_id'] != ANONYMOUS)
+ {
+ $forum_unread[$parent_id] = true;
+ }
+
+
+ // Show most recent last post info on parent if we're a subforum
+ if (isset($forum_rows[$parent_id]) && $row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
+ {
+ $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
+ $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
+ $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
+ $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
+ $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
+ }
+ else
+ {
+ $forum_rows[$forum_id]['forum_id_last_post'] = $row['forum_id'];
}
}
$db->sql_freeresult();
+/*
+ if ($config['load_db_lastread'])
+ {
+ }
+ else
+ {
+ $forum_unread = array();
+ $sql = "SELECT forum_id, topic_id, topic_last_post_time
+ FROM " . TOPICS_TABLE . "
+ WHERE topic_last_post_time > " . ((sizeof($tracking_forums)) ? min($tracking_forums) : time() - 86400) . "
+ $sql_forum_track;
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if (($tracking_forums[$row['forum_id']] > $tracking_topics[$row['topic_id']] &&
+ $row['topic_last_post_time'] > $tracking_forums[$row['forum_id']]) ||
+ ($tracking_topics[$row['topic_id']] > $tracking_forums[$row['forum_id']] &&
+ $row['topic_last_post_time'] > $tracking_topics[$row['topic_id']]))
+ {
+ $forum_unread[$row['forum_id']] = $row['topic_last_post_time'];
+ }
+ }
+ }
+*/
+
if ($display_moderators)
{
get_moderators($forum_moderators, $forum_ids);
}
+
$root_id = $root_data['forum_id'];
foreach ($forum_rows as $row)
{
@@ -161,40 +210,23 @@ function display_forums($root_data = '', $display_moderators = TRUE)
}
$visible_forums++;
-
$forum_id = $row['forum_id'];
- //
- $unread_topics = ($user->data['user_id'] != ANONYMOUS && $row['unread_count'] < $row['forum_last_post_time']) ? 1 : 0;
- //
+ // Generate list of subforums if we need to
if (isset($subforums[$forum_id]))
{
-
$alist = array();
- foreach ($subforums[$forum_id] as $sub_forum_id => $subforum_row)
+ foreach ($subforums[$forum_id] as $sub_forum_id => $subforum_name)
{
- $unread_topics += ($user->data['user_id'] != ANONYMOUS && $subforum_row['unread_count'] < $subforum_row['forum_last_post_time']) ? 1 : 0;
-
- if (!empty($subforum_row['forum_name']))
+ if (!empty($subforum_name))
{
- $alist[$sub_forum_id] = $subforum_row['forum_name'];
- }
-
- if ($subforum_row['forum_last_post_time'] > $row['forum_last_post_time'])
- {
- $row['forum_last_post_time'] = $subforum_row['forum_last_post_time'];
- $row['forum_last_post_id'] = $subforum_row['forum_last_post_id'];
- $row['forum_last_poster_name'] = $subforum_row['forum_last_poster_name'];
- $row['forum_last_poster_id'] = $subforum_row['forum_last_poster_id'];
- $row['forum_id_last_post'] = $subforum_row['forum_id'];
+ $alist[$sub_forum_id] = $subforum_name;
}
}
if (sizeof($alist))
{
- @natsort($alist);
-
$links = array();
foreach ($alist as $subforum_id => $subforum_name)
{
@@ -205,18 +237,18 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$l_subforums = (count($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
}
- $folder_image = ($unread_topics) ? 'sub_forum_new' : 'sub_forum';
+ $folder_image = ($forum_unread[$forum_id]) ? 'sub_forum_new' : 'sub_forum';
}
else
{
- $folder_image = ($unread_topics) ? 'forum_new' : 'forum';
- $row['forum_id_last_post'] = $row['forum_id'];
+ $folder_image = ($forum_unread[$forum_id]) ? 'forum_new' : 'forum';
$subforums_list = '';
$l_subforums = '';
}
- //
+
+ // Which folder should we display?
if ($row['forum_status'] == ITEM_LOCKED)
{
$folder_image = 'forum_locked';
@@ -224,10 +256,11 @@ function display_forums($root_data = '', $display_moderators = TRUE)
}
else
{
- $folder_alt = ($unread_topics) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
+ $folder_alt = ($forum_unread[$forum_id]) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
}
- //
+
+ // Create last post link information, if appropriate
if ($row['forum_last_post_id'])
{
$last_post_time = $user->format_date($row['forum_last_post_time']);
@@ -242,7 +275,8 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$last_post_time = $last_poster = $last_poster_url = $last_post_url = '';
}
- //
+
+ // Output moderator listing ... if applicable
$l_moderator = $moderators_list = '';
if ($display_moderators && !empty($forum_moderators[$forum_id]))
{
diff --git a/phpBB/index.php b/phpBB/index.php
index b7b3489765..8b6b93cf29 100644
--- a/phpBB/index.php
+++ b/phpBB/index.php
@@ -36,16 +36,14 @@ $auth->acl($user->data);
// Handle marking posts
if ($mark_read == 'forums')
{
- if ($userdata['user_id'])
+ if ($userdata['user_id'] != ANONYMOUS)
{
markread('markall');
}
- $template->assign_vars(array(
- 'META' => '')
- );
+ meta_refresh(3, "index.$phpEx$SID");
- $message = $user->lang['Forums_marked_read'] . '
' . sprintf($user->lang['RETURN_INDEX'], '', ' ');
+ $message = $user->lang['FORUMS_MARKED'] . '
' . sprintf($user->lang['RETURN_INDEX'], '', ' ');
trigger_error($message);
}
diff --git a/phpBB/install/schemas/mysql_schema.sql b/phpBB/install/schemas/mysql_schema.sql
index 20a9e01696..49eaed8d05 100644
--- a/phpBB/install/schemas/mysql_schema.sql
+++ b/phpBB/install/schemas/mysql_schema.sql
@@ -229,6 +229,19 @@ CREATE TABLE phpbb_forums (
KEY forum_last_post_id (forum_last_post_id)
);
+
+# --------------------------------------------------------
+#
+# Table structure for table 'phpbb_forums_marking'
+#
+CREATE TABLE phpbb_forums_marking (
+ user_id mediumint(9) UNSIGNED DEFAULT '0' NOT NULL,
+ forum_id mediumint(9) UNSIGNED DEFAULT '0' NOT NULL,
+ mark_time int(11) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (user_id, forum_id)
+);
+
+
# --------------------------------------------------------
#
# Table structure for table 'phpbb_forums_watch'
@@ -744,7 +757,6 @@ CREATE TABLE phpbb_topics (
#
CREATE TABLE phpbb_topics_marking (
user_id mediumint(9) UNSIGNED DEFAULT '0' NOT NULL,
- forum_id mediumint(9) UNSIGNED DEFAULT '0' NOT NULL,
topic_id mediumint(9) UNSIGNED DEFAULT '0' NOT NULL,
mark_type tinyint(4) DEFAULT '0' NOT NULL,
mark_time int(11) DEFAULT '0' NOT NULL,
diff --git a/phpBB/language/en/lang_main.php b/phpBB/language/en/lang_main.php
index a7c50e2184..a0727dc6ef 100644
--- a/phpBB/language/en/lang_main.php
+++ b/phpBB/language/en/lang_main.php
@@ -71,6 +71,7 @@ $lang = array(
'GO' => 'Go',
'JUMP_TO' => 'Jump to',
+ 'SEARCH_FOR' => 'Search for',
'SUBMIT' => 'Submit',
'RESET' => 'Reset',
'CANCEL' => 'Cancel',
@@ -107,6 +108,7 @@ $lang = array(
'REPLY_WITH_QUOTE' => 'Reply with quote',
+ 'RETURN_INDEX' => 'Click %sHere%s to return to the index',
'RETURN_TOPIC' => 'Click %sHere%s to return to the topic',
'RETURN_FORUM' => 'Click %sHere%s to return to the forum',
'RETURN_LOGIN' => 'Click %sHere%s to try again',
@@ -115,7 +117,7 @@ $lang = array(
'VIEW_MESSAGE' => 'Click %sHere%s to view your message',
- 'Information' => 'Information',
+ 'INFORMATION' => 'Information',
'BOARD_DISABLE' => 'Sorry but this board is currently unavailable',
@@ -227,21 +229,23 @@ $lang = array(
'Private_Message' => 'Private Message',
'Private_Messages' => 'Private Messages',
- 'WHO_IS_ONLINE' => 'Who is Online',
- 'MARK_FORUMS_READ' => 'Mark all forums read',
- 'Forums_marked_read' => 'All forums have been marked read',
'View_forum' => 'View Forum',
- 'DISPLAY_TOPICS' => 'Display topics from previous',
- 'ALL_TOPICS' => 'All Topics',
- 'VIEW_TOPIC_ANNOUNCEMENT'=> 'Announcement:',
- 'VIEW_TOPIC_STICKY' => 'Sticky:',
- 'VIEW_TOPIC_MOVED' => 'Moved:',
- 'VIEW_TOPIC_POLL' => 'Poll:',
- 'VIEW_TOPIC_LOCKED' => 'Locked:',
+ 'WHO_IS_ONLINE' => 'Who is Online',
+ 'DISPLAY_TOPICS' => 'Display topics from previous',
+ 'ALL_TOPICS' => 'All Topics',
- 'MARK_TOPICS_READ' => 'Mark all topics read',
- 'Topics_marked_read' => 'The topics for this forum have now been marked read',
+ 'VIEW_TOPIC_ANNOUNCEMENT'=> 'Announcement:',
+ 'VIEW_TOPIC_STICKY' => 'Sticky:',
+ 'VIEW_TOPIC_MOVED' => 'Moved:',
+ 'VIEW_TOPIC_POLL' => 'Poll:',
+ 'VIEW_TOPIC_LOCKED' => 'Locked:',
+
+ 'MARK_FORUMS_READ' => 'Mark all forums read',
+ 'FORUMS_MARKED' => 'All forums have been marked read',
+
+ 'MARK_TOPICS_READ' => 'Mark all topics read',
+ 'TOPICS_MARKED' => 'The topics for this forum have now been marked read',
'RULES_POST_CAN' => 'You can post new topics in this forum',
@@ -273,7 +277,7 @@ $lang = array(
'NO_POST' => 'The requested post does not exist.',
'NO_USER' => 'The requested user does not exist.',
'NO_GROUP' => 'The requested usergroup does not exist.',
-
+ 'NO_UNREAD_POSTS' => 'There are no new unread posts for this topic.',
'LOGIN_VIEWFORUM' => 'The board administrator requires you to be registered and logged in to view this forum.',
'STOP_WATCHING_FORUM' => 'Stop watching this forum',
@@ -291,6 +295,7 @@ $lang = array(
'EMAIL_TOPIC' => 'Email to friend',
'VIEW_NEXT_TOPIC' => 'View next topic',
'VIEW_PREVIOUS_TOPIC' => 'View previous topic',
+ 'VIEW_UNREAD_POST' => 'View first unread topic',
'NO_NEWER_TOPICS' => 'There are no newer topics in this forum',
'NO_OLDER_TOPICS' => 'There are no older topics in this forum',
@@ -310,16 +315,14 @@ $lang = array(
'VIEW_IP' => 'IP',
'DELETE_POST' => 'Delete',
'DELETE_POST_WARN' => 'Once deleted the post cannot be recovered',
- 'REPORT_TO_ADMIN' => 'Report this post',
+ 'REPORT_POST' => 'Report this post',
'EDITED_TIME_TOTAL' => 'Last edited by %1$s on %2$s, edited %3$d time in total',
'EDITED_TIMES_TOTAL' => 'Last edited by %1$s on %2$s, edited %3$d times in total',
- 'POST_BEEN_REPORTED' => 'This post has been reported',
- 'POST_NOT_BEEN_APPROVED' => 'This post has not been approved',
- 'TOPIC_BEEN_REPORTED' => 'This topic has been reported',
- 'TOPIC_NOT_BEEN_APPROVED' => 'This topic has not been approved',
- 'APPROVE_POST' => 'Approve this post',
- 'READ_REPORTS' => 'Read post reports',
+ 'POST_REPORTED' => 'Click to view reports',
+ 'POST_NOT_APPROVED' => 'Click to approve post',
+ 'TOPIC_REPORTED' => 'This topic has been reported',
+ 'TOPIC_NOT_APPROVED'=> 'This topic has not been approved',
'WROTE' => 'wrote',
'QUOTE' => 'Quote',
@@ -353,6 +356,8 @@ $lang = array(
'TOTAL_VOTES' => 'Total Votes',
'VIEW_RESULTS' => 'View Results',
'POLL_VOTED_OPTION' => 'You voted for this option',
+ 'POLL_RUN_TILL' => 'Poll runs till %s', // %s = date/time
+ 'VOTE_SUBMITTED' => 'Your vote has been cast',
'VIEW_TOPIC_POST' => '1 Post',
'VIEW_TOPIC_POSTS' => '%d Posts',
@@ -444,7 +449,6 @@ $lang = array(
'POST_STORED_MOD' => 'Your message has been saved but requires approval',
'DELETED' => 'Your message has been deleted successfully',
'Poll_delete' => 'Your poll has been deleted successfully',
- 'Vote_cast' => 'Your vote has been cast',
'BBCODE_B_HELP' => 'Bold text: [b]text[/b] (alt+b)',
'BBCODE_I_HELP' => 'Italic text: [i]text[/i] (alt+i)',
'BBCODE_U_HELP' => 'Underline text: [u]text[/u] (alt+u)',
@@ -825,7 +829,6 @@ $lang = array(
'No_search_match' => 'No topics or posts met your search criteria',
'Found_search_match' => 'Search found %d match',
'Found_search_matches' => 'Search found %d matches',
- 'No_new_posts_last_visit' => 'No new posts since your last visit',
'Sorry_auth_announce' => 'Sorry but only %s can post announcements in this forum',
'Sorry_auth_sticky' => 'Sorry but only %s can post sticky messages in this forum',
@@ -1154,26 +1157,28 @@ $lang = array_merge($lang, array(
//----- post reporting
- 'REASON' => 'Reason',
- 'ADDITIONAL_INFOS' => 'Additional infos',
- 'CAN_BE_LEFT_BLANK' => '(can be left blank)',
+ 'REASON' => 'Reason',
+ 'MORE_INFO' => 'Further information',
+ 'CAN_LEAVE_BLANK' => 'This can be left blank.',
- 'POST_NOT_EXIST' => 'The post you requested does not exist',
+ 'POST_NOT_EXIST' => 'The post you requested does not exist',
- 'REPORT_TO_ADMIN_EXPLAIN' => 'Using this form you can report the selected post to forum admins',
- 'EMPTY_REPORT' => 'You must enter a description when selecting this reason',
+ 'REPORT_POST_EXPLAIN' => 'Use this form to report the selected post to the forum moderators and board administrators. Reporting should generally be used only if the post breaks forum rules.',
+ 'EMPTY_REPORT' => 'You must enter a description when selecting this reason',
- 'REPORT_NOTIFY' => 'Notify me when this report is reviewed',
- 'POST_REPORTED_SUCCESS' => 'This post has been successfully reported',
+ 'REPORT_NOTIFY' => 'Notify me',
+ 'REPORT_NOTIFY_EXPLAIN' => 'Informs you when report is read.',
- 'report_reasons' => array(
- 'title' => array(
- 'warez' => 'Warez',
- 'other' => 'Other'
+ 'POST_REPORTED_SUCCESS' => 'This post has been successfully reported',
+
+ 'REPORT_REASONS' => array(
+ 'TITLE' => array(
+ 'WAREZ' => 'Warez',
+ 'OTHER' => 'Other'
),
- 'description' => array(
- 'warez' => 'The post contains links to illegal or pirated software',
- 'other' => 'The reported post does not fit into any other category, please use the description field'
+ 'DESCRIPTION' => array(
+ 'WAREZ' => 'The post contains links to illegal or pirated software',
+ 'OTHER' => 'The reported post does not fit into any other category, please use the description field'
)
)
));
diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php
index 2e93425382..9e6999fde0 100644
--- a/phpBB/memberlist.php
+++ b/phpBB/memberlist.php
@@ -33,17 +33,26 @@ $auth->acl($user->data);
$mode = (isset($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : '';
$user_id = (isset($_GET['u'])) ? intval($_GET['u']) : ANONYMOUS;
-// Can this user view profiles/memberslist?
-if (!$auth->acl_gets('u_viewprofile', 'a_'))
-{
- if ($user->data['user_id'] != ANONYMOUS)
- {
- trigger_error($user->lang['NO_VIEW_USERS']);
- }
- login_box(preg_replace('#.*?([a-z]+?\.' . $phpEx . '.*?)$#i', '\1', htmlspecialchars($_SERVER['REQUEST_URI'])));
+switch ($mode)
+{
+ case 'email':
+ break;
+ default:
+ // Can this user view profiles/memberslist?
+ if (!$auth->acl_gets('u_viewprofile', 'a_'))
+ {
+ if ($user->data['user_id'] != ANONYMOUS)
+ {
+ trigger_error($user->lang['NO_VIEW_USERS']);
+ }
+
+ login_box(preg_replace('#.*?([a-z]+?\.' . $phpEx . '.*?)$#i', '\1', htmlspecialchars($_SERVER['REQUEST_URI'])));
+ }
+ break;
}
+
$start = (isset($_GET['start'])) ? intval($_GET['start']) : 0;
$form = (!empty($_GET['form'])) ? htmlspecialchars($_GET['form']) : 0;
$field = (isset($_GET['field'])) ? htmlspecialchars($_GET['field']) : 'username';
@@ -517,7 +526,7 @@ switch ($mode)
$db->sql_freeresult($result);
// Do the SQL thang
- $sql = "SELECT username, user_id, user_colour, user_viewemail, user_posts, user_regdate, user_rank, user_from, user_website, user_email, user_sig, user_icq, user_aim, user_yim, user_msnm, user_avatar, user_avatar_type, user_allowavatar, user_lastvisit
+ $sql = "SELECT username, user_id, user_colour, user_viewemail, user_posts, user_regdate, user_rank, user_from, user_website, user_email, user_icq, user_aim, user_yim, user_msnm, user_avatar, user_avatar_type, user_allowavatar, user_lastvisit
FROM " . USERS_TABLE . "
WHERE user_id <> " . ANONYMOUS . "
$where_sql
diff --git a/phpBB/report.php b/phpBB/report.php
index e4c0feadf4..c44342b831 100644
--- a/phpBB/report.php
+++ b/phpBB/report.php
@@ -28,7 +28,7 @@ include($phpbb_root_path . 'common.'.$phpEx);
$user->start();
$user->setup();
$auth->acl($user->data);
-// End session management
+
// var definitions
$post_id = (!empty($_REQUEST['p'])) ? intval($_REQUEST['p']) : 0;
@@ -36,38 +36,6 @@ $reason_id = (!empty($_REQUEST['reason_id'])) ? intval($_REQUEST['reason_id']) :
$notify = (!empty($_REQUEST['notify']) && $user->data['user_id'] != ANONYMOUS) ? TRUE : FALSE;
$description = (!empty($_REQUEST['description'])) ? stripslashes($_REQUEST['description']) : '';
-// Start output of page
-$page_title = $user->lang['REPORT_TO_ADMIN'];
-include($phpbb_root_path . 'includes/page_header.' . $phpEx);
-
-$sql = 'SELECT f.*, t.*, p.*
- FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
- WHERE p.post_id = $post_id
- AND p.topic_id = t.topic_id
- AND p.forum_id = f.forum_id";
-$result = $db->sql_query($sql);
-
-if (!$row = $db->sql_fetchrow($result))
-{
- trigger_error('POST_NOT_EXIST');
-}
-
-$forum_id = $row['forum_id'];
-$topic_id = $row['topic_id'];
-
-// Checking permissions
-if (!$auth->acl_get('f_list', $forum_id))
-{
- trigger_error('POST_NOT_EXIST');
-}
-if (!$auth->acl_get('f_read', $forum_id))
-{
- trigger_error('USER_CANNOT_READ');
-}
-if (!$auth->acl_get('f_report', $forum_id))
-{
- trigger_error('USER_CANNOT_REPORT');
-}
// Has the report been cancelled?
if (isset($_POST['cancel']))
@@ -75,15 +43,49 @@ if (isset($_POST['cancel']))
redirect("viewtopic.$phpEx$SID&p=$post_id#$post_id");
}
+
+// Grab all relevant data
+$sql = 'SELECT f.*, t.*, p.*
+ FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
+ WHERE p.post_id = $post_id
+ AND p.topic_id = t.topic_id
+ AND p.forum_id = f.forum_id";
+$result = $db->sql_query($sql);
+
+if (!($forum_data = $db->sql_fetchrow($result)))
+{
+ trigger_error($user->lang['POST_NOT_EXIST']);
+}
+
+$forum_id = $forum_data['forum_id'];
+$topic_id = $forum_data['topic_id'];
+
+
+// Check required permissions
+$acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
+foreach ($acl_check_ary as $acl => $error)
+{
+ if (!$auth->acl_get($acl, $forum_id))
+ {
+ trigger_error($user->lang[$error]);
+ }
+}
+unset($acl_check_ary);
+
+
// Has the report been confirmed?
if (!empty($_POST['reason_id']))
{
- $result = $db->sql_query('SELECT reason_name FROM ' . REASONS_TABLE . " WHERE reason_id = $reason_id");
- $row = $db->sql_fetchrow($result);
- if (!$row || (!$description && $row['reason_name'] == 'other'))
+ $sql = 'SELECT reason_name
+ FROM ' . REASONS_TABLE . "
+ WHERE reason_id = $reason_id";
+ $result = $db->sql_query($sql);
+
+ if (!($row = $db->sql_fetchrow($result)) || (!$description && $row['reason_name'] == 'other'))
{
trigger_error('EMPTY_REPORT');
}
+ $db->sql_freeresult($result);
$sql_ary = array(
'reason_id' => (int) $reason_id,
@@ -94,61 +96,69 @@ if (!empty($_POST['reason_id']))
'report_text' => (string) $description
);
- $sql = 'INSERT INTO ' . REPORTS_TABLE . $db->sql_build_array('INSERT', $sql_ary);
+ $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' .
+ $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
if (!$row['post_reported'])
{
- $db->sql_query('UPDATE ' . POSTS_TABLE . ' SET post_reported = 1 WHERE post_id = ' . $post_id);
- }
- if (!$row['topic_reported'])
- {
- $db->sql_query('UPDATE ' . TOPICS_TABLE . ' SET topic_reported = 1 WHERE topic_id = ' . $topic_id);
+ $sql = 'UPDATE ' . POSTS_TABLE . '
+ SET post_reported = 1
+ WHERE post_id = ' . $post_id;
+ $db->sql_query($sql);
}
- trigger_error($user->lang['POST_REPORTED_SUCCESS'] . '
' . sprintf($user->lang['RETURN_TOPIC'], "", ''));
+ if (!$row['topic_reported'])
+ {
+ $sql = 'UPDATE ' . TOPICS_TABLE . '
+ SET topic_reported = 1
+ WHERE topic_id = ' . $topic_id;
+ $db->sql_query($sql);
+ }
+
+ meta_refresh(3, "viewtopic.$phpEx$SID&p=$post_id#$post_id");
+
+ $message = $user->lang['POST_REPORTED_SUCCESS'] . '
' . sprintf($user->lang['RETURN_TOPIC'], "", '');
+ trigger_error($message);
// TODO: warn moderators or something ;)
}
+
// Generate the form
+$sql = 'SELECT *
+ FROM ' . REASONS_TABLE . '
+ ORDER BY reason_priority ASC';
+$result = $db->sql_query($sql);
-generate_forum_nav($row);
-
-$result = $db->sql_query('SELECT * FROM ' . REASONS_TABLE . ' ORDER BY reason_priority ASC');
while ($row = $db->sql_fetchrow($result))
{
- if (!empty($user->lang['report_reasons']['title'][$row['reason_name']]))
- {
- $reason_name = $user->lang['report_reasons']['title'][$row['reason_name']];
- }
- else
- {
- $reason_name = ucwords(str_replace('_', ' ', $row['reason_name']));
- }
+ $row['reason_name'] = strtoupper($row['reason_name']);
- if (!empty($user->lang['report_reasons']['description'][$row['reason_name']]))
- {
- $reason_description = $user->lang['report_reasons']['description'][$row['reason_name']];
- }
- else
- {
- $reason_description = $row['reason_description'];
- }
+ $reason_name = (!empty($user->lang['REPORT_REASONS']['TITLE'][$row['reason_name']])) ? $user->lang['REPORT_REASONS']['TITLE'][$row['reason_name']] : ucwords(str_replace('_', ' ', $row['reason_name']));
+
+ $reason_description = (!empty($user->lang['REPORT_REASONS']['DESCRIPTION'][$row['reason_name']])) ? $user->lang['REPORT_REASONS']['DESCRIPTION'][$row['reason_name']] : $row['reason_description'];
$template->assign_block_vars('reason', array(
'ID' => $row['reason_id'],
'NAME' => htmlspecialchars($reason_name),
- 'DESCRIPTION' => htmlspecialchars($reason_description)
- ));
+ 'DESCRIPTION' => htmlspecialchars($reason_description))
+ );
}
$template->assign_var('S_CAN_NOTIFY', ($user->data['user_id'] == ANONYMOUS) ? FALSE : TRUE);
+
+
+// Start output of page
+$page_title = $user->lang['REPORT_TO_ADMIN'];
+include($phpbb_root_path . 'includes/page_header.' . $phpEx);
+
+generate_forum_nav($forum_data);
+
$template->set_filenames(array(
- 'body' => 'report.html'
-));
+ 'body' => 'report_body.html')
+);
include($phpbb_root_path . 'includes/page_tail.' . $phpEx);
-
?>
\ No newline at end of file
diff --git a/phpBB/templates/subSilver/index_body.html b/phpBB/templates/subSilver/index_body.html
index 8ee2906ab9..9e48288e6b 100644
--- a/phpBB/templates/subSilver/index_body.html
+++ b/phpBB/templates/subSilver/index_body.html
@@ -35,7 +35,7 @@
{forumrow.L_MODERATOR_STR}: {forumrow.MODERATORS}
{forumrow.L_SUBFORUM_STR} {forumrow.SUBFORUMS}
{JUMPBOX} | -
{JUMPBOX} | +
{postrow.POST_ICON} | @@ -106,35 +106,27 @@||||||||||||||||||
' . sprintf($user->lang['RETURN_FORUM'], '', ' '); trigger_error($message); } - +/* // Do the forum Prune - cron type job ... if ($config['prune_enable'] && $auth->acl_get('a_')) { @@ -160,7 +158,7 @@ if ($forum_data['forum_postable']) auto_prune($forum_id, $forum_data['prune_days'], $forum_data['prune_freq']); } } - +*/ // Forum rules, subscription info and word censors $s_watching_forum = $s_watching_forum_img = ''; @@ -173,11 +171,12 @@ if ($forum_data['forum_postable']) $censors = array(); obtain_word_list($censors); + // Topic ordering options $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); - $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => array('t.poll_last_vote', 't.topic_last_post_time'), 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views'); + $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views'); $s_limit_days = $s_sort_key = $s_sort_dir = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir); @@ -190,14 +189,13 @@ if ($forum_data['forum_postable']) $sql = 'SELECT COUNT(topic_id) AS num_topics FROM ' . TOPICS_TABLE . " WHERE forum_id = $forum_id - AND (topic_last_post_time >= $min_post_time - OR poll_last_vote >= $min_post_time) + AND (topic_last_post_time >= $min_post_time) " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'); $result = $db->sql_query($sql); $start = 0; $topics_count = ($row = $db->sql_fetchrow($result)) ? $row['num_topics'] : 0; - $sql_limit_time = "AND (t.topic_last_post_time >= $min_post_time OR t.poll_last_vote >= $min_post_time)"; + $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time"; } else { @@ -214,8 +212,8 @@ if ($forum_data['forum_postable']) } // Select the sort order - $sql_sort_dir = ($sort_dir == 'd') ? 'DESC' : 'ASC'; - $sql_sort_order = ((is_array($sort_by_sql[$sort_key])) ? implode(" $sql_sort_dir, ", $sort_by_sql[$sort_key]) : $sort_by_sql[$sort_key]) . " $sql_sort_dir"; + $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); + // Basic pagewide vars $post_alt = (intval($forum_data['forum_status']) == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'POST_NEW_TOPIC'; @@ -224,7 +222,7 @@ if ($forum_data['forum_postable']) 'PAGINATION' => generate_pagination("viewforum.$phpEx$SID&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir", $topics_count, $config['topics_per_page'], $start), 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), 'TOTAL_TOPICS' => ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count), - 'MOD_CP' => ($auth->acl_gets('m_', $forum_id)) ? sprintf($user->lang['MCP'], '', '') : '', + 'MOD_CP' => ($auth->acl_gets('m_', $forum_id)) ? sprintf($user->lang['MCP'], "session_id&f=$forum_id\">", '') : '', 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '', 'POST_IMG' => (intval($forum_data['forum_status']) == ITEM_LOCKED) ? $user->img('btn_locked', $post_alt) : $user->img('btn_post', $post_alt), @@ -244,19 +242,18 @@ if ($forum_data['forum_postable']) 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'], - 'S_IS_POSTABLE' => TRUE, - 'S_SELECT_SORT_DIR' => $s_sort_dir, - 'S_SELECT_SORT_KEY' => $s_sort_key, - 'S_SELECT_SORT_DAYS'=> $s_limit_days, - 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false, - 'S_WATCH_FORUM' => $s_watching_forum, - 'S_FORUM_ACTION' => 'viewforum.' . $phpEx . $SID . '&f=' . $forum_id . "&start=$start", + 'S_IS_POSTABLE' => TRUE, + 'S_SELECT_SORT_DIR' => $s_sort_dir, + 'S_SELECT_SORT_KEY' => $s_sort_key, + 'S_SELECT_SORT_DAYS' => $s_limit_days, + 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false, + 'S_WATCH_FORUM' => $s_watching_forum, + 'S_FORUM_ACTION' => "viewforum.$phpExx$SIDx&f=$forum_id&start=$start", + 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, + 'S_SEARCHBOX_ACTION' => "search.$phpEx$SID&f=$forum_id", - 'S_SHOW_SEARCHBOX' => ($auth->acl_gets('f_search', 'm_', 'a_', $forum_id)) ? true : false, - 'S_SEARCHBOX_ACTION'=> "search.$phpEx$SID&f=$forum_id", - - 'U_POST_NEW_TOPIC' => 'posting.' . $phpEx . $SID . '&mode=post&f=' . $forum_id, - 'U_MARK_READ' => 'viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '&mark=topics') + 'U_POST_NEW_TOPIC' => "posting.$phpEx$SID&mode=post&f=$forum_id", + 'U_MARK_READ' => "viewforum.$phpEx$SID&f=$forum_id&mark=topics") ); @@ -269,9 +266,9 @@ if ($forum_data['forum_postable']) $total_topics = 0; $row_ary = array(); - $sql_approved = ($auth->acl_gets('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'; + $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'; $sql_tracking = (($config['load_db_lastread'] || $config['load_db_track']) && $user->data['user_id'] != ANONYMOUS) ? 'LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')' : ''; - $sql_select = (($config['load_db_lastread'] || $config['load_db_track']) && $user->data['user_id'] != ANONYMOUS) ? ', tt.mark_type' : ''; + $sql_select = (($config['load_db_lastread'] || $config['load_db_track']) && $user->data['user_id'] != ANONYMOUS) ? ', tt.mark_type, tt.mark_time' : ''; $sql = "SELECT t.* $sql_select FROM (" . TOPICS_TABLE . " t @@ -362,30 +359,33 @@ if ($forum_data['forum_postable']) $folder_new = 'folder_locked_new'; } - $unread_topic = true; - if ($user->data['user_id'] != ANONYMOUS && - ($row['topic_last_post_time'] <= $row['lastread_time'] || - $row['topic_last_post_time'] < (time() - $config['lastread'])) - ) + $unread_topic = ($user->data['user_id'] != ANONYMOUS) ? true : false; + if ($user->data['user_id'] != ANONYMOUS) { - $unread_topic = false; + $topic_check = (!$config['load_db_lastread']) ? $tracking_topics[$topic_id] : $row['mark_time']; + $forum_check = (!$config['load_db_lastread']) ? $tracking_forums[$forum_id] : $forum_data['mark_time']; + + if ($topic_check > $row['topic_last_post_time'] || $forum_check > $row['topic_last_post_time']) + { + $unread_topic = false; + } } - $newest_post_img = ($unread_topic) ? '' . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . ' ' : ''; + $newest_post_img = ($unread_topic) ? "" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . ' ' : ''; $folder_img = ($unread_topic) ? $folder_new : $folder; $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); - if (($config['load_db_lastread'] || $config['load_db_track']) && $row['mark_type']) + if (!empty($row['mark_type'])) { $folder_img .= '_posted'; } } - if (intval($row['poll_start'])) + if (!empty($row['poll_start'])) { $topic_type .= $user->lang['VIEW_TOPIC_POLL']; } @@ -402,7 +402,7 @@ if ($forum_data['forum_postable']) $times = 1; for($j = 0; $j < $replies + 1; $j += intval($config['posts_per_page'])) { - $goto_page .= '' . $times . ''; + $goto_page .= "$times"; if ($times == 1 && $total_pages > 4) { $goto_page .= ' ... '; @@ -424,9 +424,9 @@ if ($forum_data['forum_postable']) // Generate all the URIs ... - $view_topic_url = 'viewtopic.' . $phpEx . $SID . '&f=' . $forum_id . '&t=' . $topic_id; + $view_topic_url = "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"; - $last_post_img = '' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . ''; + $last_post_img = "' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . ''; $topic_author = ($row['topic_poster'] != ANONYMOUS) ? "' : ''; $topic_author .= ($row['topic_poster'] != ANONYMOUS) ? $row['topic_first_poster_name'] : (($row['topic_first_poster_name'] != '') ? $row['topic_first_poster_name'] : $user->lang['GUEST']); @@ -476,14 +476,41 @@ if ($forum_data['forum_postable']) $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE) ? 1 : 0; $i++; + + + if ($config['load_db_lastread']) + { + if ($row['mark_time'] > $row['topic_last_post_time'] && !isset($update_forum)) + { + $update_forum = true; + } + else if ((isset($row['mark_time']) && $row['topic_last_post_time'] > $row['mark_time']) || (empty($row['mark_time']) && $row['topic_last_post_time'] > $forum_data['mark_time'])) + { + $update_forum = false; + } + } + else + { + if ($tracking_topics[$topic_id] > $row['topic_last_post_time'] && !isset($update_forum)) + { + $update_forum = true; + } + else if ((isset($tracking_topics[$topic_id]) && $row['topic_last_post_time'] > $tracking_topics[$topic_id]) || (!isset($tracking_topics[$topic_id]) && $row['topic_last_post_time'] > $tracking_forums[$forum_id])) + { + $update_forum = false; + } + } } } - if ($user->data['user_id'] != ANONYMOUS) + // This is rather a fudge but it's the best I can think of without requiring information + // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find + // any it updates the forum last read cookie. This requires that the user visit the forum + // after reading a topic + if ($user->data['user_id'] != ANONYMOUS && $update_forum) { - // $mark_topics isn't set as of now - //setcookie($config['cookie_name'] . '_t', serialize($mark_topics), 0, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); + markread('mark', $forum_id); } } diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index b1e47f444f..3985e980f6 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -75,7 +75,7 @@ while ($row = $db->sql_fetchrow($result)) if (!$row['user_allow_viewonline'] || !$row['session_allow_viewonline']) { - $view_online = ($auth->acl_gets('u_viewonline', 'a_')) ? true : false; + $view_online = ($auth->acl_gets('u_viewonline')) ? true : false; $hidden_users++; $username = '' . $username . ''; diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index d0d457b65a..d2cfb2d09e 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -24,6 +24,12 @@ $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); + +// Start session management +$user->start(); +$auth->acl($user->data); + + // Initial var setup $forum_id = (isset($_GET['f'])) ? max(intval($_GET['f']), 0) : 0; $topic_id = (isset($_GET['t'])) ? max(intval($_GET['t']), 0) : 0; @@ -49,32 +55,49 @@ if (empty($topic_id) && empty($post_id)) } -// Start session management -$user->start(); - -// Configure style, language, etc. -$auth->acl($user->data); - // Find topic id if user requested a newer or older topic if (isset($_GET['view']) && empty($post_id)) { - if ($_GET['view'] == 'newest') + if ($_GET['view'] == 'unread') { - if ($user->session_id) + if ($user->data['user_id'] != ANONYMOUS) { + if ($config['load_db_lastread']) + { + switch (SQL_LAYER) + { + case 'oracle': + break; + + default: + $sql_lastread = 'LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . ' + AND tt.topic_id = p.topic_id)'; + $sql_unread_time = ' tt.mark_time OR tt.mark_time IS NULL'; + } + } + else + { + $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_t']) : array(); + $sql_unread_time = (!empty($tracking_topics[$topic_id])) ? $tracking_topics[$topic_id] : 0; + } + $sql = "SELECT p.post_id - FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u - WHERE s.session_id = '$user->session_id' - AND u.user_id = s.session_user_id - AND p.topic_id = $topic_id + FROM (" . POSTS_TABLE . " p + $sql_lastread) + WHERE p.topic_id = $topic_id " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND p.post_approved = 1') . " - AND p.post_time >= u.user_lastvisit + AND (p.post_time >= $sql_unread_time) ORDER BY p.post_time ASC"; $result = $db->sql_query_limit($sql, 1); if (!($row = $db->sql_fetchrow($result))) { - trigger_error('No_new_posts_last_visit'); + // Setup user environment so we can process lang string + $user->setup(); + + meta_refresh(3, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); + $message = $user->lang['NO_UNREAD_POSTS'] . ' ' . sprintf($user->lang['RETURN_TOPIC'], "", ''); + trigger_error($message); } redirect("viewtopic.$phpEx$SID&p=" . $row['post_id'] . "#" . $row['post_id']); @@ -154,7 +177,6 @@ if ($user->data['user_id'] != ANONYMOUS) // is done so navigation, forum name, etc. remain consistent with where // user clicked to view a global topic -// Note: I can't remember if it was suggested but we could create a virtual forum for globals with forum_id = 0 (altough MySQL would not like it much because of the auto_increment phpbb_forum.forum_id field =\) // Note2: after much inspection, having to find a valid forum_id when making return_to_topic links for global announcements in mcp is a pain. The easiest solution is to let admins choose under what forum topics should be seen when forum_id is not specified (preferably a public forum) if (!$forum_id) { @@ -177,7 +199,8 @@ if (!$topic_data = $db->sql_fetchrow($result)) extract($topic_data); -$user->setup(); +// Setup look and feel +$user->setup(false, $forum_style); // Start auth check @@ -350,28 +373,10 @@ $reply_img = ($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) ? $u $post_img = ($forum_status == ITEM_LOCKED) ? $user->img('post_locked', $user->lang['FORUM_LOCKED']) : $user->img('btn_post', $user->lang['POST_NEW_TOPIC']); -/* -// Set a cookie for this topic -if ($user->data['user_id'] != ANONYMOUS) -{ - $mark_topics = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_t'])) : array(); - - $mark_topics[$forum_id][$topic_id] = 0; - setcookie($config['cookie_name'] . '_t', serialize($mark_topics), 0, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); -} -*/ - - // Grab censored words $censors = array(); obtain_word_list($censors); -// Replace naughty words in title -if (sizeof($censors)) -{ - $topic_title = preg_replace($censors['match'], $censors['replace'], $topic_title); -} - // Navigation links generate_forum_nav($topic_data); @@ -385,6 +390,12 @@ get_moderators($forum_moderators, $forum_id); // This is only used for print view so ... $server_path = (!isset($_GET['view'])) ? '' : (($config['cookie_secure']) ? 'https://' : 'http://') . trim($config['server_name']) . (($config['server_port'] <> 80) ? ':' . trim($config['server_port']) . '/' : '/') . trim($config['script_path']) . '/'; +// Replace naughty words in title +if (sizeof($censors)) +{ + $topic_title = preg_replace($censors['match'], $censors['replace'], $topic_title); +} + // Send vars to template $template->assign_vars(array( 'FORUM_ID' => $forum_id, @@ -395,7 +406,7 @@ $template->assign_vars(array( 'PAGINATION' => (isset($_GET['view']) && $_GET['view'] == 'print') ? '' : $pagination, 'PAGE_NUMBER' => (isset($_GET['view']) && $_GET['view'] == 'print') ? '' : on_page($total_posts, $config['posts_per_page'], $start), 'TOTAL_POSTS' => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts), - 'MCP' => ($auth->acl_get('m_', $forum_id)) ? sprintf($user->lang['MCP'], "session_id . "&t=$topic_id&start=$start&st=$sort_days&sk=$sort_key&sd=$sort_dir&posts_per_page=" . $config['posts_per_page'] . '">', '') : '', + 'MCP' => ($auth->acl_get('m_', $forum_id)) ? sprintf($user->lang['MCP'], "session_id . "&f=$forum_id&t=$topic_id&start=$start&st=$sort_days&sk=$sort_key&sd=$sort_dir&posts_per_page=" . $config['posts_per_page'] . '">', '') : '', 'MODERATORS' => (sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '', 'POST_IMG' => $post_img, @@ -409,23 +420,23 @@ $template->assign_vars(array( 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, - 'S_TOPIC_ACTION' => "viewtopic.$phpEx$SID&t=" . $topic_id . "&start=$start", + 'S_TOPIC_ACTION' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&start=$start", 'S_TOPIC_MOD' => ($topic_mod != '') ? '' : '', 'S_MOD_ACTION' => "mcp.$phpEx?sid=" . $user->session_id . "&t=$topic_id&quickmod=1", 'S_WATCH_TOPIC' => $s_watching_topic, - 'S_SHOW_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, + 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, 'S_SEARCHBOX_ACTION' => "search.$phpEx$SID&f=$forum_id", - 'U_TOPIC' => $server_path . 'viewtopic.' . $phpEx . '?t=' . $topic_id, + 'U_TOPIC' => $server_path . "viewtopic.$phpEx?f=$forum_id&t=$topic_id", 'U_FORUM' => $server_path, - 'U_VIEW_TOPIC' => "viewtopic.$phpEx$SID&t=$topic_id&start=$start&st=$sort_days&sk=$sort_key&sd=$sort_dir&hilit=$highlight", + 'U_VIEW_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&start=$start&st=$sort_days&sk=$sort_key&sd=$sort_dir&hilit=$highlight", 'U_VIEW_FORUM' => $view_forum_url, 'U_VIEW_OLDER_TOPIC' => $view_prev_topic_url, - 'U_VIEW_NEWER_TOPIC' => $view_next_topic_url, - 'U_PRINT_TOPIC' => "viewtopic.$phpEx$SID&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir&view=print", - 'U_EMAIL_TOPIC' => "viewtopic.$phpEx$SID&t=$topic_id&view=email", + 'U_VIEW_NEWER_TOPIC' => $view_next_topic_url, + 'U_PRINT_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir&view=print", + 'U_EMAIL_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=email", 'U_POST_NEW_TOPIC' => $new_topic_url, 'U_POST_REPLY_TOPIC' => $reply_topic_url) @@ -447,58 +458,89 @@ if (!empty($poll_start)) } $db->sql_freeresult($result); - $sql = "SELECT poll_option_id - FROM " . POLL_VOTES_TABLE . " - WHERE topic_id = $topic_id - AND vote_user_id = " . $user->data['user_id']; - $result = $db->sql_query($sql); - - $voted_id = array(); - if ($row = $db->sql_fetchrow($result)) + if ($user->data['user_id'] != ANONYMOUS) { - do + $sql = "SELECT poll_option_id + FROM " . POLL_VOTES_TABLE . " + WHERE topic_id = $topic_id + AND vote_user_id = " . $user->data['user_id']; + $result = $db->sql_query($sql); + + $voted_id = array(); + if ($row = $db->sql_fetchrow($result)) { - $voted_id[] = $row['poll_option_id']; + do + { + $voted_id[] = $row['poll_option_id']; + } + while ($row = $db->sql_fetchrow($result)); } - while ($row = $db->sql_fetchrow($result)); + $db->sql_freeresult($result); } - $db->sql_freeresult($result); - - if (isset($_POST['castvote'])) + else { - if (sizeof($voted_id) == $poll_max_options && !$auth->acl_get('f_votechg', $forum_id)) + // Cookie based guest tracking ... I don't like this but hum ho + // it's oft requested. This relies on "nice" users who don't feel + // the need to delete cookies to mess with results. We could get + // a little more clever by time limiting based on ip's but ultimately + // it can be overcome without great difficulty. + if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id])) { - trigger_error($user->lang['ALREADY_VOTED']); + $voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]); } + } + $s_can_vote = (((!sizeof($voted_id) && $auth->acl_get('f_vote', $forum_id)) || $auth->acl_get('f_votechg', $forum_id)) && + ($poll_length != 0 && $poll_start + $poll_length > time()) && + $topic_status != ITEM_LOCKED && + $forum_status != ITEM_LOCKED) ? true : false; + $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($voted_id)) || $_GET['vote'] = 'viewresult') ? true : false; + + if (isset($_POST['castvote']) && $s_can_vote) + { $voted_id = array_map('intval', $_POST['vote_id']); if (!sizeof($voted_id) || sizeof($voted_id) > $poll_max_options) { - $message = (!sizeof($option_voted)) ? 'NO_VOTE_OPTION' : 'TOO_MANY_VOTE_OPTIONS'; - trigger_error($user->lang[$message]); + meta_refresh(5, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); + + $message = (!sizeof($voted_id)) ? 'NO_VOTE_OPTION' : 'TOO_MANY_VOTE_OPTIONS'; + $message = $user->lang[$message] . ' ' . sprintf($user->lang['RETURN_TOPIC'], "", ''); + trigger_error($message); } foreach ($voted_id as $option) { - $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . " (topic_id, poll_option_id, vote_user_id, vote_user_ip) - VALUES ($topic_id, $option, " . $user->data['user_id'] . ", '$user->ip')"; - $db->sql_query($sql); - - $sql = "UPDATE " . POLL_OPTIONS_TABLE . " + $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " SET poll_option_total = poll_option_total + 1 WHERE poll_option_id = $option AND topic_id = $topic_id"; $db->sql_query($sql); + + if ($user->data['user_id'] != ANONYMOUS) + { + $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . " (topic_id, poll_option_id, vote_user_id, vote_user_ip) + VALUES ($topic_id, $option, " . $user->data['user_id'] . ", '$user->ip')"; + $db->sql_query($sql); + } } - $sql = "UPDATE " . TOPICS_TABLE . " - SET poll_last_vote = " . time() . " + if ($user->data['user_id'] == ANONYMOUS) + { + setcookie($config['cookie_name'] . '_poll_' . $topic_id, implode(',', $voted_id), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); + } + + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET poll_last_vote = ' . time() . ', topic_last_post_time = ' . time() . " WHERE topic_id = $topic_id"; $db->sql_query($sql); - } - $display_results = (sizeof($voted_id) || ($poll_length != 0 && $poll_start + $poll_length < time()) || $_GET['vote'] == 'viewresult' || !$auth->acl_get('f_vote', $forum_id) || $topic_status == ITEM_LOCKED || $forum_status == ITEM_LOCKED) ? true : false; + + meta_refresh(5, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); + + $message = $user->lang['VOTE_SUBMITTED'] . ' ' . sprintf($user->lang['RETURN_TOPIC'], "", ''); + trigger_error($message); + } $poll_total = 0; foreach ($poll_info as $poll_option) @@ -516,7 +558,7 @@ if (!empty($poll_start)) 'POLL_OPTION_ID' => $poll_option['poll_option_id'], 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'], 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'], - 'POLL_OPTION_PERCENT' => $vote_percent, + 'POLL_OPTION_PERCENT' => $option_pct_txt, 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * $user->theme['poll_length']), true), 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $voted_id)) ? true : false) ); @@ -529,11 +571,13 @@ if (!empty($poll_start)) 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'), 'L_MAX_VOTES' => ($poll_max_options == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $poll_max_options), + 'L_POLL_LENGTH' => ($poll_length) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_length + $poll_start)) : '', - 'S_HAS_POLL_OPTIONS'=> !$display_results, - 'S_HAS_POLL_DISPLAY'=> $display_results, + 'S_HAS_POLL' => true, + 'S_CAN_VOTE' => $s_can_vote, + 'S_DISPLAY_RESULTS' => $s_display_results, 'S_IS_MULTI_CHOICE' => ($poll_max_options > 1) ? true : false, - 'S_POLL_ACTION' => "viewtopic.$phpEx$SID&t=$topic_id&sk=$sort_key&sd=$sort_dir", + 'S_POLL_ACTION' => "viewtopic.$phpEx$SID&t=$topic_id&sk=$sort_key&sd=$sort_dir", 'U_VIEW_RESULTS' => "viewtopic.$phpEx$SID&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir&vote=viewresult") ); @@ -612,6 +656,11 @@ do } } + + // Define the global bbcode bitfield, will be used to load bbcodes + $bbcode_bitfield |= $row['bbcode_bitfield']; + + // Cache various user specific data ... so we don't have to recompute // this each time the same user appears on this page if (!isset($user_cache[$poster_id])) @@ -648,15 +697,18 @@ do } else { - $user_sig = ($row['user_sig'] && $config['allow_sig']) ? $row['user_sig'] : ''; - if ($user_sig) + $user_sig = ''; + if ($row['enable_sig'] && $row['user_sig'] && $config['allow_sig']) { + $user_sig = $row['user_sig']; + $bbcode_bitfield |= $row['user_sig_bbcode_bitfield']; + // if (!$auth->acl_get('f_html', $forum_id)) // { // $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig); // } - $user_sig = (empty($row['user_allowsmile']) || empty($config['enable_smilies'])) ? preg_replace('# ", $user_cache[$poster_id]['user_sig']); + $user_cache[$poster_id]['sig'] = str_replace("\n", ' ', $user_cache[$poster_id]['sig']); $user_cache[$poster_id]['sig_parsed'] = TRUE; } @@ -1015,7 +1062,7 @@ foreach ($rowset as $key => $row) 'POST_DATE' => $user->format_date($row['post_time']), 'POST_SUBJECT' => $row['post_subject'], 'MESSAGE' => $message, - 'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '', + 'SIGNATURE' => $user_cache[$poster_id]['sig'], 'EDITED_MESSAGE'=> $l_edited_by, 'RATING' => $rating, @@ -1282,9 +1329,6 @@ unset($rowset); unset($user_cache); -// Mark topics read -markread('topic', $forum_id, $topic_id, $topic_data['topic_last_post_id']); - // Udate the attachment download counts if (count($update_count)) { @@ -1319,12 +1363,17 @@ $nav_links['up'] = array( ); +// Mark topics read +markread('topic', $forum_id, $topic_id, $topic_data['topic_last_post_id']); + + // Change encoding if appropriate if ($force_encoding != '') { $user->lang['ENCODING'] = $force_encoding; } + // Output the page $page_title = $user->lang['View_topic'] .' - ' . $topic_title; include($phpbb_root_path . 'includes/page_header.'.$phpEx); |