Changing of votes ... possible new icons for "new votes since last view" in viewforum

git-svn-id: file:///svn/phpbb/trunk@4455 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-08-29 00:30:17 +00:00
parent 9798d795ce
commit ed6948732a
2 changed files with 76 additions and 59 deletions

View file

@ -16,12 +16,10 @@ $phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1); $phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx); include($phpbb_root_path . 'common.'.$phpEx);
// Start session // Start session
$user->start(); $user->start();
$auth->acl($user->data); $auth->acl($user->data);
// Start initial var setup // Start initial var setup
$forum_id = (isset($_REQUEST['f'])) ? max(intval($_REQUEST['f']), 0) : 0; $forum_id = (isset($_REQUEST['f'])) ? max(intval($_REQUEST['f']), 0) : 0;
$mark_read = (!empty($_GET['mark'])) ? htmlspecialchars($_GET['mark']) : ''; $mark_read = (!empty($_GET['mark'])) ? htmlspecialchars($_GET['mark']) : '';
@ -203,7 +201,7 @@ if ($forum_data['forum_type'] == FORUM_POST)
$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'); $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 = ''; $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); gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir);
// Limit topics to certain time frame, obtain correct topic count // Limit topics to certain time frame, obtain correct topic count
if ($sort_days) if ($sort_days)
@ -419,17 +417,24 @@ if ($forum_data['forum_type'] == FORUM_POST)
if ($user->data['user_id'] != ANONYMOUS) if ($user->data['user_id'] != ANONYMOUS)
{ {
$unread_topic = true; $unread_topic = $new_votes = true;
if ($mark_time_topic >= $row['topic_last_post_time'] || $mark_time_forum >= $row['topic_last_post_time']) if ($mark_time_topic >= $row['topic_last_post_time'] || $mark_time_forum >= $row['topic_last_post_time'] || ($row['topic_last_post_time'] == $row['poll_last_vote'] && $replies))
{ {
$unread_topic = false; $unread_topic = false;
} }
/*
if ($row['poll_start'] && ($mark_time_topic >= $row['poll_last_vote'] || $mark_time_forum >= $row['poll_last_vote']))
{
$new_votes = false;
}*/
} }
else else
{ {
$unread_topic = false; $unread_topic = $new_votes = false;
} }
// $folder_new .= ($new_votes) ? '_vote' : '';
$newest_post_img = ($unread_topic) ? "<a href=\"viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id&amp;view=unread#unread\">" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : ''; $newest_post_img = ($unread_topic) ? "<a href=\"viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id&amp;view=unread#unread\">" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : '';
$folder_img = ($unread_topic) ? $folder_new : $folder; $folder_img = ($unread_topic) ? $folder_new : $folder;
$folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
@ -441,7 +446,7 @@ if ($forum_data['forum_type'] == FORUM_POST)
} }
} }
if (!empty($row['poll_start'])) if (!$row['poll_start'])
{ {
$topic_type .= $user->lang['VIEW_TOPIC_POLL']; $topic_type .= $user->lang['VIEW_TOPIC_POLL'];
} }

View file

