PDA

View Full Version : Who Downloaded This Attachment - for Gold


Mr Blunt
04-04-2004, 10:00 PM
// **********************************************
// **********************************************
// Hack to track Who Downloaded attachments
// Old vb2 hack modified to vbulletin 3.0 Gold
// Credit to TWTCommish for the original vb2 hack
// https://vborg.vbsupport.ru/showthread.php?t=36900
// **********************************************
// **********************************************
4 new templates
2 modified templates
1 modified php file
1 new php file

This hack allows admins, supermods, and mods to see who downloads each file. If you want to allow other groups, just add/subtract them from whodownloaded.php on the top line as desired.

Although I rewrote and tested this myself, and it works like a charm now, I'm not offering support for this. I'm just a Joe Average. This is an old old hack. I just had to change some words like "gettemplate" to "fetch_template" and "dooutput" to "print_output" and one instance of "post" changed to "attachment". Also had to modify table structures and of course figure out where to put everything. I'm fairly certain that this is up-to-snuff but don't take my word for it.

It doesn't track IP's or how many times a user may have downloaded. It just brings up a popup window with the usernames that have downloaded this atachment. Who knows, maybe someone else will build upon this.

Forgive me if I posted this in the wrong place or if it shouldn't be here at all.
Mods, feel free to do what you wish with this.
Just trying to give a little back to those who have taught me.


// **********************************************
// create a new template - whodownloads
// **********************************************
<html>
<head>
<title>Who Downloaded This?</title>
$headinclude
<script language="JavaScript">self.focus();</script>
</head>
<body>

<table cellpadding="10" cellspacing="0" border="0" width="100%"><tr><td>

<table cellpadding="4" cellspacing="$stylevar[cellspacing]" border="0" width="100%">
<tr>
<td class="tcat" width="100%"><b>Total Downloads: $total</b></td>
</tr>
<tr>
<td class="alt1" width="100%"><b>User</b></td>
</tr>

$whodownloadsbit

<tr id="cat">
<td class="thead" width="100%" align="center"><a href="javascript:window.close();">Close Window</a></td>
</tr>
</table>

</td></tr></table>
</body>
</html>


// **********************************************
// **********************************************
// create a new template - whodownloadsbit
// **********************************************
<tr>
<td class="thead"><a href="member.php?s=$session[sessionhash]&action=getinfo&userid=$download[userid]" target="_blank">$download[username]</a></td>
</tr>


// **********************************************
// **********************************************
// create a new template - whodownloads_error
// **********************************************
<tr>
<td class="thead">No downloads found.</td>
</tr>


// **********************************************
// **********************************************
// create a new template - whodownloads_error_nop
// **********************************************
<tr>
<td class="thead">Sorry, no Permisson.</td>
</tr>


// **********************************************
// **********************************************
// Find this in template - headinclude
// **********************************************
<script type="text/javascript" src="clientscript/vbulletin_global.js"></script>
<if condition="$show['popups']"><script type="text/javascript" src="clientscript/vbulletin_menu.js"></script></if>

// **********************************************
// Change it to this
// **********************************************
<script type="text/javascript" src="clientscript/vbulletin_global.js"></script>
<if condition="$show['popups']"><script type="text/javascript" src="clientscript/vbulletin_menu.js"></script></if>
<script language="JavaScript">
<!-- START HIDE
function whodownloaded(attachmentid)
{
window.open
("whodownloaded.php?s=$session[sessionhash]&attachmentid=" + attachmentid, "whodownloaded", "toolbar=no, scrollbars=yes, resizable=no, width=240, height=300, top=50, left=50");
}
-->
</script>


