A Hopefully simple request
#1 04-07-2013 
I come forward with a hopefully simple copy and paste request. I am looking for a way to add more than one section of announcements to the portal page and more than one list of latest threads to the portal.
Idk who will take this request, but if not leefish, then you will need to know why i guess. My site has 4 different sections of material and I just want the relevant information to show under the specified tab on the portal.
Yin, proud to be a member of LeeFish since Mar 2012.
And proud to be the owner of Atlas Productions - Cavern Of Creativity!
(This post was last modified: 21-07-2014 10:49 AM by leefish.)

#2 04-07-2013 
aha, we actually did this for Deb's site, OeC. Basically, you have to duplicate the announcements code and the latest threads code. It does add queries though.

#3 04-07-2013 
How do I do that? Just the rename announcements.php to something like announcements2.php? And where can I find the latestthreads.php code?

#4 04-07-2013 
Its all in the portal php file. Big Grin

#5 04-07-2013 
Slap Will take a look in there. I see the code. So I just copy and paste, but instead put the ids of the forums that i want instead of it pointing to settings right? And rename the variable.
Yin, proud to be a member of LeeFish since Mar 2012.
And proud to be the owner of Atlas Productions - Cavern Of Creativity!

#6 04-07-2013 
Pretty much Big Grin

#7 04-07-2013 
Where it says: if(!empty($mybb->settings['portal_mugen_announcementsfid']))
That checks the mybb settings right? Can I just remove that and it's closing bracket since it will not have to use settings from mybb?

Do I add my ids where it says explode? Example:
$mugen_announcementsfids = explode(',', $mybb->settings['portal_mugen_announcementsfid']);

changes to

$mugen_announcementsfids = explode(',', 1,2,3);

Oh and one more thing. If I put a Category ID will it automatically add the forums from that category or do I have to put them all in individually?

#8 04-07-2013 
You have to put the forums in individually, what you do is you set a new variable;

like so

Code:
$mybb->settings['otherportal_announcementsfid'] = '7,14,22,29,53,55,73,78';
$mybb->settings['otherportal_numannouncements'] = '12';

and then in your copy of the announcements code, where is says "portal_announcements" make that otherportal. Don't change the templates, just the variables used in the query.

#9 04-07-2013 
:| For some reason it is deciding not to work. I mean, I have it working and displaying, but it's still displaying everything I guess. I'm not sure I'm grasping the concept. I copy and pasted the code and came up with this:

