MyBB Community Forums

Full Version: Threadlog - Stylise Participants & Add X-thread
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello!

I'm hoping someone can help me out? I'd like to stylise the participants in the Threadlog addon, to make them match their usergroup colours. Unfortunately I'm no good at PHP so I have no idea what to do ><

This is the Addon and this is a picture of what it looks like now:
[Image: 2b58a746796dddf61ffd204d941ca51e.png]

I am also very interested in learning how to pull x-thread details into the Threadlog! I know it can be done, I'm just not educated enough to figure out how. So any assistance there would be outstanding!

THanks for dropping by!

Thistle
Bump Smile
Find:
        // get the username and UID of current user
        $userquery = $db->simple_select('users', 'username', 'uid = '. $uid .'');

        // make sure single quotes are replaced so we don't muck up queries
        $username = str_replace("'", "'", $db->fetch_field($userquery, 'username'));

Repalce with:
        // get the username and UID of current user
        $userquery = $db->simple_select('users', 'uid, username, usergroup, displaygroup', 'uid = '. $uid .'');

        $user_data = $db->fetch_array($userquery);

        isset($user_data['uid']) || error('Invalid user.');

        $username = htmlspecialchars_uni($user_data['username']);

        $username_formatted = format_name($username, $user_data['usergroup'], $user_data['displaygroup']);

Then you will be able to use {$username_formatted} in any template the plugin uses.
Now, for the xThreads part, bear with me in the process as I didn't test this.

Find:
$query = $db->simple_select("threads", "tid,fid,subject,dateline,replies,lastpost,lastposter,lastposteruid,prefix,closed", "visible = 1". $tids . $forum_select ." ORDER BY `tid` DESC LIMIT ". $start .", ". $per_page);

Replace with:
		$threadfield_cache = xthreads_gettfcache();

		$xt_fields = '';

		if(!empty($threadfield_cache))
		{
			$fids = empty($fids) ? false : array_map('intval', explode(',', $fids));
			$all_fids = empty($fids);
			$xt_fields = '';
			foreach($threadfield_cache as $k => &$v) {
				$available = (!$v['forums']) || $all_fids;
				if(!$available)
					foreach(explode(',', $v['forums']) as $fid) {
						if(isset($fids[$fid])) {
							$available = true;
							break;
						}
					}
				if($available)
					$xt_fields .= ', tfd.`'.$v['field'].'` AS `xthreads_'.$v['field'].'`';
			}
		}

	$query = $db->simple_select("threads t LEFT JOIN {$db->table_prefix}threadfields_data tfd ON (tfd.tid=t.tid) LEFT JOIN {$db->table_prefix}users lu ON (lu.uid=t.lastposteruid)", "t.*{$xt_fields},lu.uid AS lastposter_uid,lu.usergroup AS lastposter_usergroup,lu.displaygroup AS lastposter_displaygroup", "t.visible=1". str_replace('tid', 't.tid', $tids) . str_replace('fid', 't.fid', $forum_select ) , array('limit' => $per_page, 'limit_start' => $start, 'order_by' => 't.tid', 'order_dir' => 'desc'));

	$xt_tids = '';
	!$threadfield_cache || $xt_tids = '0,'.$topics;

Find:
$page_total++;

Add after:
		$threadfields = array();

		if(!empty($threadfield_cache)) {
			xthreads_set_threadforum_urlvars('thread', $thread['tid']);
			xthreads_set_threadforum_urlvars('forum', $thread['fid']);

			foreach($threadfield_cache as $k => &$v) {
				if($v['forums'] && strpos(','.$v['forums'].',', ','.$thread['fid'].',') === false)
					continue;

				xthreads_get_xta_cache($v, $xt_tids);

				$threadfields[$k] =& $thread['xthreads_'.$k];
				xthreads_sanitize_disp($threadfields[$k], $v, ($thread['username'] !== '' ? $thread['username'] : $thread['threadusername']));
			}
		}

Then cross your fingers and try to use the {$threadfields} array in the threadlog_row template.

Find:
$thread_latest_poster = "<a href=\"{$mybb->settings['bburl']}/member.php?action=profile&uid=". $thread['lastposteruid'] ."\">". $thread['lastposter'] ."</a>";

Replace with:
$thread_latest_poster = htmlspecialchars_uni($thread['lastposter']);

