Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Attachments show up as links if larger than a certain size. Details »»
Attachments show up as links if larger than a certain size.
Version: 1.00, by Zzed Zzed is offline
Developer Last Online: Feb 2012 Show Printable Version Email this Page

Version: 2.2.x Rating:
Released: 03-31-2002 Last Update: Never Installs: 2
 
No support by the author.

Note: I have revised this hack to use the MySql LENGTH() function.

This hack alters the attachment view property. If the size of the attached
image is larger than a specified size, the attachment will show up as a
hyperlink as opposed to the actual image.

The size limit for the time being is hardcoded at 50000. I know I should
have made it configurable. My apologies. I will work on it if anyone is
interested.

This hack was requested by Fzale.

Here are the instructions on how to implement it.

In admin/functions.php, look for the following text:
PHP Code:
        if ($post[attachmentid]!=and $post[attachmentvisible]) {
                
$post[attachmentextension]=strtolower(getextension($post[filename]));
                if (
$post[attachmentextension]=="gif" or $post[attachmentextension]=="jpg" or $post[attachmentextension]=="jpeg" or $post[attac\
hmentextension]=="jpe" or $post[attachmentextension]=="png") {
                        if ((
$viewattachedimages) and ($bbuserinfo[userid]==or $bbuserinfo[showimages])) {
                                eval(
"\$post[attachment] = \"".gettemplate("postbit_attachmentimage")."\";");
                        } else {
                                eval(
"\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
                        }
                } else {
                        eval(
"\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
                }
        } else {
                
$post[attachment]="";
        } 
And replace it with the following:
PHP Code:
//
// Attachment size hack
//
                        
global $DB_site;
                        
$attachinfo=$DB_site->query_first("SELECT LENGTH(filedata) as ATTLEN from attachment where attachmentid = '$post[attachmentid]'");
                        if(
$attachinfo[ATTLEN] > 50000) {
                                
$ok_to_watch=0;
                        }
                        else {
                                
$ok_to_watch=1;
                        }
                        if ((
$ok_to_watch) and ($viewattachedimages) and ($bbuserinfo[userid]==or $bbuserinfo[showimages])) {
                                eval(
"\$post[attachment] = \"".gettemplate("postbit_attachmentimage")."\";");
                        } else {
                                eval(
"\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
                        }
                } else {
                        eval(
"\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
                }
        } else {
                
$post[attachment]="";
        } 
Your feedback will be appreciated.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #12  
Old 04-02-2002, 10:07 PM
freakyshiat freakyshiat is offline
 
Join Date: Nov 2001
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think it still adds another query per attachment Zzed.. but its cool for now, more than what I had before
Reply With Quote
  #13  
Old 04-03-2002, 07:33 AM
Zzed's Avatar
Zzed Zzed is offline
 
Join Date: Feb 2002
Location: Glendale, CA, USA
Posts: 463
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think that given the fact that not every post has an attachment, the query in showthread.php will have to make an unnecessary hit to the database for every post.

FireFly's idea to use the LENGTH() function was quite ingenious because what comes back from the query within the hack is an integer and not a block of data.
Reply With Quote
  #14  
Old 05-12-2002, 06:09 PM
freakyshiat freakyshiat is offline
 
Join Date: Nov 2001
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by FireFly
Very nice.
Although, I think you should use LENGTH() directly in MySQL as I think it will be faster than catching the data for PHP. And, you should also do this query in showthread.php, in that huge query that gets all the info. That way you don't need to add another query for every attachment you have in the thread. Good job nonetheless!
could you tell me how do to do that?
Reply With Quote
  #15  
Old 05-12-2002, 10:32 PM
Smoothie Smoothie is offline
 
Join Date: Oct 2001
Location: New York
Posts: 1,834
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

question, so if what you have set as an attachment limit on file size in your admin cp, this over rides that, and shows a link to the attached file? Say for example I have a larger file size limit set in the admin cp than what is allowed in this hack.
Reply With Quote
  #16  
Old 05-13-2002, 03:19 PM
freakyshiat freakyshiat is offline
 
Join Date: Nov 2001
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have it set to 100k in the CP ; in the hack it is set to 50k ; so files under 50k shows up as pic, over 50k and under 100k as a link

Firefly, Help
Reply With Quote
  #17  
Old 05-13-2002, 07:28 PM
Mutt's Avatar
Mutt Mutt is offline
 
Join Date: Nov 2001
Posts: 331
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i've been thinking about installing a version of this, but instead of checking the lenght every time, I was going to add a new row to the attachment table and storing the size there when the file is attached. dimensions are checked then anyway. then just check the stored value in the db when the page is loaded. would there be any down side to doing it this way?
Reply With Quote
  #18  
Old 06-07-2002, 01:31 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, I would be VERY intersted on making the size configurable. This is almost excatly what I have been looking for. Is there any way to maybe have it show the size of the attachment in the message itself right next to the word "Attachment"? Like in kb size?

Quote:
Originally posted by Zzed
Note: I have revised this hack to use the MySql LENGTH() function.

This hack alters the attachment view property. If the size of the attached
image is larger than a specified size, the attachment will show up as a
hyperlink as opposed to the actual image.

The size limit for the time being is hardcoded at 50000. I know I should
have made it configurable. My apologies. I will work on it if anyone is
interested.

This hack was requested by Fzale.

Here are the instructions on how to implement it.

In admin/functions.php, look for the following text:
PHP Code:
        if ($post[attachmentid]!=and $post[attachmentvisible]) {
                
$post[attachmentextension]=strtolower(getextension($post[filename]));
                if (
$post[attachmentextension]=="gif" or $post[attachmentextension]=="jpg" or $post[attachmentextension]=="jpeg" or $post[attac\
hmentextension]=="jpe" or $post[attachmentextension]=="png") {
                        if ((
$viewattachedimages) and ($bbuserinfo[userid]==or $bbuserinfo[showimages])) {
                                eval(
"\$post[attachment] = \"".gettemplate("postbit_attachmentimage")."\";");
                        } else {
                                eval(
"\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
                        }
                } else {
                        eval(
"\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
                }
        } else {
                
$post[attachment]="";
        } 
And replace it with the following:
PHP Code:
//
// Attachment size hack
//
                        
global $DB_site;
                        
$attachinfo=$DB_site->query_first("SELECT LENGTH(filedata) as ATTLEN from attachment where attachmentid = '$post[attachmentid]'");
                        if(
$attachinfo[ATTLEN] > 50000) {
                                
$ok_to_watch=0;
                        }
                        else {
                                
$ok_to_watch=1;
                        }
                        if ((
$ok_to_watch) and ($viewattachedimages) and ($bbuserinfo[userid]==or $bbuserinfo[showimages])) {
                                eval(
"\$post[attachment] = \"".gettemplate("postbit_attachmentimage")."\";");
                        } else {
                                eval(
"\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
                        }
                } else {
                        eval(
"\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
                }
        } else {
                
$post[attachment]="";
        } 
Your feedback will be appreciated.
Reply With Quote
  #19  
Old 06-09-2002, 11:11 AM
nuno's Avatar
nuno nuno is offline
 
Join Date: Oct 2001
Posts: 469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this hacks adds an extra query per attachment
Reply With Quote
  #20  
Old 07-30-2002, 02:15 AM
Sadie Frost's Avatar
Sadie Frost Sadie Frost is offline
 
Join Date: Dec 2001
Location: Pittsburgh
Posts: 307
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A great idea Something I would like to see (and I am not complaining I swear) is to have this work for picture size in pixels. I hate seeing the horozontal scroll, but I also like to be able to view attachments. Just a suggestion for the future
Reply With Quote
  #21  
Old 07-31-2002, 08:11 PM
Martin64's Avatar
Martin64 Martin64 is offline
 
Join Date: Nov 2001
Posts: 390
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sounds like an excellent hack, but I would also like to see a "pixel" add-on for it.
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 04:06 PM.


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.05067 seconds
  • Memory Usage 2,371KB
  • Queries Executed 25 (?)
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
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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_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