Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #11  
Old 08-16-2009, 02:08 PM
rin rin is offline
 
Join Date: Aug 2004
Location: Mainland of China
Posts: 109
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey thanks! =) Your code works properly.
Now I tried to stop the script from executing.
I tried using die() and exit() but both did not stop the script from showing the attachment.
What would I need to do in order to stop the attachment from showing up?
Reply With Quote
  #12  
Old 08-17-2009, 06:24 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

exit; should stop execution of the script. Are you sure the code is actually run?
Reply With Quote
  #13  
Old 08-17-2009, 09:39 AM
rin rin is offline
 
Join Date: Aug 2004
Location: Mainland of China
Posts: 109
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What I tried was to create a new plugin with hook "attachment_start" and with the simple line exit(). But still, the attachment would show up. I cleared the cache and it still showed up.

--------------- Added [DATE]1250506111[/DATE] at [TIME]1250506111[/TIME] ---------------

Got it working now.
Strange thing is, it will not exit the script when the thumb and attachment have been cached before?
Is there a better hook for this purpose than attachment_start?

--------------- Added [DATE]1250506751[/DATE] at [TIME]1250506751[/TIME] ---------------

It is very strange. On my test installation, it would work with 2 pictures, it would not work with another and it would show the path to the other instead of anything else.
Reply With Quote
  #14  
Old 08-17-2009, 01:03 PM
AndrewD AndrewD is offline
 
Join Date: Jul 2002
Location: Scotland
Posts: 3,486
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rin View Post
What I tried was to create a new plugin with hook "attachment_start" and with the simple line exit(). But still, the attachment would show up. I cleared the cache and it still showed up.

--------------- Added [DATE]1250506111[/DATE] at [TIME]1250506111[/TIME] ---------------

Got it working now.
Strange thing is, it will not exit the script when the thumb and attachment have been cached before?
Is there a better hook for this purpose than attachment_start?

--------------- Added [DATE]1250506751[/DATE] at [TIME]1250506751[/TIME] ---------------

It is very strange. On my test installation, it would work with 2 pictures, it would not work with another and it would show the path to the other instead of anything else.
I imagine this is a consequence of how your browser handles files. attachment.php sends a series of browser headers, including some which allow the browser to cache the file for a year. Once those headers have been sent, you no longer have control over file delivery because it is being picked up locally and not retransmitted.
Reply With Quote
  #15  
Old 08-17-2009, 01:55 PM
rin rin is offline
 
Join Date: Aug 2004
Location: Mainland of China
Posts: 109
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yup, I have just tried around a little bit and found out that cached attachments are shown in either case.
May I ask for help on this one:
Code:
$query = $db->query_read("SELECT current_bandwidth FROM " . TABLE_PREFIX . "user WHERE userid = " . $vbulletin->userinfo[userid]);

$add = $query[current_bandwidth] + 550;
Either the mySQL query is corrupt or the value of $query[current_bandwidth] is 0. Which it should not be since it has some value in the database. My guess would be that I can not call the value via the method I used. But after searching around, also in vBulletin code I didn't find a suitable solution.
Reply With Quote
  #16  
Old 08-17-2009, 02:27 PM
AndrewD AndrewD is offline
 
Join Date: Jul 2002
Location: Scotland
Posts: 3,486
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rin View Post
Yup, I have just tried around a little bit and found out that cached attachments are shown in either case.
May I ask for help on this one:
Code:
$query = $db->query_read("SELECT current_bandwidth FROM " . TABLE_PREFIX . "user WHERE userid = " . $vbulletin->userinfo[userid]);

$add = $query[current_bandwidth] + 550;
Either the mySQL query is corrupt or the value of $query[current_bandwidth] is 0. Which it should not be since it has some value in the database. My guess would be that I can not call the value via the method I used. But after searching around, also in vBulletin code I didn't find a suitable solution.
Reading from the database is a two-stage process, unless you are sure that there is only a single record to fetch. You either use the following sequence:

Code:
$asb = $vbulletin->db->query_read("
	SELECT current_bandwidth FROM " . TABLE_PREFIX . "user 
	WHERE userid = " . $vbulletin->userinfo[userid]);
while ($query = $vbulletin->db->fetch_array($asb)) {
// process record
}
or, if you arre certain there is one record only, the following:

Code:
$query = $vbulletin->db->query_first("
	SELECT current_bandwidth FROM " . TABLE_PREFIX . "user 
	WHERE userid = " . $vbulletin->userinfo[userid]);
Reply With Quote
  #17  
Old 08-17-2009, 02:53 PM
rin rin is offline
 
Join Date: Aug 2004
Location: Mainland of China
Posts: 109
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great news. You just helped me to get the script working. Here's the code:
Code:
$limit = 10000000;
$query = $vbulletin->db->query_first("
	SELECT current_bandwidth FROM " . TABLE_PREFIX . "user 
	WHERE userid = " . $vbulletin->userinfo[userid]);

$add = $query['current_bandwidth'] + $attachmentinfo['filesize'];

$vbulletin->db->query_write("
	UPDATE " . TABLE_PREFIX . "user 
	SET current_bandwidth = $add
	WHERE userid = " . $vbulletin->userinfo[userid]
	);
if($add > $limit)
{ exit(); }
Working! One more thing I was wondering, if exiting the script like this, it will cache a blank attachment. So in case I up the limit a bit, it will not reload the actual attachment, but still show the blank one. I guess there's no easy way around this except for emptying the cache.
Also, currently, when the limit is crossed, it will show a blank attachment. Is it possible to use the space for a proper message telling the user that their bandwidth has exceeded the allowance?
Simply adding a print wouldn't do the trick.
Reply With Quote
  #18  
Old 08-17-2009, 04:09 PM
AndrewD AndrewD is offline
 
Join Date: Jul 2002
Location: Scotland
Posts: 3,486
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rin View Post
One more thing I was wondering, if exiting the script like this, it will cache a blank attachment. So in case I up the limit a bit, it will not reload the actual attachment, but still show the blank one. I guess there's no easy way around this except for emptying the cache.

Also, currently, when the limit is crossed, it will show a blank attachment. Is it possible to use the space for a proper message telling the user that their bandwidth has exceeded the allowance?
Simply adding a print wouldn't do the trick.
You need to construct and send an appropriate html error page, including non-caching headers.
Reply With Quote
  #19  
Old 08-18-2009, 01:23 AM
rin rin is offline
 
Join Date: Aug 2004
Location: Mainland of China
Posts: 109
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I found this article. Is it helpful to follow some of its instructions for the task that you described?
https://vborg.vbsupport.ru/showthread.php?t=98009
Reply With Quote
  #20  
Old 08-18-2009, 04:37 AM
AndrewD AndrewD is offline
 
Join Date: Jul 2002
Location: Scotland
Posts: 3,486
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rin View Post
I found this article. Is it helpful to follow some of its instructions for the task that you described?
https://vborg.vbsupport.ru/showthread.php?t=98009
You could simply try:

Code:
eval(standard_error('Unable to download attachment - bandwidth allowance exceeded'));
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:55 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04620 seconds
  • Memory Usage 2,266KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete