Recent Topics

1 Dec 06, 2008 03:34    

Hey all,

I'm trying to get an embedded gallery2 page working in b2evolution much the same way that the wordpress plugin works. It works for the most part but I am having trouble with where to place the javascript and css files that are included as part of the gallery2 theme.

Right now I have to do something like this to generate an embedded gallery2 page.

$gallery = $this->runGallery($baseurl, $embeduri);

This gives me an array with keys 'bodyHtml', 'javascript', 'css' which each contain html.

I would like to put the css and javascript in the head portion of the page but I don't want the overhead of running gallery (reading the gallery database generating a gallery2 page etc) on every b2evo page. I would like to be able to tell if I'm viewing the gallery2 embedded page from within the SkinBeginHtmlHead plugin hook.

Right now I have a very cobbled and broken implementation tries to figure out if you are viewing it based on the current url in SkinBeginHtmlHead. runGallery is called there and the bodyHtml is saved in a member variable for later use by DisplayItemAsHtml. This currently breaks with different url schemes.

Is there a good way to do this? I can put the css and javascript html in the post body but that just seems wrong. I could also put them in the footer via SkinBeginHtmlFooter since that is called after any calls to DisplayItemAsHtml. I could probably do that safely for javascript but it would be dumb to do that for css.

I'm open to other possibilities such as putting the javascript and css elsewhere or creating some kinds of options for setting the javascript and css manually via a plugin option but those would largely depend on what theme you had selected in gallery2 (I'll investigate possibilities such as forcing the use of particular themes when generating gallery2 pages also).

Any help or advise would be appreciated.

2 Dec 06, 2008 09:20

I'm assuming by the fact that you're using DisplayItemAsHtml() that there's something in the post body that triggers a gallery ?

In which case :

<?php
function SkinBeginHtmlHead()
{
	global $MainList;
	while( $Item = & mainlist_get_item() )
	{
		if( [your gallery condition ] )
		{ // this is a gallery post
			// do your js/css stuff
		}
	}
	$MainList->restart();
}
?>

¥

3 Dec 06, 2008 10:28

Well, the post itself is created by the plugin and it remembers the id (The post is really a page). It also sets the plugin as a renderer for that post. So when DisplayItemAsHtml is called I check if the item id is right and if so I display the gallery.

The check on MainList might just work. I'll give it a try.


Form is loading...