| [', $post['board']['link'], '] |
', $post['subject'], '
', $txt['by'], ' ', $post['poster']['link'], '
', $post['is_new'] ? ' ' : '', '
|
', $post['time'], ' |
| [', $post['board']['link'], '] |
', $post['subject'], '
', $txt['by'], ' ', $post['poster']['link'], '
', !$post['is_new'] ? '' : ' ', '
|
', $post['time'], ' |
| ', $txt['views'], ' | ', $txt['replies'], ' | |
|---|---|---|
| ', $topic['link'], ' | ', comma_format($topic['num_views']), ' | ', comma_format($topic['num_replies']), ' |
|
', $query_members[$member]['link'], '
', $query_members[$member]['blurb'], ' ', $query_members[$member]['avatar']['image'], ' |
 . '.gif)
',
'option' => parse_bbc($option[0]),
'vote_button' => ''
);
}
$return['allowed_warning'] = $row['max_votes'] > 1 ? sprintf($txt['poll_options6'], min(count($options), $row['max_votes'])) : '';
if ($output_method != 'echo')
return $return;
if ($allow_view_results)
{
echo '
';
}
else
echo $txt['poll_cannot_see'];
}
function ssi_showPoll($topic = null, $output_method = 'echo')
{
global $db_prefix, $txt, $settings, $boardurl, $user_info, $context, $smcFunc, $modSettings;
$boardsAllowed = boardsAllowedTo('poll_view');
if (empty($boardsAllowed))
return array();
if ($topic === null && isset($_REQUEST['ssi_topic']))
$topic = (int) $_REQUEST['ssi_topic'];
else
$topic = (int) $topic;
$request = $smcFunc['db_query']('', '
SELECT
p.id_poll, p.question, p.voting_locked, p.hide_results, p.expire_time, p.max_votes, p.guest_vote, b.id_board
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}polls AS p ON (p.id_poll = t.id_poll)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
WHERE t.id_topic = {int:current_topic}
AND {query_see_board}' . (!in_array(0, $boardsAllowed) ? '
AND b.id_board IN ({array_int:boards_allowed_see})' : '') . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}' : '') . '
LIMIT 1',
array(
'current_topic' => $topic,
'boards_allowed_see' => $boardsAllowed,
'is_approved' => 1,
)
);
// Either this topic has no poll, or the user cannot view it.
if ($smcFunc['db_num_rows']($request) == 0)
return array();
$row = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);
// Check if they can vote.
$already_voted = false;
if (!empty($row['expire_time']) && $row['expire_time'] < time())
$allow_vote = false;
elseif ($user_info['is_guest'])
{
// There's a difference between "allowed to vote" and "already voted"...
$allow_vote = $row['guest_vote'];
// Did you already vote?
if (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))
{
$already_voted = true;
}
}
elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board']))
$allow_vote = false;
else
{
$request = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}log_polls
WHERE id_poll = {int:current_poll}
AND id_member = {int:current_member}
LIMIT 1',
array(
'current_member' => $user_info['id'],
'current_poll' => $row['id_poll'],
)
);
$allow_vote = $smcFunc['db_num_rows']($request) == 0;
$already_voted = $allow_vote;
$smcFunc['db_free_result']($request);
}
// Can they view?
$is_expired = !empty($row['expire_time']) && $row['expire_time'] < time();
$allow_view_results = allowedTo('moderate_board') || $row['hide_results'] == 0 || ($row['hide_results'] == 1 && $already_voted) || $is_expired;
$request = $smcFunc['db_query']('', '
SELECT COUNT(DISTINCT id_member)
FROM {db_prefix}log_polls
WHERE id_poll = {int:current_poll}',
array(
'current_poll' => $row['id_poll'],
)
);
list ($total) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$request = $smcFunc['db_query']('', '
SELECT id_choice, label, votes
FROM {db_prefix}poll_choices
WHERE id_poll = {int:current_poll}',
array(
'current_poll' => $row['id_poll'],
)
);
$options = array();
$total_votes = 0;
while ($rowChoice = $smcFunc['db_fetch_assoc']($request))
{
censorText($rowChoice['label']);
$options[$rowChoice['id_choice']] = array($rowChoice['label'], $rowChoice['votes']);
$total_votes += $rowChoice['votes'];
}
$smcFunc['db_free_result']($request);
$return = array(
'id' => $row['id_poll'],
'image' => empty($pollinfo['voting_locked']) ? 'poll' : 'locked_poll',
'question' => $row['question'],
'total_votes' => $total,
'is_locked' => !empty($pollinfo['voting_locked']),
'allow_vote' => $allow_vote,
'allow_view_results' => $allow_view_results,
'topic' => $topic
);
// Calculate the percentages and bar lengths...
$divisor = $total_votes == 0 ? 1 : $total_votes;
foreach ($options as $i => $option)
{
$bar = floor(($option[1] * 100) / $divisor);
$barWide = $bar == 0 ? 1 : floor(($bar * 5) / 3);
$return['options'][$i] = array(
'id' => 'options-' . $i,
'percent' => $bar,
'votes' => $option[1],
'bar' => ' . '.gif)
',
'option' => parse_bbc($option[0]),
'vote_button' => ''
);
}
$return['allowed_warning'] = $row['max_votes'] > 1 ? sprintf($txt['poll_options6'], min(count($options), $row['max_votes'])) : '';
if ($output_method != 'echo')
return $return;
if ($return['allow_vote'])
{
echo '
';
}
else
{
echo '
| ', $txt['file'], ' | ', $txt['posted_by'], ' | ', $txt['downloads'], ' | ', $txt['filesize'], ' |
|---|---|---|---|
| ', $attach['file']['link'], ' | ', $attach['member']['link'], ' | ', $attach['file']['downloads'], ' | ', $attach['file']['filesize'], ' |