<?php
/*
********************************************************************************************************
G2 Session Handling
********************************************************************************************************
*/
/**
* Initialize Gallery; must be called before most GalleryEmbed methods can be used.
* This method should only be called once during the lifetime of the request.
*
* @param NULL
* @return string GalleryStatus
*/
function g2_init() {
// Get WPG2 Option Settings
//$wpg2_option = get_option('wpg2_options');
//$wpg2_g2path = get_option('wpg2_g2paths');
// /echo ROOT_DIR;
$g2_embeduri = "/root/name/albums/Albums.php";
$g2_url = "/root/gallery2/";
$g2_filepath = '/file/path/gallery2/';
$g2_errorredirect = "/error/";
@include_once($g2_filepath.'embed.php');
if (!defined('G2PARTINIT')) {
// Initialise GalleryAPI
$ret = GalleryEmbed::init( array(
'embedUri' => $g2_embeduri,
'g2Uri' => $g2_url,
'loginRedirect' => $g2_errorredirect,
'fullInit' => true)
);
} else {
// Initialise GalleryAPI
$ret = GalleryEmbed::init( array(
'embedUri' => $g2_embeduri,
'g2Uri' => $g2_url,
'loginRedirect' => $g2_errorredirect)
);
}
if ($ret) {
$ret->getAsHtml();
return $ret;
} else {
// Declate G2 Init so we do not do it again..
define("G2INIT", "True");
return $ret;
}
}
/*
********************************************************************************************************
G2 User Handling
********************************************************************************************************
*/
/**
* Logs in the externally mapped Gallery2 User Account
*
* @param NULL
* @return string GalleryStatus
*/
function g2_login() {
// Get WPG2 Option Settings
session_start();
$user_ID = $_SESSION['user_id'];
// Initalise the WP Capacitiy Class
//$userrole = new WP_User($user_ID);
if (!defined('G2INIT')) {
$ret = g2_init();
if (!$ret) {
// Try to Login with Current WP User Mapping via G2 ExternalID if user has Gallery2_user
if ($user_ID) {
if (true) {
$ret = GalleryEmbed::isExternalIdMapped($user_ID, 'GalleryUser');
if (!$ret) {
list ($ret, $user) = GalleryCoreApi::loadEntityByExternalId($user_ID, 'GalleryUser');
}
if ($ret) {
echo "NEed to create a new user";
die();
//g2_create_user($user_ID);
}
$ret = GalleryEmbed::checkActiveUser($user_ID);
if ($ret) {
return $ret;
}
} else {
// Otherwise Guest
$ret = GalleryEmbed::checkActiveUser('');
if ($ret) {
return $ret;
}
}
} else {
// Otherwise Guest
$ret = GalleryEmbed::checkActiveUser('');
if ($ret) {
return $ret;
}
}
} else
$ret;
return $ret;
}
}
function getuseralbum()
{
$userid = $_SESSION['user_id'];
if (isset($userid)) {
list ($ret, $user) = GalleryCoreApi::loadEntityByExternalId($userid, 'GalleryUser');
}
list ($ret, $albumId) =
GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $user->getId());
if ($ret) {
//error condition
echo "error in getting user album id";
}
$_GET['g2_itemId'] = $albumId;
}
if (!defined('G2INIT')) {
$ret = g2_login();
if ($ret) {
echo '<h2>' . __('Fatal G2 error:', 'wpg2') . '</h2>' . $ret;
exit;
}
}
$request = $_GET['view'];
if($request == "useralbum")
{
getuseralbum();
}
$g2data = GalleryEmbed::handleRequest();
if(isset($g2data) && !($g2data['isDone']))
{
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo($g2data['headHtml']);
echo($g2data['bodyHtml']);
echo '</html>';
}
$ret = GalleryEmbed::done();
?>
Posts: 1378
Ok this code looks really familiar for some reason Can you post the debug log when you get the session error as I suspect this issue is due to the lack of Wordpress Session Handling you may need to add session handling to the wp-config.php file..
On a side note interested in what you are achieving here..
____________________________________
Wordpress / Gallery2 (WPG2) Plugin, , WPG2 Documentation, WPG2 Demo