Hi,

Please can you help with the syntax for the following code:

print swf('imagegallery.swf', array('params' => array('width' => '457', 'height' => '446'), 'flashvars' => array('initialURL' => '+escape(document.location)')));

How do I pass the Javascript (escape(document.location) ?

Thanks.

Comments

kingandy’s picture

I'm not sure I get exactly what you're trying to do, but I think you'd do better to generate the document location using PHP instead of javascript. PHP has immediate knowledge of the page address so you don't need to go through JS. It's all available thorough an array called $_SERVER. Unfortunately I don't think there's a single field that contains the whole address, so you may have to assemble your own variable.

The $_SERVER documentation should help you out ... I'd recommend getting the site name from $_SERVER['HTTP_HOST'] and the path from $_SERVER['REQUEST_URI'] - this combination should give you the exact text that was entered into the address bar, regardless of clean URLs or apache rewrites or what-have-you.

So you'll end up with something like this:

 $initialURL = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
print swf('imagegallery.swf', array('params' => array('width' => '457', 'height' => '446'), 'flashvars' => array('initialURL' => $initialURL))); 
sittard’s picture

I'm trying to set up permalinks for slideshow pro (http://wiki.slideshowpro.net/SSPfl/UG-Permalinks) the page URL looks like this:

http://mydomain.com/slideshow.html#id=nature&num=4  

So the idea is to get the SWF to read the document URL and display the correct image from the gallery. Unfortunately it's not possible to get the anchor of the current URL using $_SERVER (http://drupal.org/node/140773) otherwise that would have been a brilliant solution.

Thanks.

tbbjr’s picture

I too am trying to set an SSP xmlfile="http://www.mydomain.com/ssp_director/images.php?gallery=1 " but I am using the swf syntax in a Block Body. Is there any way to pass a var using this syntax? I want to make it as easy as possible to update or have additional blocks using the same swf in the future. It feels like this should be very easy I think it is just a matter of syntax. (i.e. <swf file="http://www.mydomain.com/gallery.swf" var='xmlfile="http://www.mydomain.com/ssp_director/images.php?gallery=1"' >) Any assistance would be greatly appreciated.

I am using the jQuery Flash plugin for embedding if this matters.

***************************
**** After Further Attempts ****
***************************
I can add the xmlfile value but now I need to escape the ? and = in the string. It looks as though the swftools.module is looping through all flashvars and replacing the characters (i.e. function _swftools_get_flashvars_string(&$flashvars)) but I need the characters for the xmlfile to be as entered.

So what is entered as :
<swf file="http://www.mydomain.com/banner.swf" flashvars="xmlfile=http://www.mydomain.com/ssp_director/images.php?album=1" width="600" height="290">

Renders as:
"src": "http://www.mydomain.com/banner.swf", "flashvars": "xmlfile=http://www.mydomain.com/ssp_director/images.php%3Falbum\x26width=600\x26height=290"

sittard’s picture

This is the code that I ended up using on my page/block:

<?php $dir = base_path() . "sites/default/files/";?>
<script type="text/javascript">
var flashvars = {initialURL: escape(document.location)}
var params = {
base: ".",
allowfullscreen: "true"
}             
var attributes = {}
swfobject.embedSWF("<?php print $dir?>imagegallery.swf", "imagegallery-inner", "457", "446", "9.0.0", false, flashvars, params, attributes);
</script>

<p>&nbsp;</p>
<div id="imagegallery">
<div id="imagegallery-inner">You need Adobe Flash to view this gallery</div>
</div>

Hopefully it helps!