Running SMF 2.0 and TP 1.0 RC2 on a test server to test blocks we use in a 2.0 environment (as we plan to update soon).
Sorry I can't list the other info requested as it doesn't really apply. It's a test site, so mods and other things change frequently, and I would rather not give a link on a public forum to my test site.
We have a specialized poll block that I have had trouble updating with the new 2.0 database calls. We use this block for member voting and its a requirement I have it working for 2.0 if we are going to upgrade.
function myPoll($num_recent = null, $include_boards = null, $output_method = 'echo')
{
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;
$include_boards = empty($include_boards) ? array() : $include_boards;
//Find any polls the user has voted on so we can kill em.
$p_request = db_query("
SELECT
ID_POLL
FROM
{$db_prefix}log_polls
WHERE ID_MEMBER = $ID_MEMBER
ORDER BY ID_POLL DESC", __FILE__, __LINE__);
$pollids = array();
while ($prow = mysql_fetch_assoc($p_request))
{
$pollids[] = array(
'id' => $prow['ID_POLL']);
}
//print_r($pollids);
//echo "<BR>";
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = db_query("
SELECT DISTINCT m.posterTime, ms.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, b.ID_BOARD, b.name AS bName, p.expireTime, t.ID_POLL,
IFNULL(mem.realName, m.posterName) AS posterName, " . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= m.ID_MSG_MODIFIED AS isRead,
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . ", LEFT(m.body, 384) AS body, m.smileysEnabled, m.icon
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = t.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = b.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
LEFT JOIN {$db_prefix}polls AS p ON (p.ID_POLL = t.ID_POLL)
LEFT JOIN {$db_prefix}log_polls AS lp ON (lp.ID_POLL = t.ID_POLL)
WHERE t.ID_LAST_MSG = m.ID_MSG
AND b.ID_BOARD = t.ID_BOARD" . (empty($include_boards) ? '' : "
AND b.ID_BOARD IN (" . implode(', ', $include_boards) . ")") . "
AND $user_info[query_see_board]
AND ms.ID_MSG = t.ID_FIRST_MSG
AND t.ID_POLL > 0
AND p.votingLocked = 0
ORDER BY t.ID_POLL DESC
LIMIT $num_recent", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
{
If ($row['expireTime'] == 0 || time() < $row['expireTime'])
{
// Build the array.
$posts[] = array(
'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>',
'link2' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '">' . $row['subject'] . '</a>',
'poll_id' => $row['ID_POLL'],
);
//print_r($posts);
//echo "<BR>";
foreach ($pollids AS $i) {
foreach($posts AS $k) {
If ($k['poll_id'] == $i['id']) {
//echo "Got it!!!<br>";
array_pop($posts);
}
}
}
}
}
mysql_free_result($request);
// Just return it.
if ($output_method != 'echo' || empty($posts))
return $posts;
echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">
[', $post['link'], ']
</td>
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt[525], ' ', $post['link'], '
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>', '
</td>
</tr>';
echo '
</table>';
}
//The block**************************************************************
global $scripturl;
echo '
<table border="0" width="100%" cellspacing="1" cellpadding="1" class="windowbg3">';
$what=myPoll('10', array(30, 79), 'array');
If (!empty($what))
{
foreach ($what as $topic)
{
echo '
<tr>
<td class="windowbg" valign="middle" width="80%">
' . '<img src="Themes/Enterprise_smf11final_tp/images/topic/normal_poll.gif"></img> ' . $topic['link2'],' ';
echo '
</td>
<td class="windowbg" align="center" width="20%">
', $topic['link'] ,'
<td>
</tr>';
}
}
else
{
echo '
<tr>
<td class="windowbg" align="center" width="100%">No Available Polls.</td>
</tr>';
}
echo '
</table>';
I was wondering if anyone could help me update the code for 2.0. Primarily just need help updating to the new database calls (which I attempted but apparently sucked at it...).
Such as $ID_MEMBER should now be $user_info['id'] equivalent. I seem to be missing something or not getting certain ones just right.
Give this a try and report any errors if you have some.
function myPoll($num_recent = null, $include_boards = null, $output_method = 'echo')
{
global $context, $settings, $scripturl, $txt, $smcFunc, $user_info;
$include_boards = empty($include_boards) ? array() : $include_boards;
//Find any polls the user has voted on so we can kill em.
$p_request = $smcFunc['db_query']('', '
SELECT id_poll
FROM {db_prefix}log_polls
WHERE id_member = {int:user}
ORDER BY id_poll DESC',
array('user' => $user_info['id'])
);
$pollids = array();
while ($prow = $smcFunc['db_fetch_assoc']($p_request))
{
$pollids[] = array('id' => $prow['id_poll']);
}
//print_r($pollids);
//echo "<BR>";
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = $smcFunc['db_query']('', '
SELECT DISTINCT m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS bName, p.expire_time, t.id_poll,
IFNULL(mem.real_name, m.poster_name) AS posterName, ' . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS isRead,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . ', LEFT(m.body, 384) AS body, m.smileys_enabled, m.icon
FROM ({db_prefix}messages AS m, {db_prefix}topics AS t, {db_prefix}boards AS b, {db_prefix}messages AS ms)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = '.$user_info['id'].')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = '.$user_info['id'].')' : '') . '
LEFT JOIN {db_prefix}polls AS p ON (p.id_poll = t.id_poll)
LEFT JOIN {db_prefix}log_polls AS lp ON (lp.id_poll = t.id_poll)
WHERE t.id_last_msg = m.id_msg
AND b.id_board = t.id_board' . (empty($include_boards) ? '' : '
AND b.id_board IN ({array_int:include_boards})') . '
AND {query_see_board}
AND ms.id_msg = t.id_first_msg
AND t.id_poll > 0
AND p.voting_locked = 0
ORDER BY t.id_poll DESC
LIMIT {int:num}',
array('include_boards' => $include_boards, 'num' => $num_recent)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['expire_time'] == 0 || time() < $row['expire_time'])
{
// Build the array.
$posts[] = array(
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bName'] . '</a>',
'link2' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '">' . $row['subject'] . '</a>',
'poll_id' => $row['id_poll'],
);
//print_r($posts);
//echo "<BR>";
foreach ($pollids AS $i)
{
foreach($posts AS $k)
{
if ($k['poll_id'] == $i['id'])
{
//echo "Got it!!!<br>";
array_pop($posts);
}
}
}
}
}
$smcFunc['db_free_result']($request);
// Just return it.
if ($output_method != 'echo' || empty($posts))
return $posts;
echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">[', $post['link'], ']</td>
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['link'], '
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '
</td>
</tr>';
echo '
</table>';
}
//The block**************************************************************
global $scripturl;
echo '
<table border="0" width="100%" cellspacing="1" cellpadding="1" class="windowbg3">';
$what = myPoll('10', array(30, 79), 'array');
if (!empty($what))
{
foreach ($what as $topic)
{
echo '
<tr>
<td class="windowbg" valign="middle" width="80%">
' . '<img src="Themes/Enterprise_smf11final_tp/images/topic/normal_poll.gif"></img> ' . $topic['link2'],' ';
echo '
</td>
<td class="windowbg" align="center" width="20%">
', $topic['link'] ,'
<td>
</tr>';
}
}
else
{
echo '
<tr>
<td class="windowbg" align="center" width="100%">No Available Polls.</td>
</tr>';
}
echo '
</table>';
Thanks for the help. :)
Parse error: syntax error, unexpected T_ARRAY in ... line 14...
This line here is causing the error:
array('user' => $user_info['id'])
According to that.
Running it 2 ways, both giving the same error.
Updated post above. Try code again.
Fantastic! That seems to have done it.
Is currently working in a block just fine now on the test site.
Thanks so much!