MyBB Community Forums

Full Version: Recent Threads On Index [Updated 02-09-21]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
(2015-04-12, 04:41 PM)tzameti13 Wrote: [ -> ]I am trying to show only Author and Last post. I have commented out

<!--
<td class="tcat" width="30" style="font-size: 9pt; text-align: center;"><strong>Forum</strong></td>
<td class="tcat" width="30" style="font-size: 9pt; text-align: center;"><strong>Posts</strong></td>
//-->

<!--
<td class="{$trow}">{$thread[\'forum\']}</td>
<td class="{$trow}"><a href="javascript:MyBB.whoPosted({$thread[\'tid\']});">{$thread[\'replies\']}</a></td>
//-->


But it shows the forum and posts. What should I do?

Try removing the // before you close the html comment tag or remove the column completely.

(2015-04-13, 05:24 PM)AURA Wrote: [ -> ]Is there any way for, for example threads to be broken up depending on which category e.g The Games Category which has all the posts in that category and then The Discussion Category and all threads there? I wanted to make a dynamically tabbed table for the Recent Threads and make the user able to switch between the Games and Discussion tab? I've seen this on another site, but I am unsure if it was a request or possible on this plugin?

Likely a custom request / modification. I didn't do that.
Nice
Thanks
I have this mod installed twice on my forum, so that I can pull from two different sections at the same time. The both work fine when in the footer of the site but once I move them to the header, the one I modified quits working.


Here's the modified version. Did I miss something somewhere? I can't figure out why the modified version won't work in the header.


<?php

 
/* Hooks */

$plugins->add_hook("index_end", "recentthread_ooc_list_threads");
$plugins->add_hook("global_start", "recentthread_ooc_get_templates");
$plugins->add_hook("global_intermediate", "recentthread_ooc_global_intermediate");
$plugins->add_hook("xmlhttp", "recentthread_ooc_refresh_threads");

function recentthread_ooc_info()
{
return array(
"name" => "Recent Threads OOC",
"description" => "A plug-in that shows the most recent threads on the index.",
"author" => "Mark Janssen",
"version" => "8.0",
"codename" => "recentthreads_ooc",
"compatibility" => "18*"
);
}

function recentthread_ooc_install()
{
    global $db, $mybb;

    if($mybb->version_code < 1801)
    {
        flash_message("Sorry, but this plugin requires you to update to 1.8.1 or higher.", "error");
        admin_redirect("index.php?module=config-plugins");
    }

    // Add some settings
    $new_setting_group = array(
    "name" => "recentthreads_ooc",
    "title" => "Recent Threads Settings OOC",
    "description" => "Customize various aspects of recent threads",
    "disporder" => 77,
    "isdefault" => 0
    );

    $gid = $db->insert_query("settinggroups", $new_setting_group);

    $new_setting[] = array(
    "name" => "recentthread_ooc_threadcount",
    "title" => "Number of Threads",
    "description" => "How many threads are shown.",
    "optionscode" => "numeric",
    "disporder" => 1,
    "value" => 15,
    "gid" => $gid
    );

    $new_setting[] = array(
    "name" => "recentthread_ooc_threadavatar",
    "title" => $db->escape_string("Show thread starter's avatar"),
    "description" => $db->escape_string("If set to yes, the thread starter's avatar will be shown."),
    "optionscode" => "yesno",
    "disporder" => 2,
    "value" => 0,
    "gid" => $gid
    );

    $new_setting[] = array(
    "name" => "recentthread_ooc_lastavatar",
    "title" => $db->escape_string("Show last poster's avatar"),
    "description" => $db->escape_string("If set to yes, the last poster's avatar will be shown."),
    "optionscode" => "yesno",
    "disporder" => 3,
    "value" => 0,
    "gid" => $gid
    );

    $new_setting[] = array(
    "name" => "recentthread_ooc_forumskip",
    "title" => "Forums To Ignore",
    "description" => "The forums threads should not be pulled from.",
    "optionscode" => "forumselect",
    "disporder" => 4,
    "value" => "",
    "gid" => $gid
    );

    $new_setting[] = array(
    "name" => "recentthread_ooc_subject_length",
    "title" => "Max Title Length",
    "description" => "The amount of characters before the rest of the title is truncated. Enter 0 for no limit.",
    "optionscode" => "numeric",
    "disporder" => 5,
    "value" => 0,
    "gid" => $gid
    );

    $new_setting[] = array(
    "name" => "recentthread_ooc_subject_breaker",
    "title" => "Word Breaking",
    "description" => "If selected, the title will be kept to full words only in cut off.",
    "optionscode" => "yesno",
    "disporder" => 6,
    "value" => 0,
    "gid" => $gid
    );

    $new_setting[] = array(
    "name" => "recentthread_ooc_which_groups",
    "title" => "Permissions",
    "description" => "These groups cannot view the reccent threads on index.",
    "optionscode" => "groupselect",
    "disporder" => 7,
    "value" => 7,
    "gid" => $gid
    );

    $db->insert_query_multiple("settings", $new_setting);
    rebuild_settings();
}

function recentthread_ooc_is_installed()
{
    global $db;
    $query = $db->simple_select("settinggroups", "*", "name='recentthreads_ooc'");
    if($db->num_rows($query))
    {
        return TRUE;
    }
    return FALSE;
}

function recentthread_ooc_activate()
{
    global $db;
    $new_template['recentthread_ooc'] = '<table border="0" cellspacing="1" cellpadding="6" class="tborder" style="clear: both;">
    <tr>
    <th class="thead" colspan="4" style="text-align:left; font-size: 10pt;">~ Recent Threads ~</th>
    </tr>
    </table>
    <div class="scroll">
    <table border="0" cellspacing="1" cellpadding="6" class="tborder">
    <tr>
    <td class="tcat" width="230" style="font-size: 9pt; text-align: center;"><strong>Thread / Author</strong></td>
    <td class="tcat" width="30" style="font-size: 9pt; text-align: center;"><strong>Forum</strong></td>
    <td class="tcat" width="30" style="font-size: 9pt; text-align: center;"><strong>Posts</strong></td>
    <td class="tcat" width="140" style="font-size: 9pt; text-align: center;"><strong>Last Post</strong></td>
    </tr>
    {$recentthreads_ooc}
    </table>
    </div>';

    $new_template['recentthread_ooc_thread'] = '<tr>
    <td class="{$trow}"><a href="{$threadlink}">{$thread[\'subject\']}</a><br />{$thread[\'author\']}<br />{$posteravatar}</td>
    <td class="{$trow}">{$thread[\'forum\']}</td>
    <td class="{$trow}"><a href="javascript:MyBB.whoPosted({$thread[\'tid\']});">{$thread[\'replies\']}</a></td>
    <td class="{$trow}">{$lastposttimeago}<br />
    <a href="{$lastpostlink}">Last Post:</a> {$lastposterlink}<br />{$lastavatar}</td>
    </tr>';

    $new_template['recentthread_ooc_avatar'] = '<img src="{$avatarurl}" {$dimensions} alt="{$avatarurl}" />';

    $new_template['recentthread_ooc_headerinclude'] = '<script type="text/javascript">
  <!--
var refresher = window.setInterval(function () {refresh_recent_threads()}, 30000);
    var stopper = window.setTimeout(function() { stop_recent_threads()}, 900000);
    function refresh_recent_threads()
    {
      var xmlhttp;
if(window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
      xmlhttp.onreadystatechange=function()
      {
        if(xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("recentthreads_ooc").innerHTML=xmlhttp.responseText;
    }
      }
      xmlhttp.open("GET","xmlhttp.php?action=recent_threads",true);
xmlhttp.send();
    }
    function stop_recent_threads()
    {
      clearInterval(refresher);
    }
  // -->
  </script>';

    foreach($new_template as $title => $template)
{
$new_template = array('title' => $db->escape_string($title), 'template' => $db->escape_string($template), 'sid' => '-1', 'version' => '1800', 'dateline' => TIME_NOW);
$db->insert_query('templates', $new_template);
}

    require_once MYBB_ROOT . "/inc/adminfunctions_templates.php";

    find_replace_templatesets('index', "#" . preg_quote('{$forums}') . "#i", '{$forums}<div id="recentthreads_ooc">{$recentthread_ooctable}</div>');
    find_replace_templatesets('index', "#" . preg_quote('{$headerinclude}') . "#i", '{$headerinclude}{$recentthread_ooc_headerinclude}');
}

function recentthread_ooc_deactivate()
{
    global $db;
    $db->delete_query("templates", "title IN('recentthread_ooc','recentthread_ooc_thread','recentthread_ooc_avatar','recentthread_ooc_headerinclude')");

    require_once MYBB_ROOT . "/inc/adminfunctions_templates.php";

    find_replace_templatesets('index', "#" . preg_quote('{$recentthread_ooc_headerinclude}') . "#i", '');
    find_replace_templatesets('index', "#" . preg_quote('<div id="recentthreads_ooc">{$recentthread_ooctable}</div>') . "#i", '');
}

function recentthread_ooc_uninstall()
{
    global $db;
    $query = $db->simple_select("settinggroups", "gid", "name='recentthreads_ooc'");
    $gid = $db->fetch_field($query, "gid");
    if(!$gid)
    {
        return;
    }
    $db->delete_query("settinggroups", "name='recentthreads_ooc'");
    $db->delete_query("settings", "gid=$gid");
    rebuild_settings();
}

function recentthread_ooc_list_threads($return=false)
{
global $mybb, $db, $templates, $recentthread_ooctable, $recentthreads_ooc, $settings, $canviewrecentthreads_ooc, $cache, $theme;
    // First check permissions
    if(!recentthread_ooc_can_view())
    {
        return;
    }
require_once MYBB_ROOT."inc/functions_search.php";
    $threadlimit = (int) $mybb->settings['recentthread_ooc_threadcount'];
    if(!$threadlimit) // Provide a fallback
    {
   $threadlimit = 15;
    }
$onlyusfids = array();
// Check group permissions if we can't view threads not started by us
$group_permissions = forum_permissions();
foreach($group_permissions as $fid => $forum_permissions)
{
if($forum_permissions['canonlyviewownthreads'] == 1)
{
$onlyusfids[] = $fid;
}
}
if(!empty($onlyusfids))
{
$where .= "AND ((t.fid IN(".implode(',', $onlyusfids).") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(".implode(',', $onlyusfids)."))";
}
$approved = 0;

// Moderators can view unapproved threads
if($mybb->usergroup['canmodcp']==1) {
$approved = -1;
}
$unsearchableforums = get_unsearchable_forums();
    $unviewableforums = get_unviewable_forums();
    if($unsearchableforums && $unviewableforums)
    {
        $forumarray = explode(",", $unsearchableforums . "," . $unviewableforums);
        $newarray = array_unique($forumarray);
        $unsearchableforumssql = " AND t.fid NOT IN(" . implode(",", $newarray) . ") ";
    }
    // Take into account any ignored forums
    if($mybb->settings['recentthread_ooc_forumskip'])
    {
        $ignoreforums = " AND t.fid NOT IN(" . $mybb->settings['recentthread_ooc_forumskip'] . ") ";
    }
    $forums = $cache->read("forums");
$query = $db->query("
SELECT t.*, u.username AS userusername, u.usergroup, u.displaygroup, u.avatar as threadavatar, u.avatardimensions as threaddimensions, lp.usergroup AS lastusergroup, lp.avatar as lastavatar, lp.avatardimensions as lastdimensions, lp.displaygroup as lastdisplaygroup
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
LEFT JOIN ".TABLE_PREFIX."users lp ON (t.lastposteruid=lp.uid)
WHERE 1=1 $where AND t.visible > {$approved} {$unsearchableforumssql} {$ignoreforums}
ORDER BY t.lastpost DESC
LIMIT $threadlimit
");
while($thread = $db->fetch_array($query))
{
            $trow = alt_trow();
            $thread['forum'] = $forums[$thread['fid']]['name'];
            $threadlink = get_thread_link($thread['tid'], "", "newpost");
            $lastpostlink = get_thread_link($thread['tid'], "", "lastpost");
$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
            $lastposttimeago = my_date("relative", $thread['lastpost']);
$lastposter = $thread['lastposter'];
$lastposteruid = $thread['lastposteruid'];
$thread['author'] = build_profile_link(format_name($thread['userusername'], $thread['usergroup'], $thread['displaygroup']), $thread['uid']);
// Don't link to guest's profiles (they have no profile).
if($lastposteruid == 0)
{
$lastposterlink = $lastposter;
}
else
{
$lastposterlink = build_profile_link(format_name($lastposter, $thread['lastusergroup'], $thread['lastdisplaygroup']), $lastposteruid);
}
            if($mybb->settings['recentthread_ooc_threadavatar'])
            {
                $threadavatar = format_avatar($thread['threadavatar'], $thread['threaddimensions']);
                $avatarurl = $threadavatar['image'];
                $dimensions = $threadavatar['width_height'];
                eval("\$posteravatar = \"".$templates->get("recentthread_ooc_avatar")."\";");
            }
            if($mybb->settings['recentthread_ooc_lastavatar'])
            {
                $lastposteravatar = format_avatar($thread['lastavatar'], $thread['lastdimensions']);
                $avatarurl = $lastposteravatar['image'];
                $dimensions = $lastposteravatar['width_height'];
                eval("\$lastavatar = \"".$templates->get("recentthread_ooc_avatar")."\";");
            }
            // Now check the length of subjects
            $length = (int) $mybb->settings['recentthread_ooc_subject_length'];
            if(strlen($thread['subject']) > $length && $length != 0)
            {
                // Figure out if we need to split it up.
                $title = my_substr($thread['subject'], 0, $length);
                if($mybb->settings['recentthread_ooc_subject_breaker'])
                {
                    $words = explode(" ", $title);
                    $count = count($words) -1;
                    $currenttitle = "";
                    for($x = 0; $x < $count; $x++)
                    {
                        $currenttitle .= $words[$x] . " ";
                    }
                    $thread['subject'] = $currenttitle . " ...";
                }
                if(!$mybb->settings['recentthread_ooc_subject_breaker'])
                {
                    $thread['subject'] = $title . "...";
                }
            }

            // Moderator stuff baby!
            if(is_moderator($thread['fid']))
            {
                $ismod = TRUE;
                // fetch the inline mod column
            }
            else
            {
                $ismod = FALSE;
            }
            if(is_moderator($thread['fid'], "caneditposts") || $fpermissions['caneditposts'] == 1)
            {
           $can_edit_titles = 1;
            }
            else
            {
           $can_edit_titles = 0;
            }
            $inline_edit_class = '';
   if(($thread['uid'] == $mybb->user['uid'] && $thread['closed'] != 1 && $mybb->user['uid'] != 0 && $can_edit_titles == 1) || $ismod == true)
   {
   $inline_edit_class = "subject_editable";
   }

eval("\$recentthreads_ooc .= \"".$templates->get("recentthread_ooc_thread")."\";");
            unset($posteravatar);
            unset($lastavatar);
}
        eval("\$recentthread_ooctable = \"".$templates->get("recentthread_ooc")."\";");
        if($return)
        {
            return $recentthread_ooctable;
        }
}

function recentthread_ooc_get_templates()
{
    global $templatelist;
    if(THIS_SCRIPT == "index.php")
    {
        $templatelist .= ",recentthread_ooc,recentthread_ooc_thread,recentthread_ooc_avatar,recentthread_ooc_headerinclude";
    }
}

function recentthread_ooc_global_intermediate()
{
    global $templates, $recentthread_ooc_headerinclude;
    if(THIS_SCRIPT == "index.php" && recentthread_ooc_can_view())
    {
        eval("\$recentthread_ooc_headerinclude = \"".$templates->get("recentthread_ooc_headerinclude")."\";");
    }
}

function recentthread_ooc_refresh_threads()
{
    global $db, $mybb, $canviewrecentthreads_ooc;
    if($mybb->input['action'] == "recent_threads")
    {
        require_once MYBB_ROOT . "/inc/plugins/recentthread_ooc.php";
        if(recentthread_ooc_can_view())
        {
            echo(recentthread_ooc_list_threads(true));
        }
        die;
    }
}

function recentthread_ooc_can_view()
{
    global $mybb;
    if($mybb->settings['recentthread_ooc_which_groups'])
    {
        $disallowedgroups = explode(",", $mybb->settings['recentthread_ooc_which_groups']);
        $mygroups = $mybb->user['usergroup'];
        if($mybb->user['additionalgroups'])
        {
            $mygroups .= "," . $mybb->user['additionalgroups'];
        }
        $groups = explode(",", $mygroups);
        foreach($groups as $group)
        {
            if(in_array($group, $disallowedgroups))
            {
                return FALSE;
            }
        }
        return TRUE;
    }
    else
    {
         return TRUE;
    }
}

?>

[php]<?php
/*
Recent Topics
by: vbgamer45
http://www.mybbhacks.com
Copyright 2011  MyBBHacks.com

############################################
License Information:

Links to http://www.mybbhacks.com must remain unless
branding free option is purchased.
#############################################
*/
if(!defined('IN_MYBB'))
 die('This file cannot be accessed directly.');

$plugins->add_hook("global_start", "recenttopicsindexooc_show");

function recenttopicsindexooc_info()
{

 return array(
 "name" => "Recent Topics Index Page OOC",
 "description" => "Adds Recent Topics to the index page",
 "website" => "http://www.mybbhacks.com",
 "author" => "vbgamer45",
 "authorsite" => "http://www.mybbhacks.com",
 "version" => "1.0.2",
 "guid" => "3244972b3e44b82b52b12594a6af9261",
 "compatibility" => "1*"
 );
}


function recenttopicsindexooc_install()
{
 global $mybb, $db;
 // Create Tables/Settings
 $db->query("INSERT  INTO ".TABLE_PREFIX."settings (sid, name, title, description, optionscode, value, disporder, gid) VALUES (NULL, 'recenttopicslimitooc', 'Recent Topics To Show OOC', 'The number of recent topics you wish to display on the main index page', 'text', '10', 1, 6);");

 rebuild_settings();


}

function recenttopicsindexooc_is_installed()
{
 global $db;
 $query = $db->write_query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE `name` = 'recenttopicslimitooc'");

 if($db->num_rows($query) > 0)
 return true;
 else
 return false;
}

function recenttopicsindexooc_uninstall()
{
 global $mybb, $db;

 $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'recenttopicslimitooc'");

 rebuild_settings();
}


function recenttopicsindexooc_activate()
{
  require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  $returnStatus1 = find_replace_templatesets("index", "#".preg_quote('{$forums}') . "#i", '{$forums}' . "\n" . '{$recenttopicsooc}');


}

function recenttopicsindexooc_deactivate()
{
  require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  $returnStatus1 = find_replace_templatesets(
  "index", "#".preg_quote('{$forums}' . "\n" . '{$recenttopicsooc}') . "#i",
  '{$forums}',0);


}

function recenttopicsindexooc_show()
{
 global $db, $mybb, $page, $recenttopicsooc, $theme, $lang, $permissioncache;

 $lang->load('recenttopicsindexooc');

 require_once MYBB_ROOT."inc/functions_search.php";

 if (empty($mybb->settings['recenttopicslimitooc']))
 $mybb->settings['recenttopicslimitooc'] = 10;

 // Run the Query
 
    // !!! FIX private forum exposure!!!
   if ( !is_array($permissioncache) ||(is_array($permissioncache) && ((count($permissioncache)==1) && (isset($permissioncache['-1']) && ($permissioncache['-1'] = "1"))))) 
       $permissioncache = forum_permissions();

 $unsearchforums = get_unsearchable_forums();
 if($unsearchforums)
 $where_sql .= " AND t.fid NOT IN ($unsearchforums)";

 $inactiveforums = get_inactive_forums();
 if ($inactiveforums)
 $where_sql .= " AND t.fid NOT IN ($inactiveforums)";


 $query = $db->query("
 SELECT
 t.tid, t.fid, t.subject, t.lastposteruid, t.lastposter, t.lastpost, f.name
 FROM ".TABLE_PREFIX."threads as t,  ".TABLE_PREFIX."forums as f
 WHERE f.fid = t.fid AND t.visible = 1 $where_sql
 ORDER BY t.lastpost DESC LIMIT " . $mybb->settings['recenttopicslimitooc']);
 while($threadRow = $db->fetch_array($query))
 {
 $recenttopicsooc .= '';
 $subject = my_substr($threadRow['subject'], 0, 50);
 $subject = htmlspecialchars_uni($subject);
 $postdate = my_date($mybb->settings['dateformat'], $threadRow['lastpost']);
 $posttime = my_date($mybb->settings['timeformat'], $threadRow['lastpost']);

 $recenttopicsooc .= '<div class="lp_entry">
 <div class="lp_thread">' . $prefix['pid'] . '<a href="showthread.php?tid=' . $threadRow['tid'] . '&action=lastpost">' . $subject .'</a></div><div class="lp_thread_info">'  . $lang->recenttopics_by . (!empty($threadRow['lastposteruid']) ? ' <a href="member.php?action=profile&uid=' . $threadRow['lastposteruid'] . '">' . $threadRow['lastposter'] . '</a>' : $threadRow['lastposter']) . ' in <a href="forumdisplay.php?fid=' . $threadRow['fid'] . '">' . $threadRow['name'] . '</a></div></div>';
 }

}


?>
[/php]
It won't work in the header because it is being called after the header template is evaluated.

I'd also like to know if you changed the function names or if you downloaded it from a third party since I am the author of the plugin.
I changed it. I've done it before with a different plugin and it worked.

How can I get this to operate with two instance, if it's possible?

EDIT: Got it working. On the modified, we changed the hook to be

$plugins->add_hook("global_start","recentthread_ooc_list_threads");


instead of "index_end".
Quick question.

How would I go about installing two instances of this?

I'd like to be able to separate recent posts into two different categories instead of filtering them into one compiled list. The above method did not work.
What you need to do is duplicate the function, calling it recentthread_bottom or _2 or something similar.

then make the new templates by duplicating the templates too, renaming them. (maybe you dont need to change them, just the links on the index

I got it to work after month of experimenting, I dunno if its the best way to do it, because it hits the database twice and on the index it it may slow it down.

I actually got three of them running on the index, seems to be ok, and the hosting service isnt complaining Wink
Is there a way to only show recent threads, instead of posts?
(2015-04-26, 11:10 PM)nollidnosnhoj Wrote: [ -> ]Is there a way to only show recent threads, instead of posts?


it is recent threads out of the box i believe, only the original topic is shown
hi, i have installed the latest version, how move to header?
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42