Warning: The author of this contribution does not provide support for it anymore.

Board3 Portal

Modifying portal.php (adding News Article and Top Five MODs) - Board3 Portal

Modifying portal.php (adding News Article and Top Five MODs)

by DFORMS » Wed Jan 25, 2012 6:47 pm

Hey thanks for this great MOD! I would love to use it on my site : http://fragnet.ca but I need some help modifying the portal.php. I've installed a test version here : http://quebecod.ca.

On the index page of my site (http://fragnet.ca) I'm using the template version of the 'Show forum threads as news articles' MOD (to display recent threads + messages at the bottom of my site) and the 'Top Five' MOD (to display the recent threads in the left column of my site).

Only want to use parts of the portal. I would like to use all 3 (portal, news articles and top five) together.

This is my index page (http://fragnet.ca):

Code: Select all

<?php

            define('IN_PHPBB', true);
            $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';    // Replace with your own root path
            $phpEx = substr(strrchr(__FILE__, '.'), 1);
            include_once($phpbb_root_path . 'common.' . $phpEx);
            include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
            include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);

            // Start session management
            $user->session_begin();
            $auth->acl( $user->data );
            $user->setup('mods/news_articles');
           

            // Gets the name of this file
            $this_file = get_this_filesname(__FILE__);

            /*
               FROM HERE, you can now change whatever you want in order to suit your needs.
               For example, you can build the datas to however you like. OR you can change the output variables.
               That is where the html gets outputted.
               If you know php variables and html, you can modify that to your own usage.
            */
            //
            // User Config Options
            //
            $fora_ids = array(359, 381, 406, 450, 536, 525, 530, 514, 519, 391, 590, 594, 555, 358, 618, 549, 566, 420, 415, 567, 580, 573, 593, 581);   // array of forum ids you want posts from
            $parent_ids = true;   // array of parent forum ids, set to false if not used
            $articles = 15;         // number of posts to return
            $offset = 58;         // offset : Set this variable if you don't want the result set begin on the first entry
            $children = true;      // This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
            $sort_order = sort_order_query('active_desc');
            $allow_attach = false;   // Show attachments, if any ?
            $allow_ranks = true;   // Show ranks ?
            $allow_sigs = false;      // Show signatures ?
            $allow_avatar = true;   // Show avatars ?

            //  Get the posts
            $posts = get_news($fora_ids, $parent_ids, $articles, $offset, $children, $sort_order, $allow_attach, $allow_ranks, $allow_sigs, $allow_avatar);

        //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'includes/top_five.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//

            // Assign Common vars
            // Language vars are in: language/en/mods/news_articles.php
            $template->assign_vars(array(
               'L_BREADCRUMBS'   => $user->lang['LN_BREADCRUMBS'],
               'L_NUM_REPLIES'   => $user->lang['LN_NUM_REPLIES'],
               'L_NUM_VIEWS'   => $user->lang['LN_NUM_VIEWS'],
               'L_POST_ATTACHMENT'   => $user->lang['LN_POST_ATTACHMENTS'],
               'L_ATTACHMENTS'   => $user->lang['LN_ATTACHMENTS'],
               'L_IS_ATTACHMENTS'   => $user->lang['LN_IS_ATTACHMENTS'],
               'L_NUM_ATTACHMENTS'   => $user->lang['LN_NUMBER_ATTACHMENTS'],
               'L_ATTACH_DOWNLOADS'   => $user->lang['LN_ATTACH_DOWNLOADS'],
               'L_ATTACH_COMMENTS'      => $user->lang['LN_ATTACH_COMMENTS'],
               'L_DOWNLOAD_EXPLAIN'   => $user->lang['LN_DOWNLOAD_EXPLAIN'],
               'L_POSTED_ON'   => $user->lang['LN_POSTED_ON'],
               'L_POSTED_BY'   => $user->lang['LN_POSTED_BY'],
               'L_RANK_TITLE'   => $user->lang['LN_RANK_TITLE'],
               'L_DISCUSS_TOPIC'   => $user->lang['LN_DISCUSS_TOPIC'],
               'L_INDEX'      => $user->lang['FORUM_INDEX'],
               
               'U_INDEX'      => append_sid($phpbb_root_path),
            ));

            // Build the output
            foreach($posts as $post)
            {
               // First set all the data in vars
               $bbcode_options    = (($post['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);

               // Actual Post
               $post_text      = generate_text_for_display($post['post_text'], $post['bbcode_uid'], $post['bbcode_bitfield'], $bbcode_options);
               $post_text      = bbcode_nl2br($post_text);
               $post_text      = smiley_text($post_text);
               $post_link      = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, array('f' => $post['forum_id'], 't' => $post['topic_id'])) . '#p' . $post['post_id'];
               $post_subject   = censor_text($post['topic_title']);
               $post_time      = $user->format_date($post['post_time']);
               $post_replies_count      = $post['topic_replies_real'];
               $post_views    = $post['topic_views'];
               // Post Tracking (Is it unread or not?)
               $topic_tracking_info = get_complete_topic_tracking($post['forum_id'], $post['topic_id'], false);
               $is_this_unread = (isset($topic_tracking_info[$post['topic_id']]) && $post['topic_last_post_time'] > $topic_tracking_info[$post['topic_id']]) ? true : false;
               // Post Icons
               $post_icon = $icon_alt_text = $topic_type = '';
               topic_status($post, $post['topic_replies_real'], $is_this_unread, $post_icon, $icon_alt_text, $topic_type);
               $post_icon = $user->img($post_icon, $icon_alt_text, false, '', 'src');
               $icon_alt_text = $user->lang[$icon_alt_text];
               // Attachments
               $is_there_attachments    = $post['is_there_attachments'];
               $post_attachments    = $post['attachments'];
               $post_attachment_names    = $post['attachment_names'];
               $post_attachment_downloads    = $post['attachment_downloads'];
               $post_attachment_comments    = $post['attachment_comments'];
               $post_attachment_filesize    = $post['attachment_filesize'];
               $num_of_attachments    = $post['num_of_attachments'];

               
               $poster_avatar = $user_rank_title = $user_rank_image = $user_signature = '';
               // User Information
               if($post['allow_avatar'])
               {
                 $poster_avatar = get_user_avatar($post['user_avatar'], $post['user_avatar_type'], $post['user_avatar_width'], $post['user_avatar_height']);
               }
               $poster_link   = append_sid($phpbb_root_path . 'memberlist.' . $phpEx, array('mode' => 'viewprofile', 'u' => $post['user_id']));
               $poster_name   = get_username_string('full', $post['user_id'], $post['topic_last_poster_name'], $post['user_colour']);
               // Ranks
               if($post['allow_ranks'])
               {
                 if($post['user_id'] != ANONYMOUS)
                 {
            //       unset($user_rank_title, $user_rank_image, $user_rank_image_relative_src);
                   unset($user_rank_image_relative_src);
                   get_user_rank($post['user_rank_id'], $post['user_posts'], $user_rank_title, $user_rank_image, $user_rank_image_relative_src);
                 }
               }
               // Signatures
               if($post['allow_sigs'])
               {
                 $user_signature  = generate_text_for_display($post['user_sig'], $post['user_sig_bbcode_uid'], $post['user_sig_bbcode_bitfield'], $bbcode_options);
                 $user_signature  = bbcode_nl2br($user_signature);
                 $user_signature  = smiley_text($user_signature);
               }

               // THE BUILDING BLOCKS ARE DONE!
               // ITS TIME TO START PUTTING THE BLOCKS TOGETHER INTO COHERENT HTML
               $template->assign_block_vars('postrow', array(
                  'POST_ID'         => $post['post_id'],
                  'POST_ICON'         => $post_icon,
                  'POST_ICON_ALT'      => $icon_alt_text,
                  'POST_SUBJECT'      => $post_subject,
                 
                  'S_UNREAD'         => ($is_this_unread ? true : false),

                  'U_POST_LINK'      => $post_link,
                 
                  'REPLY_COUNT'      => $post_replies_count,
                  'VIEW_COUNT'      => $post_views,
                  'HAS_ATTACHMENTS'   => $is_there_attachments,
                  'POST_TIME'         => $post_time,
                  'POST_AUTHOR'      => $poster_name,
                  'POSTER_AVATAR'      => $poster_avatar,
                  'POSTER_PROFILE'   => $poster_link,
                  'RANK_TITLE'      => $user_rank_title,
                  'RANK_IMG'         => $user_rank_image,
                 
                  'MESSAGE'         => $post_text,
                 
                  'SIGNATURE'       => (!empty($user_signature) ? $user_signature : ''),
                  'L_ATTACH_SHOWN'   => ($allow_attach ? $user->lang['LN_ATTACH_DISPLAY'] : $user->lang['LN_ATTACH_NOT_DISPLAY']),
                  ));

               // Breadcrumbs
               if(isset($post['breadcrumb_ids']))
               {
                 foreach($post['breadcrumb_ids'] as $name => $id)
                 {
                  $template->assign_block_vars('postrow.nav_links', array(
                     'U_VIEW_FORUM'   => append_sid($phpbb_root_path . 'viewforum.' . $phpEx, array('f' => $id)),
                     'FORUM_NAME'   =>   $name,
                  ));
                 }
               }
               if($is_there_attachments && $post['allow_attachments'])
               {
                 foreach($post_attachment_filesize as &$filesize)
                 {
                   $filesize = get_formatted_filesize($filesize);
                 }
                 unset($filesize); // Breaking reference

                 for($j=key($post_attachments);$j<$num_of_attachments;$j++)
                 {
                  $template->assign_block_vars('postrow.attachments', array(
                     'NUM_ATTACHMENTS'   => $num_of_attachments,
                     'URL_ATTACHMENT'   => $post_attachments[$j],
                     'NAME_ATTACHMENT'   => $post_attachment_names[$j],
                     'HAS_COMMENTS'   => (!empty($post_attachment_comments[$j]) ? true : false),
                     'ATTACHMENT_COMMENT'   => (!empty($post_attachment_comments[$j]) ? $post_attachment_comments[$j] : ''),
                     'DOWNLOAD_COUNT'   => ( ($post_attachment_downloads[$j] > 0) ? $post_attachment_downloads[$j] : 0),
                     'FILESIZE'         => $post_attachment_filesize[$j],
                  ));
                 }
               }
            }

            $template->assign_block_vars('navlinks', array(
               'U_VIEW_FORUM'   => append_sid($phpbb_root_path . $this_file . '.' . $phpEx),
               'FORUM_NAME'   => $user->lang['LN_FORUM_NEWS'],
            ));

            // Output page
            page_header($user->lang['LN_FORUM_NEWS']);

            $template->set_filenames(array(
               'body' => 'page_index.html')
            );

            page_footer();
            exit;

            /*
            * Start Functions block
            */
            /*
            * Get the name of the file
            *
            * @param $info passed as __FILE__
            * @return (string) the name of the file minus the file ext
            */
            function get_this_filesname($info)
            {
               // Gets the name of this file
               $this_file = pathinfo($info);
               return substr($this_file['basename'], 0, strpos($this_file['basename'], '.'));
            }

            /*
            * @param String $sort_order Has 12 options: (Default is recent_desc)
            * Options:
                1. 'recent_asc' Gives oldest to newest topics
                2. 'recent_desc' Vice versa
                3. 'active_asc' Gives the early replied to recently replied
                4. 'active_desc' Vice versa
                5. 'subject_asc' Gives it in alphabetical order
                6. 'subject_desc' Vice versa
                7. 'author_asc' Gives authors in alphabetical order
                8. 'author_desc' Vice versa
                9. 'views_asc' Gives the least views to most views
               10. 'views_desc' Vice versa
               11. 'replies_asc' Gives the least replies to the most replies
               12. 'replies_desc' Vice versa
            * @return String $sort_order_query The mysql coding to be used in the get_news function
            */
            function sort_order_query($sort_order)
            {
               // switches for sort_order
               switch ($sort_order)
               {
                 case 'recent_asc':
                   $sort_order_query = 't.topic_time ASC';
                   break;
                 case 'recent_desc':
                   $sort_order_query = 't.topic_time DESC';
                   break;
                 case 'active_asc':
                   $sort_order_query = 't.topic_last_post_id ASC';
                   break;
                 case 'active_desc':
                   $sort_order_query = 't.topic_last_post_id DESC';
                   break;
                 case 'subject_asc':
                   $sort_order_query = 't.topic_title ASC';
                   break;
                 case 'subject_desc':
                   $sort_order_query = 't.topic_title DESC';
                   break;
                 case 'author_asc':
                   $sort_order_query = 't.topic_last_poster_name ASC';
                   break;
                 case 'author_desc':
                   $sort_order_query = 't.topic_last_poster_name DESC';
                   break;
                 case 'views_asc':
                   $sort_order_query = 't.topic_views ASC';
                   break;
                 case 'views_desc':
                   $sort_order_query = 't.topic_views DESC';
                   break;
                 case 'replies_asc':
                   $sort_order_query = 't.topic_replies_real ASC';
                   break;
                 case 'replies_desc':
                   $sort_order_query = 't.topic_replies_real DESC';
                   break;
                 default:
                   $sort_order_query = 't.topic_time DESC';

               }
               return($sort_order_query);
            }

            /** VERSION 4.09
            * Retrieve the first post of each topic in a given forum
            *
            * @param Array $forum_ids  An array containing all the forum ids of the forums that must be included
            * @param Array $parent_only_ids An array containg the forum ids that will only give you the topics inside that forum, and not any children. It is used to mix up with $forum_ids. However if $include_children is false, this will do nothing. If you do not want to use it, declare false on it when calling the function
            * @param Integer $limit The maximum number of topics to be returned
            * @param Integer $offset Set this variable if you don't want the result set begin on the first entry
            * @param Boolean $include_children This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
            * @param String $sort_order It is mysql coding of the query order. This is given by the sort_order_query function (Default is t.topic_time DESC)
            * @param Boolean $allow_attachments (Default is true) Displays attachments (NOT INLINE IT WILL SHOW ALL ATTACHMENTS BUT INLINE WILL NOT BE PROCESSED)
            * @param Boolean $allow_ranks (Default is true) Display ranks
            * @param Boolean $allow_sigs (Default is true) Display signatures
            * @param Boolean $allow_avatar (Default is true) Display avatars
            * @return Array $posts An array holding all the posts and their data
            *
            * NOTES: If you want forum posts + children (subforum) posts. Check include_children as true and check false for $parent_only_ids.
            * If you want forum posts + children (subforum) posts + forum posts not including children posts. Check include_children as true, and input values for $forum_ids and $parent_only_ids
            * If you only want forum posts, DO NOT check $forum_ids as false and use $parent_only_ids. You must check $include_children as false, and simply input values for $forum_ids, and check $parent_only_ids as false.
            * Remember that $parent_only_ids only work when $forum_ids are working regardless of $include_children. So $forum_ids is always the first one you have to use.
            * The function will not output topics which are not approved.
            */
            function get_news($forum_ids = array(), $parent_only_ids = array(), $limit = 10, $offset = 0, $include_children = false, $sort_order = 't.topic_time DESC', $allow_attachments = true, $allow_ranks = true, $allow_sigs = true, $allow_avatar = true)
            {
               global $db, $phpbb_root_path, $phpEx;

               if (!is_array($forum_ids))
               {
                 $forum_ids = array($forum_ids);
               }
               if (!is_array($parent_only_ids))
               {
                 $parent_only_ids = array($parent_only_ids);   
               }

               // If required merge the children into the $forum_ids
               if ($include_children)
               {
                 // This can get very heavy when specifing a big array $forum_ids
                 $child_forums = array();
                 foreach ($forum_ids as $parent)
                 {
                   $children = get_forum_branch($parent, 'children');
                   foreach ($children as $child)
                   {
                     $child_forums[] = $child['forum_id'];
                   }
                 }
                 // Merge
                 $forum_ids = array_merge($forum_ids, $child_forums, $parent_only_ids);
               }

               // Remove duplicates
               $forum_ids = array_unique($forum_ids);

               $post_query = 'p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, t.topic_id, t.forum_id, t.topic_title, t.topic_status, t.poll_start, t.topic_views, t.topic_replies_real, t.topic_type, t.topic_last_poster_name, t.topic_last_post_id, t.topic_last_post_time, u.user_id, u.user_colour';
               if($allow_ranks)
               {
                 $post_query .= ',u.user_rank, u.user_posts';
               }
               if($allow_sigs)
               {
                 $post_query .= ',u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield';
               }
               if($allow_avatar)
               {
                 $post_query .= ',u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height';
               }

               // Now select the post data
               $post_sql_ary = array(
                 'SELECT'   => $post_query,
                 'FROM'      => array(
                   POSTS_TABLE      => 'p',
                   TOPICS_TABLE   => 't',
                 ),
                 'LEFT_JOIN'    => array(
                   array(
                     'FROM'    => array(USERS_TABLE => 'u'),
                     'ON'    => 'u.user_id = p.poster_id',
                   ),
                 ),
                 'WHERE'        => '(' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND p.post_id = t.topic_last_post_id AND t.topic_approved = 1)',
                 'ORDER_BY'    => 't.topic_type DESC,' . $sort_order, #DELETE t.topic_type DESC if you do not want to preserve announcements and stickies.
               );
               $sql   = $db->sql_build_query('SELECT', $post_sql_ary);
               $result   = $db->sql_query_limit($sql, $limit, $offset);

               // Set an array with the posts
               $posts   = array();
               while ($post = $db->sql_fetchrow($result))
               {
                 // Getting the Attachments
                 if($allow_attachments && $post['post_attachment'])
                 {
            //       unset($attachment_urls, $attachment_ids, $attachment_names,$attachment_downloads, $attachment_comments, $attachment_filesize, $num_of_attachment_ids);
                   $attachments_sql_ary = array(
                     'SELECT'   => 'a.attach_id, a.real_filename, a.download_count, a.attach_comment, a.filesize',
                     'FROM'      => array(
                        ATTACHMENTS_TABLE      => 'a',
                     ),
                     'WHERE'        => '(a.post_msg_id = ' . $post['post_id'] . ' AND a.in_message = 0)',
                     'ORDER_BY'    => 'a.attach_id DESC',
                   );
                   $attachments_sql   = $db->sql_build_query('SELECT', $attachments_sql_ary);
                   $attachments_result = $db->sql_query($attachments_sql);

                   $attachment_urls = $attachment_ids = $attachment_names = array();
                   $attachment_downloads = $attachment_comments = $attachment_filesize = array();
                   while ($row = $db->sql_fetchrow($attachments_result))
                   {
                        $attachment_ids[] = $row['attach_id'];
                        $attachment_names[] = $row['real_filename'];
                        $attachment_downloads[] = $row['download_count'];
                        $attachment_comments[] = $row['attach_comment'];
                        $attachment_filesize[] = $row['filesize'];
                   }
                   $db->sql_freeresult($attachments_result);

                   $num_of_attachment_ids = count($attachment_ids);
                   for($i=key($attachment_ids);$i<$num_of_attachment_ids;$i++)
                   {
                     $attachment_urls[$i] = $phpbb_root_path . 'download/file.' . $phpEx . '?id=' . $attachment_ids[$i];
                   }
                 }

                 // Getting the Breadcrumbs
                 unset($breadcrumb_ids);
                 if($post['forum_id'] > 0)
                 {
                   $breadcrumb_ids_sql_ary = array(
                     'SELECT'   => 'f.forum_id, f.forum_name',
                     'FROM'      => array(
                        FORUMS_TABLE      => 'f',
                     ),
                     'WHERE'    => '(f.left_id <= (SELECT left_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . ') AND f.right_id >= (SELECT right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . '))',
                   );
                   $bread_crumb_ids_sql   = $db->sql_build_query('SELECT', $breadcrumb_ids_sql_ary);
                   $bread_crumb_ids_result = $db->sql_query($bread_crumb_ids_sql);
                   while ($row = $db->sql_fetchrow($bread_crumb_ids_result))
                   {
                        $breadcrumb_ids[$row['forum_name']] = $row['forum_id'];
                   }
                   $db->sql_freeresult($bread_crumb_ids_result);
                 }

                 $posts[] = array(
                   // FOR POSTS
                   'forum_id'            => $post['forum_id'],
                   'post_id'            => $post['post_id'],
                   'post_time'            => $post['post_time'],
                   'post_text'            => $post['post_text'],
                   // PARSING
                   'bbcode_bitfield'      => $post['bbcode_bitfield'],
                   'bbcode_uid'         => $post['bbcode_uid'],
                   'enable_bbcode'         => $post['enable_bbcode'],
                   'enable_smilies'      => $post['enable_smilies'],
                   'enable_magic_url'      => $post['enable_magic_url'],
                   // TOPIC DETAILS
                   'topic_id'            => $post['topic_id'],
                   'topic_title'         => $post['topic_title'],
                   'topic_views'         => $post['topic_views'],
                   'topic_replies_real'   => $post['topic_replies_real'],
                   'topic_type'            => $post['topic_type'],
                   'topic_last_post_id'    => $post['topic_last_post_id'],
                   'topic_last_post_time'    => $post['topic_last_post_time'],
                   'topic_status'    => $post['topic_status'],
                   // POLL
                   'poll_start'         => $post['poll_start'],
                   // ATTACHMENTS
                   'allow_attachments'      => $allow_attachments,
                   'is_there_attachments'   => $post['post_attachment'],
                   'attachments'          => (isset($attachment_urls) ? $attachment_urls : array() ),
                   'attachment_names'       => (isset($attachment_names) ? $attachment_names : array() ),
                   'attachment_downloads'    => (isset($attachment_downloads) ? $attachment_downloads : array() ),
                   'attachment_comments'    => (isset($attachment_comments) ? $attachment_comments : array() ),
                   'attachment_filesize'    => (isset($attachment_filesize) ? $attachment_filesize : array() ),
                   'num_of_attachments'    => (isset($num_of_attachment_ids) ? $num_of_attachment_ids : 0 ),
                   // BREADCRUMBS
                   'breadcrumb_ids'       => $breadcrumb_ids,

                   // FOR USER
                   'user_id'            => $post['user_id'],
                   'topic_last_poster_name'   => $post['topic_last_poster_name'],
                   'user_colour'         => $post['user_colour'],
                   // AVATAR
                   'allow_avatar'          => $allow_avatar,
                   'user_avatar'         => ( ($allow_avatar == true) ? $post['user_avatar'] : ''),
                   'user_avatar_type'      => ( ($allow_avatar == true) ? $post['user_avatar_type'] : ''),
                   'user_avatar_width'      => ( ($allow_avatar == true) ? $post['user_avatar_width'] : 0),
                   'user_avatar_height'   => ( ($allow_avatar == true) ? $post['user_avatar_height'] : 0),
                   // RANKS
                   'allow_ranks'          => $allow_ranks,
                   'user_rank_id'          => ( ($allow_ranks == true) ? $post['user_rank'] : -1),
                   'user_posts'          => ( ($allow_ranks == true) ? $post['user_posts'] : 0),
                   // SIGNATURES
                   'allow_sigs'         => $allow_sigs,
                   'user_sig'             => ( ($allow_sigs == true) ? $post['user_sig'] : ''),
                   'user_sig_bbcode_uid'    => ( ($allow_sigs == true) ? $post['user_sig_bbcode_uid'] : ''),
                   'user_sig_bbcode_bitfield'    => ( ($allow_sigs == true) ? $post['user_sig_bbcode_bitfield'] : ''),
                 );
               }
               $db->sql_freeresult($result);

               // Return it
               return $posts;
            }

            ?>

You can see that I am ''merging'' the template version of the 'Show forum threads as news articles' MOD and the 'Top Five' MOD using this line:

Code: Select all

//-- mod: top five ---------------------------------------------------------//
  include($phpbb_root_path . 'includes/top_five.' . $phpEx);
//-- end: top five ---------------------------------------------------------//

top_five.php:

Code: Select all

<?php
/**
*
* @package phpBB3
* @version $Id:
* @copyright (c) 2010 Rich McGirr
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
   exit;
}

/**
* Include only once.
*/
if (!defined('INCLUDES_TOP_FIVE_PHP'))
{
   define('INCLUDES_TOP_FIVE_PHP', true);
   
   global $auth, $cache, $user, $db, $phpbb_root_path, $phpEx, $template;

    $user->add_lang('mods/top_five');

   $excluded_forums = array('561', '560', '442', '569', '585', '586', '604', '614', '615', '617');

   // we have auths, change the sql query below
   $sql_and = (sizeof($excluded_forums)) ? ' AND ' . $db->sql_in_set('t.forum_id', $excluded_forums, true) : '';
   
   
   
   // grab all posts that meet criteria and auths
   $sql_ary = array(
      'SELECT'   => 'u.user_id, u.username, u.user_colour, t.topic_title, t.forum_id, t.topic_last_post_id, t.topic_last_post_time, t.topic_last_poster_name',
      'FROM'      => array(TOPICS_TABLE => 't'),
      'LEFT_JOIN'   => array(
         array(
            'FROM'   => array(USERS_TABLE => 'u'),
            'ON'   => 't.topic_last_poster_id = u.user_id',
            ),
      ),
      'WHERE'      => 't.topic_approved = 1 AND t.topic_status <> ' . ITEM_MOVED . ' ' . $sql_and,
      'ORDER_BY'   => 't.topic_last_post_time DESC',
   );

   $result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_ary), 41);
   $is_row = false;
    while( $row = $db->sql_fetchrow($result) )
    {
      $is_row = true;
      $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']);
      $topic_title = censor_text($row['topic_title']);
      $is_guest = $row['user_id'] != ANONYMOUS ? false : true;
         
          $template->assign_block_vars('top_five_topic',array(
             'U_TOPIC'       => $view_topic_url,
             'USERNAME_FULL'   => $is_guest ? $user->lang['BY'] . ' ' . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['topic_last_poster_name']) : $user->lang['BY'] . ' ' . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
         'LAST_TOPIC_TIME'   => $user->format_date($row['topic_last_post_time']),
             'TOPIC_TITLE'    => $user->lang['IN'] . ' ' . $topic_title));
    }

    $db->sql_freeresult($result);

   // if user doesn't have permission to read any forums, show a message
   if (!$is_row)
   {
      $template->assign_block_vars('top_five_topic', array(
         'NO_TOPIC_TITLE'   => $user->lang['NO_TOPIC_EXIST'],
      ));
   }
   // top five posters
   // an array of user types we dont' bother with
   // could add board founder (USER_FOUNDER) if wanted
   $ignore_users = array(USER_IGNORE, USER_INACTIVE);
   
   if (($user_posts = $cache->get('_top_five_posters')) === false)
   {
       $user_posts = array();

      // grab users with most posts
       $sql = 'SELECT user_id, username, user_colour, user_posts
             FROM ' . USERS_TABLE . '
         WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
            AND user_posts <> 0
          ORDER BY user_posts DESC';
      $result = $db->sql_query_limit($sql, 5);

      while ($row = $db->sql_fetchrow($result))
      {
         $user_posts[$row['user_id']] = array(
            'user_id'      => $row['user_id'],
                'username'      => $row['username'],
                'user_colour'   => $row['user_colour'],
            'user_posts'    => $row['user_posts'],
         );
      }
        $db->sql_freeresult($result);

      // cache this data for five minutes, this improves performance
      $cache->put('_top_five_posters', $user_posts, 300);
   }

   foreach ($user_posts as $row)
   {
      $username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);

      $template->assign_block_vars('top_five_active',array(
         'S_SEARCH_ACTION'   => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $row['user_id'] . '&sr=posts'),
         'POSTS'          => $row['user_posts'],
         'USERNAME_FULL'      => $username_string)
      );
    }

    // newest registered users
   if (($newest_users = $cache->get('_top_five_newest_users')) === false)
   {
       $newest_users = array();

       // grab most recent registered users
      $sql = 'SELECT user_id, username, user_colour, user_regdate
         FROM ' . USERS_TABLE . '
         WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
            AND user_inactive_reason = 0
         ORDER BY user_regdate DESC';
      $result = $db->sql_query_limit($sql, 5);

      while ($row = $db->sql_fetchrow($result))
      {
         $newest_users[$row['user_id']] = array(
            'user_id'            => $row['user_id'],
            'username'            => $row['username'],
              'user_colour'         => $row['user_colour'],
                'user_regdate'         => $row['user_regdate'],
         );
      }
       $db->sql_freeresult($result);

      // cache this data for ever, cache is purged when adding or deleting users
      $cache->put('_top_five_newest_users', $newest_users);
   }

   foreach ($newest_users as $row)
   {
      $username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);

      $template->assign_block_vars('top_five_newest',array(
         'REG_DATE'         => $user->format_date($row['user_regdate']),
         'USERNAME_FULL'      => $username_string)
      );
   }
}
?>