if($thread['lastposter_uid'])
{
	$thread_latest_poster = build_profile_link(format_name($thread_latest_poster, $thread['lastposter_usergroup'], $thread['lastposter_displaygroup']), $thread['lastposter_uid']);
}
I think you meant the last poster formatted name and not the thread owner name, which my first post was about.

Because of the necessary code I decided to merge the last poster name formatting code with the xThreads required code above.

Edit: I did test the changes and seem to work for me.
Hi Omar! Thanks so much!

The 'Last Post' has been formatted. Is it possible to also format the Participants, also?

And for some reason the 'xthread' portion isn't working for me. It's not bringing up an error, but it also isn't posting the appropriate fields.

[Image: 3324a5d449d0f37b08701876bbaf40a3.png]

This is my threadlog_row:
[Image: 1ba0a6a1c53aa8d8bd9994ef8c901e3b.png]
Don't use the super global, simply {$threadfields['key']}.

Edit: I don't think there is a need for the super global, but in case you think that is a possibility, find:
global $mybb, $templates, $theme, $lang, $header, $headerinclude, $footer, $uid, $tid;

Add after:
global $threadfields;
For the participants I will share a bit of changes. Find:
            // set up skills/attributes, but only if it exists!
            if($db->table_exists('usernotes')) {
                $usernotes = '';
                $query5 = $db->simple_select("usernotes", "*", "tid = ". $thread['tid'] ." AND uid = ".$uid);
                $usernotes = $db->fetch_array($query5);
            }

            // set up participants
            $thread_participants = 'N/A';
            $i = 0;
            $query4 = $db->simple_select("posts", "DISTINCT uid, username", "tid = ". $thread['tid'] ." AND uid != '". $uid ."'");
            while($participant = $db->fetch_array($query4)) {
                $i++;
                if($i == 1) {
                    $thread_participants = "<a href=\"{$mybb->settings['bburl']}/member.php?action=profile&uid=". $participant['uid'] ."\">". $participant['username'] ."</a>";
                } else {
                    $thread_participants .= ", <a href=\"{$mybb->settings['bburl']}/member.php?action=profile&uid=". $participant['uid'] ."\">". $participant['username'] ."</a>";
                }
            }

Replace with:
            // set up skills/attributes, but only if it exists!
            if($table_exists) {
                $usernotes = '';
                $query5 = $db->simple_select("usernotes", "*", "tid = ". $thread['tid'] ." AND uid = ".$uid);
                $usernotes = $db->fetch_array($query5);
            }

            // set up participants
            $thread_participants = 'N/A';
            $i = 0;
            $thread_participants = $comma = '';
            if(!empty($participants_cache[$thread['tid']]))
            {
                foreach($participants_cache[$thread['tid']] as $participant) {
                    $i++;
                    $username = htmlspecialchars_uni($participant['username']);
                    $username = format_name($username, $participant['usergroup'], $participant['displaygroup']);
                    $username = build_profile_link($username, $participant['uid']);
                    $thread_participants .= $comma.$username;
                    $comma = $lang->comma;
                }
            }

Find:
        if($db->num_rows($query) < 1)
        {
            eval("\$threadlog_list .= \"". $templates->get("threadlog_nothreads") ."\";");
        }

Add after:
        else
        {
            $table_exists = $db->table_exists('usernotes');

            $query4 = $db->simple_select("posts p LEFT JOIN {$db->table_prefix}users u ON (u.uid=p.uid)", "DISTINCT p.uid, p.tid, u.uid, u.username, u.usergroup, u.displaygroup", "p.uid!={$uid}".str_replace('tid', 'p.tid', $tids), ['group_by' => 'p.pid']);

            $participants_cache = [];

            while($participant = $db->fetch_array($query4)) {
                $participants_cache[$participant['tid']][$participant['uid']] = $participant;
            }
        }
Thanks again!

I'm doing something wrong, somewhere, and I'm not sure what! The xthreads aren't working despite following your instructions which I had no issue following for the other things? Not sure where I'm messing up.

Also, whomever was the last poster has decided to take over everyone's threadlog lol. I'm not sure why. At first it was Cassandra-Jade, so I made a post, to see if it was because she was the last poster in that thread, and now all the threadlogs belong to ThistleProse lol. its whomever is at the bottom of the list of participants.

[Image: 577f652f0d2ae631b660188071001365.png]
Are you using a unmodified plugin copy?
Pages: 1 2