TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,970
  • Latest: bynw
Stats
  • Total Posts: 196,055
  • Total Topics: 21,337
  • Online today: 194
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 172
  • Total: 172

SSI Attachments Problem

Started by NeoX, August 18, 2012, 02:42:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NeoX

 :)

Hello every one ,
After put the following code in ssi.php

function ssi_recentPostsAttach($num_recent = 8, $exclude_boards = null, $output_method = 'echo')
{
   global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
   global $user_info, $modSettings, $func;

   if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
      $exclude_boards = array($modSettings['recycle_board']);
   else
      $exclude_boards = empty($exclude_boards) ? array() : $exclude_boards;

   // Find all the posts.  Newer ones will have higher IDs.
   $request = db_query("
      SELECT
         m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.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
      FROM ({$db_prefix}messages AS m, {$db_prefix}boards AS b)
         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 = m.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
         LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = m.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
      WHERE m.ID_MSG >= " . ($modSettings['maxMsgID'] - 25 * min($num_recent, 5)) . "
         AND b.ID_BOARD = m.ID_BOARD" . (empty($exclude_boards) ? '' : "
         AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
         AND $user_info[query_see_board]
      ORDER BY m.ID_MSG DESC
      LIMIT $num_recent", __FILE__, __LINE__);
   $posts = array();
   $messages = 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 it!
      censorText($row['subject']);
      censorText($row['body']);

      $messages[] = $row['ID_MSG'];

      // Build the array.
      $posts[$row['ID_MSG']] = 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' => $row['ID_TOPIC'],
         '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'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
         'new' => !empty($row['isRead']),
         'new_from' => $row['new_from'],
         'images' => array(),
      );
   }
   mysql_free_result($request);

   $request = db_query("
      SELECT
         m.ID_MSG, m.ID_TOPIC,
         IFNULL(big.ID_ATTACH, 0) AS bigId, big.filename AS bigFilename, big.width AS bigWidth, big.height AS bigHeight,
         IFNULL(thn.ID_ATTACH, 0) AS thnId, thn.filename AS thnFilename, thn.width AS thnWidth, thn.height AS thnHeight
      FROM {$db_prefix}messages AS m
         LEFT JOIN {$db_prefix}attachments AS big ON (big.ID_MSG = m.ID_MSG AND big.attachmentType = 0)
         LEFT JOIN {$db_prefix}attachments AS thn ON (thn.ID_ATTACH = big.ID_THUMB)
      WHERE m.ID_MSG IN (" . implode(', ', $messages) . ")
      ORDER BY m.ID_MSG DESC", __FILE__, __LINE__);
   while ($row = mysql_fetch_assoc($request))
   {
      if ($row['thnId'] != 0)
         $image = array(
            'id' => $row['thnId'],
            'url' => $scripturl . '?action=dlattach;topic=' . $row['ID_TOPIC'] . '.0;attach=' . $row['thnId'] . ';image',
            'link' => $scripturl . '?action=dlattach;topic=' . $row['ID_TOPIC'] . '.0;attach=' . $row['bigId'] . ';image',
            'filename' => $row['thnFilename'],
            'width' => $row['thnWidth'],
            'height' => $row['thnHeight']
         );
      elseif ($row['bigId'] != 0 && $row['bigWidth'] > 0 && $row['bigHeight'] > 0)
         $image = array(
            'id' => $row['bigId'],
            'url' => $scripturl . '?action=dlattach;topic=' . $row['ID_TOPIC'] . '.0;attach=' . $row['bigId'] . ';image',
            'link' => $scripturl . '?action=dlattach;topic=' . $row['ID_TOPIC'] . '.0;attach=' . $row['bigId'] . ';image',
            'filename' => $row['bigFilename'],
            'width' => $row['bigWidth'],
            'height' => $row['bigHeight']
         );
      else
         $image = array();

      if (isset($posts[$row['ID_MSG']]['images']))
         $posts[$row['ID_MSG']]['images'][] = $image;
      else
         $posts[$row['ID_MSG']]['images'] = array($image);
   }
   mysql_free_result($request);

   foreach($posts as $key => $post)
   {
      $imagefound = false;
   
      foreach ($post['images'] as $img)
      {

         if ($imagefound == true)
            break;

         if (isset($img['id']))
         {
            $posts[$key]['image'] = '<a href="' . $post['href'] . '"><img src="' . $img['url'] . '" width="' . $img['width'] . '" height="' . $img['height'] . '" alt="" /></a>';
            $imagefound = true;
         }
      }
   }

   // Just return it.
   if ($output_method != 'echo' || empty($posts))
      return $posts;

<DIV ALIGN="CENTER">
<table width="90%">
<tr>';
   foreach ($posts as $post)
      echo '
         <tr>
            <td valign="top">
               <a href="', $post['href'], '">', $post['subject'], '</a>
             
                             ', $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>', '

               ', !empty($post['image']) ? $post['image'] : '', '
            </td>
         </tr>
</tr>
</table></div>';
}


and make a new tp php block with this inside

ssi_recentPostsAttach();


I have this error in Tinyportal PHP Block:

Database Error
Query was empty
File: /SSI.php
Line: 2054

In line 2054 I found this

ORDER BY m.ID_MSG DESC", __FILE__, __LINE__);

I think this is an error with code, I use SMF 2.0.2 a Tinyportal 1.107
Thank You very much!

:)

IchBin

db_query() was for SMF1. You need to change the queries you have in their to use the format for SMF2. You can learn more about that here:
http://simplemachines.org/community/?topic=224166.0

NeoX


This website is proudly hosted on Crocweb Cloud Website Hosting.