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
Hey there! So I am trying to add a thread prefix to top stats sidebar for recent activity threads, but I'm not sure which variable to use.

My code:

<div class="activitylast trow1">
	<div class="avataracty">{$tpl['avatar']}</div>
	<div class="latestthreads">
		<a href="{$tpl['subjectlink']}&action=newpost">{$tpl['subject']}</a>
		<div class="time-latestthread">
			by {$tpl['profilelink']}, <span class="smalltext">{$tpl['date']}</span>
		</div>
	</div>
</div>

I have tried the default Mybb prefix variable, but not working
Bump if anyone can help
You have to edit the .php file of the plugin.

1) Open PHP file and go to function "widget_LastActiveThreads()"...
2) Search for "$sql = SELECT ..." (in line 310 (roundabout)).
Then you need to add "t.prefix" as an additional field in concunction with an INNER JOIN to the table "mybb_threadprefixes" ON t.prefix = mybb_threadprefixes.pid.
2) Create another $tpl variable some rows below and the prefix is also available in the template - just use the existing tpl assignment as a pattern for your own tpl['prefix'] variable.

[ExiTuS]
(2019-08-06, 10:24 PM)[ExiTuS] Wrote: [ -> ]You have to edit the .php file of the plugin.

1) Open PHP file and go to function "widget_LastActiveThreads()"...
2) Search for "$sql = SELECT ..." (in line 310 (roundabout)).
Then you need to add "t.prefix" as an additional field in concunction with an INNER JOIN to the table "mybb_threadprefixes" ON t.prefix = mybb_threadprefixes.pid.
2) Create another $tpl variable some rows below and the prefix is also available in the template - just use the existing tpl assignment as a pattern for your own tpl['prefix'] variable.

[ExiTuS]

So I understand everything up to about the 3rd line. How should I be putting that code in? This is where I've got lol.

  $sql = "SELECT t.lastposteruid, t.tid, t.subject, t.threadprefix, t.lastpost, t.fid, u.usergroup, u.displaygroup, u.avatar, u.avatardimensions, u.username, u.uid
                FROM ".TABLE_PREFIX."threads t
                INNER JOIN ".TABLE_PREFIX."users u ON (u.uid=t.lastposteruid) 
                WHERE 1=1 {$tpl['ignore_forums']} {$unapproved_where} {$permsql} AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
                ORDER BY t.lastpost DESC LIMIT ". (int)$this->getConfig('Limit_LastActiveThreads') ."";
        $result = $db->query($sql);
        while ($row = $db->fetch_array($result))
        {
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]
(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]

Tried doing this, but it made all the avatars go white in TopStats. Maybe I input
$tpl['prefix'] = $row['prefix']; # Just the plain text of the prefix
$tpl['prefix_style'] = $row['displaystyle']; # The formatted prefix styled in ACP
incorrectly.

Where should that code go to? Sorry for all the questions.. kinda lost when it comes to this. Didn't think it would be THIS much for it lol.
Thank u nonetheless for ur help so far
It's all in the same .php file within the same code block. $tpl variables are just some lines below the SQL code.

[ExiTuS]
(2019-08-08, 10:34 PM)[ExiTuS] Wrote: [ -> ]It's all in the same .php file within the same code block. $tpl variables are just some lines below the SQL code.

[ExiTuS]

Seems like even adding the first few code with inner join, it will give the default avatar to everyone in topstats
Tested the modification again with a new plugin file from scratch.
My code is fine and working and should not affect avatars.

But one more change:
Use a left join instead of inner join:

LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)

[ExiTuS]
(2019-08-09, 10:07 AM)[ExiTuS] Wrote: [ -> ]Tested the modification again with a new plugin file from scratch.
My code is fine and working and should not affect avatars.

But one more change:
Use a left join instead of inner join:

LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)

[ExiTuS]

Not sure why it's still doing it

https://i.gyazo.com/8674da79de4246193f3b...51dce0.png

Is our plugin the same?

Working now!

I guess adding the
u.avatar, u.avatardimensions
is not in the original topStats.php file, which is what was removing the avatar image
Pages: 1 2