@ -1,47 +1,41 @@
<?php <?php
/*************************************************************************** // -------------------------------------------------------------
* viewtopic.php //
* ------------------- // $Id$
* begin : Saturday, Feb 13, 2001 //
* copyright : (C) 2001 The phpBB Group // FILENAME : viewtopic.php
* email : support@phpbb.com // STARTED : Sat Feb 13, 2001
* // COPYRIGHT : © 2001, 2003 phpBB Group
* $Id$ // WWW : http://www.phpbb.com/
* // LICENCE : GPL vs2.0 [ see /docs/COPYING ]
***************************************************************************/ //
// -------------------------------------------------------------
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
define('IN_PHPBB', true); define('IN_PHPBB', true);
$phpbb_root_path = './'; $phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1); $phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx); include($phpbb_root_path . 'common.'.$phpEx);
// Start session management // Start session management
$user->start(); $user->start();
$auth->acl($user->data); $auth->acl($user->data);
// Initial var setup // Initial var setup
$forum_id = (isset($_GET['f'])) ? max(intval($_GET['f']), 0) : 0; $forum_id = (isset($_GET['f'])) ? max(intval($_GET['f']), 0) : 0;
$topic_id = (isset($_GET['t'])) ? max(intval($_GET['t']), 0) : 0; $topic_id = (isset($_GET['t'])) ? max(intval($_GET['t']), 0) : 0;
$post_id = (isset($_GET['p'])) ? max(intval($_GET['p']), 0) : 0; $post_id = (isset($_GET['p'])) ? max(intval($_GET['p']), 0) : 0;
$start = (isset($_GET['start'])) ? max(intval($_GET['start']), 0) : 0; $voted_id = (isset($_POST['vote_id'])) ? array_map('intval', $_POST['vote_id']) : 0;
$view = (isset($_GET['view'])) ? htmlspecialchars($_GET['view']) : '';
$start = (isset($_GET['start'])) ? max(intval(&$_GET['start']), 0) : 0;
$view = (isset($_GET['view'])) ? htmlspecialchars($_GET['view']) : false;
$rate = (isset($_GET['rate'])) ? intval($_GET['rate']) : false;
$sort_days = (!empty($_REQUEST['st'])) ? max(intval($_REQUEST['st']), 0) : 0; $sort_days = (!empty($_REQUEST['st'])) ? max(intval($_REQUEST['st']), 0) : 0;
$sort_key = (!empty($_REQUEST['sk'])) ? htmlspecialchars($_REQUEST['sk']) : 't'; $sort_key = (!empty($_REQUEST['sk'])) ? htmlspecialchars($_REQUEST['sk']) : 't';
$sort_dir = (!empty($_REQUEST['sd'])) ? htmlspecialchars($_REQUEST['sd']) : 'a'; $sort_dir = (!empty($_REQUEST['sd'])) ? htmlspecialchars($_REQUEST['sd']) : 'a';
$update = (isset($_POST['update'])) ? true : false;
$hilit_words = (isset($_GET['hilit'])) ? urldecode(&$_GET['hilit']) : false;
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
// Do we have a topic or post id? // Do we have a topic or post id?
if (!$topic_id && !$post_id) if (!$topic_id && !$post_id)
@ -49,8 +43,6 @@ if (!$topic_id && !$post_id)
trigger_error('NO_TOPIC'); trigger_error('NO_TOPIC');
} }
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
// Find topic id if user requested a newer or older topic // Find topic id if user requested a newer or older topic
$unread_post_id = ''; $unread_post_id = '';
if ($view && !$post_id) if ($view && !$post_id)
@ -221,7 +213,7 @@ if ($forum_password)
// Not final in the slightest! Far too simplistic // Not final in the slightest! Far too simplistic
if (isset($_GET['rate'])) if ($rate)
{ {
// Check for rating count for previous X time // Check for rating count for previous X time
@ -401,21 +393,17 @@ obtain_icons($icons);
// Was a highlight request part of the URI? // Was a highlight request part of the URI?
$highlight_match = $highlight = ''; $highlight_match = $highlight = '';
if (isset($_GET['hilit'])) if ($hilit_words)
{ {
// Split words and phrases foreach (explode(' ', trim($hilit_words)) as $word)
$words = explode(' ', trim(htmlspecialchars(urldecode($_GET['hilit']))));
foreach ($words as $word)
{ {
if (trim($word) != '') if (trim($word))
{ {
$highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*?', preg_quote($word, '#')); $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*?', preg_quote($word, '#'));
} }
} }
unset($words);
$highlight = urlencode($_GET['hilit']); $highlight = htmlspecialchars(urlencode($hilit_words));
} }
@ -469,7 +457,7 @@ if (sizeof($censors))
$template->assign_vars(array( $template->assign_vars(array(
'FORUM_ID' => $forum_id, 'FORUM_ID' => $forum_id,
'FORUM_NAME' => $forum_name, 'FORUM_NAME' => $forum_name,
'FORUM_DESC' => strip_tags($forum_desc), 'FORUM_DESC' => $forum_desc,
'TOPIC_ID' => $topic_id, 'TOPIC_ID' => $topic_id,
'TOPIC_TITLE' => $topic_title, 'TOPIC_TITLE' => $topic_title,
'PAGINATION' => $pagination, 'PAGINATION' => $pagination,
@ -540,6 +528,7 @@ if (!empty($poll_start))
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
$cur_voted_id = array();
if ($user->data['user_id'] != ANONYMOUS) if ($user->data['user_id'] != ANONYMOUS)
{ {
$sql = 'SELECT poll_option_id $sql = 'SELECT poll_option_id
@ -548,10 +537,9 @@ if (!empty($poll_start))
AND vote_user_id = ' . $user->data['user_id']; AND vote_user_id = ' . $user->data['user_id'];
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$voted_id = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$voted_id[] = $row['poll_option_id']; $cur_voted_id[] = $row['poll_option_id'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }
@ -564,20 +552,19 @@ if (!empty($poll_start))
// it can be overcome without great difficulty. // it can be overcome without great difficulty.
if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id])) if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
{ {
$voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]); $cur_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)) && $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) ||
(($poll_length != 0 && $poll_start + $poll_length > time()) || ($poll_length == 0)) && $auth->acl_get('f_votechg', $forum_id)) &&
(($poll_length != 0 && $poll_start + $poll_length > time()) || $poll_length == 0) &&
$topic_status != ITEM_LOCKED && $topic_status != ITEM_LOCKED &&
$forum_status != ITEM_LOCKED) ? true : false; $forum_status != ITEM_LOCKED) ? true : false;
$s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($voted_id)) || $_GET['vote'] = 'viewresult') ? true : false; $s_display_results = (!$s_can_vote || ($s_can_vote && $voted_id) || $view = 'viewpoll') ? true : false;
if (isset($_POST['castvote']) && $s_can_vote) if ($update && $s_can_vote)
{ {
$voted_id = array_map('intval', $_POST['vote_id']);
if (!sizeof($voted_id) || sizeof($voted_id) > $poll_max_options) if (!sizeof($voted_id) || sizeof($voted_id) > $poll_max_options)
{ {
meta_refresh(5, "viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id"); meta_refresh(5, "viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id");
@ -589,6 +576,11 @@ if (!empty($poll_start))
foreach ($voted_id as $option) foreach ($voted_id as $option)
{ {
if (in_array($option, $cur_voted_id))
{
continue;
}
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . "
SET poll_option_total = poll_option_total + 1 SET poll_option_total = poll_option_total + 1
WHERE poll_option_id = $option WHERE poll_option_id = $option
@ -603,6 +595,27 @@ if (!empty($poll_start))
} }
} }
foreach ($cur_voted_id as $option)
{
if (!in_array($option, $voted_id))
{
$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 = 'DELETE FROM ' . POLL_VOTES_TABLE . "
WHERE topic_id = $topic_id
AND poll_option_id = $option
AND vote_user_id = " . $user->data['user_id'];
$db->sql_query($sql);
}
}
}
if ($user->data['user_id'] == ANONYMOUS) 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']); setcookie($config['cookie_name'] . '_poll_' . $topic_id, implode(',', $voted_id), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']);
@ -613,7 +626,6 @@ if (!empty($poll_start))
WHERE topic_id = $topic_id"; WHERE topic_id = $topic_id";
$db->sql_query($sql); $db->sql_query($sql);
meta_refresh(5, "viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id"); meta_refresh(5, "viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id");
$message = $user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id\">", '</a>'); $message = $user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id\">", '</a>');
@ -638,7 +650,7 @@ if (!empty($poll_start))
'POLL_OPTION_RESULT' => $poll_option['poll_option_total'], 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'],
'POLL_OPTION_PERCENT' => $option_pct_txt, 'POLL_OPTION_PERCENT' => $option_pct_txt,
'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250), true), 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250), true),
'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $voted_id)) ? true : false) 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false)
); );
} }
@ -657,7 +669,7 @@ if (!empty($poll_start))
'S_IS_MULTI_CHOICE' => ($poll_max_options > 1) ? true : false, 'S_IS_MULTI_CHOICE' => ($poll_max_options > 1) ? true : false,
'S_POLL_ACTION' => "viewtopic.$phpEx$SID&amp;t=$topic_id&amp;$u_sort_param", 'S_POLL_ACTION' => "viewtopic.$phpEx$SID&amp;t=$topic_id&amp;$u_sort_param",
'U_VIEW_RESULTS' => "viewtopic.$phpEx$SID&amp;t=$topic_id&amp;$u_sort_param&amp;vote=viewresult") 'U_VIEW_RESULTS' => "viewtopic.$phpEx$SID&amp;t=$topic_id&amp;$u_sort_param&amp;view=viewpoll")
); );
unset($poll_info); unset($poll_info);