Would it be possible to get some help achieving this?

Again thank you for this great MOD!
Last edited by DFORMS on Thu Jan 26, 2012 10:31 pm
User avatar
DFORMS
Registered User
Posts: 225
Joined: Sun May 30, 2010 12:13 am
Contact:

Re: Modifying portal.php (News Article and Top Five MODs)

by DFORMS » Wed Jan 25, 2012 10:37 pm

OK, I got it working but it's not loading properly : s see here : http://quebecod.ca/index.php. Anyways, I am a student and I just started learning PHP so this code is probably totally screwed up. So yea I merged the portal.php with the index.php (http://fragnet.ca) displayed in my previous post. I also merged the lang_portal.php (language) with the news_article.php (language).

Here is the twisted monster I spawned:

Code: Select all

<?php

            define('IN_PHPBB', true);
         define('IN_PORTAL', true);

            $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';    // Replace with your own root path
            $phpEx = substr(strrchr(__FILE__, '.'), 1);
            include_once($phpbb_root_path . 'common.' . $phpEx);
            include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
            include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
         
         include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
            include($phpbb_root_path . 'portal/includes/functions.' . $phpEx);
         
         $portal_config = obtain_portal_config();

            // Start session management
            $user->session_begin();
            $auth->acl( $user->data );
            $user->setup('mods/news_articles');
         
if (!$portal_config['portal_enable'])
{
   redirect(reapply_sid($phpbb_root_path . 'index.' . $phpEx));
}

$load_center = true;

// Always load center column html-file in portal
$template->assign_var('S_CENTER_COLUMN', true);

if (file_exists($phpbb_root_path . 'install/index.' . $phpEx) && ($user->data['user_type'] == USER_FOUNDER))
{
   $template->assign_var('S_DISPLAY_GENERAL', true);
   $load_center = false;
}

if ($portal_config['portal_phpbb_menu'])
{
   $template->assign_var('S_DISPLAY_PHPBB_MENU', true);
}

if ($portal_config['version_check_time'] + 86400 < time())
{
   // Scare the user of outdated versions
   if (!function_exists('mod_version_check'))
   {
      $phpbb_admin_path = $phpbb_root_path . 'adm/';
      include($phpbb_root_path . 'portal/includes/functions_version_check.' . $phpEx);
   }
   set_portal_config('version_check_time', time());
   set_portal_config('version_check_version', mod_version_check(true));
}

if ($auth->acl_get('a_') && version_compare($portal_config['portal_version'], $portal_config['version_check_version'], '<') && $portal_config['portal_version_check'])
{
   $user->add_lang('mods/lang_portal_acp');
   $template->assign_vars(array(
      'PORTAL_VERSION_CHECK'         => sprintf($user->lang['NOT_UP_TO_DATE'], $user->lang['PORTAL']),
   ));
}

if ($load_center)
{
   if ($portal_config['portal_forum_index'])
   {
      display_forums('', $config['load_moderators'], false);

      $template->assign_vars(array(
         'FORUM_IMG'                  => $user->img('forum_read', 'NO_NEW_POSTS'),
         'FORUM_NEW_IMG'               => $user->img('forum_unread', 'NEW_POSTS'),
         'FORUM_LOCKED_IMG'            => $user->img('forum_read_locked', 'NO_NEW_POSTS_LOCKED'),
         'FORUM_NEW_LOCKED_IMG'         => $user->img('forum_unread_locked', 'NO_NEW_POSTS_LOCKED'),
         'S_DISPLAY_PORTAL_FORUM_INDEX'   => true,
         'U_MARK_FORUMS'               => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums') : '',
         'U_MCP'                     => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=front', true, $user->session_id) : '',
      ));
   }

   if ($portal_config['portal_recent'])
   {
      include($phpbb_root_path . 'portal/block/recent.' . $phpEx);
   }

   if ($portal_config['portal_wordgraph'])
   {
      include($phpbb_root_path . 'portal/block/wordgraph.' . $phpEx);
   }

   if ($portal_config['portal_poll_topic'])
   {
      include($phpbb_root_path . 'portal/block/poll.' . $phpEx);
   }

   if ($portal_config['portal_welcome'])
   {
      include($phpbb_root_path . 'portal/block/welcome.' . $phpEx);
   }

   if ($portal_config['portal_welcome_guest'])
   {
      $template->assign_var('S_DISPLAY_WELCOME_GUEST', true);
   }

   if ($portal_config['portal_announcements'])
   {
      include($phpbb_root_path . 'portal/block/announcements.' . $phpEx);
      $template->assign_var('S_ANNOUNCE_COMPACT', $portal_config['portal_announcements_style']);
   }

   if ($portal_config['portal_news'])
   {
      include($phpbb_root_path . 'portal/block/news.' . $phpEx);
      $template->assign_var('S_NEWS_COMPACT', $portal_config['portal_news_style']);
   }

   if ($portal_config['portal_custom_center'] || $portal_config['portal_custom_small'])
   {
      include($phpbb_root_path . 'portal/block/custom.' . $phpEx);
   }

   if ($portal_config['portal_pay_s_block'] || ($portal_config['portal_pay_c_block']))
   {
      include($phpbb_root_path . 'portal/block/donate.' . $phpEx);
   }

   if ($config['load_online'] && $config['load_online_time'] && $portal_config['portal_whois_online'])
   {
      include($phpbb_root_path . 'portal/block/whois_online.' . $phpEx);
   }
}

