Support » Plugin: Adaptive Images for WordPress » Replace $_COOKIE[‘resolution’] with urldecode($_COOKIE[‘resolution’])

  • Resolved rickey29

    (@rickey29)


    Dear developer,

    Could we do following updating?

    OPEN
    wp-content/plugins/adaptive-images/adaptive-images-script.php

    FIND
    $cookie_resolution = $_COOKIE[‘resolution’];

    REPLACE WITH
    $cookie_resolution = urldecode($_COOKIE[‘resolution’]);

    In detail, I develop an AMP plugin, I want this plugin will be compatible with mine. Since JavaScript is not allowed in AMP, I have to remove your JS (within web pages), and replace with PHP setcookie(). Since comma is an invalid character for setcookie/setrawcookie, comma is replaced with %2C (by PHP urlencode() internally). So I need a urldecode() to change the %2C back to comma.

    I believe this updating is compatible with your original usage.

    Thanks for your support. Any question, we can talk.

    Rickey

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Takis Bouyouris

    (@nevma)

    Hello, Rickey,

    Thank you for your feedback.

    My first thought is that such a change will not break anything. I have one question, though. Our plugin normally relies on Javascript in order to detect the client screen dimensions. If you remove this Javascript, how do you do this alternatively?

    Cheers,
    Takis

    Hi Takis,

    Thanks for your support.

    AMP has its solution: https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md , search keyword VIEWPORT_WIDTH then you will find detail explanation and example.

    Any question, please let me know.

    Have a nice day.

    Rickey

    Plugin Author Takis Bouyouris

    (@nevma)

    Heloo again, Rickey,

    This is some very interesting info, thank you very much, I was not aware of it! I see that you can use such variables in AMP in ways like:

    <amp-pixel src="https://foo.com/pixel?viewportHeight=VIEWPORT_WIDTH"></amp-pixel>

    One thing that we have already implemented is accessing images with url parameters like:

    <img src="https://foo.com/path/to/image.jpg?resolution=360,1" alt="" />

    Note the url parameter ?resolution=360,1 at the end of the url. This is equivalent to asking from the server to serve an image from a device of 360 pixels wide and a device pixel ratio of 1. It was meant for debugging purposes, but it does work anyway! You get the picture…

    Do you think it would be possible for you to utilise this feature as well?

    Cheers,
    Takis

    Hi Takis,

    I understand your requirement, I will try to make it. Any question and/or progress, I will let you know.

    Rickey

    Plugin Author Takis Bouyouris

    (@nevma)

    Hello, Rickey,

    Thank you for cooperating with me! Don’t get me wrong, though, I am not rejecting your proposal, I am just trying to check out all possibilities.

    Let me know how it goes and we will take it from there!

    Cheers,
    Takis

    Hi Takis,

    I am very sorry I find the urldecode() is not necessary for neither my AMP scenario nor your debug scenario.

    Let me explain. When the cookie value is input by JavaScript, I read the value from Google Chrome Developer Tools, the comma is ‘,’; when the cookie value is input from PHP, in Chrome Developer Tools, the comma is ‘%2C’. I do some searching in Stack Overflow, find a urldecode() is necessary for the conversion, so I write this post. Actually, I did not debug your code at this time.

    Today, when I debug your code (for your image file link debug issue), I find the $_COOKIE[‘resolution’] always gets a ‘,’ (comma, never %2C), no matter the input is from JavaScript or from PHP. Looks like PHP do the conversion (from %2C to comma) automatically for us.

    Regarding the image link debug issue, my understanding is, within PHP code, you can never get a ‘%2C’ in cookie value (because PHP converts all %2C to comma), so you need not worry about this issue.

    Sorry again for the inconvenience. You can forget my ticket/this post.

    Thanks for your support and have a nice day.

    Rickey

    Plugin Author Takis Bouyouris

    (@nevma)

    No inconvenience at all, my friend. Always happy to discuss these issues!

    Cheers,
    Takis

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Replace $_COOKIE[‘resolution’] with urldecode($_COOKIE[‘resolution’])’ is closed to new replies.