Skip to content

url() not resolved correctly #38

Closed

Description

@sebastianschmid

I had the issue that only the "stylesheet_dir"-part of a converted "url()"-path was displayed, not the filename or any parts put into the parantheses.

Solution was in function _filterStylesheetUri() (Plugin.class.php)

$matches wasn't associative, but rather numerical array. so, $matches['url'] etc returned nothing; replacing by $matches[2] works now.

Maybe this is actually just an issue of that hosting provider, but just for the record...

PHP Version 5.2.6-1+lenny6

Activity

  1. kkatpki commented on Jun 17, 2013

    @kkatpki

    I believe it has to do with the use of named back-references (https://github.com/oncletom/wp-less/search?q=%3FP%3C&ref=cmdform&type=Code) in preg_replace_callback, which is only supported in PHP 5.3 and above, from what I gather.

    In PHP 5.2, those back-references fall through as numerically keyed arrays.

    A temporary work-around for PHP 5.2 users is to change the array keys to their expected numerical index, as shown below from Plugin.class.php, around line 124.

        protected function _filterStylesheetUri($matches)
        {
            if (preg_match('#^(http|@|data:|/)#Ui', $matches[2])) {
                return $matches[0];
            }
    
            return sprintf('url(%s%s%1$s)',
                $matches[1],
                $this->_TmpBaseDir . '/' . $matches[2]
            );
        }

    Long-term, the plugin author should cite PHP 5.3 as the minimum requirement, or simply remove the named back-reference dependencies.

    A reasonable compromise, without sacrificing too much readability, is to pull the regex match into local variables via list:

        protected function _filterStylesheetUri($matches)
        {
            list($full, $quote, $url) = $matches;
    
            if (preg_match('#^(http|@|data:|/)#Ui', $url)) {
                return $full;
            }
    
            return sprintf('url(%s%s%1$s)',
                $quote,
                $this->_TmpBaseDir . '/' . $url
            );
        }
  2. sebastianschmid commented on Jun 17, 2013

    @sebastianschmid
    CollaboratorAuthor

    hmm, I would like to see that plugin having no greater requirements than wordpress, which has php 5.2 afair.
    this would only lead to lots of negative reviews, since hosters don't always have the latest and greatest...

  3. thom4parisot commented on Jun 18, 2013

    @thom4parisot
    Owner
  4. kkatpki commented on Jun 18, 2013

    @kkatpki

    @oncletom Yes, but it seems that named back-references were not allowed to propagate outside of the pattern until PHP 5.3.

  5. kkatpki commented on Jun 18, 2013

    @kkatpki

    I've found a Stack Overflow answer that seems to reinforce the above assertion: http://stackoverflow.com/a/5255199

  6. thom4parisot commented on Jun 18, 2013

    @thom4parisot
    Owner

    OK well, if it's the only blocking problem for PHP 5.2, I invite you to open a pull request with this change.
    Thanks for coining the problem :-)

  7. sebastianschmid commented on Jun 18, 2013

    @sebastianschmid
    CollaboratorAuthor

    pull request here: #39

  8. thom4parisot commented on Aug 6, 2013

    @thom4parisot
    Owner

    I close the issue thanks to #39 and ship that in a new release (because I forgot to do it 2 months ago).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions