TinyPortal

Development => Block Codes => Topic started by: obarriel on August 15, 2011, 02:24:04 AM

Title: error related with db_query after updating to SMF 2.0
Post by: obarriel on August 15, 2011, 02:24:04 AM
Link to my site: reproductormp3(dot)net
SMF version: SMF 2.0
TP version: TP 1.0 RC2
Default Forum Language: Spanish
Theme name and version: Curve
Browser Name and Version: Firefox
Mods installed: Tinyportal
Related Error messages: Fatal error: Function name must be a string in /home/obarriel/reproductormp3.net/Sources/TPortal.php on line 3041

I was using the following custom code for a block showing the last posts in the forum

global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;

$num_recent = 16;
$include_boards = array(1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,41,42,44,45,47,49);

$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 >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
AND 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 '<span class="smallertext">','<br>';
foreach($result as $my){
  echo "$bullet";
  echo ' ', '<span class="normaltext">'.$my['board']['link'] ,': ';
  echo '<span class="normaltext", style="font-weight: bold;">'.$my['link'],' ';
echo '</span>';
  echo 'por ', '<span class="normaltext">'.$my['poster']['link'],' ';
  echo '(', '<span class="normaltext">'.$my['topic']['replies'],') ';
  // is this topic new? (assume they are logged in)
  if (!$my['new'] && $context['user']['is_logged'])
  echo '
    <a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new">
    <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';
  echo '</span>';
  echo '<span class="largetext">','<br>';
}


This code worked fine before updating to SMF 2.0. Now it gives an error that I suppose that is related to db queries.

¿Somebody knows how I need to modify it to keep it working with SMF 2.0?
Title: Re: error related with db_query after updating to SMF 2.0
Post by: IchBin on August 15, 2011, 03:17:22 AM
See if this works. Let me know if there are any errors. I tried to fix your messed up HTML output at the end, so let me know if there are any display errors too.

global $context, $settings, $scripturl, $txt, $user_info, $modSettings, $smcFunc;

$num_recent = 16;
$include_boards = array(1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,41,42,44,45,47,49);

$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 = $smcFunc['db_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 = '. $context['user']['id'].')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = '.$context['user']['id'].')' : '') . '
WHERE t.id_last_msg >= ' . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . '
AND 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})') . '
' . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? '
AND b.id_board != '. $modSettings['recycle_board'] : '') . '
AND {query_see_board}
AND ms.id_msg = t.id_first_msg
ORDER BY t.id_last_msg DESC
LIMIT {int:num}',
array('include_boards' => $include_boards, 'num' => $num_recent)
);
$posts = array();
while ($row = $smcFunc['db_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" />',
);
}

$smcFunc['db_free_result']($request);

foreach($result as $my)
{
echo $bullet .'
<span class="normaltext">'. $my['board']['link'] .'</span>: <span class="normaltext" style="font-weight: bold;">'. $my['link'] .'</span> por <span class="normaltext">'. $my['poster']['link'] .'('.$my['topic']['replies'].')';
// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new">
<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" />
</a>
</span>';
}
Title: Re: error related with db_query after updating to SMF 2.0
Post by: obarriel on August 15, 2011, 04:08:20 AM
Thank you very much,

With this code I get the following error:

Parse error: syntax error, unexpected ')' in /home/obarriel/reproductormp3.net/Sources/Load.php(2160) : eval()'d code(114) : eval()'d code on line 25

Not sure where the problem is now
Title: Re: error related with db_query after updating to SMF 2.0
Post by: IchBin on August 15, 2011, 04:11:23 AM
Updated the code above so try again. Also headed to bed, so I'll check back on this tomorrow. :)
Title: Re: error related with db_query after updating to SMF 2.0
Post by: obarriel on August 15, 2011, 04:47:21 AM
The error has changed to

Parse error: syntax error, unexpected T_VARIABLE in /home/obarriel/reproductormp3.net/Sources/Load.php(2160) : eval()'d code(114) : eval()'d code on line 31
Title: Re: error related with db_query after updating to SMF 2.0
Post by: IchBin on August 15, 2011, 03:09:48 PM
Try the code I posted above again. Small fix for that error.
Title: Re: error related with db_query after updating to SMF 2.0
Post by: obarriel on August 15, 2011, 03:59:46 PM
Now it works fine!  :)

I have added line breaks that were missing in your code

foreach($result as $my)
{
echo $bullet .'
<span class="normaltext">'. $my['board']['link'] .'</span>: <span class="normaltext" style="font-weight: bold;">'. $my['link'] .'</span> por <span class="normaltext">'. $my['poster']['link'] .'('.$my['topic']['replies'].')';
// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new">
<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" />
</a>
</span>';
                echo '<br>';
}


The only improvement I would make is to increase the separation between lines in for each input (see reproductormp3.net). Do you know how to do it?

Also where can I adjust the number of characteres of the thread title to display?

Thank you very much!
Title: Re: error related with db_query after updating to SMF 2.0
Post by: IchBin on August 15, 2011, 04:26:06 PM
I rearranged the code a bit to make it so that adding padding would be a little easier. See if this works. You can adjust the padding in the first span tag to what you need.


