MyBB Community Forums

Full Version: TopStats Thread Prefix Variable?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
@Exitus

Seems like now only threads with the prefix will show

Edit: Fixed it. It was INNER JOIN problem again.. made it LEFT JOIN and it's working. Sorry!
(2019-08-07, 09:38 AM)[ExiTuS] Wrote: [ -> ]The following code change fits your needs:

$sql = "SELECT t.lastposteruid, t.tid, t.subject, t.prefix, t.lastpost, t.fid, t.views, t.replies, u.usergroup, u.displaygroup, u.username, u.uid, p.prefix, p.displaystyle
	FROM ".TABLE_PREFIX."threads t
	INNER JOIN ".TABLE_PREFIX."users u ON (u.uid=t.lastposteruid)
	INNER JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
	...
- Add "t.prefix", "p.prefix", "p.displaystyle" to the SELECT statement.
- Add another "INNER JOIN ..." to get the prefix from table threadprefixes.

That's all SQL.

Then make the template variables available - choose any name ( $tpl[...] ) you want to use for your template.
$tpl['prefix'] = $row['prefix']; # Just the plain text of the prefix
$tpl['prefix_style'] = $row['displaystyle']; # The formatted prefix styled in ACP

Now you can use the variable {$tpl['prefix_style']} in your template.

If you want to use prefixes in other widgets of this plugin, do the same change for according SQL.

[ExiTuS]

Hey Exitus,

I am trying to add this to "LastThreads", followed the same steps, but maybe it requires something else, or I did something wrong?
$sql = "SELECT t.uid, t.tid, t.subject, t.prefix, t.dateline, t.fid, u.usergroup, u.displaygroup, u.avatar, u.avatardimensions, u.username, u.uid, p.prefix
                FROM ".TABLE_PREFIX."threads AS t
                INNER JOIN ".TABLE_PREFIX."users AS u USING (uid)
                LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
                WHERE 1=1 {$tpl['ignore_forums']} {$unapproved_where} {$permsql} AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
                ORDER BY t.tid DESC LIMIT ". (int)$this->getConfig('Limit_LastThreads') ."";
        $result = $db->query($sql);
        while ($row = $db->fetch_array($result))
        {
			$forumpermissions[$row['fid']] = forum_permissions($row['fid']);

			if(isset($forumpermissions[$row['fid']]['canonlyviewownthreads']) && $forumpermissions[$row['fid']]['canonlyviewownthreads'] == 1 && $row['uid'] != $mybb->user['uid'])
			{
				continue;
			}
			
			$subject = $parser->parse_badwords(htmlspecialchars_uni($row['subject']));
			$tpl['subject'] = (my_strlen($subject) > 30) ? my_substr($subject, 0, 30) . "..." : $subject;
            $tpl['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
    		$tpl['profilelink'] = build_profile_link($tpl['username'], $row['uid']);
            $tpl['date'] = my_date('relative', $row['dateline']);
    		$tpl['subjectlink'] = get_thread_link($row['tid']);
    		$tpl['prefix'] = $row['prefix']; # Just the plain text of the prefix
$tpl['prefix_style'] = $row['displaystyle']; # The formatted prefix styled in ACP
			$useravatar = format_avatar(htmlspecialchars_uni($row['avatar']), $row['avatardimensions'], my_strtolower($this->getConfig('AvatarWidth')));
            (!$this->getConfig('Status_Avatar')) ? '' : eval("\$tpl['avatar'] = \"".$templates->get("topStats_LastThreadsAvatar")."\";");
            eval("\$tpl['row'] .= \"" . $templates->get("topStats_LastThreadsRow") . "\";");
        }
        eval("\$topStats['LastThreads'] = \"" . $templates->get("topStats_LastThreads") . "\";");
    }
	
Hi,

For the formatted style you missed "p.displaystyle" in $sql (line 1).

Check lines 25 + 26 again!
You set a variable $useravatar that seems not used elsewhere - so why?
Hash out these lines for testing purpose and see what happens.

[ExiTuS]
(2019-09-04, 03:18 PM)[ExiTuS] Wrote: [ -> ]Hi,

For the formatted style you missed "p.displaystyle" in $sql (line 1).

Check lines 25 + 26 again!
You set a variable $useravatar that seems not used elsewhere - so why?
Hash out these lines for testing purpose and see what happens.

[ExiTuS]

Seems like the missing p.displaystyle was the problem here. Agh. And that variable $useravatar is used in other areas, it was just not included in previous postings in this thread.

Thanks again Exitus!
cancel that
Pages: 1 2