I just upgrade my forums to SMF 2.0 RC3 and TP 1.0 Beta 5.2 after using the older SMF for a long time. I am loving the changes, but some of my blocks aren't working, which is to be expected.
Here is what I used to use to have a customized recent post block in which I selected the boards in which posts were displayed and how they were displayed. It no longer works and I was wondering if someone could help me with the conversion to the newer software.
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;
$num_recent = 7;
$include_boards = array(4,12);
$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$include_boards = empty($include_boards) ? array() : $include_boards;
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = db_query("
SELECT
m.posterTime, ms.subject, m.ID_TOPIC, t.numReplies, m.ID_MEMBER, m.ID_MSG, b.ID_BOARD, b.name AS bName,
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)" : '') . "
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) . ")") . "
" . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? "
AND b.ID_BOARD != '$modSettings[recycle_board]'" : '') . "
AND $user_info[query_see_board]
AND ms.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_LAST_MSG DESC
LIMIT $num_recent", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
{
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '
')));
if ($func['strlen']($row['body']) > 128)
$row['body'] = $func['substr']($row['body'], 0, 128) . '...';
// Censor the subject.
censorText($row['subject']);
censorText($row['body']);
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
// Build the array.
$result[] = array(
'board' => array(
'id' => $row['ID_BOARD'],
'name' => $row['bName'],
'href' => $scripturl . '?board=' . $row['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
),
'topic' => array(
'id' => $row['ID_TOPIC'],
'views' => $row['numViews'],
'replies' => $row['numReplies'],
),
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => empty($row['ID_MEMBER']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => shorten_subject($row['subject'], 25),
'preview' => $row['body'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
);
}
mysql_free_result($request);
// Print out the results
echo '<font size="3"><b>Football Recent Topics</b></font> | <font size="2"><a href="http://www.bamanation.net/index.php?action=post;board=4.0">Start A New Topic Here...</a></font><br><br>';
echo '<span class="smalltext">';
foreach($result as $my){
echo "$bullet";
echo '<span class="normaltext">'.$my['link'],' ';
echo '(', '<span class="smalltext">'.$my['topic']['replies'],'</span>) ';
// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '<a href="' . $my['href'] . '">
<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';
echo '</span>';
echo '<span class="largetext">','<br>';
}
{ echo '<h5><a href="?board=4.0">...Go To The Football Forum</a></h5><br>';
}
Thanks!
Do you have a screenshot of how this used to look? I've converted it, but the layout and text sizes seem to be pretty ugly IMO. Here's the code if you want to mess with the layout. Seems to be better now that I've fixed a little html.
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $smcFunc;
$num_recent = 7;
$include_boards = array(4,12);
$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$include_boards = empty($include_boards) ? array() : $include_boards;
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = tpdb_query("
SELECT
m.poster_time, ms.subject, m.id_topic, t.num_views, t.num_replies, m.id_member, m.id_msg, b.id_board, b.name AS bName,
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])" : '') . "
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) . ")") . "
" . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? "
AND b.id_board != '$modSettings[recycle_board]'" : '') . "
AND $user_info[query_see_board]
AND ms.id_msg = t.id_first_msg
ORDER BY t.id_last_msg DESC
LIMIT $num_recent", __FILE__, __LINE__);
$posts = array();
while ($row = tpdb_fetch_assoc($request)) {
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br />' => '')));
if ($smcFunc['strlen']($row['body']) > 128)
$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
// Censor the subject.
censorText($row['subject']);
censorText($row['body']);
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
// Build the array.
$result[] = array(
'board' => array(
'id' => $row['id_board'],
'name' => $row['bName'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bName'] . '</a>'
),
'topic' => array(
'id' => $row['id_topic'],
'views' => $row['num_views'],
'replies' => $row['num_replies'],
),
'poster' => array(
'id' => $row['id_member'],
'name' => $row['posterName'],
'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['posterName'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => shorten_subject($row['subject'], 25),
'preview' => $row['body'],
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
);
}
tpdb_free_result($request);
// Print out the results
echo '<font size="3"><b>Football Recent Topics</b></font> | <font size="2"><a href="http://www.bamanation.net/index.php?action=post;board=4.0">Start A New Topic Here...</a></font><br /><br />
<span class="smalltext">';
foreach($result as $my){
echo $bullet;
echo '<span class="normaltext">'.$my['link'],' ';
echo '(', '<span class="smalltext">'.$my['topic']['replies'],'</span>) ';
// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '<a href="' . $my['href'] . '">
<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" /></a>';
echo '</span>
</span>
<br />';
}
echo '<h5><a href="?board=4.0">...Go To The Football Forum</a></h5><br />';
I looked around and I don't have a screenshot. I will look at what you posted and mess with it some, thanks Ich. Good to see you're still a part of the team. You've always been more than helpful to me.
Ich, I am getting nothing in that block. There is just a blank space...
Are you sure you copied all the code? Do you see any errors in your SMF log and server error_log ?
I just copy/pasted that code above to my forum again and it worked without a problem.
Today at 03:46:51 PM
262af4fdaf5636f1e6ce49e25020c135
Type of error: General
http://www.bamanation.net/index.php?action=tpadmin;sa=blocks2: Invalid argument supplied for foreach()File: /home3/insanem2/public_html/bamanation/Themes/default/TPortalAdmin.template.php
Line: 3553
Hmm... I don't think that error has anything to do with the block.
It goes in a PHP block right? I dropped it in there and I get nothing but a blank spot.
Yep, a PHP block. Not much I can do if you don't have any other errors in your log. Are you able to check your error_log on your server?
If you'd like, I can try to figure out what is wrong by looking at it on your site. Send me some login details if you'd like me to take a look.
I just tested it and it worked fien for me to Ich...
Well heck... PM sending now Ich. Thanks
Did you copy and paste it into another editor? Reason I ask is because when I just looked at your block, all of the formatting in the code was lost. Something definitely went wacko there. Once I copy/pasted directly into the block, it seemed to work fine for me. Your blocks look a little screwy on your frontpage, but I'll leave that up so you can see it. Let us know if you need anything else.
You know, I tried copying it and pasting it several times and notice the format was off too. I finally tried doing it into notepad even, and that still didn't keep the right format. It's probably this IE 8.
Thanks alot Ich, sorry that it was just a problem on my end.
Not a problem. It's good to know that something is happening outside the realms of what we normally think of. :) Something to remember for the future.
Quote from: insanemustang on July 02, 2010, 01:21:05 AM
You know, I tried copying it and pasting it several times and notice the format was off too. I finally tried doing it into notepad even, and that still didn't keep the right format. It's probably this IE 8.
Thanks alot Ich, sorry that it was just a problem on my end.
I've noticed this with IE8. You paste the code in and wait for a couple of seconds and the text all moves. It all goes into one big clump.
Use Firefox and this doesn't happen. I pulled my hair out trying to add some code the other day, lol.. Not sure what has changed to cause this though, it didn't do this a week or two back. :(