Adding Login Box / User Menu Outside G2
|
ryu85
Joined: 2007-09-18
Posts: 19 |
Posted: Mon, 2009-11-02 23:08
|
|
I currently have a site that is mainly powered by Gallery2. There are however a few pages that are just static content outside of G2. In my sites header ( at least when in gallery 2 ) I have the login box, that is then replaced with the user menu once the user is logged in. The problem is when a user navigates away from the gallery2 section into the static .html pages this login box disappears. This looks rather odd as the gallery has been formatted to fit well into the rest of the site, so something just vanishing from the header may be a bit confusing for users. Is there anyway to incorporate the login box outside of gallery2? I've looked at embedding but it seems a little overkill? At very basic I'll settle for copying the login box html, and a link to the users album, and just make a custom cookie detection to see if a user is logged in, but surely theres a better way I'm just not thinking of? Thanks in advance. |
|
| Login or register to post comments |

Posts: 3371
Write your own html form, using the information in this thread:
http://gallery.menalto.com/node/79854
You actually need to load *all* of the Gallery framework to generate a "real" login box, because you need the gallery Url generator, authToken etc, so that means a full embedding. But you can cheat, as I've outlined above.
(edited to correct link)
Posts: 2669
This is a snippet from an example I called g2_html_segments_example
<?php require_once ('embed.php'); // Path to Gallery's embed.php $ret = GalleryEmbed::init(array('g2Uri'=>'/gallery2/', 'embedUri'=>'/gallery2/main.php', 'fullInit'=>'false')); if ($ret) { print $ret->getAsHtml(); } $gallery->setConfig('showSidebarBlocks', false); // you can hide the sidebarblocks in fact you must to use $g2data['sidebarBlocksHtml'] $gallery->setConfig('login', true); // you can allow for login if you want //$gallery->setConfig('defaultAlbumId', 1400); // set the default home album $g2data = GalleryEmbed::handleRequest(); if ($g2data['isDone']) { exit; } GalleryEmbed::done(); ?> <!-- Gallery's headHtml --><h1>$g2data['headHtml']</h1> You'll have to view source for the headHtml. <?php echo $g2data['headHtml']; ?> <!-- End Gallery's headHtml --><!-- Gallery's bodyHtml --><h1>$g2data['bodyHtml']</h1> <?php echo $g2data['bodyHtml']; ?> <!-- End Gallery's bodyHtml --><!-- Gallery's sidebarBlocksHtml --><h1>$g2data['sidebarBlocksHtml']</h1> <?php foreach ($g2data['sidebarBlocksHtml'] as $snippet) { echo $snippet; } ?> <!-- End Gallery's sidebarBlocksHtml -->in particular it shows you how to separate the different html returned by gallery to use how you want.
But as Alec points out it requires booting up gallery per request.
If you get interested in embedding here is a handy tool.
-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2
Posts: 19
Thanks guys,
alecmyers: I had thought about "cheating" by just writing the form yea, but it would be nice to incorporate the authTokens like you said.
suprsidr: Cheers for this I'll have a little play, and see what happens. If i get it working hopefully I'll be able to provide some more detailed instructions as I feel it'll be a nice feature for people who have some files outside of G2 for content that they want to 'integrate' into G2 a bit better.
Shall report back shortly!
Posts: 19
Hmmm, little tricker than I first thought.
I've got the gallery embedded fine. This is quite a tailored install of gallery2 I've got for this site. It currently doesn't use the sidebar, which appears ( with that embed code above ) to be the only place to isolate certain 'elements'. My login area is included from theme.tpl as follows:
{if $user.isRegisteredUser}
{g->block type="core.SystemLinks"order="core.YourAccount core.Login core.Logout" othersAt=4}
{else}
<p><strong>looking for your photo album?</strong> <a href="" id="open-login">find it here</a></p>
<div id="login-box">
{g->block type="core.LoginBlock" }
</div>
{/if}
What I could do (and tried successfully) is just include the login box in the sidebar and output that and hide it from my main gallery view, only showing in the embed version, however then I don't get the options of Show menu if logged in, without customising the main login block.. Which wouldn't be the end of the world I suppose.
An ideal situation would be to wrap my static html files in my theme.tpl but since bodyHTML returns the entire album display this doesn't seem possible?
Apologies if this seems like a stream of consciousness, helps me think lol
Posts: 3371
You don't need to "isolate certain elements". Create a gallery URL that returns a plain login-box in an otherwise empty page (by writing a 5-line module, with one View, which has a three-line template with the login url generated in smarty "{g->url...}" ) then provide that url to your call to GalleryEmbed::init(...)
What is returned in $g2data['bodyHtml'] is the result of that template, already rendered, in html, which you can then echo as part of your form.
It's up to you how you distribute the rest of the login form html between the g2 template and your embedding code, as long the login url itself is generated within smarty/gallery. If the user is already logged in then you can detect this in your mini-template, and return appropriate html in that case too.
Presto-hey.
Posts: 2669
If your login block is in your sidebar, you'd need to know which positions its in to display just the login block ie.
echo $g2data['sidebarBlocksHtml'][2];
if the login block was in the third position.
-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2
Posts: 19
Cheers again guys, alecmyers i'll give what you're saying a try, have never create a module before so will have to have a look into that first. I'll report back my findings :D
suprsidr, thanks for that mate, I sorta assumed that could happen after doing a var_dump on the g2data array. the only issue I have with it is that i'd have to modfiy the core login block to add the if statement to show menus instead of login box once logged in. Looks like a custom module may have to be the way forward, I'll do a little digging.
Posts: 3371
Don't be troubled by the thought of creating a module. It needs to consist only of one file - a module.inc file, and that only needs about 10 standard lines.
See for instance: http://gallery.menalto.com/node/91847#comment-324342 - a complete module+event-handler in one file.