// load blocks in the left column
if($portal_config['portal_left_column'])
{
   $template->assign_var('S_LEFT_COLUMN', true);
   
   if ($portal_config['portal_main_menu'])
   {
      include($phpbb_root_path . 'portal/block/main_menu.' . $phpEx);
   }
   
   if ($portal_config['portal_search'])
   {
      include($phpbb_root_path . 'portal/block/search.' . $phpEx);
   }
   
   if ($portal_config['portal_birthdays'])
   {
      include($phpbb_root_path . 'portal/block/birthday_list.' . $phpEx);
   }

   if ($portal_config['portal_attachments'] && $config['allow_attachments'])
   {
      include($phpbb_root_path . 'portal/block/attachments.' . $phpEx);
   }
   
   if ($portal_config['portal_top_posters'])
   {
      include($phpbb_root_path . 'portal/block/top_posters.' . $phpEx);
   }

   if ($portal_config['portal_latest_members'])
   {
      include($phpbb_root_path . 'portal/block/latest_members.' . $phpEx);
   }

   if ($portal_config['portal_random_member'])
   {
      include($phpbb_root_path . 'portal/block/random_member.' . $phpEx);
   }
   
   if ($portal_config['portal_link_us'])
   {
      include($phpbb_root_path . 'portal/block/link_us.' . $phpEx);
   }
   
   if ($portal_config['portal_change_style'])
   {
      include($phpbb_root_path . 'portal/block/change_style.' . $phpEx);
   }

   if ($portal_config['portal_clock'])
   {
      $template->assign_var('S_DISPLAY_CLOCK', true);
   }
}

// load blocks in the right column
if($portal_config['portal_right_column'])
{
   $template->assign_var('S_RIGHT_COLUMN', true);

   if ($portal_config['portal_user_menu'])
   {
      // show login box and user menu
      // only registered user see user menu
      if ($user->data['is_registered'])
      {
         include($phpbb_root_path . 'portal/block/user_menu.' . $phpEx);
      }
      else
      {
         include($phpbb_root_path . 'portal/block/login_box.' . $phpEx);
      }
      $template->assign_var('S_DISPLAY_USERMENU', true);
      
      if($config['allow_topic_notify'] || $config['allow_forum_notify'])
      {
         $template->assign_var('S_DISPLAY_SUBSCRIPTIONS', true);
      }
   }
   
   if ($portal_config['portal_advanced_stat'])
   {
      include($phpbb_root_path . 'portal/block/statistics.' . $phpEx);
   }

   if ($portal_config['portal_minicalendar'])
   {
      include($phpbb_root_path . 'portal/block/mini_cal.' . $phpEx);
   }

   if ($portal_config['portal_leaders'] && $portal_config['portal_leaders_ext'])
   {
      include($phpbb_root_path . 'portal/block/leaders_ext.' . $phpEx);
   }
   elseif ($portal_config['portal_leaders'])
   {
      include($phpbb_root_path . 'portal/block/leaders.' . $phpEx);
   }
   
   if ($portal_config['portal_load_last_visited_bots'])
   {
      include($phpbb_root_path . 'portal/block/latest_bots.' . $phpEx);
   }
   
   if ($portal_config['portal_friends'])
   {
      include($phpbb_root_path . 'portal/block/friends.' . $phpEx);
   }
   
   if ($portal_config['portal_links'])
   {
      include($phpbb_root_path . 'portal/block/links.' . $phpEx);
   }
}

include($phpbb_root_path . 'portal/block/additional_blocks.' . $phpEx);

$template->assign_vars(array(
   'PORTAL_LEFT_COLUMN'   => $portal_config['portal_left_column_width'],
   'PORTAL_RIGHT_COLUMN'   => $portal_config['portal_right_column_width'],
));
           
            // Gets the name of this file
            $this_file = get_this_filesname(__FILE__);

            /*
               FROM HERE, you can now change whatever you want in order to suit your needs.
               For example, you can build the datas to however you like. OR you can change the output variables.
               That is where the html gets outputted.
               If you know php variables and html, you can modify that to your own usage.
            */
            //
            // User Config Options
            //
            $fora_ids = array(2);   // array of forum ids you want posts from
            $parent_ids = true;   // array of parent forum ids, set to false if not used
            $articles = 5;         // number of posts to return
            $offset = 0;         // offset : Set this variable if you don't want the result set begin on the first entry
            $children = true;      // This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
            $sort_order = sort_order_query('active_desc');
            $allow_attach = false;   // Show attachments, if any ?
            $allow_ranks = true;   // Show ranks ?
            $allow_sigs = false;      // Show signatures ?
            $allow_avatar = true;   // Show avatars ?

            //  Get the posts
            $posts = get_news($fora_ids, $parent_ids, $articles, $offset, $children, $sort_order, $allow_attach, $allow_ranks, $allow_sigs, $allow_avatar);

        //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'includes/top_five.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//

            // Assign Common vars
            // Language vars are in: language/en/mods/news_articles.php
            $template->assign_vars(array(
               'L_BREADCRUMBS'   => $user->lang['LN_BREADCRUMBS'],
               'L_NUM_REPLIES'   => $user->lang['LN_NUM_REPLIES'],
               'L_NUM_VIEWS'   => $user->lang['LN_NUM_VIEWS'],
               'L_POST_ATTACHMENT'   => $user->lang['LN_POST_ATTACHMENTS'],
               'L_ATTACHMENTS'   => $user->lang['LN_ATTACHMENTS'],
               'L_IS_ATTACHMENTS'   => $user->lang['LN_IS_ATTACHMENTS'],
               'L_NUM_ATTACHMENTS'   => $user->lang['LN_NUMBER_ATTACHMENTS'],
               'L_ATTACH_DOWNLOADS'   => $user->lang['LN_ATTACH_DOWNLOADS'],
               'L_ATTACH_COMMENTS'      => $user->lang['LN_ATTACH_COMMENTS'],
               'L_DOWNLOAD_EXPLAIN'   => $user->lang['LN_DOWNLOAD_EXPLAIN'],
               'L_POSTED_ON'   => $user->lang['LN_POSTED_ON'],
               'L_POSTED_BY'   => $user->lang['LN_POSTED_BY'],
               'L_RANK_TITLE'   => $user->lang['LN_RANK_TITLE'],
               'L_DISCUSS_TOPIC'   => $user->lang['LN_DISCUSS_TOPIC'],
               'L_INDEX'      => $user->lang['FORUM_INDEX'],
               
               'U_INDEX'      => append_sid($phpbb_root_path),
            ));

            // Build the output
            foreach($posts as $post)
            {
               // First set all the data in vars
               $bbcode_options    = (($post['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);

               // Actual Post
               $post_text      = generate_text_for_display($post['post_text'], $post['bbcode_uid'], $post['bbcode_bitfield'], $bbcode_options);
               $post_text      = bbcode_nl2br($post_text);
               $post_text      = smiley_text($post_text);
               $post_link      = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, array('f' => $post['forum_id'], 't' => $post['topic_id'])) . '#p' . $post['post_id'];
               $post_subject   = censor_text($post['topic_title']);
               $post_time      = $user->format_date($post['post_time']);
               $post_replies_count      = $post['topic_replies_real'];
               $post_views    = $post['topic_views'];
               // Post Tracking (Is it unread or not?)
               $topic_tracking_info = get_complete_topic_tracking($post['forum_id'], $post['topic_id'], false);
               $is_this_unread = (isset($topic_tracking_info[$post['topic_id']]) && $post['topic_last_post_time'] > $topic_tracking_info[$post['topic_id']]) ? true : false;
               // Post Icons
               $post_icon = $icon_alt_text = $topic_type = '';
               topic_status($post, $post['topic_replies_real'], $is_this_unread, $post_icon, $icon_alt_text, $topic_type);
               $post_icon = $user->img($post_icon, $icon_alt_text, false, '', 'src');
               $icon_alt_text = $user->lang[$icon_alt_text];
               // Attachments
               $is_there_attachments    = $post['is_there_attachments'];
               $post_attachments    = $post['attachments'];
               $post_attachment_names    = $post['attachment_names'];
               $post_attachment_downloads    = $post['attachment_downloads'];
               $post_attachment_comments    = $post['attachment_comments'];
               $post_attachment_filesize    = $post['attachment_filesize'];
               $num_of_attachments    = $post['num_of_attachments'];

               
               $poster_avatar = $user_rank_title = $user_rank_image = $user_signature = '';
               // User Information
               if($post['allow_avatar'])
               {
                 $poster_avatar = get_user_avatar($post['user_avatar'], $post['user_avatar_type'], $post['user_avatar_width'], $post['user_avatar_height']);
               }
               $poster_link   = append_sid($phpbb_root_path . 'memberlist.' . $phpEx, array('mode' => 'viewprofile', 'u' => $post['user_id']));
               $poster_name   = get_username_string('full', $post['user_id'], $post['topic_last_poster_name'], $post['user_colour']);
               // Ranks
               if($post['allow_ranks'])
               {
                 if($post['user_id'] != ANONYMOUS)
                 {
            //       unset($user_rank_title, $user_rank_image, $user_rank_image_relative_src);
                   unset($user_rank_image_relative_src);
                   get_user_rank($post['user_rank_id'], $post['user_posts'], $user_rank_title, $user_rank_image, $user_rank_image_relative_src);
                 }
               }
               // Signatures
               if($post['allow_sigs'])
               {
                 $user_signature  = generate_text_for_display($post['user_sig'], $post['user_sig_bbcode_uid'], $post['user_sig_bbcode_bitfield'], $bbcode_options);
                 $user_signature  = bbcode_nl2br($user_signature);
                 $user_signature  = smiley_text($user_signature);
               }

               // THE BUILDING BLOCKS ARE DONE!
               // ITS TIME TO START PUTTING THE BLOCKS TOGETHER INTO COHERENT HTML
               $template->assign_block_vars('postrow', array(
                  'POST_ID'         => $post['post_id'],
                  'POST_ICON'         => $post_icon,
                  'POST_ICON_ALT'      => $icon_alt_text,
                  'POST_SUBJECT'      => $post_subject,
                 
                  'S_UNREAD'         => ($is_this_unread ? true : false),

                  'U_POST_LINK'      => $post_link,
                 
                  'REPLY_COUNT'      => $post_replies_count,
                  'VIEW_COUNT'      => $post_views,
                  'HAS_ATTACHMENTS'   => $is_there_attachments,
                  'POST_TIME'         => $post_time,
                  'POST_AUTHOR'      => $poster_name,
                  'POSTER_AVATAR'      => $poster_avatar,
                  'POSTER_PROFILE'   => $poster_link,
                  'RANK_TITLE'      => $user_rank_title,
                  'RANK_IMG'         => $user_rank_image,
                 
                  'MESSAGE'         => $post_text,
                 
                  'SIGNATURE'       => (!empty($user_signature) ? $user_signature : ''),
                  'L_ATTACH_SHOWN'   => ($allow_attach ? $user->lang['LN_ATTACH_DISPLAY'] : $user->lang['LN_ATTACH_NOT_DISPLAY']),
                  ));

               // Breadcrumbs
               if(isset($post['breadcrumb_ids']))
               {
                 foreach($post['breadcrumb_ids'] as $name => $id)
                 {
                  $template->assign_block_vars('postrow.nav_links', array(
                     'U_VIEW_FORUM'   => append_sid($phpbb_root_path . 'viewforum.' . $phpEx, array('f' => $id)),
                     'FORUM_NAME'   =>   $name,
                  ));
                 }
               }
               if($is_there_attachments && $post['allow_attachments'])
               {
                 foreach($post_attachment_filesize as &$filesize)
                 {
                   $filesize = get_formatted_filesize($filesize);
                 }
                 unset($filesize); // Breaking reference

                 for($j=key($post_attachments);$j<$num_of_attachments;$j++)
                 {
                  $template->assign_block_vars('postrow.attachments', array(
                     'NUM_ATTACHMENTS'   => $num_of_attachments,
                     'URL_ATTACHMENT'   => $post_attachments[$j],
                     'NAME_ATTACHMENT'   => $post_attachment_names[$j],
                     'HAS_COMMENTS'   => (!empty($post_attachment_comments[$j]) ? true : false),
                     'ATTACHMENT_COMMENT'   => (!empty($post_attachment_comments[$j]) ? $post_attachment_comments[$j] : ''),
                     'DOWNLOAD_COUNT'   => ( ($post_attachment_downloads[$j] > 0) ? $post_attachment_downloads[$j] : 0),
                     'FILESIZE'         => $post_attachment_filesize[$j],
                  ));
                 }
               }
            }

            $template->assign_block_vars('navlinks', array(
               'U_VIEW_FORUM'   => append_sid($phpbb_root_path . $this_file . '.' . $phpEx),
               'FORUM_NAME'   => $user->lang['LN_FORUM_NEWS'],
            ));

            // Output page
            page_header($user->lang['LN_FORUM_NEWS']['PORTAL']);

            $template->set_filenames(array(
               'body' => '/portal/portal_body.html')
            );
         
         make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

            page_footer();
            exit;

            /*
            * Start Functions block
            */
            /*
            * Get the name of the file
            *
            * @param $info passed as __FILE__
            * @return (string) the name of the file minus the file ext
            */
            function get_this_filesname($info)
            {
               // Gets the name of this file
               $this_file = pathinfo($info);
               return substr($this_file['basename'], 0, strpos($this_file['basename'], '.'));
            }

            /*
            * @param String $sort_order Has 12 options: (Default is recent_desc)
            * Options:
                1. 'recent_asc' Gives oldest to newest topics
                2. 'recent_desc' Vice versa
                3. 'active_asc' Gives the early replied to recently replied
                4. 'active_desc' Vice versa
                5. 'subject_asc' Gives it in alphabetical order
                6. 'subject_desc' Vice versa
                7. 'author_asc' Gives authors in alphabetical order
                8. 'author_desc' Vice versa
                9. 'views_asc' Gives the least views to most views
               10. 'views_desc' Vice versa
               11. 'replies_asc' Gives the least replies to the most replies
               12. 'replies_desc' Vice versa
            * @return String $sort_order_query The mysql coding to be used in the get_news function
            */
            function sort_order_query($sort_order)
            {
               // switches for sort_order
               switch ($sort_order)
               {
                 case 'recent_asc':
                   $sort_order_query = 't.topic_time ASC';
                   break;
                 case 'recent_desc':
                   $sort_order_query = 't.topic_time DESC';
                   break;
                 case 'active_asc':
                   $sort_order_query = 't.topic_last_post_id ASC';
                   break;
                 case 'active_desc':
                   $sort_order_query = 't.topic_last_post_id DESC';
                   break;
                 case 'subject_asc':
                   $sort_order_query = 't.topic_title ASC';
                   break;
                 case 'subject_desc':
                   $sort_order_query = 't.topic_title DESC';
                   break;
                 case 'author_asc':
                   $sort_order_query = 't.topic_last_poster_name ASC';
                   break;
                 case 'author_desc':
                   $sort_order_query = 't.topic_last_poster_name DESC';
                   break;
                 case 'views_asc':
                   $sort_order_query = 't.topic_views ASC';
                   break;
                 case 'views_desc':
                   $sort_order_query = 't.topic_views DESC';
                   break;
                 case 'replies_asc':
                   $sort_order_query = 't.topic_replies_real ASC';
                   break;
                 case 'replies_desc':
                   $sort_order_query = 't.topic_replies_real DESC';
                   break;
                 default:
                   $sort_order_query = 't.topic_time DESC';

               }
               return($sort_order_query);
            }

            /** VERSION 4.09
            * Retrieve the first post of each topic in a given forum
            *
            * @param Array $forum_ids  An array containing all the forum ids of the forums that must be included
            * @param Array $parent_only_ids An array containg the forum ids that will only give you the topics inside that forum, and not any children. It is used to mix up with $forum_ids. However if $include_children is false, this will do nothing. If you do not want to use it, declare false on it when calling the function
            * @param Integer $limit The maximum number of topics to be returned
            * @param Integer $offset Set this variable if you don't want the result set begin on the first entry
            * @param Boolean $include_children This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
            * @param String $sort_order It is mysql coding of the query order. This is given by the sort_order_query function (Default is t.topic_time DESC)
            * @param Boolean $allow_attachments (Default is true) Displays attachments (NOT INLINE IT WILL SHOW ALL ATTACHMENTS BUT INLINE WILL NOT BE PROCESSED)
            * @param Boolean $allow_ranks (Default is true) Display ranks
            * @param Boolean $allow_sigs (Default is true) Display signatures
            * @param Boolean $allow_avatar (Default is true) Display avatars
            * @return Array $posts An array holding all the posts and their data
            *
            * NOTES: If you want forum posts + children (subforum) posts. Check include_children as true and check false for $parent_only_ids.
            * If you want forum posts + children (subforum) posts + forum posts not including children posts. Check include_children as true, and input values for $forum_ids and $parent_only_ids
            * If you only want forum posts, DO NOT check $forum_ids as false and use $parent_only_ids. You must check $include_children as false, and simply input values for $forum_ids, and check $parent_only_ids as false.
            * Remember that $parent_only_ids only work when $forum_ids are working regardless of $include_children. So $forum_ids is always the first one you have to use.
            * The function will not output topics which are not approved.
            */
            function get_news($forum_ids = array(), $parent_only_ids = array(), $limit = 10, $offset = 0, $include_children = false, $sort_order = 't.topic_time DESC', $allow_attachments = true, $allow_ranks = true, $allow_sigs = true, $allow_avatar = true)
            {
               global $db, $phpbb_root_path, $phpEx;

               if (!is_array($forum_ids))
               {
                 $forum_ids = array($forum_ids);
               }
               if (!is_array($parent_only_ids))
               {
                 $parent_only_ids = array($parent_only_ids);   
               }

               // If required merge the children into the $forum_ids
               if ($include_children)
               {
                 // This can get very heavy when specifing a big array $forum_ids
                 $child_forums = array();
                 foreach ($forum_ids as $parent)
                 {
                   $children = get_forum_branch($parent, 'children');
                   foreach ($children as $child)
                   {
                     $child_forums[] = $child['forum_id'];
                   }
                 }
                 // Merge
                 $forum_ids = array_merge($forum_ids, $child_forums, $parent_only_ids);
               }

               // Remove duplicates
               $forum_ids = array_unique($forum_ids);

               $post_query = 'p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, t.topic_id, t.forum_id, t.topic_title, t.topic_status, t.poll_start, t.topic_views, t.topic_replies_real, t.topic_type, t.topic_last_poster_name, t.topic_last_post_id, t.topic_last_post_time, u.user_id, u.user_colour';
               if($allow_ranks)
               {
                 $post_query .= ',u.user_rank, u.user_posts';
               }
               if($allow_sigs)
               {
                 $post_query .= ',u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield';
               }
               if($allow_avatar)
               {
                 $post_query .= ',u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height';
               }

               // Now select the post data
               $post_sql_ary = array(
                 'SELECT'   => $post_query,
                 'FROM'      => array(
                   POSTS_TABLE      => 'p',
                   TOPICS_TABLE   => 't',
                 ),
                 'LEFT_JOIN'    => array(
                   array(
                     'FROM'    => array(USERS_TABLE => 'u'),
                     'ON'    => 'u.user_id = p.poster_id',
                   ),
                 ),
                 'WHERE'        => '(' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND p.post_id = t.topic_last_post_id AND t.topic_approved = 1)',
                 'ORDER_BY'    => 't.topic_type DESC,' . $sort_order, #DELETE t.topic_type DESC if you do not want to preserve announcements and stickies.
               );
               $sql   = $db->sql_build_query('SELECT', $post_sql_ary);
               $result   = $db->sql_query_limit($sql, $limit, $offset);

               // Set an array with the posts
               $posts   = array();
               while ($post = $db->sql_fetchrow($result))
               {
                 // Getting the Attachments
                 if($allow_attachments && $post['post_attachment'])
                 {
            //       unset($attachment_urls, $attachment_ids, $attachment_names,$attachment_downloads, $attachment_comments, $attachment_filesize, $num_of_attachment_ids);
                   $attachments_sql_ary = array(
                     'SELECT'   => 'a.attach_id, a.real_filename, a.download_count, a.attach_comment, a.filesize',
                     'FROM'      => array(
                        ATTACHMENTS_TABLE      => 'a',
                     ),
                     'WHERE'        => '(a.post_msg_id = ' . $post['post_id'] . ' AND a.in_message = 0)',
                     'ORDER_BY'    => 'a.attach_id DESC',
                   );
                   $attachments_sql   = $db->sql_build_query('SELECT', $attachments_sql_ary);
                   $attachments_result = $db->sql_query($attachments_sql);

                   $attachment_urls = $attachment_ids = $attachment_names = array();
                   $attachment_downloads = $attachment_comments = $attachment_filesize = array();
                   while ($row = $db->sql_fetchrow($attachments_result))
                   {
                        $attachment_ids[] = $row['attach_id'];
                        $attachment_names[] = $row['real_filename'];
                        $attachment_downloads[] = $row['download_count'];
                        $attachment_comments[] = $row['attach_comment'];
                        $attachment_filesize[] = $row['filesize'];
                   }
                   $db->sql_freeresult($attachments_result);

                   $num_of_attachment_ids = count($attachment_ids);
                   for($i=key($attachment_ids);$i<$num_of_attachment_ids;$i++)
                   {
                     $attachment_urls[$i] = $phpbb_root_path . 'download/file.' . $phpEx . '?id=' . $attachment_ids[$i];
                   }
                 }

                 // Getting the Breadcrumbs
                 unset($breadcrumb_ids);
                 if($post['forum_id'] > 0)
                 {
                   $breadcrumb_ids_sql_ary = array(
                     'SELECT'   => 'f.forum_id, f.forum_name',
                     'FROM'      => array(
                        FORUMS_TABLE      => 'f',
                     ),
                     'WHERE'    => '(f.left_id <= (SELECT left_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . ') AND f.right_id >= (SELECT right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . '))',
                   );
                   $bread_crumb_ids_sql   = $db->sql_build_query('SELECT', $breadcrumb_ids_sql_ary);
                   $bread_crumb_ids_result = $db->sql_query($bread_crumb_ids_sql);
                   while ($row = $db->sql_fetchrow($bread_crumb_ids_result))
                   {
                        $breadcrumb_ids[$row['forum_name']] = $row['forum_id'];
                   }
                   $db->sql_freeresult($bread_crumb_ids_result);
                 }

                 $posts[] = array(
                   // FOR POSTS
                   'forum_id'            => $post['forum_id'],
                   'post_id'            => $post['post_id'],
                   'post_time'            => $post['post_time'],
                   'post_text'            => $post['post_text'],
                   // PARSING
                   'bbcode_bitfield'      => $post['bbcode_bitfield'],
                   'bbcode_uid'         => $post['bbcode_uid'],
                   'enable_bbcode'         => $post['enable_bbcode'],
                   'enable_smilies'      => $post['enable_smilies'],
                   'enable_magic_url'      => $post['enable_magic_url'],
                   // TOPIC DETAILS
                   'topic_id'            => $post['topic_id'],
                   'topic_title'         => $post['topic_title'],
                   'topic_views'         => $post['topic_views'],
                   'topic_replies_real'   => $post['topic_replies_real'],
                   'topic_type'            => $post['topic_type'],
                   'topic_last_post_id'    => $post['topic_last_post_id'],
                   'topic_last_post_time'    => $post['topic_last_post_time'],
                   'topic_status'    => $post['topic_status'],
                   // POLL
                   'poll_start'         => $post['poll_start'],
                   // ATTACHMENTS
                   'allow_attachments'      => $allow_attachments,
                   'is_there_attachments'   => $post['post_attachment'],
                   'attachments'          => (isset($attachment_urls) ? $attachment_urls : array() ),
                   'attachment_names'       => (isset($attachment_names) ? $attachment_names : array() ),
                   'attachment_downloads'    => (isset($attachment_downloads) ? $attachment_downloads : array() ),
                   'attachment_comments'    => (isset($attachment_comments) ? $attachment_comments : array() ),
                   'attachment_filesize'    => (isset($attachment_filesize) ? $attachment_filesize : array() ),
                   'num_of_attachments'    => (isset($num_of_attachment_ids) ? $num_of_attachment_ids : 0 ),
                   // BREADCRUMBS
                   'breadcrumb_ids'       => $breadcrumb_ids,

                   // FOR USER
                   'user_id'            => $post['user_id'],
                   'topic_last_poster_name'   => $post['topic_last_poster_name'],
                   'user_colour'         => $post['user_colour'],
                   // AVATAR
                   'allow_avatar'          => $allow_avatar,
                   'user_avatar'         => ( ($allow_avatar == true) ? $post['user_avatar'] : ''),
                   'user_avatar_type'      => ( ($allow_avatar == true) ? $post['user_avatar_type'] : ''),
                   'user_avatar_width'      => ( ($allow_avatar == true) ? $post['user_avatar_width'] : 0),
                   'user_avatar_height'   => ( ($allow_avatar == true) ? $post['user_avatar_height'] : 0),
                   // RANKS
                   'allow_ranks'          => $allow_ranks,
                   'user_rank_id'          => ( ($allow_ranks == true) ? $post['user_rank'] : -1),
                   'user_posts'          => ( ($allow_ranks == true) ? $post['user_posts'] : 0),
                   // SIGNATURES
                   'allow_sigs'         => $allow_sigs,
                   'user_sig'             => ( ($allow_sigs == true) ? $post['user_sig'] : ''),
                   'user_sig_bbcode_uid'    => ( ($allow_sigs == true) ? $post['user_sig_bbcode_uid'] : ''),
                   'user_sig_bbcode_bitfield'    => ( ($allow_sigs == true) ? $post['user_sig_bbcode_bitfield'] : ''),
                 );
               }
               $db->sql_freeresult($result);

               // Return it
               return $posts;
            }

            ?>

I will not be using the column positioning. I will place the blocks manually. Still need help creating a proper version, thanks!

I will keep working on it and post my updates here.
User avatar
DFORMS
Registered User
Posts: 225
Joined: Sun May 30, 2010 12:13 am
Contact:

Re: Modifying portal.php (adding News Article and Top Five MODs)

by DFORMS » Thu Jan 26, 2012 11:27 pm

OK, so now I am using the code from forum/portal/block/latest_members.php etc. directly in my index.php:

Code: Select all

<?php

    define('IN_PHPBB', true);
   define('IN_PORTAL', true); // portal_start

    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';    // Replace with your own root path
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include_once($phpbb_root_path . 'common.' . $phpEx);
    include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
         
   include($phpbb_root_path . 'includes/message_parser.' . $phpEx); // portal
    include($phpbb_root_path . 'portal/includes/functions.' . $phpEx); // portal
         
   $portal_config = obtain_portal_config(); // portal_start

    // Start session management
    $user->session_begin();
    $auth->acl( $user->data );
    $user->setup('mods/news_articles');
         

/* poll_start */
$user->add_lang('viewtopic');

$view = request_var('view', '');
$update = request_var('update', false);
$poll_view = request_var('polls', '');

$poll_view_ar = (strpos($poll_view, ',') !== FALSE) ? explode(',', $poll_view) : (($poll_view != '') ? array($poll_view) : array());

if ($update && $portal_config['portal_poll_allow_vote'])
{
   $up_topic_id = request_var('t', 0);
   $up_forum_id = request_var('f', 0);
   $voted_id = request_var('vote_id', array('' => 0));

   $cur_voted_id = array();
   if ($user->data['is_registered'])
   {
      $sql = 'SELECT poll_option_id
         FROM ' . POLL_VOTES_TABLE . '
         WHERE topic_id = ' . $up_topic_id . '
            AND vote_user_id = ' . $user->data['user_id'];
      $result = $db->sql_query($sql);

      while ($row = $db->sql_fetchrow($result))
      {
         $cur_voted_id[] = $row['poll_option_id'];
      }
      $db->sql_freeresult($result);
   }
   else
   {
      // Cookie based guest tracking ... I don't like this but hum ho
      // it's oft requested. This relies on "nice" users who don't feel
      // the need to delete cookies to mess with results.
      if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $up_topic_id]))
      {
         $cur_voted_id = explode(',', request_var($config['cookie_name'] . '_poll_' . $up_topic_id, 0, false, true));
         $cur_voted_id = array_map('intval', $cur_voted_id);
      }
   }

   $sql = 'SELECT t.poll_length, t.poll_start, t.poll_vote_change, t.topic_status, f.forum_status, t.poll_max_options
         FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
         WHERE t.forum_id = f.forum_id AND t.topic_id = " . (int) $up_topic_id . " AND t.forum_id = " . (int) $up_forum_id;
   $result = $db->sql_query_limit($sql, 1);
   $topic_data = $db->sql_fetchrow($result);
   $db->sql_freeresult($result);

   $s_can_up_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $up_forum_id)) ||
      ($auth->acl_get('f_votechg', $up_forum_id) && $topic_data['poll_vote_change'])) &&
      (($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) &&
      $topic_data['topic_status'] != ITEM_LOCKED &&
      $topic_data['forum_status'] != ITEM_LOCKED) ? true : false;

   if($s_can_up_vote)
   {
      if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id))
      {
         $redirect_url = append_sid("{$phpbb_root_path}portal.$phpEx");

         meta_refresh(5, $redirect_url);
         if (!sizeof($voted_id))
         {
            $message = 'NO_VOTE_OPTION';
         }
         else if (sizeof($voted_id) > $topic_data['poll_max_options'])
         {
            $message = 'TOO_MANY_VOTE_OPTIONS';
         }
         else
         {
            $message = 'VOTE_CONVERTED';
         }

         $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_PORTAL'], '<a href="' . $redirect_url . '">', '</a>');
         trigger_error($message);
      }

      foreach ($voted_id as $option)
      {
         if (in_array($option, $cur_voted_id))
         {
            continue;
         }

         $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
            SET poll_option_total = poll_option_total + 1
            WHERE poll_option_id = ' . (int) $option . '
               AND topic_id = ' . (int) $up_topic_id;
         $db->sql_query($sql);

         if ($user->data['is_registered'])
         {
            $sql_ary = array(
               'topic_id'         => (int) $up_topic_id,
               'poll_option_id'   => (int) $option,
               'vote_user_id'      => (int) $user->data['user_id'],
               'vote_user_ip'      => (string) $user->ip,
            );

            $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
            $db->sql_query($sql);
         }
      }

      foreach ($cur_voted_id as $option)
      {
         if (!in_array($option, $voted_id))
         {
            $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
               SET poll_option_total = poll_option_total - 1
               WHERE poll_option_id = ' . (int) $option . '
                  AND topic_id = ' . (int) $up_topic_id;
            $db->sql_query($sql);

            if ($user->data['is_registered'])
            {
               $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
                  WHERE topic_id = ' . (int) $up_topic_id . '
                     AND poll_option_id = ' . (int) $option . '
                     AND vote_user_id = ' . (int) $user->data['user_id'];
               $db->sql_query($sql);
            }
         }
      }

      if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
      {
         $user->set_cookie('poll_' . $up_topic_id, implode(',', $voted_id), time() + 31536000);
      }

      $sql = 'UPDATE ' . TOPICS_TABLE . '
         SET poll_last_vote = ' . time() . "
         WHERE topic_id = $up_topic_id";
      //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
      $db->sql_query($sql);

      $redirect_url = append_sid("{$phpbb_root_path}portal.$phpEx");

      meta_refresh(5, $redirect_url);
      trigger_error($user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_PORTAL'], '<a href="' . $redirect_url . '">', '</a>'));
   }
}

$where = '';
$poll_forums = false;

// Get readable forums
$forum_list = array();

$forum_list = array_unique(array_keys($auth->acl_getf('f_read', true)));

if($portal_config['portal_poll_topic_id'] !== '')
{
   $poll_forums_config  = explode(',' ,$portal_config['portal_poll_topic_id']);
   
   if($portal_config['portal_poll_exclude_id'])
   {
      $forum_list = array_unique(array_diff($forum_list, $poll_forums_config));
   }
   else
   {
      $forum_list = array_unique(array_intersect($poll_forums_config, $forum_list));
   }
}

$where = '';

if(sizeof($forum_list))
{
   $poll_forums = true;
   $where = 'AND ' . $db->sql_in_set('t.forum_id', $forum_list);
}

