The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Attachment.php
Hello,
I was wondering about the following: If I download or view an attachment via the vBulletin attachment.php, would it be possible to write its filesize into the database? My idea is this: Every time a member downloads something, the filesize will be added to a user-specific table. Once the number in that table matches or is bigger than the allowed quota, the attachment.php would return an error. That quota-number in the table would then periodically be erased. Generally, the question is: Can I get this data (attachment filesize) and write it into the database? |
#2
|
||||
|
||||
The filesize for each attachment is already stored in the database. It is stored in the "filesize" field in attachment.
|
#3
|
|||
|
|||
Great, I have just installed a test installation and can see what you refer to.
I don't have the chance to check for filesystem attachments, but I assume it is the same method, each attachment getting its own attachment ID and the filesize info in the database. So in order to control a users bandwidth consumption, I would grab the attachments filesize when attachment.php is called and add it to the user specific attachment_quota table. Can you point me to a tutorial how to write vBulletin addons? As I tried looking around but didn't find anything. Or would you suggest that I hard-code it into the files? |
#4
|
|||
|
|||
Gotta bump this. =)
|
#5
|
||||
|
||||
There isn't really one particular tutorial on how to write a product. You can look through the articles forum, but I think most users learn by looking at other products to see how it was done.
|
#6
|
|||
|
|||
Instead of patching the attachment system, you could try the Links and Downloads Manager, which includes bandwidth control. See url in my signature.
|
#7
|
|||
|
|||
Quote:
Seeing how many attachments I am serving, I would prefer to have the limit as simple as possible. Only adding a new row to all members, summing and controlling their bandwidth usage that way. --------------- Added [DATE]1250388287[/DATE] at [TIME]1250388287[/TIME] --------------- Please bear with me. Since I have asked for an addon like this for several days and so far no one else sees its uses, I might want to try and code it myself with my rather limited knowledge of php and mysql. So if I want to start, I would like to ask you some questions. The hook to be used for an addon like this should be attachment_start, right? Then I want to write the code similar to this: Code:
GET attachment-filesize -> write filesize to member download quota table check member-usergroup; if is member of X usergroup = limit quota->X bytes if member-download-quota > usergroup-limit THEN stop and write attachment quota message. if member-download-quota <= usergroup limit THEN go on. Is it a good approach? --------------- Added [DATE]1250393636[/DATE] at [TIME]1250393636[/TIME] --------------- So far, I got this: Code:
if($vbulletin-userinfo['usergroupid'] = 7) { $download_quota = 15728640; } // Moderators if($vbulletin-userinfo[download_quota'] < $download_quota) { $new_download_quota = $vbulletin-userinfo['download_quota'] + $attachmentinfo['filesize']; $db->query_write(" UPDATE " . TABLE_PREFIX . "user SET download_quota = $new_download_quota WHERE userid = $vbulletin-userinfo[userid] ") } else { print "error"; } Then I set a different download quota for all existing usergroups. In this case it's 15 MB in bytes. Then I go check if the users current download_quota is less than the allowed 15MB. If that is the case, I will add the filesize of the current attachment to the download_quota field for the specific user. If it's bigger I return error. =) Is it that simple? |
#8
|
|||
|
|||
Quote:
I'm not sure of the need for a separate table for the user group allowances, although this is a straightforward solution. Another approach would be to hold this array as a serialised string in the data cache. This would reduce the required sql traffic. |
#9
|
|||
|
|||
Hi Andrew, thanks for your reply.
Since most of the attachments are pictures and less than 200KB in filesize, I wouldn't mind broken transfers. If in the membership plan 10MB bandwidth are mentioned, I would secretly allow members a bandwidth consumption of around 15MB to avoid situations like that. I would reduce usergroups to the basic ones and don't let members have multiple usergroups. In my case those would simply be: Banned and Guests (no access anyway), Unsubscribed, Subscribed, Actives and the obvious i.e. Moderators and Administrators. Because I am thinking about a subscription plan for my website. So I need to make it more valueable for members to pay a sum once in a while. I want to achieve that by giving users bandwith (or not). I have further worked on it: Code:
if($vbulletin->userinfo['usergroupid'] = 6) { $limitation = 1; } $result = $db->query_read("SELECT current_bandwidth FROM " . TABLE_PREFIX . "user WHERE userid = $vbulletin->userinfo[userid]); // Get the current bandwidth usage $current_quota = $result['current_bandwidth'] + $attachmentinfo['filesize']; // Calculate the current quota being used including the file which the user wants to download now. if($current_quota < $limitation) { SHOW ATTACHMENT } else { DON'T SHOW ATTACHMENT } $db_query_write("UPDATE " . TABLE_PREFIX . "user SET current_bandwidth = $current_quota WHERE userid = $vbulletin->userinfo['userid']"); So please, if by looking over the code you find anything which doesn't match up, I hope you can help me. Cheers --------------- Added [DATE]1250419067[/DATE] at [TIME]1250419067[/TIME] --------------- As predicted, it doesn't work. When opening attachments, it will not write the quota into the database. I use the "attachment_start" hook. --------------- Added [DATE]1250431666[/DATE] at [TIME]1250431666[/TIME] --------------- Strange enough, even if I active the following plugin, all thumbnails and attachments are broken. Code:
$db->query_write(" UPDATE " . TABLE_PREFIX . "user SET current_bandwidth = 10 WHERE userid = $vbulletin->userinfo[userid] "); |
#10
|
|||
|
|||
Quote:
Code:
$vbulletin->db->query_write(" UPDATE " . TABLE_PREFIX . "user SET current_bandwidth = 10 WHERE userid = " . $vbulletin->userinfo[userid] ); |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|