theme_image() should check for absolute urls

jscheel - March 25, 2008 - 20:56
Project:Drupal
Version:7.x-dev
Component:theme system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

When calling theme_image(), the only way to properly display images that are absolute urls, is to set getsize = false. This should happen automatically for external urls. Patch attached will check for an absolute url and go ahead with image theming if it is absolute.

AttachmentSizeStatusTest resultOperations
theme_image_absolute.patch1.07 KBIgnoredNoneNone

#1

jscheel - March 25, 2008 - 20:56
Status:active» needs review

#2

moshe weitzman - March 26, 2008 - 18:31
Status:needs review» needs work

strpos() would be a bit faster and more readable, no? otherwise, nice work.

#3

jscheel - March 26, 2008 - 23:36
Status:needs work» needs review

Good point moshe. This patch uses stripos(), and only checks for http at position 0. I axed the ftp protocol because I'm pretty sure you can't even use ftp as an image source. stripos() brings about a 26% speed increase over preg_match(). If we would rather go with strpos(), it would be closer to a 50% increase, but we lose the robustness of case-insensitive matching.

AttachmentSizeStatusTest resultOperations
theme_image_absolute_2.patch1.05 KBIgnoredNoneNone

#4

moshe weitzman - March 27, 2008 - 02:00

i have never ever see http capitalized. i don't think we need to support that.

#5

jscheel - March 27, 2008 - 13:41

I'm fine with strpos(), especially since it cuts the execution time almost by half, and I have attached a patch doing so.

Just for discussion though: this quote is from Internet Standard STD66, section 3.1, regarding URI schemes:

Although schemes are case-insensitive, the canonical form is lowercase and documents that specify schemes must do so with lowercase letters. An implementation should accept uppercase letters as equivalent to lowercase in scheme names (e.g., allow "HTTP" as well as "http") for the sake of robustness but should only produce lowercase scheme names for consistency.

AttachmentSizeStatusTest resultOperations
theme_image_absolute_3.patch1.05 KBIgnoredNoneNone

#6

moshe weitzman - March 31, 2008 - 18:31
Status:needs review» reviewed & tested by the community

thats better. thx.

#7

jscheel - June 26, 2008 - 13:16

Do I need to do anything else at this point, or is this just waiting on Dries's review for committing?

#8

Dries - June 26, 2008 - 21:09
Status:reviewed & tested by the community» needs work

No test case?

#9

jscheel - June 28, 2008 - 06:13

Argh, called me out on it, Dries! Ok... ok.... attached is a new patch that also includes some fixes for spaces in-between attributes in the generated html. I have also attached a test for the absolute image issue, as well as my new spacing fixes. This is the first test I have ever written, so I may be dead wrong in my approach :P

Just for performance sake, I tested this new patch by executing theme_image() 100 times. The average total increase after 5 rounds was approx. 2.09 milliseconds, which means each call to theme_image() was increased by 0.0209 milliseconds, which I believe is negligible. Is this ok?

AttachmentSizeStatusTest resultOperations
issue_238681.patch1.35 KBIgnoredNoneNone
theme.test2.39 KBIgnoredNoneNone

#10

jscheel - June 28, 2008 - 06:14
Status:needs work» needs review

#11

jscheel - July 22, 2008 - 22:13
Status:needs review» needs work

Hmm, now that I think about it, this shouldn't check for "http" because that's too ambiguous. What if there is an internal link like "httpstuffiscool"?

#12

alexanderpas - July 24, 2008 - 17:33

how about simply checking for http:// or https:// on the first positions to determine for internal links?

#13

jscheel - September 2, 2008 - 13:53

Here's a new patch. I don't really like having two potential strpos checks, so if you can think of a better way, I am definitely all ears.

AttachmentSizeStatusTest resultOperations
theme_image_absolute_4.patch1.38 KBIgnoredNoneNone

#14

jscheel - September 4, 2008 - 20:08
Status:needs work» needs review

#15

webchick - November 5, 2008 - 20:15

I'd like to get this in. Just spent a half hour trying to get theme_image() to work with private files. :P

Could we re-use menu_path_is_external()?

#16

webchick - November 5, 2008 - 20:22

How about something like this instead?

AttachmentSizeStatusTest resultOperations
drupal-theme-image-absolute-urls-238681-16.patch633 bytesIgnoredNoneNone

#17

webchick - November 5, 2008 - 20:23
Category:feature request» bug report
Priority:minor» normal

This is at least a normal priority, and I'm going to change it to a bug report instead. theme_image() and file_create_url() should work nicely with one another.

#18

webchick - November 5, 2008 - 21:19

#19

webchick - November 6, 2008 - 00:24
Status:needs review» won't fix

Yeah. Marking this one a "won't fix" in favour of the other.

Solving the problem this way incurs a minute performance penalty on every call to theme('image'), even if people aren't using private files. The other patch has the same effect but only with those files you're specifically calling file_create_url() on.

 
 

Drupal is a registered trademark of Dries Buytaert.