Code:
//------------------------------------------------------------------------------------------------------------------------------------
// Yin - MUGEN Announcements
$mugen_announcements = '';
$mybb->settings['portal_mugen_announcementsfid'] = '130,184';
$mybb->settings['nummugen_announcements'] = '1';
if(!empty($mybb->settings['portal_mugen_announcementsfid']))
{
    // Get latest news mugen_announcements
    // First validate announcement fids:
    $mugen_announcementsfids = explode(',', $mybb->settings['portal_mugen_announcementsfid']);
    if(is_array($mugen_announcementsfids))
    {
        foreach($mugen_announcementsfids as $fid)
        {
            $fid_array[] = intval($fid);
        }
        $mugen_announcementsfids = implode(',', $fid_array);
    }
    // And get them!
    foreach($forum_cache as $fid => $f)
    {
        if(is_array($fid_array) && in_array($fid, $fid_array))
        {
            $forum[$fid] = $f;
        }
    }

    $nummugen_announcements = intval($mybb->settings['portal_nummugen_announcements']);
    if(!$nummugen_announcements)
    {
        $nummugen_announcements = 10; // Default back to 10
    }

    $pids = '';
    $tids = '';
    $comma = '';
    $posts = array();
    $query = $db->query("
        SELECT p.pid, p.message, p.tid, p.smilieoff
        FROM ".TABLE_PREFIX."posts p
        LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
        WHERE t.fid IN (".$mugen_announcementsfids.") AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
        ORDER BY t.dateline DESC
        LIMIT 0, {$nummugen_announcements}"
    );
    while($getid = $db->fetch_array($query))
    {
        $pids .= ",'{$getid['pid']}'";
        $tids .= ",'{$getid['tid']}'";
        $posts[$getid['tid']] = $getid;
    }
    if(!empty($posts))
    {
        $pids = "pid IN(0{$pids})";
        // Now lets fetch all of the attachments for these posts
        $query = $db->simple_select("attachments", "*", $pids);
        while($attachment = $db->fetch_array($query))
        {
            $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
        }

        if(is_array($forum))
        {
            foreach($forum as $fid => $forumrow)
            {
                $forumpermissions[$fid] = forum_permissions($fid);
            }
        }

        $icon_cache = $cache->read("posticons");

        $query = $db->query("
            SELECT t.*, t.username AS threadusername, u.username, u.avatar, u.avatardimensions
            FROM ".TABLE_PREFIX."threads t
            LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
            WHERE t.fid IN (".$mugen_announcementsfids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
            ORDER BY t.dateline DESC
            LIMIT 0, {$nummugen_announcements}"
        );
        while($mugen_announcements = $db->fetch_array($query))
        {
            // Make sure we can view this mugen_announcements
            if($forumpermissions[$mugen_announcements['fid']]['canview'] == 0 || $forumpermissions[$mugen_announcements['fid']]['canviewthreads'] == 0 || $forumpermissions[$mugen_announcements['fid']]['canonlyviewownthreads'] == 1 && $mugen_announcements['uid'] != $mybb->user['uid'])
            {
                continue;
            }

            $mugen_announcements['message'] = $posts[$mugen_announcements['tid']]['message'];
            $mugen_announcements['pid'] = $posts[$mugen_announcements['tid']]['pid'];
            $mugen_announcements['smilieoff'] = $posts[$mugen_announcements['tid']]['smilieoff'];
            $mugen_announcements['threadlink'] = get_thread_link($mugen_announcements['tid']);
            
            if($mugen_announcements['uid'] == 0)
            {
                $profilelink = htmlspecialchars_uni($mugen_announcements['threadusername']);
            }
            else
            {
                $profilelink = build_profile_link($mugen_announcements['username'], $mugen_announcements['uid']);
            }
            
            if(!$mugen_announcements['username'])
            {
                $mugen_announcements['username'] = $mugen_announcements['threadusername'];
            }
            $mugen_announcements['subject'] = htmlspecialchars_uni($parser->parse_badwords($mugen_announcements['subject']));
            if($mugen_announcements['icon'] > 0 && $icon_cache[$mugen_announcements['icon']])
            {
                $icon = $icon_cache[$mugen_announcements['icon']];
                $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
            }
            else
            {
                $icon = "&nbsp;";
            }
            if($mugen_announcements['avatar'] != '')
            {
                $avatar_dimensions = explode("|", $mugen_announcements['avatardimensions']);
                if($avatar_dimensions[0] && $avatar_dimensions[1])
                {
                    $avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\"";
                }
                if (!stristr($mugen_announcements['avatar'], 'http://'))
                {
                    $mugen_announcements['avatar'] = $mybb->settings['bburl'] . '/' . $mugen_announcements['avatar'];
                }        
                $avatar = "<td class=\"trow1\" width=\"1\" align=\"center\" valign=\"top\"><img src=\"{$mugen_announcements['avatar']}\" alt=\"\" {$avatar_width_height} /></td>";
            }
            else
            {
                $avatar = '';
            }
            $anndate = my_date($mybb->settings['dateformat'], $mugen_announcements['dateline']);
            $anntime = my_date($mybb->settings['timeformat'], $mugen_announcements['dateline']);

            if($mugen_announcements['replies'])
            {
                eval("\$numcomments = \"".$templates->get("portal_mugen_announcements_numcomments")."\";");
            }
            else
            {
                eval("\$numcomments = \"".$templates->get("portal_mugen_announcements_numcomments_no")."\";");
                $lastcomment = '';
            }
            
            $plugins->run_hooks("portal_mugen_announcements");

            $parser_options = array(
                "allow_html" => $forum[$mugen_announcements['fid']]['allowhtml'],
                "allow_mycode" => $forum[$mugen_announcements['fid']]['allowmycode'],
                "allow_smilies" => $forum[$mugen_announcements['fid']]['allowsmilies'],
                "allow_imgcode" => $forum[$mugen_announcements['fid']]['allowimgcode'],
                "allow_videocode" => $forum[$mugen_announcements['fid']]['allowvideocode'],
                "filter_badwords" => 1
            );
            if($mugen_announcements['smilieoff'] == 1)
            {
                $parser_options['allow_smilies'] = 0;
            }

            $message = $parser->parse_message($mugen_announcements['message'], $parser_options);
            
            if(is_array($attachcache[$mugen_announcements['pid']]))
            { // This post has 1 or more attachments
                $validationcount = 0;
                $id = $mugen_announcements['pid'];
                foreach($attachcache[$id] as $aid => $attachment)
                {
                    if($attachment['visible'])
                    { // There is an attachment thats visible!
                        $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
                        $attachment['filesize'] = get_friendly_size($attachment['filesize']);
                        $ext = get_extension($attachment['filename']);
                        if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
                        {
                            $isimage = true;
                        }
                        else
                        {
                            $isimage = false;
                        }
                        $attachment['icon'] = get_attachment_icon($ext);
                        // Support for [attachment=id] code
                        if(stripos($message, "[attachment=".$attachment['aid']."]") !== false)
                        {
                            if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
                            { // We have a thumbnail to show (and its not the "SMALL" enough image
                                eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
                            }
                            elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$mugen_announcements['fid']]['candlattachments'] == 1)
                            {
                                // Image is small enough to show - no thumbnail
                                eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";");
                            }
                            else
                            {
                                // Show standard link to attachment
                                eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
                            }
                            $message = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $message);
                        }
                        else
                        {
                            if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '')
                            { // We have a thumbnail to show
                                eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
                                if($tcount == 5)
                                {
                                    $thumblist .= "<br />";
                                    $tcount = 0;
                                }
                                ++$tcount;
                            }
                            elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions[$mugen_announcements['fid']]['candlattachments'] == 1)
                            {
                                // Image is small enough to show - no thumbnail
                                eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";");
                            }
                            else
                            {
                                eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";");
                            }
                        }
                    }
                    else
                    {
                        $validationcount++;
                    }
                }
                if($post['thumblist'])
                {
                    eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";");
                }
                if($post['imagelist'])
                {
                    eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";");
                }
                if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist'])
                {
                    eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";");
                }
            }

            eval("\$mugen_announcements .= \"".$templates->get("portal_mugen_announcement")."\";");
            unset($post);
        }
    }
}

Is that right?

In my template, I use {$mugen_announcements}

Edit: Actually, that code does not even work lol. I have to revert it.

#10 04-07-2013 
Hmm, intheory that should work - you say it is getting all the forums, not just the ones you specified?



Sorry, that is a members only option