Calling GalleryEmbed::init()

nmahlin

Joined: 2005-09-26
Posts: 19
Posted: Tue, 2005-10-25 17:27

Looking at the wp integration code I integrated my CMS with g2. One thing I left out of my code was the variable that flags gallery as being initialized. Following the wp code I have the following:

Quote:
runGallery();

function g2_manage_hmd2user($user_ID)
{

// If G2 User not active then link or create.
$ret = GalleryEmbed::checkActiveUser($user_ID);
if ($ret->isError())
{
$customer = db_query("SELECT * from customers where customer_id = $user_ID"));
list ($ret, $g2finduser ) = GalleryCoreApi::fetchUserByUsername ($customer['email_address']);
//if no error then map the hmd to g2id
if (!$ret->isError())
{
GalleryEmbed::addExternalIdMapEntry($user_ID, $g2finduser->_id, 'GalleryUser');
if ($ret->isError())
echo "<h2>Fatal G2 error:</h2> " .$ret->getAsHtml();
}
//otherwise we must create a g2 account
else
{

$ret = GalleryEmbed::createUser( $user_ID, array ( 'username' => $customer['email'], 'email' => $customer['email'], 'fullname' => $customer['firstname'].' '.$customer['lastname'],'hashedpassword' => $customer['password'], 'hashmethod' => 'md5'));
//Check for G2 Error on Add
if ($ret->isError())
{
echo "<h2>Fatal G2 error:</h2> " .$ret->getAsHtml();
}
$ret = GalleryEmbed::checkActiveUser($user_ID);
//GalleryEmbed::done();
}
}

return $ret;

}
function g2_init()
{
require_once('./gallery2/embed.php');
$data = array();
// initiate G2
$ret = GalleryEmbed::init(array('embedUri' => 'main.php',
'embedPath' => '/',
'relativeG2Path' => './gallery2',
'loginRedirect' => 'login.php',
'activeUserId' => ''));
if ($ret->isError()) {
// a real problem, handle it, i.e. raise error or echo error message
echo "<h2>Fatal G2 error</h2> Here's the error from G2: " .$ret->getAsHtml();
get_footer();
exit;
}
return $ret;
}
function g2_login() {
$user_ID = $_SESSION['customer_id'];
echo 'User Id: '.$user_ID;
$ret = g2_init();
if (!$ret->isError())
if ($user_ID)
$ret = g2_manage_hmd2user($user_ID);
else
GalleryEmbed::checkActiveUser('');
return $ret;
}
function runGallery() {
$ret = g2_login();

if ($ret) {

$g2data = GalleryEmbed::handleRequest();

if ($g2data['isDone']) {
exit; // G2 has already sent output (redirect or binary data)
}

// Display G2 Output
echo $g2data['headHtml']; //Include the gallery header
echo $g2data['bodyHtml']; //Display the gallery content

//Close Gallery Connection
// flush_it();
GalleryEmbed::done();

}

My question is do I only need init() run once and not everytime? Which means the g2_manage_hmd2user($user_ID) would set a init flag to True.

Thanks

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-10-25 18:43

call ::init once for each http request. no less no more.