Link based on Thread Starter in a Forum

← General Stuff — Started 28 Mar, 2011

Hi Tomm

As you know I have been plodding along on my stats system, and I have a question regarding "hooking" into the threads php (maybe - or maybe I need to hook into somewhere else).

I have a nifty downloads stats page Shy , and I would like to give users a direct link to it from the dropdown menu I have for users - but only if they actually HAVE stats to show.

Example:

User has started a thread in forum x. Therefore user is an uploader and will have stats (assuming anything is actually downloaded). I would like to query that the user is an uploader and then show the link to the stats - if they have no stats then no link to show.

Any tips on how I can do this?
[Image: leelink.gif]
Shameless plug on your downloads stats page? Tongue

Can you explain where exactly you want to be putting the link? Basically, if the user has uploaded anything they'll have a record of it in the xtattachments table. You just need to do a simple select and then look for the results, and if there are any, add it to the dropdown. (I'm not clear on the dropdown logistics! Whereabouts are they?).

PHP Code:
$query $db->simple_select("xtattachments""uid""uid = '{$thread['uid']}'");

if(
$db->num_rows($query))
{
    
// At least one row was returned, display it in the dropdown box
    // Code here to add it


Replace {$thread['uid']} with whatever it needs to figure out the user ID you're looking for.
Well, I have a user CP link in my header_welcome_block - they click on their avatar and the dropdown appears.

I was also thinking of editing the existing link in userCP to only show IF the user has uploads.

Also, what is the benefit of a simple select over the other kind of query? Can you do joins in simple selects?
[Image: leelink.gif]
Tomm
29 Mar, 2011, 7:54 am (This post was last modified: 29 Mar, 2011 7:54 am by Tomm.)
PHP Code:
$query $db->simple_select("xtattachments""uid""uid = '{$thread['uid']}' AND attach = '".$db->escape_string($mybb->input['attach'])."'");

$query $db->query("SELECT uid FROM ".TABLE_PREFIX."xtattachments WHERE uid = '{$thread['uid']}' AND attach = '".$db->escape_string($mybb->input['attach'])."'");

$query mysql_query("SELECT uid FROM ".TABLE_PREFIX."xtattachments WHERE uid = '{$thread['uid']}' AND attach = '".mysql_real_escape_string($mybb->input['attach'])."'"); 

Simple Select can be used to query specific tables - the examples above are exactly the same, and all return the same results. It can't do joins, but if you're able to get the same information (just like whether they've uploaded something) with a one line query rather than a join it's better to do a Simple Select. It's quick, simple and straight to the point.

The importance of the Database Class in MyBB is that it handles all forms of database systems as well as having lots of quick and easy functions to manipulate the data without calling extra PHP. For example, $result = $db->fetch_array($query) is exactly the same as $result = mysql_fetch_assoc($query) - here you're only supporting MySQL, but by using the class, you're supporting PgSQL and SQLite as well. It's just easier. Tongue

Using the following function will probably work as you want it to. Feel free to modify the query if you want something different (or of course if it doesn't work!). It needs to be hooked into global_end.

PHP Code:
function leefishhead_global()
{
    global 
$db$mybb$headerinclude;

    if(!
$mybb->user['uid'])
    {
        
// User is a guest, they won't have this
        
return false;
    }

    
$query $db->simple_select("xtattachments""uid""uid = '{$mybb->user['uid']}'");

    if(
$db->num_rows($query))
    {
        
// User has uploads
        
$find 'My Profile</span></a>';
        
$replace "\n<a href=\"".$mybb->settings['bburl']."/usercp.php?action=stats\" class=\"popup_item\">                        
<span class=\"smalltext\">Upload Stats</span></a>"
;

        
$headerinclude str_replace($find$find.$replace$headerinclude);
    }

I've just remembered - by fixing your javascript yesterday, the post reputation should work too. Shy
leesester
29 Mar, 2011, 12:29 pm (This post was last modified: 29 Mar, 2011 12:31 pm by leesester.)
Hmm, nope, it now says remove my vote instead of remove my thanks...and when I click it now says "are you sure you wish to remove the vote" I say "ok" the popup vanishes, vote not removed.

ALSO

Exciting news (well for me anyway) I got the jQuery table sorter to work Smile I now need it to really sort rather than be weirdly random - but I am getting tables sorting without a page refresh.

Big Grin

ALSO - Editted to add: leefishhead!!!
[Image: leelink.gif]
Hmm, it looks like I jubilated too soon - tablesorter BREAKS as soon as I put jQuery No.Conflict in, and as I am using MYBB with Prototype then thats a bit of a major issue.

I did see a thing for prototype called TableKit, but I also remember something about Prototype 1.7. I am a bit wary putting this table kit thing in if 1.6.4 is going to break it.
[Image: leelink.gif]
Hmm, when I debugged your javascript for post reputation, the problem was the general.js we fixed. Very strange. I'll take a look soon.

MyBB 1.6.3 will be coming with Prototype 1.7 - so if TableKit needs it then you'll be OK. 1.6.2 can also run fine with the new Prototype, so by upgrading early there should be no problems if you want to start working on it now. 1.6.4 will hopefully include a partial rewrite of the javascript to take advantage of Prototype 1.7.
OK I found your post reputation problem - the post rep javascript isn't included in the page. I'm guessing it's another xThreads issue because it doesn't know which "postbit" to be putting the javascript in. I'll try and get round that.
Should it be in the header? If I could work out how to concatenate my javascript I would not care...

ALSO

Prototype+JQueryDatatables = pretty nice I thought (only took me like 5 hours to figure out the conflict.......)

http://www.leefish.nl/mybb/misc.php?page=Week_Online#
[Image: leelink.gif]

User(s) browsing this thread: 2 Guest(s)