Breaks URL rewriting modules
josegabriel.st - August 31, 2009 - 16:14
| Project: | SWF Tools |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
Description
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:
<?php
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.
?>I've created a patch against the PURL 6.x-1.0-beta4.
Thanks!
--
José Sánchez.
www.deviancefactory.com
| Attachment | Size |
|---|---|
| purl.patch | 741 bytes |

#1
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/facesbecame/og/users/562/facesetc.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.. :)
#2
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.
#3
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.
#4
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
#5
Tripped me up too.. had to finally install Komodo for the debugging fun!
We have the 2.5 version of SWFTOOLS.
#6
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?