g2_GALLERYSID fix

penfield888

Joined: 2004-03-02
Posts: 43
Posted: Sun, 2008-11-09 18:39

At least in my case, g2Image inserts URLs with a g2_GALLERYSID on them. I can't imagine any case where anyone would want this, but perhaps such a case exists. I've also seen other people wrestle with how to get rid of it.

I just took a brute force approach and got rid of any and all occurrences in the g2image code. It works for me. No guarantees that it will not break you site. I don't see any downside to this though. If your generated HTML has no g2_GALLERYSID parameters, it won't do anything.

If it does have that parameter, this code will strip it out. I have made the regex such that if there is a parameter after the SID, it deletes the & separator too, so that if getting rid of the SID makes the next param the first one, it will properly have the ? in front of it.

I'm using the Drupal gallery module with the g2Image add-on, so I'm not sure where this would appear in your file structure, but for me it's in the
/lots/of/stuff/g2image/jscripts/functions.js file.

On line 374, I added this:

Quote:
/* hack to filter g2_GALLERYSID from URL */
htmlCode = htmlCode.replace(/g2_GALLERYSID=[^&"]+&?/g, '');

So now it looks like this, in context

Quote:
/* hack to filter g2_GALLERYSID from URL */
htmlCode = htmlCode.replace(/g2_GALLERYSID=[^&"]+&?/g, '');

insertHtml(htmlCode,obj);
}

That regex still leaves a ? at the end of the URL. I might be able to figure it out with a lookahead, but the easy way is just to use two regexes and slightly more overhead. This should do it (untested). The first regex grabs any SIDs with another paramter after and puts in the correct delimiter (? or &). Then it looks to see if there are any SIDS that haven't been replaced yet because they don't have any parameter after them, and it gets rid of those.

Quote:

htmlCode = htmlCode.replace(/([\?&])g2_GALLERYSID=[^&"]+&/g, '$1');
htmlCode = htmlCode.replace(/([\?&])g2_GALLERYSID=[^&"]+/g, '');

I hope this helps. It would be nice to see it integrated into the distro (please please please) so you wouldn't have to fold it in with each upgrade.

BTW, the reason this matters is that Google and other search engines will consider different session IDs to be having different URLs. So it could think you have two or six or sixty pages, where you only have one. That's suboptimal.

Gallery 2, by default, does not serve up a g2_GALLERYSID to search engines when they crawl your site (at least it's not supposed to).

Take care.

------------------------------
Yosemite Explorer - info and virtual "tours" of Yosemite
Yosemite Photos - the part that actually uses Gallery

 
jeffj

Joined: 2007-11-09
Posts: 37
Posted: Mon, 2010-04-19 13:04

I'm curious... what is the reason this code is added? Is it necessary? Maybe I'm missing something, but it seems like a lot of unwanted code to me.

--
Jeff Johnston
http://johnstonjournal.com

 
godt09

Joined: 2010-06-12
Posts: 10
Posted: Sat, 2010-06-12 08:39

Sorry to resurrect this thread, but I have exhausted every other possibility of solving the problem of images not appearing in the g2image popup. When I view the code I see the g2_GALLERYSID... inclusion. I have g2image plugin installed in b2evolution and as a TinyMCE plugin, as per instructions, um, somewhere.

Where do I insert these:

htmlCode = htmlCode.replace(/([\?&])g2_GALLERYSID=[^&"]+&/g, '$1');
htmlCode = htmlCode.replace(/([\?&])g2_GALLERYSID=[^&"]+/g, '');

?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2010-06-12 12:35

just look through g2image.php and change:
array('forceFullUrl'=>true)
to:
array('forceFullUrl'=>true, 'forceSessionId' => false)
there are 4 or 5 occurrences

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2010-06-12 12:46

It's important to understand the use of the g2_GALLERYSID paramater.

The value is the session key in the G2 session table. It's usually not included in urls because it's available from the browser request as a cookie. However it *is* included in the url in two situations:

1. Whenever the browser has cookies turned off the session key has to be passed in the url
2. In the first set of urls generated after a session is started - because at that stage Gallery has no way to know if cookies are being returned or not. If a cookie is received, and it contains the same data as the g2_GALLERYSID the Gallery knows that cookies are active and no longer needs to include the data in urls for that session.

Situation 1 is an extension of situation 2: if no cookie is received and a g2_GALLERYSID is in the url then it needs to be propagated in future urls for that session.

If all your urls continually have g2_GALLERYSID then your browser is not returning cookies. Or the request is generated by some non-browser software without cookie code.

Also note that not all Gallery requests generate sessions - those that follow from logins, cart contents or various other state-type information do.

 
godt09

Joined: 2010-06-12
Posts: 10
Posted: Sat, 2010-06-12 23:48

Thanks people. Replies much appreciated. I am encountering this problem with all browsers, all of which are accepting cookies. If I use FF to inspect the element - being a blank image cell in the g2image popup when editing a post in b2evolution, I get this, for example:

http://domain/gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=36&g2_GALLERYSID=TMP_SESSION_ID_DI_NOISSES_PMT

Each URL for each image cell will identify a discrete image number, so I assume it is the g2_GALLERYSID parameter which causes the problem still.

 
godt09

Joined: 2010-06-12
Posts: 10
Posted: Sat, 2010-06-12 23:30

Suprsidr,

Do I need also to insert somewhere the two lines

htmlCode....

?

 
godt09

Joined: 2010-06-12
Posts: 10
Posted: Sat, 2010-06-12 23:59

Suprsidr,

Just changed code as you suggest. No session id parameter now, but still no image. Just the blank image cell. I have permissions set to 'all access' for albums I am using to test.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2010-06-13 02:53
 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2010-06-13 11:49

@godt09
your problem has no relation to this thread and the sessionId fix.

the g2Uri in your g2Image or possibly your b2evolution is incorrect.
g2Image is looking for gallery in yoursite.com/au/gallery2/main.php whereas gallery is actually located in yoursite.com/gallery2/main.php

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2010-06-13 12:02

I adjusted the g2Uri and the embedUri - now your images show in g2Image. (not sure if the embedUri is correct)

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
godt09

Joined: 2010-06-12
Posts: 10
Posted: Sun, 2010-06-13 23:09

[Bangs head against desk]

Good grief. I've spent 2 days going over settings, reinstalling, and failed to read those paths properly. Thanks for devoting your time to overcoming my stupidity. I think when I saw the Gallery 2 plugin find the Gallery2 directory, I assumed paths would be obvious. Obviously not to me.

Thanks again.