foreach($result as $my)
{
echo $bullet .'
<span class="normaltext" style="padding: 8px">' . $my['board']['link'] . ' : <span class="normaltext" style="font-weight: bold;">'. $my['link'] .'</span>
por '. $my['poster']['link'] .'('.$my['topic']['replies'].')'; 
// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new">
<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" />
</a>
</span>';
                echo '<br />';
}
Title: Re: error related with db_query after updating to SMF 2.0
Post by: obarriel on August 15, 2011, 04:42:04 PM
I may have expressed wrongly what I wanted to increase is the interline separation or spacing between lines for each post.
Title: Re: error related with db_query after updating to SMF 2.0
Post by: IchBin on August 15, 2011, 06:14:25 PM
That is what I think the code should do, is it not working or something? Adding the padding like I did should put 5px of space between each line.
Title: Re: error related with db_query after updating to SMF 2.0
Post by: obarriel on August 15, 2011, 06:20:31 PM
It is not putting vertical space between lines. It only puts space between the bullet and the first letter of the line.
Title: Re: error related with db_query after updating to SMF 2.0
Post by: ZarPrime on August 15, 2011, 06:47:17 PM
I think rather than a line break at the end of the code, a horizontal line (hr) would look better.  Have you tried that?

ZarPrime
Title: Re: error related with db_query after updating to SMF 2.0
Post by: IchBin on August 15, 2011, 06:55:51 PM
Put the bullet inside the span.

Change this:
echo $bullet .'
   <span class="normaltext" style="padding: 8px">' . $my['board']['link'] . ' :

To this:
echo '
   <span class="normaltext" style="padding: 8px">'. $bullet . $my['board']['link'] . ' :

Change the padding: 8px; to line-height: 1.5em; and see if that helps. If it does not, please leave your code in place so I can inspect it on your site to see what needs to be changed.
Title: Re: error related with db_query after updating to SMF 2.0
Post by: obarriel on August 15, 2011, 08:21:19 PM
Putting the bullet inside the span gives me an error.

With an horizontal line looks quite good and the vertical spacing is more or less what I wanted

This is the code I use now:

global $context, $settings, $scripturl, $txt, $user_info, $modSettings, $smcFunc;

$num_recent = 16;
$include_boards = array(1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,41,42,44,45,47,49);

$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 = $smcFunc['db_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 = '. $context['user']['id'].')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = '.$context['user']['id'].')' : '') . '
WHERE t.id_last_msg >= ' . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . '
AND 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})') . '
' . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? '
AND b.id_board != '. $modSettings['recycle_board'] : '') . '
AND {query_see_board}
AND ms.id_msg = t.id_first_msg
ORDER BY t.id_last_msg DESC
LIMIT {int:num}',
array('include_boards' => $include_boards, 'num' => $num_recent)
);
$posts = array();
while ($row = $smcFunc['db_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" />',
);
}

$smcFunc['db_free_result']($request);
// Print out the results
  echo '<span class="smallertext">','<br>';
foreach($result as $my)
{
echo $bullet .'
<span class="normaltext" style="padding: 8px">' . $my['board']['link'] . ' : <span class="normaltext" style="font-weight: bold;">'. $my['link']  .'</span>
por '. $my['poster']['link'] .'('.$my['topic']['replies'].')'; 
// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new">
<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" />
</a>
</span>';
                echo '<hr />';
}
Title: Re: error related with db_query after updating to SMF 2.0
Post by: IchBin on August 16, 2011, 03:21:38 AM
How come you added this part?
echo '<span class="smallertext">','<br>';

That actually is incorrect as every tag must have an ending tag. You start the < span > tag but do not end it. Do you need that code there for some reason?

Try this code:
global $context, $settings, $scripturl, $txt, $user_info, $modSettings, $smcFunc;

$num_recent = 16;
$include_boards = array(1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,41,42,44,45,47,49);

$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 = $smcFunc['db_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 = '. $context['user']['id'].')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = '.$context['user']['id'].')' : '') . '
WHERE t.id_last_msg >= ' . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . '
AND 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})') . '
' . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? '
AND b.id_board != '. $modSettings['recycle_board'] : '') . '
AND {query_see_board}
AND ms.id_msg = t.id_first_msg
ORDER BY t.id_last_msg DESC
LIMIT {int:num}',
array('include_boards' => $include_boards, 'num' => $num_recent)
);
$posts = array();
while ($row = $smcFunc['db_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" />',
);
}

$smcFunc['db_free_result']($request);
// Print out the results
foreach($result as $my)
{
echo '<span class="normaltext" style="padding: 8px">' . $bullet . $my['board']['link'] . ' : <span class="normaltext" style="font-weight: bold;">'. $my['link']  .'</span>
por '. $my['poster']['link'] .'('.$my['topic']['replies'].')'; 
// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new">
<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" />
</a>
</span>';
                echo '<hr />';
}
Title: Re: error related with db_query after updating to SMF 2.0
Post by: obarriel on August 21, 2011, 06:19:31 PM
Sorry for not reporting before. This code works just fine. There was an small error with ID_BOARD written in capital letters, once corrected the code is:


global $context, $settings, $scripturl, $txt, $user_info, $modSettings, $smcFunc;

$num_recent = 16;
$include_boards = array(1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,41,42,44,45,47,49);

$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 = $smcFunc['db_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 = '. $context['user']['id'].')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = '.$context['user']['id'].')' : '') . '
WHERE t.id_last_msg >= ' . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . '
AND 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})') . '
' . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? '
AND b.id_board != '. $modSettings['recycle_board'] : '') . '
AND {query_see_board}
AND ms.id_msg = t.id_first_msg
ORDER BY t.id_last_msg DESC
LIMIT {int:num}',
array('include_boards' => $include_boards, 'num' => $num_recent)
);
$posts = array();
while ($row = $smcFunc['db_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" />',
);
}

$smcFunc['db_free_result']($request);
// Print out the results
foreach($result as $my)
{
echo '<span class="normaltext" style="padding: 8px">' . $bullet  . $my['board']['link'] . ' : <span class="normaltext" style="font-weight: bold;">'. $my['link']  .'</span>
por '. $my['poster']['link'] .'('.$my['topic']['replies'].')'; 
// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new">
<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" />
</a>
</span>';
                echo '<hr />';
}


Anybody who wants to use it you can check the output at www.reproductormp3.net