First of all: thanks for an awesome product. I'm mindboggled by the amount of work put into this project, and even more so by the fact that it's all absolutely free. You are next on my "FOSS projects to donate to"-list.
Having just recently (like, today) begun following the developers' discussion on G2 (which, by the way is looking way beyond alpha-stage), I've not yet grasped the programming structure of G2. So pardon me, if the answer to this is obvious.
I've installed from CVS (8 hrs ago) and everything went without a hitch. I'm on Debian Sarge, Apache 1.3 and PHP 4.9. Now I'm looking to do what I did with Gallery 1.x [1], which is embed it into my own PHP-based website. It ought to be rather simple, since I have a generic header and footer that could be just wrapped around G2's code, but I'm confused about which approach is The Proper One (tm). I've looked at global.tpl.local but am not sure if Smarty will let me include PHP (seems to treat it somehow). Do I need to create my own theme? Or is there another template that I have to look at?
I realize that G2 has some CSS and other stuff that needs to be there, and most of global.tpl is obviously crucial, but how do I go about inserting my own <HEAD>-stuff with an include()-statement?
Thanks for any pointers you can give me.
G.
[1] See my post here and guide here
Posts: 8601
http://smarty.php.net/
I think you can use {php} to add raw php.. check the docs.
Posts: 52
Oh .. I suddenly see the force in utilizing Smarty for templating G2. Good job!
Never fiddled with Smarty before, though, and after getting most of what I outlined above working, I still have one issue:
G2's default <HEAD> (in global.tpl) contains a Smarty-statement:
which cannot be ignored. However, in order to get my own PHP header and it's contents snuck in before G2, I've replaced the entire <HEAD> in global.tpl.local with an include-statement to my own header. So the call-sequence is something like (G2 <- Smarty <- global.tpl.local <- include PHP header <- back to global.tpl.local).
According to the the Smarty docs, I have access to the Smarty-object thru the PHP variable $this in my header, but how can I make Smarty evaluate that one line and throw it into the cache along with the rest of the template? The Smarty docs don't seem to mention this.
My plan for my PHP header was something like:
Except that there's no such function in Smarty.
Does someone with more Smarty-knowledge than me (ie. 0+) have a clue on this?
Thanks,
G.
Posts: 328
geddeth, I would use a more "standard" way of embeding G2 in your PHP application. Instead of using Smarty as a glue, you should use PHP and our embed.php script that is specifically designed for this kind of task.
This will make sure that the Gallery Framework is loaded (which includes a proper working Smarty) and you don't have to worry about (almost) anyhing.
Your PHP code is for example called "photo_album.php" and will look somehow like:
You see, after calling handleRequest() you will have the headHtml and bodyHtml content in this array for your usage. Just place it where you want them to appear.
Anyway, this is documented in docs/EMBEDDING, you can read much more details there. Please note that the whole embeding API is still a work in progress and might change. Maybe you find other useful stuff you want added there so your input on that is also welcome.
Cheers,
Ernesto
Posts: 52
baschny, thanks a lot for that information. I'm sorry for the late reply, I somehow got unwatched for this topic.
Anyway, I'll have a look at it straight away and report what happens. I forgot to mention in my first post, that I had actually seen the EMBEDDING document, but found it kinda bloated for my needs (and hard to figure out, actually). But your approach is much more understandable, I'm really happy that you thought of this scenario as well, so it's so easy to embed.
I'll be in touch.
Thanks,
G.
Posts: 52
Okay, it's installed from latest CVS. It was quite easy to figure out, and the method is very flexible and fits nicely into my own code.
One thing, though - the $g2data['headHtml']-variable which fits into the HTML header contains a <TITLE>-tag. This seems out of place, since one will often have the title of one's website here. It would be more useful, if the $g2data-array contained a string with the Gallery name along with the albums (and sub-albums) you were currently in. That way, one could use it anywhere on the current page, even in the <TITLE>, if one preferred that (which I do). So it would be, e.g.
<HEAD><TITLE>MyWebSite :: <?php echo $g2data['naviString']; ?></TITLE></HEAD>
or something similar. Might need some config option for e.g. a path seperator.
Another thing is that I can't figure out how to implement the Gallery login procedure. I don't have seperate user logins, but I do have a few Gallery users (and admin, of course). It seems like I have to build the login form myself. Why not have an option that includes the default Gallery login-link in $g2data['bodyHtml'] for cases where one prefers not to synchronize Gallery users with the embedding application's?
Otherwise, kudos for the way the Gallery output is simply available to be used in this way - it can hardly be any simpler.
Thanks,
G.
Posts: 8601
yup, we're aware of the title thing but haven't yet figured out a solution.
if you're not going to sync users then do you want to use the G2 login view? the embed class assumes the embedding app will take care of logins, so the G2 login is disabled by default, but you can turn it back on if you like.. you can see where it gets turned off in GalleryEmbed::init.. just do GalleryCapabilities::set('login', true) after your init call but before handleRequest..
Posts: 52
mindless: Thats exactly what I wanted, thanks. Apart from the <TITLE>-bit, I've achieved everything I wanted, and more.
Is the GalleryCapabilities documented anywhere (apart from source)?
G.
Posts: 8601
no, not yet.. eventually this should be in docs/EMBEDDING.
for the title thing, for now you can do some regular expressions on the returned header content to pull out the title..
Posts: 52
Yes, I did something to that effect for the time being. Thanks.
Posts: 32509
We should definitely add some methods to embed.php like
getPageTitle()
getCSSLinks()
getJavascript()
even if they just contain some regexp to extract the strings from the head HTML and return it.
I mean, I have written the regexp, geddeth, walkah for drupal, etc. and they all do the same.
IMO the regexp I have isn't that bad, we could just move it to embed.php.
Posts: 52
Today's changes to embed.php (in CVS) seem to alter the way all this works. The EMBEDDING doc doesn't seem to reflect or, or else I'm not reading it right.
Now, it seems $g2data is just NULL. Here's the essentials of my code:
Can anyone explain?
Posts: 8601
check the CMS Integration topic in this forum.. I posted all about it.
and docs/EMBEDDING is updated to match the changes.
(Edit: so if you see anything that seems wrong in the docs, let me know!)
Posts: 52
Hmm .. odd. I didn't change anything in my code, but after updating from CVS, all is back to normal. Weird.