collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 420
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

NEED HELP? If you're looking for support with Simple Portal, look no further than the Support Board!

Author Topic: Modify BoardNews Block  (Read 3255 times)

0 Members and 1 Guest are viewing this topic.

Offline Nigel

  • Semi Newbie
  • *
  • Posts: 9
  • SMF Version: 1.1.8
  • SP Version: 2.2
Modify BoardNews Block
« on: April 30, 2009, 10:35:08 AM »
Hi,

I'm wondering if there a way I can copy and modify the code used for the default news (BoardNews) block on SP?
Because the layout and contents of this block is perfect for my site. Unfortunately  since I'd like to gather news data from different Boards I needed to create a PHP block and the results were not even close to the default SP news block  :|

This is what I got so far:
Code: [Select]
   global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
   global $smcFunc, $return, $color_profile, $func;

   loadLanguage('Stats');

  $boards =4;
   $limit = 5;
   $start = 0;
   $length = 250;
   $avatars = 1;

   $limit = max(0, $limit);
   $start = max(0, $start);

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

   // Load the message icons - the usual suspects.
   $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 the post ids.
   $request = db_query("
      SELECT ID_FIRST_MSG
      FROM {$db_prefix}topics
      WHERE ID_BOARD = $boards
      ORDER BY ID_FIRST_MSG DESC
      LIMIT $start, $limit", __FILE__, __LINE__);
   $posts = array();
   while ($row = mysql_fetch_assoc($request))
      $posts[] = $row['ID_FIRST_MSG'];
   mysql_free_result($request);

   if (empty($posts))
      return array();

   // 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.numViews, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked, mem.avatar, a.ID_ATTACH, a.attachmentType, a.filename
      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)
         LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = m.ID_MEMBER)
      WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
         AND m.ID_MSG = t.ID_FIRST_MSG
      ORDER BY t.ID_FIRST_MSG DESC
      LIMIT " . count($posts), __FILE__, __LINE__);
   $return = array();
   $colorids = array();
   while ($row = mysql_fetch_assoc($request))
   {
      //on html replace the length... to prevent style errors... normal only admin can use this so this is the admin fault! Boardnews
      $oldlength = $length;
      if(stripos($row['body'], '[html]') !== false) {
         $length = strrpos(strtolower($row['body']), '[/html]')+7;
      }

      // If we want to limit the length of the post.
      if (!empty($length) && $func['strlen']($row['body']) > $length)
      {
         $row['body'] = $func['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'] = $func['substr']($row['body'], 0, $cutoff);
         $row['body'] .= '...';
      }
     
      //So is there a unclosed bbc near the end try to truncate them
      if(strrpos($row['body'], '[') > strrpos($row['body'], ']')) {
         $row['body'] = $func['substr']($row['body'], 0, strrpos($row['body'], '['));
         $row['body'] .= '...';
      }

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

      //Fix the the html fix for admins back to an normal way =).
      if($oldlength != $length)
         $length = $oldlength;

      // Check if the topic icon exists.
      if (!isset($icon_sources[$row['icon']]))
         $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
     
      if (stristr($row['avatar'], 'http://') && !empty($modSettings['avatar_check_size']))
      {
         $sizes = url_image_size($row['avatar']);

         // Does your avatar still fit the maximum size?
         if ($modSettings['avatar_action_too_large'] == 'option_refuse' && is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
         {
            // Fix it permanently!
            $row['avatar'] = '';
            updateMemberData($row['ID_MEMBER'], array('avatar' => '\'\''));
         }
      }

      // Check that this message icon is there...
      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';

      censorText($row['subject']);
      censorText($row['body']);
     
      //Collect the color ids :)
      if(!empty($row['ID_MEMBER']))
         $colorids[$row['ID_MEMBER']] = $row['ID_MEMBER'];

      $return[] = array(
         'id' => $row['ID_TOPIC'],
         'message_id' => $row['ID_MSG'],
         'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
         'subject' => $row['subject'],
         'time' => timeformat($row['posterTime']),
         'timeyear' => timeformat($row['posterTime'], '%d %b %y'),
         'timeday' => timeformat($row['posterTime'], '%H:%M:%S'),
         'timestamp' => forum_time(true, $row['posterTime']),
         'views' => $row['numViews'],
         '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'],
         'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'],
         'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
         'new_comment' => !empty($row['locked']) ? '' : '<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']
         ),
         'locked' => !empty($row['locked']),
         'is_last' => false,
         'avatar' => array(
            'name' => $row['avatar'],
            'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
            'href' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
            'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
         ),
      );
   }
   mysql_free_result($request);

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

   $return[count($return) - 1]['is_last'] = true;
   
   //Give some colors to the nice poster links :)   
   if(!empty($colorids) && sp_loadColors($colorids) !== false)
      foreach($return as $k => $p)
         if(!empty($color_profile[$p['poster']['id']]['link']))
            $return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];

   echo '
      <table cellpadding="0" cellspacing="0" border="0" width="100%">';

   foreach ($return as $news)
   {
      echo '
         <tr>
            <td>', $avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']) ? '
               <img src="' . $news['avatar']['href'] . '" alt="' . $news['poster']['name'] . '" width="30" style="float: right;" />' : '', '
               <div>
                  <div style="float: left; padding-right: 5px;"><a href="', $news['href'], '">', $news['icon'], '</a></div>
                  <b><a href="', $news['href'], '">', $news['subject'], '</a></b>
                  <div class="smalltext">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '</div>
                  <div class="post" style="padding: 2ex 0;">', $news['body'], '</div>
                  ', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
               </div>
            </td>
         </tr>';

      if (!$news['is_last'])
         echo '
         <tr>
            <td>
               <hr style="margin: 2ex 0;" width="100%" />
            </td>
         </tr>';
      }

      echo '
      </table>';

Any help on this?

Offline necrit

  • Newbie
  • Posts: 3
  • SMF Version: 2 RC1
  • SP Version: 2.2
Re: Modify BoardNews Block
« Reply #1 on: April 30, 2009, 03:48:18 PM »
I stumbled on that too.  check this out as i figured it out with a modified script block from elsewhere.

http://simpleportal.net/index.php?topic=2132.0