Recent Topics

1 Aug 25, 2008 03:27    

Hey all,

I'm trying to write a feature in the gallery2 plugin to allow you to have an embedded gallery2 page in b2evolution much like the [url=http://wpg2.galleryembedded.com/index.php?title=WPG2:Screenshots_of_a_Gallery2_Embedded_Page_1]wordpress version[/url].

But, I'm running into some problems that have to do with the fact that gallery2 generates relative urls in the gallery2 page. b2evolution includes a <base> tag that causes relative urls to have a base url of the installed skin's directory instead of the current url. So gallery2's generated urls end up having a base of the b2evo skin's directory and this results in an unnavigable gallery2 embedded page.

I have to be honest, if b2evo didn't have this tag I wouldn't even know it exists and I think it's a silly idea that it's in there because a lot of software manipulates urls assuming it's not there. Does anyone know why b2evo needs this <base> tag? Is this something that b2evo puts in there or is it just that most skins have it in there?

2 Aug 25, 2008 03:36

IanLewis wrote:

... I have to be honest, if b2evo didn't have this tag I wouldn't even know it exists and I think it's a silly idea that it's in there because a lot of software manipulates urls assuming it's not there. ...

Actually that's completely backwards. What you mean is that many pieces of software out there act as if the tag DOES NOT exist in the <head> section of the web page. In other words, they ASSUME base URL will be the domain name ... or possibly will be the folder the application is installed in. Nothing could be further from the truth.

So b2evolution uses sets the base tag to the URL for the skin folder in order to build a heck of a lot of internal links relative to that path. For example images in a skin folder, and style sheets that are not part of the actual skin but are called by the skin. Is this the best possible answer? NO! It is, however, how it works.

Seems like possibly the answer to your dilemma is to find out why gallery2 assumes the base tag is something that it can't be sure it is, and address that. Perhaps there is a way to tell gallery2 what it should use for the base part of a URL? I don't know because I don't know that software, but if you want to embed that tool into this tool then this tool (logically) takes priority. Alternatively, take it out of your skin and see what (if anything!) goes wrong ... then fix that.

3 Aug 25, 2008 04:17

If Gallery2 relies on relative URLs I bet they use a <base> tag as well. I think the galleries are best embedded in iframes. I even believe this is recommended by Gallery2.

Good luck

4 Aug 25, 2008 06:56

EdB wrote:

Actually that's completely backwards. What you mean is that many pieces of software out there act as if the tag DOES NOT exist in the <head> section of the web page. In other words, they ASSUME base URL will be the domain name ... or possibly will be the folder the application is installed in. Nothing could be further from the truth.

Well, yes but in most cases (cases without the <base> tag) the base URL can be found by manipulating the current request url. With the base url, anything that generates relative urls would need two parameters, the base url (from the <base> tag) and the url that we want to create a relative url from.

I have a feeling most PHP programs that generate relative urls only take the second argument and assume the first can be found from the current request url. If providing support for the <base> tag is the right way I've never seen anything that does it the right way.

It's true that it's technically part of html and probably should be supported somehow but it makes interop with other programs pretty annoying.

Afwas wrote:

If Gallery2 relies on relative URLs I bet they use a <base> tag as well.

nope.
I've personally never seen the base tag outside of b2evo.

Afwas wrote:

I think the galleries are best embedded in iframes. I even believe this is recommended by Gallery2.

Yuck. I suppose I could do it this way but I'm thinking this will cause more problems with skins than would already have to be dealt with.

I don't like iframes and the scrolling problems and cross browser display issues that come along with them. With an iframe it's hard to get the iframe to appear as if it is in the page (without a subwindow and scrollbar). Neither the wordpress gallery2 integration or the drupal gallery2 integration do it this way.

6 Aug 25, 2008 07:42

EdB wrote:

Perhaps there is a way to tell gallery2 what it should use for the base part of a URL?

There is. I give it http://mysite.com/gallery as my embedded url and if the current request url is http://mysite.com/gallery also, then it generates urls like "gallery?g2item_id=...".

I agree that's technically not right, but I've seen a lot of software that uses the current request url to manipulate urls to make links so the <base> tag doesn't feel terribly practical.

7 Aug 25, 2008 09:33

I have zero idea how you embed gallery 2 into your page, but could you cheat and ob_start() the contents and then use a regex to add the embed url to all href/src that don't start with http:// ?

¥

8 Aug 25, 2008 13:58

And actually you can remove it from your skins/_html_header.inc.php file (or something like that) or maybe it'll be in skins/yourskin/ and see what you get. Right off the top of my head you'll want to look at your style.css file and correct references to other style sheets in rsc/css/, background images (and possibly images) that would normally be found in skins/yourskin/img/ (and sometimes /images/ depending...).

After that I can't think of any clear cases that depend on the base href being installation_path/skins/yourskin/ so maybe it can be easily removed?

9 Aug 25, 2008 15:54

According to the Gallery doc you can make your own object. Obviously an edited copy of an existing one. That's where you use Smarty as script language (good luck with it). Smarty allows you to generate absolute URLs:

url

Usage: {g->url href=hrefUrl params=array arg1="param=value" arg2="param=value" htmlEntities=false forceDirect=true forceFullUrl=true forceSessionId=true|false

* htmlEntities=false replaces &amp; with & in the url (previously was forJavascript=true)
* forceDirect=true to generate a G2 site url even if embedded
* forceFullUrl=true to generate an absolute url rather than a relative path url
* forceSessionId=true/false to specify if the G2 session id should be embedded in the url; by default it is included only for non-href urls when cookies are not in use
* params= and arg#= can be used together starting in G2.2 (arg1,etc added to given params array)

[url=http://codex.gallery2.org/Gallery2:Themes:Reference:Tags]Gallery2:Themes:Reference:Tags[/url]

So with the object you had in mind you can change the URLs yourself.

Have fun

10 Aug 25, 2008 16:07

My solution may be crap, but at least it was a one liner :D

¥

12 Aug 25, 2008 16:15

Howdy ¥åßßå, My proposed solution is a single argument when you instatiate (Init) Gallery2 if I got it right from the Docs. That's even less than a single line ;)

13 Aug 25, 2008 16:30

Bugger :p ... maybe I could use a [font size=less_than_a_setting]small[/font] font ?

¥

14 Aug 26, 2008 05:38

Afwas wrote:

According to the Gallery doc you can make your own object. Obviously an edited copy of an existing one. That's where you use Smarty as script language (good luck with it). Smarty allows you to generate absolute URLs:

url

Usage: {g->url href=hrefUrl params=array arg1="param=value" arg2="param=value" htmlEntities=false forceDirect=true forceFullUrl=true forceSessionId=true|false

* htmlEntities=false replaces &amp; with & in the url (previously was forJavascript=true)
* forceDirect=true to generate a G2 site url even if embedded
* forceFullUrl=true to generate an absolute url rather than a relative path url
* forceSessionId=true/false to specify if the G2 session id should be embedded in the url; by default it is included only for non-href urls when cookies are not in use
* params= and arg#= can be used together starting in G2.2 (arg1,etc added to given params array)

[url=http://codex.gallery2.org/Gallery2:Themes:Reference:Tags]Gallery2:Themes:Reference:Tags[/url]

So with the object you had in mind you can change the URLs yourself.

Have fun

This is a reference for how to create gallery2 themes. The g object is a gallery2 smarty object that is accessable within a theme template.

g->url is a smarty function which I don't have access to via the GalleryEmbed interface. The gallery2 theme, url generation, html generation, everything is handled within gallery2 via the [url=http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryEmbed.html#methodhandleRequest]GalleryEmbed::handleRequest()[/url] function.

The options listed on the [url=http://codex.gallery2.org/Gallery2:Integration_Howto]Gallery Integration Howto[/url] that you linked to are the only options I have available via the GalleryEmbed::init() (see also: [url=http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryEmbed.html#methodinit]Docs For Class GalleryEmbed[/url]). Currently I supply a full absolute url to embedUri but it is rewritten as a relative url by gallery2 based on the current request url.

There may be a way within gallery to set an option to have skins generate full urls. I'll investigate further.

* activeUserId string/mixed - emApp user Id of the active user (empty string for anonymous/guest user)
* embedUri string - URI to access G2 via CMS application. Base URL (internally it's called baseUri) of all embedded G2 requests. Protocol and host name are optional. Examples: /index.php?module=gallery2, /portal/index.php?module=gallery2, /, http://www.example.com/index.php?module=gallery2, www.example.com/portal/index.php?module=gallery2
* g2Uri string - URI of the G2 standalone location. Path from docroot to the directory main.php is located. Protocol / host name are both optional. Examples: /gallery2/, /sub/gallery2/, http://photos.example.com/, www.example.com/photos/main.php,
* loginRedirect string - URI for redirect to emApp login view (example: /emApp/index.php)
* embedSessionString string - (optional) To support cookieless browsing, pass in key=value for emApp session key and session id value to be added as query parameter in urls
* gallerySessionId string - (optional) To support cookieless browsing, pass in G2 session id (when cookies not in use, CMS must track this value between requests)
* activeLanguage string - (optional) language code in use for this session. Format: {LANG}_{COUNTRY}, ISO language and ISO country code (e.g. en_US)
* fullInit' => boolean - (optional) call GalleryInitSecondPass (only use when not calling handleRequest). Defaults to false.
* apiVersion => array (int major, int minor) - (optional but recommended) specify to check if your integration is compatible with the Embed API

I might be able to force people to use a particular gallery2 theme that I have crafted myself to always set forceFullUrl to true but that would require them to install it in their gallery2 themes folder and the plugin wouldn't work sanely "out of the box" and might have to be modified to work with different b2evo skins. (users might have to make css changes to make it work in their b2evo skin anyway though). Plus it's a pain to explain how to do it properly as they would probably have to create a folder called local/ and put the theme inside that folder so that it's not deleted or overwritten when upgrading gallery2. I have a feeling it would be hard for users to understand.

¥åßßå wrote:

I have zero idea how you embed gallery 2 into your page, but could you cheat and ob_start() the contents and then use a regex to add the embed url to all href/src that don't start with http:// ?

Actually this sounds like the easiest and thus most plausable solution as it would be a one liner. I'll give it a try later. I could try to monkey around with GalleryCoreApi in order to be able to give the theme a custom g object that ignores the full url option and always renders full urls but that seems like a pain and even if gallery2 recognizes it as a bug and fixes it, I wouldn't be able to support earlier versions.

15 Aug 27, 2008 07:44

Go play with your testblog. You probably can do without the base tag in your skin (use your testblog to verify this idea). I think it's a relic from the past to point to the correct css file. This is handled totally different in current versions of B2evo.
EdB gave the correct answer I think. But the images he talks about are from the css file and they are relative to this css file, so I don't expect any problem there also.

If this works as planned you can add a one liner jQuery in your plugin to get rid of the base tag in any skin.
I think this is the easiest solution. Especially useful if you don't succeed in telling Gallery2 to use absolute URLs.

Good luck

16 Aug 27, 2008 11:39

That would fail if the user had js disabled ;)

¥

17 Aug 27, 2008 12:19

Ok, I'll try to see if it works. Though I'd like to avoid requiring users to download jQuery just to remove a base tag if possible. While it's included and is loaded by the admin normally, it's not loaded on the blog side unless a plugin requires it.

18 Aug 27, 2008 15:41

I presumed Gallery2 and/or the way you display your pictures isn't much fun without js.
You can ask your users to delete the one line out of their skin.
I don't know what happens if you try to override the base tag with a new base tag. you could try from your plugin.

Lots of ideas

19 Aug 27, 2008 18:49

Well, either one would work. I already tried the regex replace and that works pretty well. Offering javascript integrations with other plugins or somesuch is an idea for future features.

The next thing I need to think about is what do to about the page and multi-blogs. Currently you would have 1 gallery2_plugin install per gallery2 install but nothing really on a per blog basis so it really isn't really a per-blog feature. But creating a page is like creating a blog post; it needs a blog and category to work properly. So I need to build a good way for users to choose which blog/category to put the page in. ideas?

20 Aug 27, 2008 19:44

Have a browse of the code in this post ( [url=http://blogrum.innervisions.org.uk/tech/add-tabs-in-admin-from-a-plugin]Add tabs in admin from a plugin[/url] ), I'm *pretty* sure that one of teh tabs it adds is to your normal blog settings page which would allow you to add a settings page on a per blog basis with only one plugin install ( and ## gallery2 installs ).

I don't know if this is feasible, gallery 2 is a tad overkill for my needs, but something we sometimes do ( from a plugin ) is to create our own post type, or do you need the posts in a particular category for all this to work?

¥

21 Aug 27, 2008 19:48

Another potential solution for your <base> problem.

This is the function from inc/skins/_skin_funcs.php ( approx 332 )

/**
 * Template tag. Output HTML base tag to current skin.
 *
 * This is needed for relative css and img includes.
 */
function skin_base_tag()
{
	global $skins_url, $skin, $Blog, $disp;

	if( ! empty( $skin ) )
	{
		$base_href = $skins_url.$skin.'/';
	}
	else
	{ // No skin used:
		if( ! empty( $Blog ) )
		{
			$base_href = $Blog->gen_baseurl();
		}
		else
		{
			global $baseurl;
			$base_href = $baseurl;
		}
	}

	$target = NULL;
	if( !empty($disp) && strpos( $disp, '-popup' ) )
	{	// We are (normally) displaying in a popup window, we need most links to open a new window!
		$target = '_blank';
	}

	base_tag( $base_href, $target );
}

If you can find an early enough hook you could override the globals ;)

¥


Form is loading...