[SOLVED] URL Rewrite Plugin - how to stop [or swap] "+" being inserted into photo names where a space exists?

mexicoshaun

Joined: 2007-06-21
Posts: 15
Posted: Wed, 2012-07-18 19:27

[gallery 2] - yeah i know i should put the full info.. not needed on this one i dont thnk ;)

because url rewrite is putting the plus sign in my url's I cannot get facebook like to display the thumbnails, its very picky about the url path

URL rewrite is substituting a "+" where a space exists in the actual filename, where do i change this, e.g. tell it to use underscore instead ??

any help much appreciated as always from you g2 gurus

shaun

 
Dayo

Joined: 2005-11-04
Posts: 1642
Posted: Wed, 2012-07-18 19:49

I am not 100% sure because I haven't checked, but I don't think "+" for space is not a url rewrite doing.

In any case, the issue is most likely because PHP's urlencode function substitutes "+" for space. the equivalent urldecode function understands this and everything works well within PHP.

However, FB uses javascript to pass stuff and the JS version works differently ... leaves spaces as they are and when it tries to decode a PHP urlencoded string, the "+" remain intact.

You might be able to overcome this by using something like var myEncodedURL = "some encoded string"; var myDecodedURL = decodeURIComponent((myEncodedURL+'').replace(/\+/g, '%20')); and pass "myDecodedURL" to FB.

--
dakanji.com

 
mexicoshaun

Joined: 2007-06-21
Posts: 15
Posted: Wed, 2012-07-18 22:36

i think you are right,thanks so much, and that sounds like a good solution, can i put the needed php in album.tpl ?

 
Dayo

Joined: 2005-11-04
Posts: 1642
Posted: Thu, 2012-07-19 03:32

The code above is not PHP but javascript.

As to where to pus it, wherever the URL is being passed to FB is the answer.

I.E., you take the current URL being passed and first decode it for javascript and pass the decoded version.

--
dakanji.com

 
mexicoshaun

Joined: 2007-06-21
Posts: 15
Posted: Thu, 2012-07-19 08:07

lol, showing my noobishness! seeing as im using js already to make the lightbox that should be fine, i will just put it in line somewhere, i wonder if it would be possible/ better to do it server side though, probably no particular advantage in this case though

lucky i asked though, or i'd be scratching my head trying to understand the php decodeURIComponent command ...

thanks again

 
mexicoshaun

Joined: 2007-06-21
Posts: 15
Posted: Thu, 2012-07-19 10:24

The javascript method works well in album.tpl to rewrite the link, but I realise now that I actually need to change the og:image metatag in the <head> section of photo.tpl;
I tried doing this with the javascript method but it doesn't want to write out the results within <head></head>

So, i thought i'd try php str_replace [taking your idea a stage further]

I have tried several different methods, my main problem seems to be putting the gallery generated code inside php, I can do it without breaking the template but it doesn't render the url, just "g->url arg1="view=core.DownloadItem" arg2="itemId=`$theme.item.thumb.id`""

I am trying the following, which seems logical to me, but it breaks my template, not sure why, any suggestions would be more than welcome :)

[this is going in my conditional block for photo.tpl page, in theme.tpl]

Quote:
{assign var="urltodecode" value="{g->url arg1="view=core.DownloadItem" arg2="itemId=`$theme.item.thumb.id`"}"}
{php}
$imageurlstripped = str_replace("+", "%20", $urltodecode);
$this->assign('ogimageurl',$imageurlstripped);
{/php}

<meta property="og:image" content="{$ogimageurl}" />

 
mexicoshaun

Joined: 2007-06-21
Posts: 15
Posted: Thu, 2012-07-19 12:17

I also thought I would try this [smarty string replace], but it doesnt seem to do anything, is it because the g->url arg1="view=core.DownloadItem" arg2="itemId=`$theme.item.thumb.id`" part isn't a string? In which case how do I get it to become a string?

it doesnt break the template, and it looks better, it writes out the correct url, but still with the pesky plus signs in...

Quote:
<meta property="og:image" content="{g->url arg1="view=core.DownloadItem" arg2="itemId=`$theme.item.thumb.id`"|replace:'+':'%20'}" />

 
Dayo

Joined: 2005-11-04
Posts: 1642
Posted: Thu, 2012-07-19 15:57

Now I see what the issue is.

Forget about all the complex smarty, php or js stuff and just try adding arg3="urlEncode=false" to your "g->url" call.

--
dakanji.com

 
mexicoshaun

Joined: 2007-06-21
Posts: 15
Posted: Thu, 2012-07-19 16:16

good call, thanks for the help

i also managed to accomplish this slightly more round the houses by

{capture assign="unstripped"}{g->url arg1="view=core.DownloadItem" arg2="itemId=`$theme.item.thumb.id`"}{/capture}
<meta property="og:image" content="http://www.hen-night.org{$unstripped|replace:'+':'%20'}" />

ie using smarty replace, but urlencode=false is obviously better

thanks again