require_once($this->GetPreference('g2_embed_php'));
$ret = GalleryEmbed::init(array('fullInit' => true));
if ($ret) {
print $ret->getAsHtml();
exit;
}
$ret = GalleryEmbed::isExternalIdMapped($username,'GalleryUser');
if ($ret) {
$ret = GalleryEmbed::createUser($username,array(
'username' => $username,
'email' => $email,
'fullname' => $fullname,
'creationtimestamp' => mktime()));
if ($ret) {
print "An error occurred during the user creation <br>";
print $ret->getAsHtml();
exit;
}
}
$g2data = GalleryEmbed::handleRequest();
Posts: 57
Does anyone have any information on this? Or if its possible?
Posts: 8339
this is my code from geeklog bridge for adding admin:
function G2B_addUserToGroup( $GL_uid ) { list( $ret, $user ) = GalleryCoreApi::loadEntityByExternalId( $GL_uid, 'GalleryUser' ); //$GL_uid - geeklog uid $G2_uid = $user->getId(); $ret = GalleryCoreApi::addUserToGroup( $G2_uid, 3); //G2 admin groupid is 3 if ( $ret ) { COM_errorLog( 'Failed to add user to admin group for GL uid ['.$GL_uid.']' ); COM_errorLog( ' Here is the error message from G2:' ); COM_errorLog( $ret->getAsText() ); return false; } return true;hope this helps
-s
Posts: 57
Do i have to require anything else other than embed.php?
Posts: 8339
no, but you must init gallery before calling any gallery functions.
In my geeklog/gallery2 bridge, everytime I involve gallery (showing sidebarblocks, random imageblock, photo viewing...) I call my init function which looks something like this:
then I check to see if that user is mapped to gallery already:
if ( $ret ) { if ( $ret->getErrorCode() & ERROR_MISSING_OBJECT ) { $errStr = G2B_CreateG2User( G2B_GetG2UserFromGL() ); // if the activeUserId is "ERROR_MISSING_OBJECT" then create a new G2 user if ( $errStr ) { echo $errStr; return( false ); }create a new G2 user if he/she does not already exsist:
function G2B_CreateG2User( $GL_uid ) { global $_TABLES; $ret = G2B_G2_init(); // make sure we are don't already have an user with the same name $ret = GalleryEmbed::isExternalIdMapped( $GL_uid, 'GalleryUser' ); if ( !($ret && ( $ret->getErrorCode() & ERROR_MISSING_OBJECT )) ) return; $sql = "SELECT uid, username, fullname, passwd, email, language, UNIX_TIMESTAMP( regdate ) AS registration_ts FROM {$_TABLES['users']} WHERE uid ='{$GL_uid}' LIMIT 1"; $res = DB_query( $sql ); $row = DB_fetchArray( $res ); $args['fullname'] = $row['fullname']; $args['username'] = $row['username']; $args['hashedpassword'] = $row['passwd']; $args['hashmethod'] = 'md5'; $args['email'] = $row['email']; $args['creationtimestamp']= $row['registration_ts']; $args['language'] = G2B_MapLanguage( $row['language'] ); $res = GalleryEmbed::createUser( $GL_uid, $args ); if (( $res) && ($res->getErrorCode() & ERROR_COLLISION )) { GL_addExternalIdMap($GL_uid); return false; } $debug = "username: [{$args['username']}]<br> fullname: [{$args['fullname']}]<br> hashedpassword: [{$args['hashedpassword']}]<br> email: [{$args['email']}]<br> creationtimestamp: [{$args['creationtimestamp']}]<br> "; if ( $res ) return $debug . '<br>Failed to create G2 user with extId ['.$GL_uid.' - '.G2B_GetG2UserFromGL().'] Here is the error message from G2: <br>' . $res->getAsHtml(); } function GL_addExternalIdMap($GL_uid) { global $_TABLES; // Fetch username based on $GL_uid $sql = "SELECT username FROM {$_TABLES['users']} WHERE uid ='{$GL_uid}' LIMIT 1"; $result = DB_query( $sql ); $A = DB_fetchArray( $result ); list( $ret, $user ) = GalleryCoreApi::fetchUserByUserName($A['username']); $res = GalleryEmbed::addExternalIdMapEntry($GL_uid, $user->getId(), 'GalleryUser'); if ( $res ) { COM_errorLog( 'Failed to add externalIdMap for GL usename ['.$A['username'].']' ); COM_errorLog( ' Here is the error message from G2:' ); COM_errorLog( $res->getAsText() ); return false; } }and finally, if I'm going to add him/her to admin group, I use the function from above.
Know that this code is Geeklog specific, and should be used as a reference/example only, it is riddled with geeklog functions calls.
hope this helps
-s