aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorPaul S. Owen <psotfx@users.sourceforge.net>2003-04-26 01:17:40 +0000
committerPaul S. Owen <psotfx@users.sourceforge.net>2003-04-26 01:17:40 +0000
commit5362625eabd86278d9f7cbc7175e02e3b5f613ca (patch)
tree34adeecdc30441ba7c4b497b986415d7608b933a /phpBB/includes/functions.php
parent4e43cb51536fdfff64d8560b054ad601949deb6d (diff)
downloadforums-5362625eabd86278d9f7cbc7175e02e3b5f613ca.tar
forums-5362625eabd86278d9f7cbc7175e02e3b5f613ca.tar.gz
forums-5362625eabd86278d9f7cbc7175e02e3b5f613ca.tar.bz2
forums-5362625eabd86278d9f7cbc7175e02e3b5f613ca.tar.xz
forums-5362625eabd86278d9f7cbc7175e02e3b5f613ca.zip
Various changes, and tests ... marking/tracking is not complete ... tinkering, changing, etc. still to be done ... it's just I've made numerous and various changes to different files so a commit really is due
git-svn-id: file:///svn/phpbb/trunk@3953 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php200
1 files changed, 123 insertions, 77 deletions
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.
+ // Mark all forums as read
+
+ if ($config['load_db_lastread'])
+ {
+ $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();
+ }
+
// 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";
+ 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))
{
- // 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
+ 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() . ")";
+ 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);
- $forum_insert = implode(",\n", $forum_insert);
- $sql .= $forum_insert;
+ $db->sql_return_on_error = false;
- $db->sql_query($sql);
+ 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);
+ }
}
-
- // 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);
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)
- {
- $type_name = 'mark_type, ';
- $type_value = '1, ';
- }
- else
+ $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 = '';
- $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' => '<meta http-equiv="refresh" content="' . $time . ';url=' . $url . '">')
+ );
+}
+
// Generate login box or verify password
function login_box($s_action, $s_hidden_fields = '', $login_explain = '')