EzPortal - Portal Software for Forums

EzPortal - Made to Fit Your SMF Forum - Glad You Found Us!
+- +-

UserBox

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Recent Posts

Re: Undefined index: href by Shades
September 29, 2022, 07:05:13 pm

Re: SMF-ezportal_column_5.cache): failed to open stream: No such file or directory by EzPortal
June 04, 2022, 11:40:13 am

SMF-ezportal_column_5.cache): failed to open stream: No such file or directory by Shades
June 04, 2022, 11:29:37 am

Re: Arcade block error: failed to open stream: No such file or directory by Shades
May 20, 2022, 02:47:13 pm

Re: ezPortal 5.5 by EzPortal
May 20, 2022, 09:59:30 am

Re: ezPortal 5.5 by tigez
May 20, 2022, 08:46:15 am

Re: Undefined index: href by Shades
May 16, 2022, 02:58:21 pm

Re: Image/Attachment display issue by Shades
May 16, 2022, 02:28:35 pm

+- HTML Menu


Sample HTML Block Usage - You May Custom Code it, as needed!

Recent Topics ezBlock

Undefined index: href by Shades
September 29, 2022, 07:05:13 pm

SMF-ezportal_column_5.cache): failed to open stream: No such file or directory by EzPortal
June 04, 2022, 11:40:13 am

Arcade block error: failed to open stream: No such file or directory by Shades
May 20, 2022, 02:47:13 pm

ezPortal 5.5 by EzPortal
May 20, 2022, 09:59:30 am

Image/Attachment display issue by Shades
May 16, 2022, 02:28:35 pm

Can't delete custom actions by Shades
April 13, 2022, 12:53:28 pm

Newest Member ezblock by Shades
March 23, 2022, 12:48:32 pm

Random Download Block by Shades
March 22, 2022, 10:37:47 am

BBC Pages by EzPortal
March 21, 2022, 10:36:41 pm

Recent Topics Blocks are different from left side to right side by Shades
March 21, 2022, 02:42:38 pm

Author Topic: Topic, first attachment and 100+ characters  (Read 7349 times)

0 Members and 1 Guest are viewing this topic.

Offline timour_2

  • Posts: 3
  • Karma: 0
  • Gender: Male
Topic, first attachment and 100+ characters
« on: November 19, 2009, 03:51:02 pm »
I found a script that does it all when added to php block, except showing 100+ characters (preview) of the topic

Can anyone help me with that?


here is the script:



1) Search for your function ssi_boardNews and replace the whole function with this :

Code: [Select]
function ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt;
global $settings, $modSettings, $context;

loadLanguage('Stats');

// Must be integers....
if ($limit === null)
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
else
$limit = (int) $limit;

if ($start === null)
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
else
$start = (int) $start;

if ($board !== null)
$board = (int) $board;
elseif (isset($_GET['board']))
$board = (int) $_GET['board'];

if ($length === null)
$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
else
$length = (int) $length;

// Make sure guests can see this board.
$request = db_query("
SELECT ID_BOARD
FROM {$db_prefix}boards
WHERE " . ($board === null ? '' : "ID_BOARD = $board
AND ") . "FIND_IN_SET(-1, memberGroups)
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) == 0)
{
if ($output_method == 'echo')
die($txt['smf_news_error2']);
else
return array();
}
list ($board) = mysql_fetch_row($request);
mysql_free_result($request);

// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_BOARD = $board
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY m.ID_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$return = array();
$message_ids = array();
while ($row = mysql_fetch_assoc($request))
{
$message_ids[] = $row['ID_MSG'];
// If we want to limit the length of the post.
if (!empty($length) && strlen($row['body']) > $length)
{
$row['body'] = substr($row['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

if ($cutoff !== false)
$row['body'] = substr($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

$row['body'] = doUBBC($row['body'], $row['smileysEnabled']);

censorText($row['subject']);
censorText($row['body']);

  $return[$row['ID_MSG']] = array(
'attachments' => array(),
'id' => $row['ID_TOPIC'],
'icon' => '<img src="' . $settings['images_url'] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => $row['posterTime'],
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
'replies' => $row['numReplies'],
'new_comment' => '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'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']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
),
'is_last' => false
);
}
mysql_free_result($request);



if (empty($return))
return $return;

// Find their attachments.

$request = db_query("
SELECT ID_ATTACH, ID_MSG, filename, size, downloads
FROM {$db_prefix}attachments
WHERE ID_MSG IN (" . implode(', ', $message_ids) . ")", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))

{
$return[$row['ID_MSG']]['attachments'][] = array(
'name' => $row['filename'],
'downloads' => $row['downloads'],
'size' => round($row['size'] / 1024, 2) . ' ' . $txt['smf211'],
'byte_size' => $row['size'],
'href' => $scripturl . '?action=dlattach;topic=' . $return[$row['ID_MSG']]['id'] . '.0;id=' . $row['ID_ATTACH'],
'link' => '<a href="' . $scripturl . '?action=dlattach;topic=' . $return[$row['ID_MSG']]['id'] . '.0;id=' . $row['ID_ATTACH'] . '">' . $row['filename'] . '</a>'
);
}
mysql_free_result($request);
return $return;
}



Now you can pull out attachments.

2) Second step is easy, I managed to edit the script so the result you want (and I) is done.

Code: [Select]
$array_boardNews = ssi_boardNews(7.0, 3, null, 'array');
foreach ($array_boardNews as $news)
{
$newsImage = '' ;
if( isset( $news[ 'attachments' ][ 0 ] ) )
{
$newsImage = '<img class="news" src="' . $news[ 'attachments' ][ 0 ][ 'href' ] . ';image" alt="' . $news[ 'attachments' ][ 0 ][ 'name' ] . '" title="' . $news[ 'attachments' ][ 0 ][ 'name' ] . '" width="100" height="100"/>' ;
}
echo '<a href="'.$news['href']. '">
<div class="teaser">
<div class="teasercontent">
<h1 class="news">' . $news['subject'] . '</h1>' . $newsImage. '
</div>
<div class="teaserfooter">
</a></div>
</div>
';
}


All you have to do is editing this line :
$array_boardNews = ssi_boardNews(7.0, 3, null, 'array');

7.0 = The board out of which topics + attachments are taken.
3 = the number of how many topics (together with their images) should been shown.
That's all you have to edit.

Offline timour_2

  • Posts: 3
  • Karma: 0
  • Gender: Male
Re: Topic, first attachment and 100+ characters
« Reply #1 on: November 21, 2009, 10:51:29 am »
I finally figured it out
Here it goes in case someone will need it:



Code: [Select]
$array_boardNews = ssi_boardNews(1, 3, null, 100, 'array');
foreach ($array_boardNews as $news)
{
   $newsImage = '' ;
   if( isset( $news[ 'attachments' ][ 0 ] ) )
   {
      $newsImage = '<img class="news" src="' . $news[ 'attachments' ][ 0 ][ 'href' ] . ';image" alt="' . $news[ 'attachments' ][ 0 ][ 'name' ] . '" title="' . $news[ 'attachments' ][ 0 ][ 'name' ] . '" width="100" height="100"/>' ;
   }
echo ' </font>
   <div class="teaser">
      <div class="teasercontent">
         <table border="0" width="100%" cellspacing="0" cellpadding="0">
            <!-- MSTableType="layout" -->
            <tr>
               <td width="119" valign="top"><a href="'.$news['href']. '">
               <font size="2">' . $newsImage. ' </font>
      [/url]</td>
               <td valign="top"><font size="2"><a href="'.$news['href']. '">
                              ' . $news['subject'] . '[/url]</font>

               ' . $news['body'] . '</td>
            </tr>
         </table>
      </div>
      <div class="teaserfooter">
      [/url]</div>                 
   </div>
   ';
}

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
6394 Views
Last post January 24, 2009, 06:35:00 pm
by chinaren
0 Replies
3573 Views
Last post November 26, 2011, 02:43:29 am
by Ju de tomate
1 Replies
6040 Views
Last post September 14, 2012, 01:57:09 pm
by EzPortal
1 Replies
4619 Views
Last post October 05, 2019, 11:42:56 am
by EzPortal
2 Replies
2059 Views
Last post May 16, 2022, 02:28:35 pm
by Shades

+-SMF Gallery

Quick Menu


Powered by EzPortal