Access URL Rewrite from embedded application

checkers22

Joined: 2005-11-15
Posts: 4
Posted: Tue, 2005-11-15 22:13

Hey,

I am trying to embed Gallery2 into a PHP page. According to teh Gallery2:Embedded Rewrites tutorial and another post, you have to access the URL Rewrite admin interface from the embedded application. My question is how do I do this because when I open the page it is as if it is in guest mode. There is no link to login so I'm confused on how to access the admin interface. Any help would be greatly appreciated. And if you want me to post anything else just let me know.

Thanks,
Matt

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-15 23:03

you're supposed to login to your application and handle over the active user id to g2 in GalleryEmbed::init

before you can do that you need to map your admin user to G2's admin user with GalleryEmbed::addExternalMapEntry

 
checkers22

Joined: 2005-11-15
Posts: 4
Posted: Tue, 2005-11-15 23:52

Thanks for the quick response valiant. I believe I'm getting someplace now. I read over some other posts and I think I got it to the point where it appears that I'm logged in as admin.

I'm not quite understanding what I did though. Below is the file that I download from the integration forum. I added an entry of (6, GalleryUser, 6) into the externalidmap in the database. Is that right?

Now my problem is that the links are broken...so if I click on an image or the SiteAdmin link at the top of the page it doesn't work. Does the php file look correct?

Document Root: /var/www/
My gallery: /var/www/localhost/htdocs/gallery2/
The php file (below): /var/www/localhost/htdocs/main.php

For example here is the link to one of the images: http://example.com/localhost/htdocs/d/14-2/DSCN0013.JPG?g2_GALLERYSID=0c43bd9e09c2d8a139ba9a328891ea67

I'm not quite sure how the links should show up, but soemthing is wrong with the links. Got any ideas?

<?php

$data = runGallery();
$data['title'] = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : 'Gallery';

if (isset($data['bodyHtml'])) {
print <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>{$data['title']}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
{$data['javascript']}
{$data['css']}
</head>

<body>
{$data['bodyHtml']}
</body>
</html>
EOF;
}


function runGallery() {

    require_once('./gallery2/embed.php');
    
	$data = array();
	
    // if anonymous user, set g2 activeUser to ''
    $uid = '6';

	 
    // initiate G2 
    $ret = GalleryEmbed::init(array('embedUri' => 'main.php', 
				    'embedPath' => 'localhost/htdocs',
				    'relativeG2Path' => 'gallery2',
				    'loginRedirect' => 'index.php',
				    'activeUserId' => $uid));
    if (!$ret->isSuccess()) {
      $data['bodyHtml'] = $ret->getAsHtml();
      return $data;
    }

    // user interface: you could disable sidebar in G2 and get it as separate HTML to put it into a block
    // GalleryCapabilities::set('showSidebarBlocks', false);

    // handle the G2 request
    $g2moddata = GalleryEmbed::handleRequest();
  
    // show error message if isDone is not defined
    if (!isset($g2moddata['isDone'])) {
      $data['bodyHtml'] = 'isDone is not defined, something very bad must have happened.';
      return $data;
    }
    // exit if it was an immediate view / request (G2 already outputted some data)
    if ($g2moddata['isDone']) {
	exit; 
    }
   
    // put the body html from G2 into the xaraya template 
    $data['bodyHtml'] = isset($g2moddata['bodyHtml']) ? $g2moddata['bodyHtml'] : '';

    // get the page title, javascript and css links from the <head> html from G2
    $title = ''; $javascript = array();	$css = array();
 
    if (isset($g2moddata['headHtml'])) {
      list($data['title'], $css, $javascript) = GalleryEmbed::parseHead($g2moddata['headHtml']);
	  $data['headHtml'] = $g2moddata['headHtml'];
    }
    
    
    /* Add G2 javascript  */
    if (!empty($javascript)) {
      foreach ($javascript as $script) {
	     $data['javascript'] .= "\n".$script;
      }
    }

    /* Add G2 css  */
    if (!empty($css)) {
      foreach ($css as $style) {
	     $data['css'] .= "\n".$style;
      }
    }

    // sidebar block
    if (isset($g2moddata['sidebarBlocksHtml']) && !empty($g2moddata['sidebarBlocksHtml'])) {
      $data['sidebarHtml'] = $g2moddata['sidebarBlocksHtml'];
    }
    
    return $data;
} 

?>

Once again I appreciate all the help.

Thanks,
Matt

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-16 00:04

your php application, does it have user management? can you login to your website (apart from G2)?

 
checkers22

Joined: 2005-11-15
Posts: 4
Posted: Wed, 2005-11-16 00:38

Oh...no, at least not at this time. Is that where the idea for this script comes from? Currently I'm looking to display different albums on my website. I don't really want to modify the theme because I was hoping to in the future, have two websites linking to different albums in gallery. I was thinking that I could just use the guest account (uid='') once I got it up and working. But maybe in the future, user managmement would be added.

Right now I'm having problem with broken links. I was thinking that maybe it was because of the URL Rewrite and how it says you need to access the setup for URL Rewrite through the embedded application. I'm unable to access the SiteAdmin link in my php file because of the broken links.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-16 08:58

you don't need GalleryEmbed for your homepage then. GalleryEmbed is mainly used to embed G2 in another application and to provide user mapping/synchronization.

what you can do:

use GalleryEmbed (because you like the non-user sync features) and do not specify activeUserId as argument, just leave it out. In that case, GalleryEmbed will use the current cookie / session.
then you need to call GalleryCapabilities::set('login', true); right after GalleryEmbed::init(); and before ::handleRequest(); and you'll get the login link again.

@URLs:
set embedUri = name of your wrapper file, embedPath = path from document root to the wrapper file (certainly without localhost/htdocs, i guess it's just '/' in your case). relativeG2Path = ./gallery2/ in your case.

 
checkers22

Joined: 2005-11-15
Posts: 4
Posted: Wed, 2005-11-16 13:31

Ok...that did it...THANK YOU SOOO MUCH VALIENT...I really appreciate your helpfullness.

I have a couple more questions though...
1. I was just wondering about the URL still... if this is my setup:
Document root of website: /var/www/
Location of wrapper file: /var/www/localhost/htdocs/main1.php
Location of gallery: /var/www/location/htdocs/galler2/

Are these right?
embedUri = main1.php
embedPath = /localhost/htdocs
relativeG2Path = gallery2

2. Is there any way that I can just display a specific album with that script?

Once again...thanks a lot and I really appreciate your help!
Matt

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-16 18:26

1. yes, but do you really browse to your site with
http://somehost/localhost/htdocs/main1.php
only then it's correct.

2. well, you can add g2_view=core.ShowItem&g2_itemId=$id to the $_GET parameters in your script and then it will show this album...