// **********************************************
// **********************************************
// Find this in template - postbit_attachment
// **********************************************
<tr>
<td><img class="inlineimg" src="$stylevar[imgdir_attach]/$attachment[attachmentextension].gif" alt="<phrase 1="$attachment[attachmentextension]">$vbphrase[file_type_x]</phrase>" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
<td><a href="attachment.php?$session[sessionurl]attachmentid=$attachment[attachmentid]" target="_blank">$attachment[filename]</a> ($attachment[filesize], <phrase 1="$attachment[counter]">$vbphrase[x_views]</phrase></td>
</tr>
// **********************************************
// Change it to this
// **********************************************
<tr>
<td><img class="inlineimg" src="$stylevar[imgdir_attach]/$attachment[attachmentextension].gif" alt="<phrase 1="$attachment[attachmentextension]">$vbphrase[file_type_x]</phrase>" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
<td><a href="attachment.php?$session[sessionurl]attachmentid=$attachment[attachmentid]" target="_blank">$attachment[filename]</a> ($attachment[filesize], <phrase 1="$attachment[counter]">$vbphrase[x_views], </phrase></td>
<td><a href="javascript:whodownloaded($attachment[attachmentid])">Who Downloaded This?</a>)</td>
</tr>


// **********************************************
// **********************************************
// create a new php file - whodownloaded.php
// place it in the main forum (upload) directory
// (same directory that has attachment.php)
// **********************************************
<?php
require("./global.php");

if (($bbuserinfo[usergroupid] == 6 OR $bbuserinfo[usergroupid] == 5 OR $bbuserinfo[usergroupid] == 7) AND $attachmentid)
{
$downloads = $DB_site->query("SELECT u.userid, u.username FROM user u WHERE u.downloads LIKE \"$attachmentid%\" OR u.downloads LIKE \"%$attachmentid%\" OR u.downloads LIKE \"%$attachmentid\" ORDER BY u.username ASC");
$total = $DB_site->query_first("SELECT counter FROM attachment WHERE attachmentid = $attachmentid");
$total = $total[counter];

if (!$DB_site->num_rows($downloads))
{
eval("\$whodownloadsbit .= \"".fetch_template("whodownloads_error",1,0)."\";");
}
else
{
while ($download = $DB_site->fetch_array($downloads))
{
eval("\$whodownloadsbit .= \"".fetch_template("whodownloadsbit",1,0)."\";");
}
}
}
else
{
eval("\$whodownloadsbit .= \"".fetch_template("whodownloads_error_nop",1,0)."\";");
}

eval('print_output("' . fetch_template('whodownloads') . '");');

?>


// **********************************************
// **********************************************
// Find this in attachment.php
// **********************************************

// or doing it once an hour
$DB_site->shutdown_query("
INSERT INTO " . TABLE_PREFIX . "attachmentviews (attachmentid)
VALUES ($attachmentid)
");
}
}
// **********************************************
// Change it to this
// **********************************************

// or doing it once an hour
$DB_site->shutdown_query("
INSERT INTO " . TABLE_PREFIX . "attachmentviews (attachmentid)
VALUES ($attachmentid)
");
}
}
// here's the who downloaded hack
$dl = $DB_site->query_first("SELECT downloads FROM user WHERE userid = $bbuserinfo[userid]");
$comma = ($dl[downloads]) ? ',' : '';
$DB_site->query("
UPDATE user
SET downloads = '$dl[downloads]$comma$attachmentid'
WHERE userid = $bbuserinfo[userid]
");


// **********************************************
// **********************************************
// Run this SQL Query from Admincp
// **********************************************
ALTER TABLE user ADD COLUMN downloads TEXT NOT NULL;

If you had this installed previously, like for vb2, then don't rerun the query.
The query didn't change so I'D SUSPECT the old and new data is compatible.

And make sure you have completely removed the old vb2 hack beforehand or I suspect this would create a conflict.

lasto
04-05-2004, 09:35 AM
done it all m8

but when i click on who downloaded this - it goes to a blank page on a fresh screen instead of a popup

Went back over the hack still same thing

only thing i could`nt do was run the sql query cause of this error

An error occurred while attempting to execute your query. The following information was returned.
error number: 1060
error desc: Duplicate column name 'downloads'

but i have updated board from v2 to v3 so maybe thats why

Boofo
04-05-2004, 09:41 AM
Can we get a screenshot and also, would you please put this in the TXT file for download instead of posting the code? ;)

Mr Blunt
04-05-2004, 02:00 PM
lasto,

I don't know how much "advise" I should give since I'm a newbie.
So take this with a grain of salt.

Are you sure you removed all of the old vb2 hack before installing mine?
This would be mandatory as there's several differences.
I'd revert all of these templates and files to vb3 gold form and then install it.
Also I have no idea if this is compatible or incompatible with any other vb hacks.

Boofo,
I don't know what I can/can't post so I made a zip with whodownloaded.php, whodownloaded.xml for the templates, and then text code. If you have to remove the XML, then go for it but I don't see the harm.

Also, here's 4 screenshots from 3 different styles I run.
1st and 2nd are vb3 default and vb2 default.
3rd & 4th reflect my board's customized style.

Boofo
04-05-2004, 02:08 PM
It's better to have the code in the file so as not to make the first post so long and to help those who don't want to have to copy all of the code in the message. It just makes it easier for everyone that way. ;)

Boofo
04-05-2004, 02:09 PM
lasto,

I don't know how much "advise" I should give since I'm a newbie.
So take this with a grain of salt.

Are you sure you removed all of the old vb2 hack before installing mine?
This would be mandatory as there's several differences.
I'd revert all of these templates and files to vb3 gold form and then install it.
Also I have no idea if this is compatible or incompatible with any other vb hacks.

Boofo,
I don't know what I can/can't post so I made a zip with whodownloaded.php, whodownloaded.xml for the templates, and then text code. If you have to remove the XML, then go for it but I don't see the harm.

Also, here's 4 screenshots from 3 different styles I run.
1st and 2nd are vb3 default and vb2 default.
3rd & 4th reflect my board's customized style.

Any way to have it show how many downloads each user made?

Mr Blunt
04-05-2004, 02:12 PM
Oh ya,

If you had this installed previously, like for vb2, then don't rerun the query.
The query didn't change so I'D SUSPECT the old and new data is compatible.

Maybe you, lasto, should delete that second query under USER called DOWNLOADS(2) or whatever that second one is now named, but then again, maybe you should wait for a more qualified person to help you.

I'll edit the top post to reflect this.

Dean C
04-05-2004, 02:21 PM
Did you get permission of TWTCommish to port this modification :)?

Mr Blunt
04-05-2004, 02:26 PM
Boofo,

It's my first real hack, so I didn't want to get in trouble.
That's why I was cautious.

As for advancing the hack, I leave that up to you folks.
Personally, I'd like to see it log IP's of downloaders along with dates & times.
I think someone did this for the vb2 hack but I never saw it posted.

If I had a copy of that one, then I could probably port it over to vb3 if no one else wants to.

All I did to make this was follow the logic of the old hack and where TWT put everything and then found the appropriate new locations. I'm not "advanced" enough to "create from scratch" yet.
Sorry.

Mr Blunt
04-05-2004, 02:29 PM
Did you get permission of TWTCommish to port this modification :)?
No sir.

TWTCommish mentioned in the old thread that it's free for all and that people could build on it if they wanted, so I didn't see the need.

If you feel it's best to delete this then go for it.
I'm just a new kid on the block.
I don't want to rock any boats.

Like I said, just trying to give a little back to those who helped me learn.
I did give TWTCommish all the credit, I do believe.

Fi_InCogNiTo
04-05-2004, 06:15 PM
I couldnt find any of that code in my attachment.php file....

Where should I add this code since it's not in the file?

Mr Blunt
04-05-2004, 06:22 PM
I couldnt find any of that code in my attachment.php file....

Where should I add this code since it's not in the file?
Unless you have another hack installed, that code I listed is in there.
It's right above this line.....

$extension = strtolower(file_extension($attachmentinfo['filename']));

Are you sure your using vb3 Gold??

Fi_InCogNiTo
04-05-2004, 06:35 PM
No, ur right. I found it. I was looking in admincp/attachment.php. I used my text scanner and it didnt find it at all.....

* Fi_InCogNiTo goes off to look for another good scanner ;)

EDIT: Works :)

Vivi Ornitier
04-06-2004, 12:03 AM
I had to change the postbit code a bit in order for the template ot work.

<a href="java_script_:whodownloaded($attachment[attachmentid])">Who Downloaded This?</a>

The java_script_:whodownloaded($attachment[attachmentid]) should be changed to javascript:whodownloaded($attachment[attachmentid]);

Mr Blunt
04-06-2004, 12:38 AM
Vivi, I'm confused.
What do you click now to get the popup??

That href line you modified is the click.
The phrase "who downloaded this?" is the text I click to get the popup.

Or are you saying you just added a semi-colon inbetween ) and "
And if this semi colon is neccessary, then wouldn't it go after the question mark in the phrase??

Forgive me for questioning you.
I'm just trying to learn why.
And moreso, why mine works for me.

Link14716
04-06-2004, 03:14 AM
It's already been done for vB3... ;)

Mr Blunt
04-06-2004, 05:11 PM
It's already been done for vB3... ;)
May I ask where??
I pulled all kinds of searches here over the last few months.
I'd love to see a more advanced version if there is one floating around.

JaNa
04-26-2004, 04:49 PM
I wouldn't call this a "Major Addition" But it's useful.

/me Clicks install

XJeepguy
05-01-2004, 11:27 PM
Hi

Seems all members can see this , where do u delete the usergroup that you do NOT want to see this ? Im looking around the .php file but wanna make sure I do this correct .

Thanks

XJ

Rambo
02-06-2005, 05:28 PM
Hrm..

Anyone manage to get this working on Version 3.0.6? o_o

steadicamop
02-07-2005, 06:43 PM
I managed to get it working under 3.0.5, although I removed it as it didn't seem to be 100% functional, the link for the file also appeared twice, so I just removed a small piece of code from the bottom of it.

It's a shame as it's a handy hack to have installed.

wi11ie1950
02-23-2005, 02:22 AM
It all works graet for me as it is :):) without any fidling :):)

Thanks Mr Blunt

trulylowcarb
04-29-2005, 09:33 PM
Thanks! Working fine in vb3.07, was easy and fast to do, and I am tickled about it. Hard to gulp HARD before running that query but it looked harmless enough. I get a null error sometimes elsewhere on the forum, if only I understood what it was I did, LOL.

I do have the file name and download link repeated, after the Who Downloaded link and that seems unnecessary, so I am going to try to see if I can delete that part only -
Thanks Mr. Blunt!!

Mr Blunt
06-23-2005, 11:10 PM
Link14716 was absolutely right about mine being a 3.0.x duplicate.
I later found the other one which was definately released before mine.
My apologies ... I wish I had found it sooner.
Would have saved me a few days of work, lol.

https://vborg.vbsupport.ru/showthread.php?t=60500

So just in case someone gets an itch to port this into 3.5.0, you don't need MY permission. Instead you might take a look at the other thread and seek that author's permission (and/or -- TWTCommish's -- the real author's permission).

At first glance of 3.5.0 I think porting this might be over my head, but I might try soon if no one else does.

Mr Blunt
06-30-2005, 04:29 PM
OK, so scratch last post....
I ported this to vb3.5.0 and it appears to be working great!!


https://vborg.vbsupport.ru/showthread.php?t=93167

TORON
09-16-2005, 12:18 AM
I'd like to see how many times a user has downloaded a file to catch users sharing accounts.

Does this show how many times a user downloaded?
Does this work with 3.0.9 ?

Mr Blunt
09-16-2005, 12:35 AM
1) Yes
2) No

Check out the screenshots in the other thread.

Saves date, time, filename, fileid, userid, username, ipaddress, and alt_ip.
All this for every download.
None get overwritten, ever.

My latest version for vb350 ALSO IMPORTS all the data automatically from this old vb30x hack if you had it installed.

Honestly, I see no reason why anyone should stick with 3.0.x
3.5.0 friggin rocks!!
It's in it's final stages if you've been keeping tabs of it.

Not trying to be a jerk ... And please don't take it as me being a jerk because really I'm not .... But I think the ONLY way I would rewrite the 3.0.x version is if someone paid me money to do it .... in which case YES I WOULD because I am currently one broke mofo.

LTW
11-19-2005, 02:49 PM
My latest version for vb350 ALSO IMPORTS all the data automatically from this old vb30x hack if you had it installed.

Can i get a link to the 3.5 version please?

Can't seem to find it ...

Thanks

LTW

LTW
11-19-2005, 02:59 PM
Can i get a link to the 3.5 version please?

Can't seem to find it ...

Thanks

LTW

Nevermind ... found it ... https://vborg.vbsupport.ru/showthread.php?t=93167