Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

{html_image}

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Dave-Miller.com
Smarty n00b


Joined: 18 Apr 2003
Posts: 1

PostPosted: Fri Apr 18, 2003 10:25 pm    Post subject: {html_image} Reply with quote

Code:
// Lines 76-80 in plugins/function.html_image.php
if(substr($file,0,1) == DIR_SEP) {
  $_image_path = $basedir . DIR_SEP . $file;
} else {
  $_image_path = $file;
}


I think this is wrong, as it adds another DIR_SEP to the one that is already there. I changed mine to this:

Code:
if(substr($file,0,1) == DIR_SEP) {
  $_image_path = $basedir . $file;
} else {
  $_image_path = $file;
}


Maybe someone could tell me if this is correct?

[Edit]
I now changed DIR_SEP to '/' - I'm using Windows for development and I guess that means DIR_SEP is '\', but URLs still start '/' of course. Now absolute URLs work.
[/Edit]


Last edited by Dave-Miller.com on Sun Apr 20, 2003 4:36 pm; edited 3 times in total
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Apr 19, 2003 9:34 am    Post subject: Reply with quote

i think you are right.

another point:
the docs (at http://smarty.php.net/manual/en/language.function.html.image.php ) say: "basedir = directory to base relative paths from",
but to me it's "basedir = directory to base absolute urls from", since basedir is only used with file="/..." (files with leading slash).

and while we're at it:
why is the "link" attribute called "link" and not "href"?
to me the "link" is everything (the anchor, the image and the address it points to), and the "href" is the address it points to. but thats my personal naming opinion, maybe.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kieren
Smarty n00b


Joined: 20 Apr 2003
Posts: 1

PostPosted: Sun Apr 20, 2003 12:45 pm    Post subject: Reply with quote

Yeh i didn't quite seem to understand what was going on in html_image either, i just made link into href and did that little fix on base_dir. I also couldn't see the point in using a function for such simple html so i added a bit where the image keeps it's ratio using the input height and width as a limiting box size
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Sun Apr 20, 2003 7:03 pm    Post subject: Reply with quote

html_image is probably the least tested function in the plugin directory, feel free to submit patches Smile
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Apr 21, 2003 5:50 pm    Post subject: Reply with quote

okay i fixed the '//'. i'm still unsure if "link" shouldn't be called "href".
i could handle both names of course, but thats not lean, either.
AFAIK html_image is the only function in the plugins-directory that takes an url as argument for now, so i have no reference-name i could take for consistency.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Apr 21, 2003 8:38 pm    Post subject: Reply with quote

Consistency is difficult, but reducing the wtf syndrome is always good. I never did like the HTML attribute name on img, but who doesn't already know and expect it?

Without wanting to cause a serious riot, I submit that "src" should at least be considered over "link" and "href" since functions with html should at least be somewhat familiar to html users as it reduces a lot of mental mapping gymnastics.

In my mind it should *REALLY* be something else entirely, like "url" or "uri" or "location" Smile

2c.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Apr 21, 2003 9:01 pm    Post subject: Reply with quote

i thought of "href" since it gets rendered to href="[value]" in the template.
i think this is familiar to html-users.

[kidding]
we could make it configurable!
{html_image difficult_to_name_param_name="url" url="http://...." file="pixel.gif"} Very Happy

but i'm getting "albern" in german now, i don't know which one of
http://dict.leo.org/?search=albern fits best here there. are a lot of translations. "foolish", maybe Smile
[/kidding]

have fun
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
EyE
Smarty n00b


Joined: 23 Jun 2003
Posts: 2

PostPosted: Mon Jun 23, 2003 3:07 pm    Post subject: basedir thingies Reply with quote

Dave-Miller.com wrote:
[Edit]
I now changed DIR_SEP to '/' - I'm using Windows for development and I guess that means DIR_SEP is '\', but URLs still start '/' of course. Now absolute URLs work.
[/Edit]

I did exactly the same. Will this be changed in a future release of Smarty? The CVS version currently is still the old style.

Another point: I think the basedir parameter is forgotten to be parsed, in function.html_image.php at line 57:
Code:

 foreach($params as $_key => $_val) {
        switch($_key) {

there exists no case 'basedir' at all, so whatever basedir parameter one specifies in his template, nothing happens Confused
Another bugfix needed?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jun 24, 2003 3:08 pm    Post subject: Re: basedir thingies Reply with quote

EyE wrote:
Dave-Miller.com wrote:
[Edit]
I now changed DIR_SEP to '/' - I'm using Windows for development and I guess that means DIR_SEP is '\', but URLs still start '/' of course. Now absolute URLs work.
[/Edit]

I did exactly the same. Will this be changed in a future release of Smarty? The CVS version currently is still the old style.


hmm, this sounds okay to me too. does anybody know how window's php would react on paths like c:\foo\wwwroot/images/menu/foo.png ???
i don't have many windows php- and webserver-versions to test this on but it seemed to work okay on the IIS/php-4.3.1-cgi machine i have access to.

EyE wrote:

Another point: I think the basedir parameter is forgotten to be parsed, in function.html_image.php at line 57:
Code:

 foreach($params as $_key => $_val) {
        switch($_key) {

there exists no case 'basedir' at all, so whatever basedir parameter one specifies in his template, nothing happens Confused
Another bugfix needed?


yes, this is a bug, it'll be fixed soon.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
EyE
Smarty n00b


Joined: 23 Jun 2003
Posts: 2

PostPosted: Mon Jun 30, 2003 3:13 pm    Post subject: Re: basedir thingies Reply with quote

messju wrote:
EyE wrote:
Dave-Miller.com wrote:
[Edit]
I now changed DIR_SEP to '/' - I'm using Windows for development and I guess that means DIR_SEP is '\', but URLs still start '/' of course. Now absolute URLs work.
[/Edit]

I did exactly the same. Will this be changed in a future release of Smarty? The CVS version currently is still the old style.


hmm, this sounds okay to me too. does anybody know how window's php would react on paths like c:\foo\wwwroot/images/menu/foo.png ???
i don't have many windows php- and webserver-versions to test this on but it seemed to work okay on the IIS/php-4.3.1-cgi machine i have access to.

okay, a test-run under WindowsXP, PHP 4.3.1, running as a module under apache 2.0.45 :

The input-template:
Code:

{* webserver based, all forward slashes *}
{html_image file='/dev/projectA/styles/styleA/images/logo_100.gif'}<br/>

{* webserver based, both forward and backward, but leading slash is still forward *}
{html_image file='/dev\projectA/styles\styleA/images\logo_100.gif'}<br/>

{* webserver based, both forward and backward, but leading slash is now (incorrectly) backward *}
{html_image file='\dev\projectA/styles\styleA/images\logo_100.gif'}<br/>

{* local filesystem based, mixed, with correct first backward slash *}
{html_image file='C:\data/webroot\htdocs\dev\projectA\styles\styleA\images\logo_100.gif'}<br/>

{* local filesystem based, mixed, with (incorrect) first forward slash *}
{html_image file='C:/data/webroot\htdocs\dev\projectA/styles\styleA\images/logo_100.gif'}<br/>


and the resulting output:
Code:

<img src="/dev/projectA/styles/styleA/images/logo_100.gif" border="0" width="100" height="80" /><br/>

<img src="/dev\projectA/styles\styleA/images\logo_100.gif" border="0" width="100" height="80" /><br/>

<b>Notice:</b> Smarty error: html_image: unable to find '\dev\YaBe/work/styles\styleA/images\styleA_logo_100.gif' in <b>c:\program files\php\Smarty\libs\Smarty.class.php</b> on line <b>1042</b><br />

<img src="C:\data/webroot\htdocs\dev\projectA\styles\styleA\images\logo_100.gif" border="0" width="100" height="80" /><br/>

<img src="C:/data/webroot\htdocs\dev\projectA/styles\styleA\images/logo_100.gif" border="0" width="100" height="80" /><br/>


Note that only the one with webserver-based, incorrect leading backward slash gives problems.

And for completeness: when processing the file from a local dos box by php.exe:
output in dos-box:
Code:

<b>Notice:</b> Smarty error: html_image: unable to find '///dev/projectA/styles/styleA/images/logo_100.gif in <b>c:\program files\php\Smarty\libs\Smarty.class.php</b> on line <b>1042</b><br />

<b>Notice:</b> Smarty error: html_image: unable to find '///dev\projectA/styles\styleA/images\logo_100.gif in <b>c:\program files\php\Smarty\libs\Smarty.class.php</b> on line <b>1042</b><br />

<b>Notice:</b> Smarty error: html_image: unable to find '\dev\YaBe/work/styles\styleA/images\styleA_logo_100.gif' in <b>c:\program files\php\Smarty\libs\Smarty.class.php</b> on line <b>1042</b><br />

<img src="C:\data/webroot\htdocs\dev\projectA\styles\styleA\images\logo_100.gif" border="0" width="100" height="80" /><br/>

<img src="C:/data/webroot\htdocs\dev\projectA/styles\styleA\images/logo_100.gif" border="0" width="100" height="80" /><br/>


which makes sense, 'cause Windows doesn't know the first three types of paths.
Allright, do with it whatever you like Smile

another thing: I really think an 'alt'-attribute should be added, it is required for valid HTML, so smarty should be able to produce it.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP