Scenario:

- media-file resides in files/audio/file.mp3
- media_url ist not set, swf tools determines the correct base url.
- active input filters: GeSHi filter, Inline images, Lightbox filter, PHP evaluator, SWF Tools Filter, URL filter,Xbox Live Gamertag filter
- tested using 1 pixel out player 1.2.3

flash-vars before drupal_query_string_encode:

Array
(
[autostart] => no
[loop] => no
[soundFile] => http://www.codewut.de/files/audio/file.mp3
)

after:
autostart=no&loop=no&soundFile=http%3A/%252Fwww.codewut.de/files/audio/file.mp3

the url got messed up pretty much.

Proposed patch:

function _swftools_get_flashvars_string(&$flashvars) {

foreach ($flashvars AS $var => $value) {
$flashvars[$var] = str_replace(array('&', '=', '?'), array('%26', '%3D', '%3F'), $value);
}

$encoded = drupal_query_string_encode($flashvars);

// HACK: fix some drupal_query_string_encode anomalies.
$encoded = str_replace('%2523', '0x', $encoded);
$encoded = str_replace('%3A', ':', $encoded);
$encoded = str_replace('%252F', '/', $encoded);
return $encoded;
}

Comments

Stuart Greenfield’s picture

I got a bug report on the flash node queue as someone couldn't get flv's to play with the generic player. I tried on my set up and got the same, and I also think it is the effect of the escaping in the flashvars string. I tried the approach above and it fixed things.

Curiously the escaping seems to upset the generic player, but not Wijering.

Oceria’s picture

We too have found strange escape behavior. When using the Weijering image rotator the playlist fails when more than 6 items are added.

For more info: http://www.jeroenwijering.com/?thread=8941

will kirchheimer’s picture

I posted this response to a similar escape problem here: http://drupal.org/node/202591

This was in response to a single play problem, but I think the html generator is in the same spot for both items.

Not sure if that would provide a quicky patch to your problem,

--- snip of other post ---
Yeah, I was having that problem as well with the single file/older players

Here is my ugly solution:

swftools.module
Around line 430 (my version) in function swftools_swftools_embed, right above the html embed writer:

$foo = array('%3A/%252F');
$bar = array('://');
$P['flashvars'] = str_replace($foo, $bar, $P['flashvars']);
--- snip --

(edit - I have removed my swftools.module from this post)

Oceria’s picture

Do not use the file in #3; it rendered my site completely useless!

The hack itself however seems to work, although I did not try more than 6 items in a playlist yet. The url is correctly formatted in my site now. Good work!

will kirchheimer’s picture

Hey Oceria,

Sorry about that, it does have a number of tweaks, and is based on the dev.

Glad the hack worked for you.

I am guessing you are running the current stable? I will remove the file from my previous post

Oceria’s picture

This is a follow up on the patch in #3. Indeed now the limit has gone, but the patch also makes it impossible to use files from anywhere else than the local server.
<swflist files="http://foo.org/pic01.jpg&&http://foo.org/pic02.jpg"> does not work anymore: the error reported is:

warning: strpos() [function.strpos]: Empty delimiter. in /modules/swftools/swftools.module on line 886.

It seems the correct html output should be hard coded and not reformatted.

EDIT: yes, I am using the stable version

will kirchheimer’s picture

Would you try an edit to your php.ini file?

Add:

cgi.fix_pathinfo=0

Then comment out my patch, and see if you still have the problem. I would try it myself but the site I had the rewrite problem with doesn't allow php.ini access.

Previously I have noticed unpleasant rewriting with pathinfo, and had added the above to resolve it. But that was a couple years ago, and I don't remember the nature of the exact rewrite difficulty

Just a thought.

Alternatively, to keep the ugly patch working, maybe try this:

if($P['flashvars']!=''){
$foo = array('%3A/%252F');
$bar = array('://');
$P['flashvars'] = str_replace($foo, $bar, $P['flashvars']);
};

But, yeah agreed that url should be fixed at the source.

Oceria’s picture

Sadly this new hack does not allow for external code either.
<swflist files="http://www.nabaal.nl/pics/cartoons/clown.png">
still gives this error:
warning: strpos() [function.strpos]: Empty delimiter. in /home/hetziekenhuis.net/hetziekenhuis/sites/hetziekenhuis.net/modules/swftools/swftools.module on line 887.

However, I did not use cgi.fix_pathinfo=0 as I have no php.ini access either.
Would it be possible to change that in the .htaccess? I'll look into that later on.

Oceria’s picture

The strangest thing is now happening to my site: all of a sudden the hack to replace %3A/%252F with :// does not work anymore. I cannot remember changing anything, but it sure is strange. I am going to try and reinstall the original swf tools module and see if it now works again. Then I'll reapply the patch if needed.

will kirchheimer’s picture

My guess is you are embedding with java now? I am having that problem today, I switched embedding from raw to java on a project today, bam, no dice. I am going to try and hunt down the source today, to provide a earlier hack, so it flows out better.

will kirchheimer’s picture

Found it!

The below function (line 725 of swftools.module)

function _swftools_get_flashvars_string(&$flashvars) {

foreach ($flashvars AS $var => $value) {
$flashvars[$var] = str_replace(array('&', '=', '?'), array('%26', '%3D', '%3F'), $value);
}
$encoded = drupal_query_string_encode($flashvars);

// '#' seems to encode as %2523, reverse this, using a more robust hex prefix..
$encoded = str_replace('%2523', '0x', $encoded);

return $encoded;
}

So add ugly hack there:

function _swftools_get_flashvars_string(&$flashvars) {

foreach ($flashvars AS $var => $value) {
$flashvars[$var] = str_replace(array('&', '=', '?'), array('%26', '%3D', '%3F'), $value);
}
$encoded = drupal_query_string_encode($flashvars);

// '#' seems to encode as %2523, reverse this, using a more robust hex prefix..
$encoded = str_replace('%2523', '0x', $encoded);

// begin hack
$foo = array('%3A/%252F');
$bar = array('://');
$encoded = str_replace($foo, $bar, $encoded);
// end hack

return $encoded;
}

This seems to filter down better for javascript and raw embeding, you can remove the other location of the hack.

I am guessing it is the:

$encoded = drupal_query_string_encode($flashvars);

But not up for hunting that down today.

Oceria’s picture

#10 No, I use direct embedding. The problem was that I didn't use the hack in the right place. After reinstalling and reapplying the hack (this time in the right place) all started working properly again.

The hack you suggested does not work as well as the first one: the %3A/%252F is not converted to :// anymore and what is more, for some obscure reason the background of weijering player now turns black, even if #FFFFFF is set in the settings menu. Reversing back to the previous hack.

yan’s picture

I am having the same problem with 1 pixel out player using swftools (the other players work just fine). The hack from #11 doesn't work for me.

Oceria’s picture

Make sure you have the correct hack (not from number eleven, but from e few posts back) and that you put it in EXACTLY the correct position!

yan’s picture

Ok, now I tried the one from #3 which also didn't work. After that I found that I had to open the settings page (admin/media/swf) to have the changes take effect.

Is this problem gonna be fixed?

Stuart Greenfield’s picture

In response to #15 - if you are using the SWF Tools filter format then the filter results are cached by Drupal, so after applying the fix you need to flush the cache. Visiting an SWF Tools admin page causes this to happen. You don't have to alter any settings, just open a page.

So if you are trying out the hacks listed here you need to visit an admin page after making a change to be sure you are getting the "latest" results.

Pieno’s picture

The problem is caused by the drupal_query_string_encode() function, which in turn uses the drupal_urlencode() function. The urlencode() documentation cleary states:

# mod_rewrite unescapes %-encoded ampersands, hashes, and slashes when clean URLs are used, which are interpreted as delimiters by PHP. These characters are double escaped so PHP will still see the encoded version.
# With clean URLs, Apache changes '//' to '/', so every second slash is double escaped.

This means the drupal_query_string_encode() function is not usable for this purpose.

The solution is to generate the flashvars string by ourself, in stead of using that function. See below for my implementation:

 function _swftools_get_flashvars_string(&$flashvars) {
  $params = array();
  foreach ($flashvars AS $var => $value) {
    $params[] = $var . '=' . rawurlencode(str_replace(array('&', '=', '?'), array('%26', '%3D', '%3F'), $value));
  }
  
  $encoded = implode('&', $params);

  // '#' seems to encode as %2523, reverse this, using a more robust hex prefix..
  $encoded = str_replace('%2523', '0x', $encoded);
  return $encoded;
} 
Stuart Greenfield’s picture

A fix for this issue is built in to a new 5.x-1.x-dev release and is ready for testing. The new package will be available when the packaging scripts next run.

At the moment it uses the code suggest in this thread to re-substitute an unencoded string.

Stuart Greenfield’s picture

Status: Needs review » Fixed

Setting to fixed as new releases of SWF Tools 5.x-2.0 and SWF Tools 6.x-1.1 are now available which address this issue.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.