Yet more updates, topic marking works again ... still intend (optional) checking of "forum read" status on return to index (rather than just the current fudge of visiting the forum), obtain_ranks as a function (used in at least three scripts), removed jabber method that was needed, oops

git-svn-id: file:///svn/phpbb/trunk@4147 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-06-19 16:19:59 +00:00
parent eb6c2c54df
commit c0a013053a
5 changed files with 183 additions and 62 deletions

View file

@ -208,7 +208,7 @@ class emailer
} }
// Build header // Build header
$this->extra_headers = (($this->replyto !='') ? "Reply-to: <$this->replyto>\r\n" : '') . (($this->from != '') ? "From: <$this->from>\r\n" : "From: <" . $config['board_email'] . ">\r\n") . "Return-Path: <" . $config['board_email'] . ">\r\nMessage-ID: <" . md5(uniqid(time())) . "@" . $config['server_name'] . ">\r\nMIME-Version: 1.0\r\nContent-type: text/plain; charset=" . $this->encoding . "\r\nContent-transfer-encoding: 8bit\r\nDate: " . gmdate('D, d M Y H:i:s Z', time()) . "\r\nX-Priority: 3\r\nX-MSMail-Priority: Normal\r\nX-Mailer: PHP\r\n" . (($cc != '') ? "Cc:$cc\r\n" : '') . (($bcc != '') ? "Bcc:$bcc\r\n" : '') . trim($this->extra_headers); $this->extra_headers = (($this->replyto !='') ? "Reply-to: <$this->replyto>\r\n" : '') . (($this->from != '') ? "From: <$this->from>\r\n" : "From: <" . $config['board_email'] . ">\r\n") . "Return-Path: <" . $config['board_email'] . ">\r\nMessage-ID: <" . md5(uniqid(time())) . "@" . $config['server_name'] . ">\r\nMIME-Version: 1.0\r\nContent-type: text/plain; charset=" . $this->encoding . "\r\nContent-transfer-encoding: 8bit\r\nDate: " . gmdate('D, d M Y H:i:s Z', time()) . "\r\nX-Priority: 3\r\nX-MSMail-Priority: Normal\r\nX-Mailer: PHP\r\nX-MimeOLE: Produced By phpBB2\r\n" . trim($this->extra_headers) . (($cc != '') ? "Cc:$cc\r\n" : '') . (($bcc != '') ? "Bcc:$bcc\r\n" : '');
// Send message ... removed $this->encode() from subject for time being // Send message ... removed $this->encode() from subject for time being
if (!$this->use_queue) if (!$this->use_queue)
@ -219,9 +219,9 @@ class emailer
{ {
$this->queue->put('emailer', array( $this->queue->put('emailer', array(
'smtp_delivery' => $config['smtp_delivery'], 'smtp_delivery' => $config['smtp_delivery'],
'to' => $to, 'to' => $to,
'subject' => $this->subject, 'subject' => $this->subject,
'msg' => $this->msg, 'msg' => $this->msg,
'extra_headers' => $this->extra_headers) 'extra_headers' => $this->extra_headers)
); );
@ -240,7 +240,7 @@ class emailer
// Encodes the given string for proper display for this encoding ... nabbed // Encodes the given string for proper display for this encoding ... nabbed
// from php.net and modified. There is an alternative encoding method which // from php.net and modified. There is an alternative encoding method which
// may produce lesd output but it's questionable as to its worth in this // may produce less output but it's questionable as to its worth in this
// scenario IMO // scenario IMO
function encode($str) function encode($str)
{ {

View file

@ -505,13 +505,12 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
} }
else else
{ {
$tracking = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_f'])) : array(); $tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
if (empty($tracking[$forum_id]) || $tracking[$forum_id] < $current_time)
{
$tracking[$forum_id] = $current_time;
}
setcookie($config['cookie_name'] . '_f', serialize($tracking), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); unset($tracking[$forum_id]);
$tracking[$forum_id][0] = base_convert($current_time - $config['board_startdate'], 10, 36);
setcookie($config['cookie_name'] . '_track', serialize($tracking), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']);
unset($tracking); unset($tracking);
} }
break; break;
@ -578,9 +577,9 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
$db->sql_query($sql); $db->sql_query($sql);
} }
} }
else if (empty($tracking[$row['forum_id']]) || $tracking[$row['forum_id']] < $current_time) else
{ {
$tracking[$row['forum_id']] = $current_time; $tracking[$row['forum_id']][0] = base_convert($current_time - $config['board_startdate'], 10, 36);
} }
} }
while ($row = $db->sql_fetchrow($result)); while ($row = $db->sql_fetchrow($result));
@ -590,7 +589,7 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
if (!$config['load_db_lastread']) if (!$config['load_db_lastread'])
{ {
setcookie($config['cookie_name'] . '_f', serialize($tracking), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); setcookie($config['cookie_name'] . '_track', serialize($tracking), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']);
unset($tracking); unset($tracking);
} }
} }
@ -619,13 +618,34 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
if (!$config['load_db_lastread']) if (!$config['load_db_lastread'])
{ {
$tracking = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_t'])) : array(); $tracking = array();
if (empty($tracking[$topic_id]) || $tracking[$topic_id] < $current_time) if (isset($_COOKIE[$config['cookie_name'] . '_track']))
{ {
$tracking[$topic_id] = $current_time; $tracking = unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track']));
// If the cookie grows larger than 3000 characters we will remove
// the smallest value
if (strlen($_COOKIE[$config['cookie_name'] . '_track']) > 3000)
{
foreach ($tracking as $f => $t_ary)
{
if (!isset($m_value) || min($t_ary) < $m_value)
{
$m_value = min($t_ary);
$m_tkey = array_search($m_value, $t_ary);
$m_fkey = $f;
}
}
unset($tracking[$m_fkey][$m_tkey]);
}
} }
setcookie($config['cookie_name'] . '_t', serialize($tracking), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); if (base_convert($tracking[$forum_id][0], 36, 10) < $current_time)
{
$tracking[$forum_id][base_convert($topic_id, 10, 36)] = base_convert($current_time - $config['board_startdate'], 10, 36);
setcookie($config['cookie_name'] . '_track', serialize($tracking), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']);
}
unset($tracking); unset($tracking);
} }
break; break;
@ -768,6 +788,47 @@ function obtain_icons(&$icons)
return; return;
} }
// Obtain ranks
function obtain_ranks(&$ranks)
{
global $db, $cache;
if ($cache->exists('ranks'))
{
$ranks = $cache->get('ranks');
}
else
{
$sql = 'SELECT *
FROM ' . RANKS_TABLE . '
ORDER BY rank_min DESC';
$result = $db->sql_query($sql);
$ranks = array();
while ($row = $db->sql_fetchrow($result))
{
if ($row['rank_special'])
{
$ranks['special'][$row['rank_id']] = array(
'rank_title' => $row['rank_title'],
'rank_image' => $row['rank_image']
);
}
else
{
$ranks['normal'][] = array(
'rank_title' => $row['rank_title'],
'rank_min' => $row['rank_min'],
'rank_image' => $row['rank_image']
);
}
}
$db->sql_freeresult($result);
$cache->put('ranks', $ranks);
}
}
// Obtain allowed extensions // Obtain allowed extensions
function obtain_attach_extensions(&$extensions) function obtain_attach_extensions(&$extensions)
{ {

View file

@ -44,26 +44,23 @@ function display_forums($root_data = '', $display_moderators = TRUE)
break; break;
default: default:
$sql_lastread = 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' $sql_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)';
AND ft.forum_id = f.forum_id)';
break; break;
} }
$lastread_select = ', ft.mark_time '; $lastread_select = ', ft.mark_time ';
} }
else else
{ {
$lastread_select = ''; $sql_from = FORUMS_TABLE . ' f ';
$sql_lastread = ''; $lastread_select = $sql_lastread = '';
$tracking_forums = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_f'])) : array(); $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_t'])) : array();
} }
$sql = "SELECT f.* $lastread_select $sql = "SELECT f.* $lastread_select
FROM (" . FORUMS_TABLE . " f FROM $sql_from
$sql_lastread) $sql_where
$sql_where ORDER BY f.left_id";
ORDER BY left_id";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$branch_root_id = $root_data['forum_id']; $branch_root_id = $root_data['forum_id'];
@ -133,20 +130,9 @@ function display_forums($root_data = '', $display_moderators = TRUE)
} }
} }
/* $mark_time_forum = ($config['load_db_lastread']) ? $row['mark_time'] : ((isset($tracking_topics[$forum_id][0])) ? base_convert($tracking_topics[$forum_id][0], 36, 10) + $config['board_startdate'] : 0);
if (!empty($forum_unread[$forum_id]))
{
$forum_unread[$parent_id] = true;
}
*/
if (!isset($forum_unread[$parent_id])) if ($mark_time_forum < $row['forum_last_post_time'] && $user->data['user_id'] != ANONYMOUS)
{
$forum_unread[$parent_id] = false;
}
$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; $forum_unread[$parent_id] = true;
} }
@ -154,27 +140,56 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$db->sql_freeresult(); $db->sql_freeresult();
/* /*
if ($config['load_db_lastread']) if (isset($tracking_topics) && $user->data['user_id'] != ANONYMOUS)
{ {
} $min_forum_time = base_convert(min($tracking_topics[$forum_id]), 36, 10) + $config['board_startdate'];
else $max_forum_time = base_convert(max($tracking_topics[$forum_id]), 36, 10) + $config['board_startdate'];
{
$forum_unread = array();
$sql = "SELECT forum_id, topic_id, topic_last_post_time // $mark_time_forum && $mark_time_topic
$sql = "SELECT topic_id, topic_last_post_time
FROM " . TOPICS_TABLE . " FROM " . TOPICS_TABLE . "
WHERE topic_last_post_time > " . ((sizeof($tracking_forums)) ? min($tracking_forums) : time() - 86400) . " WHERE forum_id = $forum_id
$sql_forum_track; AND topic_last_post_time > $min_forum_time";//AND topic_last_post_time < $max_forum_time
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) $mark_time = 0;
if ($row2 = $db->sql_fetchrow($result))
{ {
if (($tracking_forums[$row['forum_id']] > $tracking_topics[$row['topic_id']] && do
$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']; $mtopic_id = base_convert($row2['topic_id'], 10, 36);
$tracking_topics[$forum_id][$mtopic_id] = base_convert($tracking_topics[$forum_id][$mtopic_id], 36, 10);
$tracking_topics[$forum_id][0] = base_convert($tracking_topics[$forum_id][0], 36, 10);
echo $row2['topic_id'] . " :: " . $tracking_topics[$forum_id][$mtopic_id] . " :: " . $tracking_topics[$forum_id][0] . " :: " . $row2['topic_last_post_time'] . " :: " . $row['post_time'] . "<br />";
if ((($row2['topic_id'] != $topic_id &&
($tracking_topics[$forum_id][$mtopic_id] >= $row2['topic_last_post_time'] ||
$tracking_topics[$forum_id][0] >= $row2['topic_last_post_time'])) ||
($row2['topic_id'] == $topic_id && $row['post_time'] <= $row2['topic_last_post_time'])) &&
!isset($mark_read))
{
$mark_read = true;
}
else
{
$mark_read = false;
}
$mark_time = max($mark_time, $row2['topic_last_post_time']);
} }
while ($row2 = $db->sql_fetchrow($result));
}
$db->sql_freeresult($result);
if ($mark_read)
{
markread('mark', $forum_id, false, $mark_time);
echo "HERE :: $mark_time :: " . time();
}
else
{
echo "HERE2";
} }
} }
*/ */
@ -245,14 +260,14 @@ function display_forums($root_data = '', $display_moderators = TRUE)
} }
} }
$folder_image = ($forum_unread[$forum_id]) ? 'sub_forum_new' : 'sub_forum'; $folder_image = (!empty($forum_unread[$forum_id])) ? 'sub_forum_new' : 'sub_forum';
} }
else else
{ {
switch ($row['forum_type']) switch ($row['forum_type'])
{ {
case FORUM_POST: case FORUM_POST:
$folder_image = ($forum_unread[$forum_id]) ? 'forum_new' : 'forum'; $folder_image = (!empty($forum_unread[$forum_id])) ? 'forum_new' : 'forum';
break; break;
case FORUM_LINK: case FORUM_LINK:
@ -273,7 +288,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
} }
else else
{ {
$folder_alt = ($forum_unread[$forum_id]) ? 'NEW_POSTS' : 'NO_NEW_POSTS'; $folder_alt = (!empty($forum_unread[$forum_id])) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
} }

View file

@ -172,6 +172,51 @@ class Jabber
} }
} }
function AccountRegistration($reg_email = NULL, $reg_name = NULL)
{
$packet = $this->SendIq($this->server, 'get', 'reg_01', 'jabber:iq:register');
if ($packet)
{
$key = $this->GetInfoFromIqKey($packet); // just in case a key was passed back from the server
unset($packet);
$payload = "<username>{$this->username}</username>
<password>{$this->password}</password>
<email>$reg_email</email>
<name>$reg_name</name>\n";
$payload .= ($key) ? "<key>$key</key>\n" : '';
$packet = $this->SendIq($this->server, 'set', 'reg_01', 'jabber:iq:register', $payload);
if ($this->GetInfoFromIqType($packet) == 'result')
{
$return_code = (isset($packet['iq']['#']['query'][0]['#']['registered'][0]['#'])) ? 1 : 2;
$this->jid = ($this->resource) ? "{$this->username}@{$this->server}/{$this->resource}" : "{$this->username}@{$this->server}";
}
elseif ($this->GetInfoFromIqType($packet) == 'error' && isset($packet['iq']['#']['error'][0]['#']))
{
// "conflict" error, i.e. already registered
if ($packet['iq']['#']['error'][0]['@']['code'] == '409')
{
$return_code = 1;
}
else
{
$return_code = 'Error ' . $packet['iq']['#']['error'][0]['@']['code'] . ': ' . $packet['iq']['#']['error'][0]['#'];
}
}
return $return_code;
}
else
{
return 3;
}
}
function SendPacket($xml) function SendPacket($xml)
{ {
$xml = trim($xml); $xml = trim($xml);

View file

@ -365,7 +365,7 @@ class ucp extends user
function avatar_remote(&$data) function avatar_remote(&$data)
{ {
global $config, $db, $user; global $config, $db, $user, $phpbb_root_path;
if (!preg_match('#^(http[s]*?)|(ftp)://#i', $data['remotelink'])) if (!preg_match('#^(http[s]*?)|(ftp)://#i', $data['remotelink']))
{ {
@ -474,7 +474,7 @@ class ucp extends user
} }
unset($url_ary); unset($url_ary);
$tmp_path = (!@ini_get('safe_mode')) ? false : './' . $config['avatar_path'] . '/tmp'; $tmp_path = (!@ini_get('safe_mode')) ? false : $phpbb_root_path . 'cache/tmp';
$filename = tempnam($tmp_path, uniqid(rand()) . '-'); $filename = tempnam($tmp_path, uniqid(rand()) . '-');
if (!($fp = @fopen($filename, 'wb'))) if (!($fp = @fopen($filename, 'wb')))
@ -498,9 +498,9 @@ class ucp extends user
list($width, $height) = getimagesize($filename); list($width, $height) = getimagesize($filename);
if ($width > $config['avatar_max_width'] || $height > $config['avatar_max_height'] || !$width || !$height) if ($width > $config['avatar_max_width'] || $height > $config['avatar_max_height'] || $width < $config['avatar_min_width'] || $height < $config['avatar_min_height'] || !$width || !$height)
{ {
$this->error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_max_width'], $config['avatar_max_height']); $this->error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height']);
return true; return true;
} }