Hi,

I found an issue, when the url() function is called before the hook_init() the URL persistent functionality stop working. An example is the swftools module, which run this line: define('SWFTOOLS_DEFAULT_BG', url(drupal_get_path('module', 'swftools') . '/shared/swftools-default.jpg', array('absolute' => TRUE))); // A generic image for use in certain contexts. that is executed when the module file is included.

I've created a patch against the PURL 6.x-1.0-beta4.

Thanks!

--
José Sánchez.
www.deviancefactory.com

CommentFileSizeAuthor
#11 url_rewrite_break-564512-11.patch1017 bytesfuzzy76
purl.patch741 bytesruloweb
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vegardjo’s picture

Hia José,

my site build with OG and Spaces, and thus PURL, was also broken after installing SWFtools: all OG / space paths were removed from the links, so what should be /mygroup/og/users/562/faces became /og/users/562/faces etc.

Anyways, your patch fixed this for me, thanks!

Don't know if this qualifies as a community review so I'm not changing the tag.. :)

smk-ka’s picture

Title: URLs are not persistent » Breaks URL rewriting modules
Project: Persistent URL » SWF Tools
Version: 6.x-1.0-beta4 » 6.x-2.x-dev
Status: Needs review » Needs work

Sorry, but even if this patch seems like it fix things, it actually just tries to detect a prefix over and over again in a brute-force manner. This patch leads to a huge overhead since the PURL prefix detection is run on every invocation of url() or l() functions (and there can be LOTS of them on one page).

The real culprit in this case are modules that call Drupal's API functions from the global PHP namespace, which leads to code execution when the system has only halfway loaded – you can't even predict which modules files have already been included and which not, and hook_init() has not even run.

The only real solution to this problem is to banish modules that are calling Drupal API functions from the global namespace (yes, not even drupal_get_path() – use dirname(__FILE__) instead), since that's a no-go. SWFTools just needs to move the causal define() into hook_init() and everything is fine.

Stuart Greenfield’s picture

Status: Needs work » Needs review

Good spot. I've fixed this on branch DRUPAL-6--2, and it is also fixed in the development work on DRUPAL-6--3 pending the next commit.

vegardjo’s picture

Hia Stuart!

First, thanks a lot for SWFTools, it really makes a huge difference!

However, this bug above actually got me again today, and I had to install the Purl patch on a different site too, to be able to still use SWFTools. I'm afraid I don't have the skills to patch SWFtools myself, but any chance you could roll a patch for this issue (or explain how to manually fix it) so we can have SWFTools work properly with Spaces / PURL?

Best, Vegard

dergachev’s picture

Tripped me up too.. had to finally install Komodo for the debugging fun!

We have the 2.5 version of SWFTOOLS.

lefnire’s picture

Works for me now, I had to cvs checkout swftools -dev (2.5's back in April). Any chance of adding a release for the -dev branches? Or mayhap tagging this puppy as a new release?

vegardjo’s picture

Seems the PURL patch (in addition to not being the right fix) also breaks Features beta 4. I did a CVS checkout of the 6.2 branch, found the fix, and manually updated my module. If someone else needs to fix this manually here's what you do:

in swftools.module, line 27, replace this line:

define('SWFTOOLS_DEFAULT_BG', url(drupal_get_path('module', 'swftools') . '/shared/swftools-default.jpg', array('absolute' => TRUE))); // A generic image for use in certain contexts

with this:

define('SWFTOOLS_DEFAULT_BG', 'shared/swftools-default.jpg'); // A generic image for use in certain contexts.

..or you could probably just run the dev version, but I chose not to in case it would introduce other problems!

Thanks again for SWFTools :)

that0n3guy’s picture

Man, I wish I would have seen this before I spent hours trying to figure out how I screwed up my open atrium install.

subscribing

Stuart Greenfield’s picture

This is fixed in 6.x-3.x.

pounard’s picture

Hello, I also experienced the bug and posted a quick and dirty patch at #960206: url() call outside any function context in swftools.module breaks some other modules init (duplicate bug). I'm posting this comment to have it appear on my dashboard and follow it.

fuzzy76’s picture

Issue summary: View changes
FileSize
1017 bytes

Reroll against 2.5 because I maintain old stuff and swftools haven't had a stable release since 2009. :-/