if ($portal_config['portal_poll_hide'])
{
   $portal_poll_hide = "AND (t.poll_start + t.poll_length > ". time() ." OR t.poll_length = 0)";
}
else
{
   $portal_poll_hide = '';
}

if ($poll_forums === true)
{

   $sql = 'SELECT t.poll_title, t.poll_start, t.topic_id,  t.topic_first_post_id, t.forum_id, t.poll_length, t.poll_vote_change, t.poll_max_options, t.topic_status, f.forum_status, p.bbcode_bitfield, p.bbcode_uid
         FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . " f
         WHERE t.forum_id = f.forum_id AND t.topic_approved = 1 AND t.poll_start > 0
         {$where}
         AND t.topic_moved_id = 0
         AND p.post_id = t.topic_first_post_id
         {$portal_poll_hide}
         ORDER BY t.poll_start DESC";
   $limit = (isset($portal_config['portal_poll_limit'])) ? $portal_config['portal_poll_limit'] : 3;
   $result = $db->sql_query_limit($sql, $limit);
   $has_poll = false;

   if ($result)
   {
      while($data = $db->sql_fetchrow($result))
      {
         $has_poll = true;
         $poll_has_options = false;

         $topic_id = (int) $data['topic_id'];
         $forum_id = (int) $data['forum_id'];

         $cur_voted_id = array();
         if($portal_config['portal_poll_allow_vote'])
         {
            if ($user->data['is_registered'])
            {
               $vote_sql = 'SELECT poll_option_id
                  FROM ' . POLL_VOTES_TABLE . '
                  WHERE topic_id = ' . $topic_id . '
                     AND vote_user_id = ' . $user->data['user_id'];
               $vote_result = $db->sql_query($vote_sql);

               while ($row = $db->sql_fetchrow($vote_result))
               {
                  $cur_voted_id[] = $row['poll_option_id'];
               }
               $db->sql_freeresult($vote_result);
            }
            else
            {
               // Cookie based guest tracking ... I don't like this but hum ho
               // it's oft requested. This relies on "nice" users who don't feel
               // the need to delete cookies to mess with results.
               if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
               {
                  $cur_voted_id = explode(',', request_var($config['cookie_name'] . '_poll_' . $topic_id, 0, false, true));
                  $cur_voted_id = array_map('intval', $cur_voted_id);
               }
            }

            $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) ||
               ($auth->acl_get('f_votechg', $forum_id) && $data['poll_vote_change'])) &&
               (($data['poll_length'] != 0 && $data['poll_start'] + $data['poll_length'] > time()) || $data['poll_length'] == 0) &&
               $data['topic_status'] != ITEM_LOCKED &&
               $data['forum_status'] != ITEM_LOCKED) ? true : false;
         }
         else
         {
            $s_can_vote = false;
         }

         $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || ($view == 'viewpoll' && in_array($topic_id, $poll_view_ar))) ? true : false;

         $poll_sql = 'SELECT po.poll_option_id, po.poll_option_text, po.poll_option_total
            FROM ' . POLL_OPTIONS_TABLE . " po
            WHERE po.topic_id = {$topic_id}
            ORDER BY po.poll_option_id";

         $poll_result = $db->sql_query($poll_sql);
         $poll_total_votes = 0;
         $poll_data = array();

         if ($poll_result)
         {
            while($polls_data = $db->sql_fetchrow($poll_result))
            {
               $poll_has_options = true;
               $poll_data[] = $polls_data;
               $poll_total_votes += $polls_data['poll_option_total'];
            }
         }
         $db->sql_freeresult($poll_result);

         $make_poll_view = array();

         if(in_array($topic_id, $poll_view_ar) === FALSE)
         {
            $make_poll_view[] = $topic_id;
            $make_poll_view = array_merge($poll_view_ar, $make_poll_view);
         }

         $poll_view_str = urlencode(implode(',', $make_poll_view));
         $portalpoll_url= append_sid("{$phpbb_root_path}portal.$phpEx", "polls=$poll_view_str");
         $portalvote_url= append_sid("{$phpbb_root_path}portal.$phpEx", "f=$forum_id&amp;t=$topic_id");
         $viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
         $poll_end = $data['poll_length'] + $data['poll_start'];

         // Parse BBCode title
         if ($data['bbcode_bitfield'])
         {
            $poll_bbcode = new bbcode();
         }
         else
         {
            $poll_bbcode = false;
         }

         $data['poll_title'] = censor_text($data['poll_title']);

         if ($poll_bbcode !== false)
         {
            $poll_bbcode->bbcode_second_pass($data['poll_title'], $data['bbcode_uid'], $data['bbcode_bitfield']);
         }

         $data['poll_title'] = bbcode_nl2br($data['poll_title']);
         $data['poll_title'] = smiley_text($data['poll_title']);
         unset($poll_bbcode);

         $template->assign_block_vars('poll', array(
            'S_POLL_HAS_OPTIONS'   => $poll_has_options,
            'POLL_QUESTION'         => $data['poll_title'],
            'U_POLL_TOPIC'         => append_sid($phpbb_root_path . 'viewtopic.' . $phpEx . '?t=' . $topic_id . '&amp;f=' . $forum_id),
            'POLL_LENGTH'         => $data['poll_length'],
            'TOPIC_ID'            => $topic_id,
            'TOTAL_VOTES'         => $poll_total_votes,
            'L_MAX_VOTES'         => ($data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $data['poll_max_options']),
            'L_POLL_LENGTH'         => ($data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
            'S_CAN_VOTE'         => $s_can_vote,
            'S_DISPLAY_RESULTS'      => $s_display_results,
            'S_IS_MULTI_CHOICE'      => ($data['poll_max_options'] > 1) ? true : false,
            'S_POLL_ACTION'         => $portalvote_url,
            'U_VIEW_RESULTS'      => $portalpoll_url . '&amp;view=viewpoll#viewpoll',
            'U_VIEW_TOPIC'         => $viewtopic_url,
         ));

         foreach($poll_data as $pd)
         {
            $option_pct = ($poll_total_votes > 0) ? $pd['poll_option_total'] / $poll_total_votes : 0;
            $option_pct_txt = sprintf("%.1d%%", round($option_pct * 100));

            // Parse BBCode option text
            if ($data['bbcode_bitfield'])
            {
               $poll_bbcode = new bbcode();
            }
            else
            {
               $poll_bbcode = false;
            }

            $pd['poll_option_text'] = censor_text($pd['poll_option_text']);

            if ($poll_bbcode !== false)
            {
               $poll_bbcode->bbcode_second_pass($pd['poll_option_text'], $data['bbcode_uid'], $data['bbcode_bitfield']);
            }

            $pd['poll_option_text'] = bbcode_nl2br($pd['poll_option_text']);
            $pd['poll_option_text'] = smiley_text($pd['poll_option_text']);
            unset($poll_bbcode);

            $template->assign_block_vars('poll.poll_option', array(
               'POLL_OPTION_ID'      => $pd['poll_option_id'],
               'POLL_OPTION_CAPTION'   => $pd['poll_option_text'],
               'POLL_OPTION_RESULT'   => $pd['poll_option_total'],
               'POLL_OPTION_PERCENT'   => $option_pct_txt,
               'POLL_OPTION_PCT'      => round($option_pct * 100),
               'POLL_OPTION_IMG'      => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)),
               'POLL_OPTION_VOTED'      => (in_array($pd['poll_option_id'], $cur_voted_id)) ? true : false
            ));
         }
      }
   }
   $db->sql_freeresult($result);

   $template->assign_vars(array(
      'S_DISPLAY_POLL'      => true,
      'S_HAS_POLL'         => $has_poll,
      'POLL_LEFT_CAP_IMG'      => $user->img('poll_left'),
      'POLL_RIGHT_CAP_IMG'   => $user->img('poll_right'),
   ));
}
/* poll_end */

/* random_member_start */
switch ($db->sql_layer)
{
   case 'postgres':
   $sql = 'SELECT *
      FROM ' . USERS_TABLE . '
      WHERE user_type <> ' . USER_IGNORE . '
      AND user_type <> ' . USER_INACTIVE . '
      ORDER BY RANDOM()';
   break;

   case 'mssql':
   case 'mssql_odbc':
   $sql = 'SELECT *
      FROM ' . USERS_TABLE . '
      WHERE user_type <> ' . USER_IGNORE . '
      AND user_type <> ' . USER_INACTIVE . '
      ORDER BY NEWID()';
   break;

   default:
   $sql = 'SELECT *
      FROM ' . USERS_TABLE . '
      WHERE user_type <> ' . USER_IGNORE . '
      AND user_type <> ' . USER_INACTIVE . '
      ORDER BY RAND()';
   break;
}

$result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result);

$avatar_img = get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']);

$rank_title = $rank_img = '';
get_user_rank($row['user_rank'], $row['user_posts'], $rank_title, $rank_img, $rank_img_src);

$username = $row['username'];
$user_id = (int) $row['user_id'];
$colour = $row['user_colour'];

$template->assign_block_vars('random_member', array(
   'USERNAME_FULL'      => get_username_string('full', $user_id, $username, $colour),
   'USERNAME'         => get_username_string('username', $user_id, $username, $colour),
   'USER_COLOR'      => get_username_string('colour', $user_id, $username, $colour),
   'U_VIEW_PROFILE'   => get_username_string('profile', $user_id, $username, $colour),

   'RANK_TITLE'   => $rank_title,
   'RANK_IMG'      => $rank_img,
   'RANK_IMG_SRC'   => $rank_img_src,

   'USER_POSTS'   => (int) $row['user_posts'],
   'AVATAR_IMG'   => $avatar_img,
   'JOINED'      => $user->format_date($row['user_regdate'], 'd.M.Y'),
   'USER_OCC'      => censor_text($row['user_occ']),
   'USER_FROM'      => censor_text($row['user_from']),
   'U_WWW'         => censor_text($row['user_website']),
));
$db->sql_freeresult($result);

$template->assign_var('S_DISPLAY_RANDOM_MEMBER', true);
/* random_member_end */

/* latest_members_start */
if (!defined('IN_PHPBB') || !defined('IN_PORTAL'))
{
   exit;
}

$sql = 'SELECT user_id, username, user_regdate, user_colour
   FROM ' . USERS_TABLE . '
   WHERE user_type <> ' . USER_IGNORE . '
      AND user_inactive_time = 0
   ORDER BY user_regdate DESC';
$result = $db->sql_query_limit($sql, $portal_config['portal_max_last_member']);

while(($row = $db->sql_fetchrow($result)) && ($row['username']))
{
   $template->assign_block_vars('latest_members', array(
      'USERNAME_FULL'   => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
      'JOINED'      => $user->format_date($row['user_regdate'], $format = 'd M'),
   ));
}
$db->sql_freeresult($result);

$template->assign_var('S_DISPLAY_LATEST_MEMBERS', true);
/* latest_members_end */

/* statistiques_start */
if (!defined('IN_PHPBB') || !defined('IN_PORTAL'))
{
   exit;
}

// Better function with only one query
function get_topics_count()
{
   global $db, $user;
   
   $return_ary = array(
      POST_ANNOUNCE => 0,
      POST_STICKY => 0,
   );
   
   $sql_in = array(
      POST_ANNOUNCE,
      POST_STICKY,
   );
   
   $sql = 'SELECT DISTINCT(topic_id) AS topic_id, topic_type AS type
            FROM ' . TOPICS_TABLE . '
            WHERE ' . $db->sql_in_set('topic_type', $sql_in, false);
   $result = $db->sql_query($sql);
   while ($row = $db->sql_fetchrow($result))
   {
      switch($row['type'])
      {
         case POST_ANNOUNCE:
            ++$return_ary[POST_ANNOUNCE];
         break;
         
         case POST_STICKY:
            ++$return_ary[POST_STICKY];
         break;
      }
   }
   $db->sql_freeresult($result);
   
   return $return_ary;
}

// Set some stats, get posts count from forums data if we... hum... retrieve all forums data
$total_posts      = $config['num_posts'];
$total_topics      = $config['num_topics'];
$total_users      = $config['num_users'];
$total_files       = $config['num_files'];

$l_total_user_s    = ($total_users == 0) ? 'TOTAL_USERS_ZERO' : 'TOTAL_USERS_OTHER';
$l_total_post_s    = ($total_posts == 0) ? 'TOTAL_POSTS_ZERO' : 'TOTAL_POSTS_OTHER';
$l_total_topic_s   = ($total_topics == 0) ? 'TOTAL_TOPICS_ZERO' : 'TOTAL_TOPICS_OTHER';

// avarage stat
$board_days = (time() - $config['board_startdate']) / 86400;

$topics_per_day      = ($total_topics) ? round($total_topics / $board_days, 0) : 0;
$posts_per_day      = ($total_posts) ? round($total_posts / $board_days, 0) : 0;
$users_per_day      = round($total_users / $board_days, 0);
$topics_per_user   = ($total_topics) ? round($total_topics / $total_users, 0) : 0;
$posts_per_user      = ($total_posts) ? round($total_posts / $total_users, 0) : 0;
$posts_per_topic   = ($total_topics) ? round($total_posts / $total_topics, 0) : 0;

if ($topics_per_day > $total_topics)
{
   $topics_per_day = $total_topics;
}

if ($posts_per_day > $total_posts)
{
   $posts_per_day = $total_posts;
}

if ($users_per_day > $total_users)
{
   $users_per_day = $total_users;
}

if ($topics_per_user > $total_topics)
{
   $topics_per_user = $total_topics;
}

if ($posts_per_user > $total_posts)
{
   $posts_per_user = $total_posts;
}

if ($posts_per_topic > $total_posts)
{
   $posts_per_topic = $total_posts;
}

$l_topics_per_day_s = ($total_topics == 0) ? 'TOPICS_PER_DAY_ZERO' : 'TOPICS_PER_DAY_OTHER';
$l_posts_per_day_s = ($total_posts == 0) ? 'POSTS_PER_DAY_ZERO' : 'POSTS_PER_DAY_OTHER';
$l_users_per_day_s = ($total_users == 0) ? 'USERS_PER_DAY_ZERO' : 'USERS_PER_DAY_OTHER';
$l_topics_per_user_s = ($total_topics == 0) ? 'TOPICS_PER_USER_ZERO' : 'TOPICS_PER_USER_OTHER';
$l_posts_per_user_s = ($total_posts == 0) ? 'POSTS_PER_USER_ZERO' : 'POSTS_PER_USER_OTHER';
$l_posts_per_topic_s = ($total_posts == 0) ? 'POSTS_PER_TOPIC_ZERO' : 'POSTS_PER_TOPIC_OTHER';

$topics_count = get_topics_count();


// Assign specific vars
$template->assign_vars(array(
   'S_DISPLAY_ADVANCED_STAT'   => true,
   'TOTAL_POSTS'            => sprintf($user->lang[$l_total_post_s], $total_posts),
   'TOTAL_TOPICS'            => sprintf($user->lang[$l_total_topic_s], $total_topics),
   'TOTAL_USERS'            => sprintf($user->lang[$l_total_user_s], $total_users),
   'NEWEST_USER'            => sprintf($user->lang['NEWEST_USER'], get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])),
   'S_ANN'                  => $topics_count[POST_ANNOUNCE],
   'S_SCT'                  => $topics_count[POST_STICKY],
   'S_TOT_ATTACH'            => ($config['allow_attachments']) ? $total_files : 0,

   // avarage stat
   'TOPICS_PER_DAY'   => sprintf($user->lang[$l_topics_per_day_s], $topics_per_day),
   'POSTS_PER_DAY'      => sprintf($user->lang[$l_posts_per_day_s], $posts_per_day),
   'USERS_PER_DAY'      => sprintf($user->lang[$l_users_per_day_s], $users_per_day),
   'TOPICS_PER_USER'   => sprintf($user->lang[$l_topics_per_user_s], $topics_per_user),
   'POSTS_PER_USER'   => sprintf($user->lang[$l_posts_per_user_s], $posts_per_user),
   'POSTS_PER_TOPIC'   => sprintf($user->lang[$l_posts_per_topic_s], $posts_per_topic),
));
/* statistiques_end */

/* user_menu_start */
if (!defined('IN_PHPBB') || !defined('IN_PORTAL'))
{
   exit;
}

//
// + new posts since last visit & you post number
//
if ($user->data['is_registered'])
{
   $ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true))));
   
   if ($auth->acl_get('m_approve'))
   {
      $m_approve_fid_ary = array(-1);
      $m_approve_fid_sql = '';
   }
   else if ($auth->acl_getf_global('m_approve'))
   {
      $m_approve_fid_ary = array_diff(array_keys($auth->acl_getf('!m_approve', true)), $ex_fid_ary);
      $m_approve_fid_sql = ' AND (p.post_approved = 1' . ((sizeof($m_approve_fid_ary)) ? ' OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) : '') . ')';
   }
   else
   {
      $m_approve_fid_ary = array();
      $m_approve_fid_sql = ' AND p.post_approved = 1';
   }

   $sql = 'SELECT COUNT(distinct t.topic_id) as total
            FROM ' . TOPICS_TABLE . ' t
            WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . '
               AND t.topic_moved_id = 0
               ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
               ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
   $result = $db->sql_query($sql);
   $new_posts_count = (int) $db->sql_fetchfield('total');
   $db->sql_freeresult($result);
   
   // unread posts
   $sql_where = 'AND t.topic_moved_id = 0
               ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
               ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
   $unread_list = array();
   $unread_list = get_unread_topics($user->data['user_id'], $sql_where, 'ORDER BY t.topic_id DESC');
   $unread_posts_count = sizeof($unread_list);
}
//
// - new posts since last visit & you post number
//


// Get user avatar and rank
$user_id = $user->data['user_id'];
$username = $user->data['username'];
$colour = $user->data['user_colour'];
$avatar_img = get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height']);
$rank_title = $rank_img = '';
get_user_rank($user->data['user_rank'], $user->data['user_posts'], $rank_title, $rank_img, $rank_img_src);


