[Pro] How to make a certain PHP script validate?

Maybe this question is a bit mysterious, I’ll explain. For a dynamic site I use phpThumb. http://phpthumb.sourceforge.net/ Works well. But. The code does not validate, because of the ampersands. I’ve tried to put this at the top of each page that seems to output the code, but no improvement.

ini_set('arg_separator.output','&');

I’ve read that I could change something on the server where the site lives, but I do not know how.

Anybody who could assist in this?

Many Thanks.

(BTW the pages with phpThumb is here:

http://www.kkv-b.se/index.php/site/gallery/stenstipendium/orntoft_2010

28 errors, all of them related to ampersands not correctly encoded…


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi
I was hoping to find some answers here, but maybe this is beyond the regulair FW practice?
My problem is that the writers of those PHP scripts seem not to be interested in delivering valid code. I get, untill now, no response at all. And I do not know how to solve it myselve, being not a PHP coder…


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Can you post the PHP code that generated this page somewhere like Gist
or Pastie? http://gist.github.com http://pastie.org

As it is, we can see the error, but not the code that’s generating it.
Make sure, if this PHP touches any databases, that you elide your
credentials before posting.

Walter

On Nov 21, 2010, at 5:14 PM, atelier wrote:

Maybe this question is a bit mysterious, I’ll explain. For a dynamic
site I use phpThumb. http://phpthumb.sourceforge.net/ Works well.
But. The code does not validate, because of the ampersands. I’ve
tried to put this at the top of each page that seems to output the
code, but no improvement.

ini_set('arg_separator.output','&');

I’ve read that I could change something on the server where the site
lives, but I do not know how.

Anybody who could assist in this?

Many Thanks.

(BTW the pages with phpThumb is here:

http://www.kkv-b.se/index.php/site/gallery/stenstipendium/orntoft_2010

28 errors, all of them related to ampersands not correctly
encoded…


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter

The full code is a complex system of different PHP pages, which I call from my FW/EE page. They live on my server. I do not know which one I shall send? I do not know whis of these output the code. The original PHP pages can be found here: (as download) http://phpthumb.sourceforge.net/


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I’ve had a quick look at the source, and I can’t see any part of it
that creates URLs. Are you using one of the “front-ends” listed on
that page to generate your links, or is this part of EE that’s
creating the HTML? The phpthumb code looks like all it does is resize
images in a very clean manner.

Walter

On Dec 4, 2010, at 9:00 AM, atelier wrote:

Hi Walter

The full code is a complex system of different PHP pages, which I
call from my FW/EE page. They live on my server. I do not know
which one I shall send? I do not know whis of these output the code.
The original PHP pages can be found here: (as download) http://phpthumb.sourceforge.net/


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

There is a large hack you can do to fix this problem, but it will make
each and every page load slower, because it slurps up the whole page
into a buffer, runs a regular expression against it, and then serves
the result.

At the very top of your display page template, you open a buffer:

ob_start();

Then the rest of your page happens, including any includes or requires
or whatever. The OB (output buffer) keeps anything from being sent to
the browser, just keeps stacking it up in the buffer so you can act on
it as a single thing.

Then at the very bottom of the page, you perform the following
operation on the content of the buffer:

print preg_replace("/&(?!#?[xX]?(?:[0-9a-fA-F]+|w{1,8});)/ 
i",'&',ob_get_clean());

That should be one long line with no spaces after the word print,
should my Mail break it up in some unusual manner.

What that regular expression is doing is finding any ampersand that is
not a part of an existing HTML tag and converting it to & I WISH I
was smart enough to have written it, but I got if in a Google search
long ago, and it was written by Shaun Inman of haveamint.com fame.

Walter

On Dec 4, 2010, at 9:00 AM, atelier wrote:

Hi Walter

The full code is a complex system of different PHP pages, which I
call from my FW/EE page. They live on my server. I do not know
which one I shall send? I do not know whis of these output the code.
The original PHP pages can be found here: (as download) http://phpthumb.sourceforge.net/


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter
Thanks. The pages does load a bit slower already because of this script, so I hesitate.
The HTML in my pages looks like this:

<a href="{path='site/medlem_bildsida'}{entry_id}"><img src="{exp:imgsizer:size src="{image_url}" width="150" justurl="yes"}" alt="{title}" /></a>

…!
and as I write this, a lightbulb lits…
oh no…

I use in that particulair place a plug-in called imgsizer, that one calls the phpthumb files, and writes the unencoded ampersand in the HTML How very stupid of me. Aargh…

I tried now first: to write

ini_set('arg_separator.output','&amp;');

in the plugin, but that did not help.
The output is still:

<a href="http://www.kkv-b.se/images/uploads/bilder/5.jpg" rel="lightbox" title="Spissgattern &#8220;Gullveig&#8221;"><img src="/phpThumb_1.7.9/phpThumb.php?src=http://www.kkv-b.se/images/uploads/bilder/5.jpg&w=200&h=165.5&q=90&amp;zc=1" style="padding:4px" alt="" width="200" height="165.5" title="Spissgattern &#8220;Gullveig&#8221;" align="" /></a>

which obviously does not validate.

Walter, If I send you that script (the plug-in, could you please have a short look where the output is gathered? Maybe I can hack the plug-in there…?

I do see a piece there that says:

/**
     * Compile the image tag
     *
     */

but I discover nowhere the separator tag (=the ampersand) is this maybe standard PHP routine somewhere? Is it a server thingy? My 2 cents, not being a coder.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

If you can post the content of the imgsizer plugin somewhere, like on
Pastie, then I can have a quick look at it next week some time. I
agree, that seems to be the culprit here.

The php.ini flag you have tried in a bunch of places is only going to
come into play if you are asking PHP to generate a querystring for you
using one of its native functions, like http_build_query(). If you see
that function being used anywhere, then you should be able to modify
the separator.

Most of the time, though, these sorts of things are done long-hand in
PHP, using something like this construction:

$vars = array('foo' => 'bar', 'baz' => 'blarg');
$work = array();
foreach($vars as $k => $v){
	$work[] = $k . '=' . urlencode($v);
}
$qs = '?' . implode('&amp;',$work);

Walter

On Dec 4, 2010, at 7:22 PM, atelier wrote:

Hi Walter
Thanks. The pages does load a bit slower already because of this
script, so I hesitate.
The HTML in my pages looks like this:

<a href="{path='site/medlem_bildsida'}{entry_id}"><img  
src="{exp:imgsizer:size src="{image_url}" width="150"  
justurl="yes"}" alt="{title}" /></a>

…!
and as I write this, a lightbulb lits…
oh no…

I use in that particulair place a plug-in called imgsizer, that one
calls the phpthumb files, and writes the unencoded ampersand in the
HTML How very stupid of me. Aargh…

I tried now first: to write

ini_set('arg_separator.output','&amp;');

in the plugin, but that did not help.
The output is still:

<a href="http://www.kkv-b.se/images/uploads/bilder/5.jpg"  
rel="lightbox" title="Spissgattern &#8220;Gullveig&#8221;"><img  
src="/phpThumb_1.7.9/phpThumb.php?src=http://www.kkv-b.se/images/uploads/bilder/5.jpg&w=200&h=165.5&q=90&amp;zc=1 
" style="padding:4px" alt="" width="200" height="165.5"  
title="Spissgattern &#8220;Gullveig&#8221;" align="" /></a>

which obviously does not validate.

Walter, If I send you that script (the plug-in, could you please
have a short look where the output is gathered? Maybe I can hack the
plug-in there…?

I do see a piece there that says:

/**
    * Compile the image tag
    *
    */

but I discover nowhere the separator tag (=the ampersand) is this
maybe standard PHP routine somewhere? Is it a server thingy? My 2
cents, not being a coder.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thans a lot.
script is here http://pastie.org/1349064
at the end I see:


/**
     * Compile the image tag
     *
     */
    private function _compileImgTag(){

        global $TMPL;

        if($this->href_only == 'yes') {
            return str_replace($this->server_path, '', $this->resized);
        }

        $size = GetImageSize($this->resized);

        $width  = $size[0];
        $height = $size[1];

        $this->image_tag = '<img ';

        // add class, id alt and title
        if($this->class != '') {
            $this->image_tag .= 'class="'.$this->class.'" ';
        }

        if($this->id != '') {
            $this->image_tag .= 'id="'.$this->id.'" ';
        }

        if($this->title != '') {
            $this->image_tag .= 'title="'.$this->title.'" ';
        }

        if($this->alt != '') {
            $this->image_tag .= 'alt="'.$this->alt.'" ';
        } else {
          $this->image_tag .= 'alt="" ';
        }

        $this->image_tag .= ' width="'.$width.'" height="'.$height.'" ';

        $image_path = str_replace($this->server_path, '', $this->resized);

        $this->image_tag .= 'src="'.$image_path.'" />';

        return $this->image_tag;

    }

but nowhere the separator.
Hope to hear from you when you have some time for this. Very much appreciated, I whish I would be able to fix this myself, really.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options