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

Reply
 
Thread Tools
Check for valid linked image and resize if too large Details »»
Check for valid linked image and resize if too large
Version: 1.00, by Locutus2999 Locutus2999 is offline
Developer Last Online: Jan 2011 Show Printable Version Email this Page

Version: 2.3.x Rating:
Released: 05-26-2003 Last Update: Never Installs: 3
Is in Beta Stage  
No support by the author.

I hate it when users link to images that are really large and cause the layout of the site to become all distorted. It's also annoying to see the image placeholder and the red "X" whenever the site hosting an image is unavailable.

This check will check the width of a linked image and if it's wider than the size you would like to allow, it will add a width attribute to the <img> tag so it will be resized. If the image is not available on the linked site, then it will display a message saying the linked image is currenty unavailable.

It only requires an edit to admin/functions.php.

Open functions.php and find the following line:

PHP Code:
$bbcode preg_replace("/\[img\](\r\n|\r|\n)*((http|https):\/\/([^;<>\(\)\"".iif($allowdynimg,"","!\*\?\&")."]+)|[a-z0-9\/\\\._\- ]+)\[\/img\]/siU""<img src=\"\\2\" border=\"0\" alt=\"\">"$bbcode); 
REPLACE it with the following code:

PHP Code:
      if (strstr($bbcode"[img]")) {
          
ob_start();
          
$img_url=preg_replace("/\[img\](\r\n|\r|\n)*((http|https):\/\/([^;<>\(\)\"".iif($allowdynimg,"","!\*\?\&")."]+)|[a-z0-9\/\\\._\- ]+)\[\/img\]/siU""\\2"$bbcode);
          
$img_url=trim(ereg_replace('<[^>]*>'''$img_url));

          
$img_size getimagesize($img_url,$info);
          if (
$img_size==false$dont_display=true;
          
ob_end_clean();
      }
      if (
$img_size[0]> 400) {
          
$bbcode preg_replace("/\[img\](\r\n|\r|\n)*((http|https):\/\/([^;<>\(\)\"".iif($allowdynimg,"","!\*\?\&")."]+)|[a-z0-9\/\\\._\- ]+)\[\/img\]/siU""<img src=\"\\2\" border=\"0\" width=\"400\" alt=\"\">"$bbcode);
      } else {
          
$bbcode preg_replace("/\[img\](\r\n|\r|\n)*((http|https):\/\/([^;<>\(\)\"".iif($allowdynimg,"","!\*\?\&")."]+)|[a-z0-9\/\\\._\- ]+)\[\/img\]/siU""<img src=\"\\2\" border=\"0\" alt=\"\">"$bbcode);
      }
      if (
$dont_display==true$bbcode="<br><i>".htmlentities("<linked image unavailable>")."</i>";
    } 

Replace $img_size[0]> 400 & width=\"400\" with the your max width and that's it.

Show Your Support

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

Comments
  #12  
Old 09-06-2003, 07:59 PM
QiQme QiQme is offline
 
Join Date: Apr 2002
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This doesn't work for me at all

If i change:

if ($img_size[0]> 400) {

to

if ($img_size[0]< 400) {

It works but that's the other way

It just don't resize with if ($img_size[0]> 400) {

Any ideas ?
Reply With Quote
  #13  
Old 01-01-2004, 10:11 PM
Xxman's Avatar
Xxman Xxman is offline
 
Join Date: Aug 2002
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by QiQme
This doesn't work for me at all

If i change:

if ($img_size[0]> 400) {

to

if ($img_size[0]< 400) {

It works but that's the other way

It just don't resize with if ($img_size[0]> 400) {

Any ideas ?
The same problem...
Reply With Quote
  #14  
Old 01-02-2004, 03:39 AM
MaDCaT75 MaDCaT75 is offline
 
Join Date: Jul 2003
Location: Southern California
Posts: 718
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

good idea but doesnt work good....
Reply With Quote
  #15  
Old 01-02-2004, 09:11 AM
CVMagic's Avatar
CVMagic CVMagic is offline
 
Join Date: Dec 2002
Location: USA/Connecticut
Posts: 36
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Erwin
Using getimagesize WILL increase server load as the image needs to be downloaded, then MySQL needs to check the image size, and resize it on the fly if it's too big, and then display it... just so you know.
I was actually thinking about making a hack like this with that exact method, what you should do is make postings.php and edit.php check for images, <img> and the bb tag form, 1st check if the image using any dynamic tags if it does then leave it be, then with the images that are not you make both scripts change the tags so something like "/postimage.php?postid=1234&imageid=2" then download them and resize them with gd or otherwise, you can look at my hack https://vborg.vbsupport.ru/showthread.php?t=59410 as an example how to, then you store both the original and the resized copy over to a new table that looks somewhat like the ones used for attachments, and reason being you'd want to store the original is to allow the admins if they want to disable this hack to have regular sized images put back in their place and also incase the image becomes a dead link in the future your board will still keep a copy of it, but also what you can do is just store the url of the original if you dont want to do that or both if you really want to give more options to admins. Oh and by the way on the posting data make sure that you somehow marker the dynamic images so later on when your doing the on the fly check for these your script wont also check the ones you created for the resized copies. Now as for editing, when a post is submitted you delete any and all entries that previously was there using something like "DELETE FROM imagestable WHERE postid='$post[id]'" That was on the posting side of the processing now for the showthread.php end, now Just check for the images with your special markers and force them with i dont know javascript or something I actually dont have the slightest clue on how to do checking and resizing on the fly that wont kill the performance aside from actually attaching the image a " NAME='postid1234imageid5' " and having an OnLoad="" javascript right in the image to resize it accourdingly. Well thats my idea on how to go about it, its not perfect but its a better method than going about it on the fly.
Reply With Quote
  #16  
Old 01-02-2004, 12:06 PM
Xxman's Avatar
Xxman Xxman is offline
 
Join Date: Aug 2002
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks a lot CVNMagic , but i'm not an expert coder .. I look for an hack that resize on-the-fly linked images not images as attachmate , anyone know that a hack working already exist ??
Reply With Quote
  #17  
Old 01-02-2004, 05:31 PM
QiQme QiQme is offline
 
Join Date: Apr 2002
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi,

I use the following file as the solution.

I'm sure someone here can make this better but it's a start.

In the zip file is a image.js and a html file as an example.

Greetz
Reply With Quote
  #18  
Old 01-02-2004, 09:40 PM
Xxman's Avatar
Xxman Xxman is offline
 
Join Date: Aug 2002
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry , but I'm not sure to have understood.
Reply With Quote
  #19  
Old 01-02-2004, 09:46 PM
MindTrix's Avatar
MindTrix MindTrix is offline
 
Join Date: Apr 2002
Location: United Kingdom
Posts: 1,833
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not understood what mate?
Reply With Quote
  #20  
Old 01-02-2004, 09:59 PM
Xxman's Avatar
Xxman Xxman is offline
 
Join Date: Aug 2002
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MindTrix
Not understood what mate?
How can I use the QiQme suggestion , and implementing it into some php script of Vbulletin ..
Reply With Quote
  #21  
Old 01-02-2004, 10:04 PM
QiQme QiQme is offline
 
Join Date: Apr 2002
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just look at the html file.

See the code used.

Paste <script type="text/javascript" src="http://www.yoursite.com/image.js"></script> in the header of your vbulletin site

Paste <SCRIPT language=javascript>check_images();</SCRIPT> in the footer of your vbulletin site

Upload the image.js to your server

and that's about 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 11:31 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.10737 seconds
  • Memory Usage 2,323KB
  • 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
  • (2)bbcode_php
  • (3)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
  • (3)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