// Assign specific vars
$template->assign_vars(array(
   'L_NEW_POSTS'   => $user->lang['SEARCH_NEW'] . '&nbsp;(' . $new_posts_count . ')',
   'L_SELF_POSTS'   => $user->lang['SEARCH_SELF'] . '&nbsp;(' . $user->data['user_posts'] . ')',
   'L_UNREAD_POSTS'=> $user->lang['SEARCH_UNREAD'] . '&nbsp;(' . $unread_posts_count . ')',

   'B3P_AVATAR_IMG'    => $avatar_img,
   'B3P_RANK_TITLE'    => $rank_title,
   'B3P_RANK_IMG'        => $rank_img,
   'RANK_IMG_SRC'    => $rank_img_src,

   'USERNAME_FULL'        => get_username_string('full', $user_id, $username, $colour),
   'B3P_USERNAME'            => get_username_string('username', $user_id, $username, $colour),
   'B3P_USER_COLOR'        => get_username_string('colour', $user_id, $username, $colour),
   'U_VIEW_PROFILE'   => get_username_string('profile', $user_id, $username, $colour),

   'U_NEW_POSTS'         => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=newposts'),
   'U_SELF_POSTS'         => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=egosearch'),
   'U_UNREAD_POSTS'      => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=unreadposts'),
   'U_UM_BOOKMARKS'      => ($config['allow_bookmarks']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=main&amp;mode=bookmarks') : '',
   'U_UM_MAIN_SUBSCRIBED'   => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=main&amp;mode=subscribed'),
   'U_MCP'               => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=front', true, $user->session_id) : '',
));
/* user_menu_start */
           
            // Gets the name of this file
            $this_file = get_this_filesname(__FILE__);

            /*
               FROM HERE, you can now change whatever you want in order to suit your needs.
               For example, you can build the datas to however you like. OR you can change the output variables.
               That is where the html gets outputted.
               If you know php variables and html, you can modify that to your own usage.
            */
            //
            // User Config Options
            //
            $fora_ids = array(2);   // array of forum ids you want posts from
            $parent_ids = true;   // array of parent forum ids, set to false if not used
            $articles = 5;         // number of posts to return
            $offset = 0;         // offset : Set this variable if you don't want the result set begin on the first entry
            $children = true;      // This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
            $sort_order = sort_order_query('active_desc');
            $allow_attach = false;   // Show attachments, if any ?
            $allow_ranks = true;   // Show ranks ?
            $allow_sigs = false;      // Show signatures ?
            $allow_avatar = true;   // Show avatars ?

            //  Get the posts
            $posts = get_news($fora_ids, $parent_ids, $articles, $offset, $children, $sort_order, $allow_attach, $allow_ranks, $allow_sigs, $allow_avatar);

        //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'includes/top_five.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//

            // Assign Common vars
            // Language vars are in: language/en/mods/news_articles.php
            $template->assign_vars(array(
               'L_BREADCRUMBS'   => $user->lang['LN_BREADCRUMBS'],
               'L_NUM_REPLIES'   => $user->lang['LN_NUM_REPLIES'],
               'L_NUM_VIEWS'   => $user->lang['LN_NUM_VIEWS'],
               'L_POST_ATTACHMENT'   => $user->lang['LN_POST_ATTACHMENTS'],
               'L_ATTACHMENTS'   => $user->lang['LN_ATTACHMENTS'],
               'L_IS_ATTACHMENTS'   => $user->lang['LN_IS_ATTACHMENTS'],
               'L_NUM_ATTACHMENTS'   => $user->lang['LN_NUMBER_ATTACHMENTS'],
               'L_ATTACH_DOWNLOADS'   => $user->lang['LN_ATTACH_DOWNLOADS'],
               'L_ATTACH_COMMENTS'      => $user->lang['LN_ATTACH_COMMENTS'],
               'L_DOWNLOAD_EXPLAIN'   => $user->lang['LN_DOWNLOAD_EXPLAIN'],
               'L_POSTED_ON'   => $user->lang['LN_POSTED_ON'],
               'L_POSTED_BY'   => $user->lang['LN_POSTED_BY'],
               'L_RANK_TITLE'   => $user->lang['LN_RANK_TITLE'],
               'L_DISCUSS_TOPIC'   => $user->lang['LN_DISCUSS_TOPIC'],
               'L_INDEX'      => $user->lang['FORUM_INDEX'],
               
               'U_INDEX'      => append_sid($phpbb_root_path),
            ));

            // Build the output
            foreach($posts as $post)
            {
               // First set all the data in vars
               $bbcode_options    = (($post['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);

               // Actual Post
               $post_text      = generate_text_for_display($post['post_text'], $post['bbcode_uid'], $post['bbcode_bitfield'], $bbcode_options);
               $post_text      = bbcode_nl2br($post_text);
               $post_text      = smiley_text($post_text);
               $post_link      = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, array('f' => $post['forum_id'], 't' => $post['topic_id'])) . '#p' . $post['post_id'];
               $post_subject   = censor_text($post['topic_title']);
               $post_time      = $user->format_date($post['post_time']);
               $post_replies_count      = $post['topic_replies_real'];
               $post_views    = $post['topic_views'];
               // Post Tracking (Is it unread or not?)
               $topic_tracking_info = get_complete_topic_tracking($post['forum_id'], $post['topic_id'], false);
               $is_this_unread = (isset($topic_tracking_info[$post['topic_id']]) && $post['topic_last_post_time'] > $topic_tracking_info[$post['topic_id']]) ? true : false;
               // Post Icons
               $post_icon = $icon_alt_text = $topic_type = '';
               topic_status($post, $post['topic_replies_real'], $is_this_unread, $post_icon, $icon_alt_text, $topic_type);
               $post_icon = $user->img($post_icon, $icon_alt_text, false, '', 'src');
               $icon_alt_text = $user->lang[$icon_alt_text];
               // Attachments
               $is_there_attachments    = $post['is_there_attachments'];
               $post_attachments    = $post['attachments'];
               $post_attachment_names    = $post['attachment_names'];
               $post_attachment_downloads    = $post['attachment_downloads'];
               $post_attachment_comments    = $post['attachment_comments'];
               $post_attachment_filesize    = $post['attachment_filesize'];
               $num_of_attachments    = $post['num_of_attachments'];

               
               $poster_avatar = $user_rank_title = $user_rank_image = $user_signature = '';
               // User Information
               if($post['allow_avatar'])
               {
                 $poster_avatar = get_user_avatar($post['user_avatar'], $post['user_avatar_type'], $post['user_avatar_width'], $post['user_avatar_height']);
               }
               $poster_link   = append_sid($phpbb_root_path . 'memberlist.' . $phpEx, array('mode' => 'viewprofile', 'u' => $post['user_id']));
               $poster_name   = get_username_string('full', $post['user_id'], $post['topic_last_poster_name'], $post['user_colour']);
               // Ranks
               if($post['allow_ranks'])
               {
                 if($post['user_id'] != ANONYMOUS)
                 {
            //       unset($user_rank_title, $user_rank_image, $user_rank_image_relative_src);
                   unset($user_rank_image_relative_src);
                   get_user_rank($post['user_rank_id'], $post['user_posts'], $user_rank_title, $user_rank_image, $user_rank_image_relative_src);
                 }
               }
               // Signatures
               if($post['allow_sigs'])
               {
                 $user_signature  = generate_text_for_display($post['user_sig'], $post['user_sig_bbcode_uid'], $post['user_sig_bbcode_bitfield'], $bbcode_options);
                 $user_signature  = bbcode_nl2br($user_signature);
                 $user_signature  = smiley_text($user_signature);
               }

               // THE BUILDING BLOCKS ARE DONE!
               // ITS TIME TO START PUTTING THE BLOCKS TOGETHER INTO COHERENT HTML
               $template->assign_block_vars('postrow', array(
                  'POST_ID'         => $post['post_id'],
                  'POST_ICON'         => $post_icon,
                  'POST_ICON_ALT'      => $icon_alt_text,
                  'POST_SUBJECT'      => $post_subject,
                 
                  'S_UNREAD'         => ($is_this_unread ? true : false),

                  'U_POST_LINK'      => $post_link,
                 
                  'REPLY_COUNT'      => $post_replies_count,
                  'VIEW_COUNT'      => $post_views,
                  'HAS_ATTACHMENTS'   => $is_there_attachments,
                  'POST_TIME'         => $post_time,
                  'POST_AUTHOR'      => $poster_name,
                  'POSTER_AVATAR'      => $poster_avatar,
                  'POSTER_PROFILE'   => $poster_link,
                  'RANK_TITLE'      => $user_rank_title,
                  'RANK_IMG'         => $user_rank_image,
                 
                  'MESSAGE'         => $post_text,
                 
                  'SIGNATURE'       => (!empty($user_signature) ? $user_signature : ''),
                  'L_ATTACH_SHOWN'   => ($allow_attach ? $user->lang['LN_ATTACH_DISPLAY'] : $user->lang['LN_ATTACH_NOT_DISPLAY']),
                  ));

               // Breadcrumbs
               if(isset($post['breadcrumb_ids']))
               {
                 foreach($post['breadcrumb_ids'] as $name => $id)
                 {
                  $template->assign_block_vars('postrow.nav_links', array(
                     'U_VIEW_FORUM'   => append_sid($phpbb_root_path . 'viewforum.' . $phpEx, array('f' => $id)),
                     'FORUM_NAME'   =>   $name,
                  ));
                 }
               }
               if($is_there_attachments && $post['allow_attachments'])
               {
                 foreach($post_attachment_filesize as &$filesize)
                 {
                   $filesize = get_formatted_filesize($filesize);
                 }
                 unset($filesize); // Breaking reference

                 for($j=key($post_attachments);$j<$num_of_attachments;$j++)
                 {
                  $template->assign_block_vars('postrow.attachments', array(
                     'NUM_ATTACHMENTS'   => $num_of_attachments,
                     'URL_ATTACHMENT'   => $post_attachments[$j],
                     'NAME_ATTACHMENT'   => $post_attachment_names[$j],
                     'HAS_COMMENTS'   => (!empty($post_attachment_comments[$j]) ? true : false),
                     'ATTACHMENT_COMMENT'   => (!empty($post_attachment_comments[$j]) ? $post_attachment_comments[$j] : ''),
                     'DOWNLOAD_COUNT'   => ( ($post_attachment_downloads[$j] > 0) ? $post_attachment_downloads[$j] : 0),
                     'FILESIZE'         => $post_attachment_filesize[$j],
                  ));
                 }
               }
            }

            $template->assign_block_vars('navlinks', array(
               'U_VIEW_FORUM'   => append_sid($phpbb_root_path . $this_file . '.' . $phpEx),
               'FORUM_NAME'   => $user->lang['LN_FORUM_NEWS'],
            ));

            // Output page
            page_header($user->lang['LN_FORUM_NEWS']['PORTAL']);

            $template->set_filenames(array(
               'body' => '/portal/portal_body.html')
            );
         
         make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

            page_footer();
            exit;

            /*
            * Start Functions block
            */
            /*
            * Get the name of the file
            *
            * @param $info passed as __FILE__
            * @return (string) the name of the file minus the file ext
            */
            function get_this_filesname($info)
            {
               // Gets the name of this file
               $this_file = pathinfo($info);
               return substr($this_file['basename'], 0, strpos($this_file['basename'], '.'));
            }

            /*
            * @param String $sort_order Has 12 options: (Default is recent_desc)
            * Options:
                1. 'recent_asc' Gives oldest to newest topics
                2. 'recent_desc' Vice versa
                3. 'active_asc' Gives the early replied to recently replied
                4. 'active_desc' Vice versa
                5. 'subject_asc' Gives it in alphabetical order
                6. 'subject_desc' Vice versa
                7. 'author_asc' Gives authors in alphabetical order
                8. 'author_desc' Vice versa
                9. 'views_asc' Gives the least views to most views
               10. 'views_desc' Vice versa
               11. 'replies_asc' Gives the least replies to the most replies
               12. 'replies_desc' Vice versa
            * @return String $sort_order_query The mysql coding to be used in the get_news function
            */
            function sort_order_query($sort_order)
            {
               // switches for sort_order
               switch ($sort_order)
               {
                 case 'recent_asc':
                   $sort_order_query = 't.topic_time ASC';
                   break;
                 case 'recent_desc':
                   $sort_order_query = 't.topic_time DESC';
                   break;
                 case 'active_asc':
                   $sort_order_query = 't.topic_last_post_id ASC';
                   break;
                 case 'active_desc':
                   $sort_order_query = 't.topic_last_post_id DESC';
                   break;
                 case 'subject_asc':
                   $sort_order_query = 't.topic_title ASC';
                   break;
                 case 'subject_desc':
                   $sort_order_query = 't.topic_title DESC';
                   break;
                 case 'author_asc':
                   $sort_order_query = 't.topic_last_poster_name ASC';
                   break;
                 case 'author_desc':
                   $sort_order_query = 't.topic_last_poster_name DESC';
                   break;
                 case 'views_asc':
                   $sort_order_query = 't.topic_views ASC';
                   break;
                 case 'views_desc':
                   $sort_order_query = 't.topic_views DESC';
                   break;
                 case 'replies_asc':
                   $sort_order_query = 't.topic_replies_real ASC';
                   break;
                 case 'replies_desc':
                   $sort_order_query = 't.topic_replies_real DESC';
                   break;
                 default:
                   $sort_order_query = 't.topic_time DESC';

               }
               return($sort_order_query);
            }

            /** VERSION 4.09
            * Retrieve the first post of each topic in a given forum
            *
            * @param Array $forum_ids  An array containing all the forum ids of the forums that must be included
            * @param Array $parent_only_ids An array containg the forum ids that will only give you the topics inside that forum, and not any children. It is used to mix up with $forum_ids. However if $include_children is false, this will do nothing. If you do not want to use it, declare false on it when calling the function
            * @param Integer $limit The maximum number of topics to be returned
            * @param Integer $offset Set this variable if you don't want the result set begin on the first entry
            * @param Boolean $include_children This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
            * @param String $sort_order It is mysql coding of the query order. This is given by the sort_order_query function (Default is t.topic_time DESC)
            * @param Boolean $allow_attachments (Default is true) Displays attachments (NOT INLINE IT WILL SHOW ALL ATTACHMENTS BUT INLINE WILL NOT BE PROCESSED)
            * @param Boolean $allow_ranks (Default is true) Display ranks
            * @param Boolean $allow_sigs (Default is true) Display signatures
            * @param Boolean $allow_avatar (Default is true) Display avatars
            * @return Array $posts An array holding all the posts and their data
            *
            * NOTES: If you want forum posts + children (subforum) posts. Check include_children as true and check false for $parent_only_ids.
            * If you want forum posts + children (subforum) posts + forum posts not including children posts. Check include_children as true, and input values for $forum_ids and $parent_only_ids
            * If you only want forum posts, DO NOT check $forum_ids as false and use $parent_only_ids. You must check $include_children as false, and simply input values for $forum_ids, and check $parent_only_ids as false.
            * Remember that $parent_only_ids only work when $forum_ids are working regardless of $include_children. So $forum_ids is always the first one you have to use.
            * The function will not output topics which are not approved.
            */
            function get_news($forum_ids = array(), $parent_only_ids = array(), $limit = 10, $offset = 0, $include_children = false, $sort_order = 't.topic_time DESC', $allow_attachments = true, $allow_ranks = true, $allow_sigs = true, $allow_avatar = true)
            {
               global $db, $phpbb_root_path, $phpEx;

               if (!is_array($forum_ids))
               {
                 $forum_ids = array($forum_ids);
               }
               if (!is_array($parent_only_ids))
               {
                 $parent_only_ids = array($parent_only_ids);   
               }

               // If required merge the children into the $forum_ids
               if ($include_children)
               {
                 // This can get very heavy when specifing a big array $forum_ids
                 $child_forums = array();
                 foreach ($forum_ids as $parent)
                 {
                   $children = get_forum_branch($parent, 'children');
                   foreach ($children as $child)
                   {
                     $child_forums[] = $child['forum_id'];
                   }
                 }
                 // Merge
                 $forum_ids = array_merge($forum_ids, $child_forums, $parent_only_ids);
               }

               // Remove duplicates
               $forum_ids = array_unique($forum_ids);

               $post_query = 'p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, t.topic_id, t.forum_id, t.topic_title, t.topic_status, t.poll_start, t.topic_views, t.topic_replies_real, t.topic_type, t.topic_last_poster_name, t.topic_last_post_id, t.topic_last_post_time, u.user_id, u.user_colour';
               if($allow_ranks)
               {
                 $post_query .= ',u.user_rank, u.user_posts';
               }
               if($allow_sigs)
               {
                 $post_query .= ',u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield';
               }
               if($allow_avatar)
               {
                 $post_query .= ',u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height';
               }

               // Now select the post data
               $post_sql_ary = array(
                 'SELECT'   => $post_query,
                 'FROM'      => array(
                   POSTS_TABLE      => 'p',
                   TOPICS_TABLE   => 't',
                 ),
                 'LEFT_JOIN'    => array(
                   array(
                     'FROM'    => array(USERS_TABLE => 'u'),
                     'ON'    => 'u.user_id = p.poster_id',
                   ),
                 ),
                 'WHERE'        => '(' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND p.post_id = t.topic_last_post_id AND t.topic_approved = 1)',
                 'ORDER_BY'    => 't.topic_type DESC,' . $sort_order, #DELETE t.topic_type DESC if you do not want to preserve announcements and stickies.
               );
               $sql   = $db->sql_build_query('SELECT', $post_sql_ary);
               $result   = $db->sql_query_limit($sql, $limit, $offset);

               // Set an array with the posts
               $posts   = array();
               while ($post = $db->sql_fetchrow($result))
               {
                 // Getting the Attachments
                 if($allow_attachments && $post['post_attachment'])
                 {
            //       unset($attachment_urls, $attachment_ids, $attachment_names,$attachment_downloads, $attachment_comments, $attachment_filesize, $num_of_attachment_ids);
                   $attachments_sql_ary = array(
                     'SELECT'   => 'a.attach_id, a.real_filename, a.download_count, a.attach_comment, a.filesize',
                     'FROM'      => array(
                        ATTACHMENTS_TABLE      => 'a',
                     ),
                     'WHERE'        => '(a.post_msg_id = ' . $post['post_id'] . ' AND a.in_message = 0)',
                     'ORDER_BY'    => 'a.attach_id DESC',
                   );
                   $attachments_sql   = $db->sql_build_query('SELECT', $attachments_sql_ary);
                   $attachments_result = $db->sql_query($attachments_sql);

                   $attachment_urls = $attachment_ids = $attachment_names = array();
                   $attachment_downloads = $attachment_comments = $attachment_filesize = array();
                   while ($row = $db->sql_fetchrow($attachments_result))
                   {
                        $attachment_ids[] = $row['attach_id'];
                        $attachment_names[] = $row['real_filename'];
                        $attachment_downloads[] = $row['download_count'];
                        $attachment_comments[] = $row['attach_comment'];
                        $attachment_filesize[] = $row['filesize'];
                   }
                   $db->sql_freeresult($attachments_result);

                   $num_of_attachment_ids = count($attachment_ids);
                   for($i=key($attachment_ids);$i<$num_of_attachment_ids;$i++)
                   {
                     $attachment_urls[$i] = $phpbb_root_path . 'download/file.' . $phpEx . '?id=' . $attachment_ids[$i];
                   }
                 }

                 // Getting the Breadcrumbs
                 unset($breadcrumb_ids);
                 if($post['forum_id'] > 0)
                 {
                   $breadcrumb_ids_sql_ary = array(
                     'SELECT'   => 'f.forum_id, f.forum_name',
                     'FROM'      => array(
                        FORUMS_TABLE      => 'f',
                     ),
                     'WHERE'    => '(f.left_id <= (SELECT left_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . ') AND f.right_id >= (SELECT right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . '))',
                   );
                   $bread_crumb_ids_sql   = $db->sql_build_query('SELECT', $breadcrumb_ids_sql_ary);
                   $bread_crumb_ids_result = $db->sql_query($bread_crumb_ids_sql);
                   while ($row = $db->sql_fetchrow($bread_crumb_ids_result))
                   {
                        $breadcrumb_ids[$row['forum_name']] = $row['forum_id'];
                   }
                   $db->sql_freeresult($bread_crumb_ids_result);
                 }

                 $posts[] = array(
                   // FOR POSTS
                   'forum_id'            => $post['forum_id'],
                   'post_id'            => $post['post_id'],
                   'post_time'            => $post['post_time'],
                   'post_text'            => $post['post_text'],
                   // PARSING
                   'bbcode_bitfield'      => $post['bbcode_bitfield'],
                   'bbcode_uid'         => $post['bbcode_uid'],
                   'enable_bbcode'         => $post['enable_bbcode'],
                   'enable_smilies'      => $post['enable_smilies'],
                   'enable_magic_url'      => $post['enable_magic_url'],
                   // TOPIC DETAILS
                   'topic_id'            => $post['topic_id'],
                   'topic_title'         => $post['topic_title'],
                   'topic_views'         => $post['topic_views'],
                   'topic_replies_real'   => $post['topic_replies_real'],
                   'topic_type'            => $post['topic_type'],
                   'topic_last_post_id'    => $post['topic_last_post_id'],
                   'topic_last_post_time'    => $post['topic_last_post_time'],
                   'topic_status'    => $post['topic_status'],
                   // POLL
                   'poll_start'         => $post['poll_start'],
                   // ATTACHMENTS
                   'allow_attachments'      => $allow_attachments,
                   'is_there_attachments'   => $post['post_attachment'],
                   'attachments'          => (isset($attachment_urls) ? $attachment_urls : array() ),
                   'attachment_names'       => (isset($attachment_names) ? $attachment_names : array() ),
                   'attachment_downloads'    => (isset($attachment_downloads) ? $attachment_downloads : array() ),
                   'attachment_comments'    => (isset($attachment_comments) ? $attachment_comments : array() ),
                   'attachment_filesize'    => (isset($attachment_filesize) ? $attachment_filesize : array() ),
                   'num_of_attachments'    => (isset($num_of_attachment_ids) ? $num_of_attachment_ids : 0 ),
                   // BREADCRUMBS
                   'breadcrumb_ids'       => $breadcrumb_ids,

                   // FOR USER
                   'user_id'            => $post['user_id'],
                   'topic_last_poster_name'   => $post['topic_last_poster_name'],
                   'user_colour'         => $post['user_colour'],
                   // AVATAR
                   'allow_avatar'          => $allow_avatar,
                   'user_avatar'         => ( ($allow_avatar == true) ? $post['user_avatar'] : ''),
                   'user_avatar_type'      => ( ($allow_avatar == true) ? $post['user_avatar_type'] : ''),
                   'user_avatar_width'      => ( ($allow_avatar == true) ? $post['user_avatar_width'] : 0),
                   'user_avatar_height'   => ( ($allow_avatar == true) ? $post['user_avatar_height'] : 0),
                   // RANKS
                   'allow_ranks'          => $allow_ranks,
                   'user_rank_id'          => ( ($allow_ranks == true) ? $post['user_rank'] : -1),
                   'user_posts'          => ( ($allow_ranks == true) ? $post['user_posts'] : 0),
                   // SIGNATURES
                   'allow_sigs'         => $allow_sigs,
                   'user_sig'             => ( ($allow_sigs == true) ? $post['user_sig'] : ''),
                   'user_sig_bbcode_uid'    => ( ($allow_sigs == true) ? $post['user_sig_bbcode_uid'] : ''),
                   'user_sig_bbcode_bitfield'    => ( ($allow_sigs == true) ? $post['user_sig_bbcode_bitfield'] : ''),
                 );
               }
               $db->sql_freeresult($result);

               // Return it
               return $posts;
            }
?>

I was hoping not having to install and modifying my database. I will do some more testing and report back here. Still hoping to get some support, thank you.
User avatar
DFORMS
Registered User
Posts: 225
Joined: Sun May 30, 2010 12:13 am
Contact:

Re: Modifying portal.php (adding News Article and Top Five MODs)

by DFORMS » Fri Jan 27, 2012 8:31 pm

Update

Code: Select all

<?php

    define('IN_PHPBB', true);
   define('IN_PORTAL', true); // portal_start

    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';    // Replace with your own root path
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include_once($phpbb_root_path . 'common.' . $phpEx);
    include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
         
   include($phpbb_root_path . 'includes/message_parser.' . $phpEx); // portal
    include($phpbb_root_path . 'portal/includes/functions.' . $phpEx); // portal
         
   $portal_config = obtain_portal_config(); // portal

    // Start session management
    $user->session_begin();
    $auth->acl( $user->data );
    $user->setup('mods/news_articles'); // portal - mixed with lang_portal
      
           
            // Gets the name of this file
            $this_file = get_this_filesname(__FILE__);

            /*
               FROM HERE, you can now change whatever you want in order to suit your needs.
               For example, you can build the datas to however you like. OR you can change the output variables.
               That is where the html gets outputted.
               If you know php variables and html, you can modify that to your own usage.
            */
            //
            // User Config Options
            //
            $fora_ids = array(2);   // array of forum ids you want posts from
            $parent_ids = true;   // array of parent forum ids, set to false if not used
            $articles = 5;         // number of posts to return
            $offset = 0;         // offset : Set this variable if you don't want the result set begin on the first entry
            $children = true;      // This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
            $sort_order = sort_order_query('active_desc');
            $allow_attach = false;   // Show attachments, if any ?
            $allow_ranks = true;   // Show ranks ?
            $allow_sigs = false;      // Show signatures ?
            $allow_avatar = true;   // Show avatars ?

            //  Get the posts
            $posts = get_news($fora_ids, $parent_ids, $articles, $offset, $children, $sort_order, $allow_attach, $allow_ranks, $allow_sigs, $allow_avatar);
      
        //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'includes/top_five.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//
      
      // portal_start
      
        //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'portal/block/latest_members.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//
      
      //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'portal/block/poll.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//
      
      //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'portal/block/random_member.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//
      
      //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'portal/block/statistics.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//
      
      //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'portal/block/user_menu.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//
      
      //-- mod: top five ---------------------------------------------------------//
           include($phpbb_root_path . 'portal/block/news.' . $phpEx);
        //-- end: top five ---------------------------------------------------------//
      
      // portal_end

            // Assign Common vars
            // Language vars are in: language/en/mods/news_articles.php
            $template->assign_vars(array(
               'L_BREADCRUMBS'   => $user->lang['LN_BREADCRUMBS'],
               'L_NUM_REPLIES'   => $user->lang['LN_NUM_REPLIES'],
               'L_NUM_VIEWS'   => $user->lang['LN_NUM_VIEWS'],
               'L_POST_ATTACHMENT'   => $user->lang['LN_POST_ATTACHMENTS'],
               'L_ATTACHMENTS'   => $user->lang['LN_ATTACHMENTS'],
               'L_IS_ATTACHMENTS'   => $user->lang['LN_IS_ATTACHMENTS'],
               'L_NUM_ATTACHMENTS'   => $user->lang['LN_NUMBER_ATTACHMENTS'],
               'L_ATTACH_DOWNLOADS'   => $user->lang['LN_ATTACH_DOWNLOADS'],
               'L_ATTACH_COMMENTS'      => $user->lang['LN_ATTACH_COMMENTS'],
               'L_DOWNLOAD_EXPLAIN'   => $user->lang['LN_DOWNLOAD_EXPLAIN'],
               'L_POSTED_ON'   => $user->lang['LN_POSTED_ON'],
               'L_POSTED_BY'   => $user->lang['LN_POSTED_BY'],
               'L_RANK_TITLE'   => $user->lang['LN_RANK_TITLE'],
               'L_DISCUSS_TOPIC'   => $user->lang['LN_DISCUSS_TOPIC'],
               'L_INDEX'      => $user->lang['FORUM_INDEX'],
               
               'U_INDEX'      => append_sid($phpbb_root_path),
            ));

            // Build the output
            foreach($posts as $post)
            {
               // First set all the data in vars
               $bbcode_options    = (($post['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);

               // Actual Post
               $post_text      = generate_text_for_display($post['post_text'], $post['bbcode_uid'], $post['bbcode_bitfield'], $bbcode_options);
               $post_text      = bbcode_nl2br($post_text);
               $post_text      = smiley_text($post_text);
               $post_link      = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, array('f' => $post['forum_id'], 't' => $post['topic_id'])) . '#p' . $post['post_id'];
               $post_subject   = censor_text($post['topic_title']);
               $post_time      = $user->format_date($post['post_time']);
               $post_replies_count      = $post['topic_replies_real'];
               $post_views    = $post['topic_views'];
               // Post Tracking (Is it unread or not?)
               $topic_tracking_info = get_complete_topic_tracking($post['forum_id'], $post['topic_id'], false);
               $is_this_unread = (isset($topic_tracking_info[$post['topic_id']]) && $post['topic_last_post_time'] > $topic_tracking_info[$post['topic_id']]) ? true : false;
               // Post Icons
               $post_icon = $icon_alt_text = $topic_type = '';
               topic_status($post, $post['topic_replies_real'], $is_this_unread, $post_icon, $icon_alt_text, $topic_type);
               $post_icon = $user->img($post_icon, $icon_alt_text, false, '', 'src');
               $icon_alt_text = $user->lang[$icon_alt_text];
               // Attachments
               $is_there_attachments    = $post['is_there_attachments'];
               $post_attachments    = $post['attachments'];
               $post_attachment_names    = $post['attachment_names'];
               $post_attachment_downloads    = $post['attachment_downloads'];
               $post_attachment_comments    = $post['attachment_comments'];
               $post_attachment_filesize    = $post['attachment_filesize'];
               $num_of_attachments    = $post['num_of_attachments'];

               
               $poster_avatar = $user_rank_title = $user_rank_image = $user_signature = '';
               // User Information
               if($post['allow_avatar'])
               {
                 $poster_avatar = get_user_avatar($post['user_avatar'], $post['user_avatar_type'], $post['user_avatar_width'], $post['user_avatar_height']);
               }
               $poster_link   = append_sid($phpbb_root_path . 'memberlist.' . $phpEx, array('mode' => 'viewprofile', 'u' => $post['user_id']));
               $poster_name   = get_username_string('full', $post['user_id'], $post['topic_last_poster_name'], $post['user_colour']);
               // Ranks
               if($post['allow_ranks'])
               {
                 if($post['user_id'] != ANONYMOUS)
                 {
            //       unset($user_rank_title, $user_rank_image, $user_rank_image_relative_src);
                   unset($user_rank_image_relative_src);
                   get_user_rank($post['user_rank_id'], $post['user_posts'], $user_rank_title, $user_rank_image, $user_rank_image_relative_src);
                 }
               }
               // Signatures
               if($post['allow_sigs'])
               {
                 $user_signature  = generate_text_for_display($post['user_sig'], $post['user_sig_bbcode_uid'], $post['user_sig_bbcode_bitfield'], $bbcode_options);
                 $user_signature  = bbcode_nl2br($user_signature);
                 $user_signature  = smiley_text($user_signature);
               }

               // THE BUILDING BLOCKS ARE DONE!
               // ITS TIME TO START PUTTING THE BLOCKS TOGETHER INTO COHERENT HTML
               $template->assign_block_vars('postrow', array(
                  'POST_ID'         => $post['post_id'],
                  'POST_ICON'         => $post_icon,
                  'POST_ICON_ALT'      => $icon_alt_text,
                  'POST_SUBJECT'      => $post_subject,
                 
                  'S_UNREAD'         => ($is_this_unread ? true : false),

                  'U_POST_LINK'      => $post_link,
                 
                  'REPLY_COUNT'      => $post_replies_count,
                  'VIEW_COUNT'      => $post_views,
                  'HAS_ATTACHMENTS'   => $is_there_attachments,
                  'POST_TIME'         => $post_time,
                  'POST_AUTHOR'      => $poster_name,
                  'POSTER_AVATAR'      => $poster_avatar,
                  'POSTER_PROFILE'   => $poster_link,
                  'RANK_TITLE'      => $user_rank_title,
                  'RANK_IMG'         => $user_rank_image,
                 
                  'MESSAGE'         => $post_text,
                 
                  'SIGNATURE'       => (!empty($user_signature) ? $user_signature : ''),
                  'L_ATTACH_SHOWN'   => ($allow_attach ? $user->lang['LN_ATTACH_DISPLAY'] : $user->lang['LN_ATTACH_NOT_DISPLAY']),
                  ));

               // Breadcrumbs
               if(isset($post['breadcrumb_ids']))
               {
                 foreach($post['breadcrumb_ids'] as $name => $id)
                 {
                  $template->assign_block_vars('postrow.nav_links', array(
                     'U_VIEW_FORUM'   => append_sid($phpbb_root_path . 'viewforum.' . $phpEx, array('f' => $id)),
                     'FORUM_NAME'   =>   $name,
                  ));
                 }
               }
               if($is_there_attachments && $post['allow_attachments'])
               {
                 foreach($post_attachment_filesize as &$filesize)
                 {
                   $filesize = get_formatted_filesize($filesize);
                 }
                 unset($filesize); // Breaking reference

                 for($j=key($post_attachments);$j<$num_of_attachments;$j++)
                 {
                  $template->assign_block_vars('postrow.attachments', array(
                     'NUM_ATTACHMENTS'   => $num_of_attachments,
                     'URL_ATTACHMENT'   => $post_attachments[$j],
                     'NAME_ATTACHMENT'   => $post_attachment_names[$j],
                     'HAS_COMMENTS'   => (!empty($post_attachment_comments[$j]) ? true : false),
                     'ATTACHMENT_COMMENT'   => (!empty($post_attachment_comments[$j]) ? $post_attachment_comments[$j] : ''),
                     'DOWNLOAD_COUNT'   => ( ($post_attachment_downloads[$j] > 0) ? $post_attachment_downloads[$j] : 0),
                     'FILESIZE'         => $post_attachment_filesize[$j],
                  ));
                 }
               }
            }

            $template->assign_block_vars('navlinks', array(
               'U_VIEW_FORUM'   => append_sid($phpbb_root_path . $this_file . '.' . $phpEx),
               'FORUM_NAME'   => $user->lang['LN_FORUM_NEWS'],
            ));

            // Output page
            page_header($user->lang['LN_FORUM_NEWS']['PORTAL']);

            $template->set_filenames(array(
               'body' => '/portal/portal_body.html')
            );
         
         make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

            page_footer();
            exit;

            /*
            * Start Functions block
            */
            /*
            * Get the name of the file
            *
            * @param $info passed as __FILE__
            * @return (string) the name of the file minus the file ext
            */
            function get_this_filesname($info)
            {
               // Gets the name of this file
               $this_file = pathinfo($info);
               return substr($this_file['basename'], 0, strpos($this_file['basename'], '.'));
            }

            /*
            * @param String $sort_order Has 12 options: (Default is recent_desc)
            * Options:
                1. 'recent_asc' Gives oldest to newest topics
                2. 'recent_desc' Vice versa
                3. 'active_asc' Gives the early replied to recently replied
                4. 'active_desc' Vice versa
                5. 'subject_asc' Gives it in alphabetical order
                6. 'subject_desc' Vice versa
                7. 'author_asc' Gives authors in alphabetical order
                8. 'author_desc' Vice versa
                9. 'views_asc' Gives the least views to most views
               10. 'views_desc' Vice versa
               11. 'replies_asc' Gives the least replies to the most replies
               12. 'replies_desc' Vice versa
            * @return String $sort_order_query The mysql coding to be used in the get_news function
            */
            function sort_order_query($sort_order)
            {
               // switches for sort_order
               switch ($sort_order)
               {
                 case 'recent_asc':
                   $sort_order_query = 't.topic_time ASC';
                   break;
                 case 'recent_desc':
                   $sort_order_query = 't.topic_time DESC';
                   break;
                 case 'active_asc':
                   $sort_order_query = 't.topic_last_post_id ASC';
                   break;
                 case 'active_desc':
                   $sort_order_query = 't.topic_last_post_id DESC';
                   break;
                 case 'subject_asc':
                   $sort_order_query = 't.topic_title ASC';
                   break;
                 case 'subject_desc':
                   $sort_order_query = 't.topic_title DESC';
                   break;
                 case 'author_asc':
                   $sort_order_query = 't.topic_last_poster_name ASC';
                   break;
                 case 'author_desc':
                   $sort_order_query = 't.topic_last_poster_name DESC';
                   break;
                 case 'views_asc':
                   $sort_order_query = 't.topic_views ASC';
                   break;
                 case 'views_desc':
                   $sort_order_query = 't.topic_views DESC';
                   break;
                 case 'replies_asc':
                   $sort_order_query = 't.topic_replies_real ASC';
                   break;
                 case 'replies_desc':
                   $sort_order_query = 't.topic_replies_real DESC';
                   break;
                 default:
                   $sort_order_query = 't.topic_time DESC';

               }
               return($sort_order_query);
            }

            /** VERSION 4.09
            * Retrieve the first post of each topic in a given forum
            *
            * @param Array $forum_ids  An array containing all the forum ids of the forums that must be included
            * @param Array $parent_only_ids An array containg the forum ids that will only give you the topics inside that forum, and not any children. It is used to mix up with $forum_ids. However if $include_children is false, this will do nothing. If you do not want to use it, declare false on it when calling the function
            * @param Integer $limit The maximum number of topics to be returned
            * @param Integer $offset Set this variable if you don't want the result set begin on the first entry
            * @param Boolean $include_children This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
            * @param String $sort_order It is mysql coding of the query order. This is given by the sort_order_query function (Default is t.topic_time DESC)
            * @param Boolean $allow_attachments (Default is true) Displays attachments (NOT INLINE IT WILL SHOW ALL ATTACHMENTS BUT INLINE WILL NOT BE PROCESSED)
            * @param Boolean $allow_ranks (Default is true) Display ranks
            * @param Boolean $allow_sigs (Default is true) Display signatures
            * @param Boolean $allow_avatar (Default is true) Display avatars
            * @return Array $posts An array holding all the posts and their data
            *
            * NOTES: If you want forum posts + children (subforum) posts. Check include_children as true and check false for $parent_only_ids.
            * If you want forum posts + children (subforum) posts + forum posts not including children posts. Check include_children as true, and input values for $forum_ids and $parent_only_ids
            * If you only want forum posts, DO NOT check $forum_ids as false and use $parent_only_ids. You must check $include_children as false, and simply input values for $forum_ids, and check $parent_only_ids as false.
            * Remember that $parent_only_ids only work when $forum_ids are working regardless of $include_children. So $forum_ids is always the first one you have to use.
            * The function will not output topics which are not approved.
            */
            function get_news($forum_ids = array(), $parent_only_ids = array(), $limit = 10, $offset = 0, $include_children = false, $sort_order = 't.topic_time DESC', $allow_attachments = true, $allow_ranks = true, $allow_sigs = true, $allow_avatar = true)
            {
               global $db, $phpbb_root_path, $phpEx;

               if (!is_array($forum_ids))
               {
                 $forum_ids = array($forum_ids);
               }
               if (!is_array($parent_only_ids))
               {
                 $parent_only_ids = array($parent_only_ids);   
               }

               // If required merge the children into the $forum_ids
               if ($include_children)
               {
                 // This can get very heavy when specifing a big array $forum_ids
                 $child_forums = array();
                 foreach ($forum_ids as $parent)
                 {
                   $children = get_forum_branch($parent, 'children');
                   foreach ($children as $child)
                   {
                     $child_forums[] = $child['forum_id'];
                   }
                 }
                 // Merge
                 $forum_ids = array_merge($forum_ids, $child_forums, $parent_only_ids);
               }

               // Remove duplicates
               $forum_ids = array_unique($forum_ids);

               $post_query = 'p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, t.topic_id, t.forum_id, t.topic_title, t.topic_status, t.poll_start, t.topic_views, t.topic_replies_real, t.topic_type, t.topic_last_poster_name, t.topic_last_post_id, t.topic_last_post_time, u.user_id, u.user_colour';
               if($allow_ranks)
               {
                 $post_query .= ',u.user_rank, u.user_posts';
               }
               if($allow_sigs)
               {
                 $post_query .= ',u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield';
               }
               if($allow_avatar)
               {
                 $post_query .= ',u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height';
               }

               // Now select the post data
               $post_sql_ary = array(
                 'SELECT'   => $post_query,
                 'FROM'      => array(
                   POSTS_TABLE      => 'p',
                   TOPICS_TABLE   => 't',
                 ),
                 'LEFT_JOIN'    => array(
                   array(
                     'FROM'    => array(USERS_TABLE => 'u'),
                     'ON'    => 'u.user_id = p.poster_id',
                   ),
                 ),
                 'WHERE'        => '(' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND p.post_id = t.topic_last_post_id AND t.topic_approved = 1)',
                 'ORDER_BY'    => 't.topic_type DESC,' . $sort_order, #DELETE t.topic_type DESC if you do not want to preserve announcements and stickies.
               );
               $sql   = $db->sql_build_query('SELECT', $post_sql_ary);
               $result   = $db->sql_query_limit($sql, $limit, $offset);

               // Set an array with the posts
               $posts   = array();
               while ($post = $db->sql_fetchrow($result))
               {
                 // Getting the Attachments
                 if($allow_attachments && $post['post_attachment'])
                 {
            //       unset($attachment_urls, $attachment_ids, $attachment_names,$attachment_downloads, $attachment_comments, $attachment_filesize, $num_of_attachment_ids);
                   $attachments_sql_ary = array(
                     'SELECT'   => 'a.attach_id, a.real_filename, a.download_count, a.attach_comment, a.filesize',
                     'FROM'      => array(
                        ATTACHMENTS_TABLE      => 'a',
                     ),
                     'WHERE'        => '(a.post_msg_id = ' . $post['post_id'] . ' AND a.in_message = 0)',
                     'ORDER_BY'    => 'a.attach_id DESC',
                   );
                   $attachments_sql   = $db->sql_build_query('SELECT', $attachments_sql_ary);
                   $attachments_result = $db->sql_query($attachments_sql);

                   $attachment_urls = $attachment_ids = $attachment_names = array();
                   $attachment_downloads = $attachment_comments = $attachment_filesize = array();
                   while ($row = $db->sql_fetchrow($attachments_result))
                   {
                        $attachment_ids[] = $row['attach_id'];
                        $attachment_names[] = $row['real_filename'];
                        $attachment_downloads[] = $row['download_count'];
                        $attachment_comments[] = $row['attach_comment'];
                        $attachment_filesize[] = $row['filesize'];
                   }
                   $db->sql_freeresult($attachments_result);

                   $num_of_attachment_ids = count($attachment_ids);
                   for($i=key($attachment_ids);$i<$num_of_attachment_ids;$i++)
                   {
                     $attachment_urls[$i] = $phpbb_root_path . 'download/file.' . $phpEx . '?id=' . $attachment_ids[$i];
                   }
                 }

                 // Getting the Breadcrumbs
                 unset($breadcrumb_ids);
                 if($post['forum_id'] > 0)
                 {
                   $breadcrumb_ids_sql_ary = array(
                     'SELECT'   => 'f.forum_id, f.forum_name',
                     'FROM'      => array(
                        FORUMS_TABLE      => 'f',
                     ),
                     'WHERE'    => '(f.left_id <= (SELECT left_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . ') AND f.right_id >= (SELECT right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . '))',
                   );
                   $bread_crumb_ids_sql   = $db->sql_build_query('SELECT', $breadcrumb_ids_sql_ary);
                   $bread_crumb_ids_result = $db->sql_query($bread_crumb_ids_sql);
                   while ($row = $db->sql_fetchrow($bread_crumb_ids_result))
                   {
                        $breadcrumb_ids[$row['forum_name']] = $row['forum_id'];
                   }
                   $db->sql_freeresult($bread_crumb_ids_result);
                 }

                 $posts[] = array(
                   // FOR POSTS
                   'forum_id'            => $post['forum_id'],
                   'post_id'            => $post['post_id'],
                   'post_time'            => $post['post_time'],
                   'post_text'            => $post['post_text'],
                   // PARSING
                   'bbcode_bitfield'      => $post['bbcode_bitfield'],
                   'bbcode_uid'         => $post['bbcode_uid'],
                   'enable_bbcode'         => $post['enable_bbcode'],
                   'enable_smilies'      => $post['enable_smilies'],
                   'enable_magic_url'      => $post['enable_magic_url'],
                   // TOPIC DETAILS
                   'topic_id'            => $post['topic_id'],
                   'topic_title'         => $post['topic_title'],
                   'topic_views'         => $post['topic_views'],
                   'topic_replies_real'   => $post['topic_replies_real'],
                   'topic_type'            => $post['topic_type'],
                   'topic_last_post_id'    => $post['topic_last_post_id'],
                   'topic_last_post_time'    => $post['topic_last_post_time'],
                   'topic_status'    => $post['topic_status'],
                   // POLL
                   'poll_start'         => $post['poll_start'],
                   // ATTACHMENTS
                   'allow_attachments'      => $allow_attachments,
                   'is_there_attachments'   => $post['post_attachment'],
                   'attachments'          => (isset($attachment_urls) ? $attachment_urls : array() ),
                   'attachment_names'       => (isset($attachment_names) ? $attachment_names : array() ),
                   'attachment_downloads'    => (isset($attachment_downloads) ? $attachment_downloads : array() ),
                   'attachment_comments'    => (isset($attachment_comments) ? $attachment_comments : array() ),
                   'attachment_filesize'    => (isset($attachment_filesize) ? $attachment_filesize : array() ),
                   'num_of_attachments'    => (isset($num_of_attachment_ids) ? $num_of_attachment_ids : 0 ),
                   // BREADCRUMBS
                   'breadcrumb_ids'       => $breadcrumb_ids,

                   // FOR USER
                   'user_id'            => $post['user_id'],
                   'topic_last_poster_name'   => $post['topic_last_poster_name'],
                   'user_colour'         => $post['user_colour'],
                   // AVATAR
                   'allow_avatar'          => $allow_avatar,
                   'user_avatar'         => ( ($allow_avatar == true) ? $post['user_avatar'] : ''),
                   'user_avatar_type'      => ( ($allow_avatar == true) ? $post['user_avatar_type'] : ''),
                   'user_avatar_width'      => ( ($allow_avatar == true) ? $post['user_avatar_width'] : 0),
                   'user_avatar_height'   => ( ($allow_avatar == true) ? $post['user_avatar_height'] : 0),
                   // RANKS
                   'allow_ranks'          => $allow_ranks,
                   'user_rank_id'          => ( ($allow_ranks == true) ? $post['user_rank'] : -1),
                   'user_posts'          => ( ($allow_ranks == true) ? $post['user_posts'] : 0),
                   // SIGNATURES
                   'allow_sigs'         => $allow_sigs,
                   'user_sig'             => ( ($allow_sigs == true) ? $post['user_sig'] : ''),
                   'user_sig_bbcode_uid'    => ( ($allow_sigs == true) ? $post['user_sig_bbcode_uid'] : ''),
                   'user_sig_bbcode_bitfield'    => ( ($allow_sigs == true) ? $post['user_sig_bbcode_bitfield'] : ''),
                 );
               }
               $db->sql_freeresult($result);

               // Return it
               return $posts;
            }

            ?>
User avatar
DFORMS
Registered User
Posts: 225
Joined: Sun May 30, 2010 12:13 am
Contact:

Re: Modifying portal.php (adding News Article and Top Five MODs)

by DFORMS » Tue Jan 31, 2012 11:26 pm

Alright, well it seems like it's working OK I guess : http://fragnet.ca. I can still manage all the options except positioning since I inserted the boxes manually in my page_index.html.
User avatar
DFORMS
Registered User
Posts: 225
Joined: Sun May 30, 2010 12:13 am
Contact:

Re: Modifying portal.php (adding News Article and Top Five M

by qoeple » Tue Sep 13, 2016 7:15 pm

Wow, do you still using PHPBB at fragment.ca ?
It is the best PHPBB modification that i ever see if so !!
Komunitas Blogger Indonesia - Blogging Comunity
buat blog gratis - Create Blog for free
pasang iklan gratis - Create Ads for free
User avatar
qoeple
Registered User
Posts: 12
Joined: Fri Dec 18, 2015 3:28 pm
Location: Indonesia
Name: Qoeple Blogger
Contact: