MyBB Community Forums
List own user threads from specific forum in menu - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Community (https://community.mybb.com/forum-12.html)
+--- Forum: General Discussion (https://community.mybb.com/forum-11.html)
+--- Thread: List own user threads from specific forum in menu (/thread-226171.html)



List own user threads from specific forum in menu - skrilaxrev - 2020-01-23

I know people don't like to be asked for code without even a clue, but I still hope for help.

What I want to do is something like this:

<?php
      $query = $db->query("
            SELECT threads from users where ID=($mybb->user['uid'])
            and WHERE FID = 12,22,53
            ORDER BY title DESC
        );
?>

This is not a real code, I simple write some stuff there. I have no coding experience.

In english language:
1. Get the user id from logged in user
2. Get all threads of him from specific forums
3. List them by title with a link to it

Could somebody make a real code out of my mess above? Angel

What I can do is the html and css around it, to list the threads from specific forums for the user in the menu.^^

I would be happy to post the finished work here.

A user in the German MYBB Support Forum helped me and wrote this code for me.

But it brings a white site on the admin plugin site.

<?php

$plugins->add_hook("global_start", "myheadermenu_threadlist");
function myheadermenu_threadlist()
{
    global $mybb, $db, $headermenu_threadlist;
    $headermenu_threadlist = "";
    if(!$mybb->user['uid'])
    {
        return;
    }
    $query = $db->simple_select("threads", "tid, subject", "uid = '{$mybb->user['uid']}' AND fid IN ('22,23,14') AND visible=1 AND closed NOT LIKE 'moved|%'", array("order_by" => 'dateline', "order_dir" => 'DESC'));
    $count = $db->num_rows($query);
    if($count > 0)
    {
        $headermenu_threadlist = "<div class=\"dropdown\">
<a class=\"first\" href=\"#\">Themen-Liste</a>
<div class=\"dropdown-content\">";
        while($result = $db->fetch_array($query))
        {
            $headermenu_threadlist .= "<a href=" . get_thread_link($result['tid']) . ">" . htmlspecialchars_uni($result['subject']) . "</a>";
        }
        $headermenu_threadlist .= "</div>
</div>"
    }
} 
?>

Anybody knows why?


RE: List own user threads from specific forum in menu - PARADOXP - 2021-06-20

maybe @crazycat can help you....


RE: List own user threads from specific forum in menu - skrilaxrev - 2021-06-20

Its already done. Somebody made me a custom plugin for this. Thank you!


RE: List own user threads from specific forum in menu - Crazycat - 2021-06-20

Don't know if you shared a part of the plugin made for you or if the person who helped you did incomplete job, but the source you show us is not a plugin, it lacks some essential functions.

And quick reading the code: every time an user load a forum page, it generates a dropdown with all his threads ? Wow, must consum a lot of resources Smile

To resume: you want that any registered user can see a list of all the threads he participates in a selection of forums ?


RE: List own user threads from specific forum in menu - skrilaxrev - 2021-06-20

Please notice, my first post in this thread is from january 2020, where I wrote nothing about a "plugin", but a "code". Later he made me an plugin out of it (SvePu), which is mentioned in my second post. So, I have no idea how you put my second post together with my first post this way, but anway. SvePu is helping with the developement of many plugins, like the thank you plugin. Here is the finished plugin!

<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.");
}

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

function meineextras_info()
{
    return array(
        "name"          => "Meine Extra Funktionen",
        "description"   => "Spezielle Fuktionen für mein Forum",
        "website"       => "https://x-invest.net/forum/",
        "author"        => "SvePu",
        "authorsite"    => "https://www.mybb.de/forum/user-10549.html",
        "version"       => "1.0",
        "codename"      => "meineextras",
        "compatibility" => "18*"
    );
}

function meineextras_activate()
{
    global $db;

    $query_add = $db->simple_select("settinggroups", "COUNT(*) as disporder");
    $disporder = $db->fetch_field($query_add, "disporder");

    $setting_group = array(
        'name' => 'meineextras',
        "title" => "Meine Extra Funktionen",
        "description" => "Einstellungen für meine extra Funktionen",
        'disporder' => $disporder+1,
        'isdefault' => 0
    );

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

    $setting_array = array(
        'meineextras_headermenu_fids' => array(
            'title' => "Foren Themen-Liste Kopfmenübereich",
            'description' => "Wähle die Foren aus, aus denen die Themen für den Kopfmenübereich gelistet werden.",
            'optionscode' => 'forumselect',
            'value' => '',
            'disporder' => 1
            ),
        'meineextras_headermenu_limit' => array(
            'title' => "Limit Themen-Liste Kopfmenübereich",
            'description' => "Wähle die maximale Anzahl an Themen aus, die in der Liste gezeigt werden sollen. (0 deaktiviert das Limit)",
            'optionscode' => 'numeric \nmin=0',
            'value' => 0,
            'disporder' => 2
            )
        );

    foreach($setting_array as $name => $setting)
    {
        $setting['name'] = $name;
        $setting['gid'] = $gid;
        $db->insert_query('settings', $setting);
    }

    rebuild_settings();

}

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

function meineextras_headermenu_threadlist()
{
    global $mybb, $db, $headermenu_threadlist;
    $headermenu_threadlist = "";
    if(!$mybb->user['uid'] || $mybb->settings['meineextras_headermenu_fids'] == "")
    {
        return;
    }

    $where = "uid = '{$mybb->user['uid']}' AND visible=1 AND closed NOT LIKE 'moved|%'";
    if($mybb->settings['meineextras_headermenu_fids'] != "-1")
    {
        $where .= " AND fid IN ({$mybb->settings['meineextras_headermenu_fids']})";
    }

    $options = array(
        'order_by' => 'dateline',
        'order_dir' => 'DESC'
    );
    if($mybb->settings['meineextras_headermenu_limit'] > 0)
    {
        $options['limit'] = (int)$mybb->settings['meineextras_headermenu_limit'];
    }

    $query = $db->simple_select("threads", "tid, subject", $where, $options);
    $count = $db->num_rows($query);
    if($count > 0)
    {
        $headermenu_threadlist = "<strong>Vorstellungen</strong>";
        while($result = $db->fetch_array($query))
        {
            $headermenu_threadlist .= "<a href=" . get_thread_link($result['tid']) . ">" . htmlspecialchars_uni($result['subject']) . "</a>";
        }
        $headermenu_threadlist .= "";
    }
}


Remember that this plugin is not showing ALL threads of a user IN the dropdown menu, but all thread from specific forums.

If you still think, it is bad coding, you can make it better any time you want. Wink


RE: List own user threads from specific forum in menu - Crazycat - 2021-06-20

Sorry, I didn't notice the date of your initial post, forget my post Smile
And SvePu makes good plugins, I won't analyse his job or do any comment about Smile