Embedding

vertlime

Joined: 2009-09-02
Posts: 3
Posted: Wed, 2009-09-02 01:08

I am quite new to things - trying to figure out embedding and am getting a bit lost.
I have a database with users and your sample is just confusing me.
I have done similar things before - all I needed to do is to change the DB, userid and path info. The password has already been validated.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 6136
Posted: Wed, 2009-09-02 01:35

First get the visual part done, and we'll work on mapping users after.
Start here.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
vertlime

Joined: 2009-09-02
Posts: 3
Posted: Wed, 2009-09-02 04:16
suprsidr wrote:
First get the visual part done, and we'll work on mapping users after.
Start here.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

I appreciate your quick response - the visual part is done and works fine.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 6136
Posted: Wed, 2009-09-02 11:47

http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryEmbed.html

When you init() gallery you pass along an array including the activeUserId which is the external userId belonging to your host app.
$ret = GalleryEmbed::init(array('embedUri'=>$_G2B_CONF['embedUri'], 'g2Uri'=>$_G2B_CONF['g2Uri'], 'loginRedirect'=>$_G2B_CONF['login_redirect'], 'activeLanguage'=>G2B_MapLanguage($_CONF['language']), 'activeUserId'=>G2B_GetG2UserFromGL(), 'fullInit'=>$full));
This is from my G2Bridge embed for geeklog.
and to map a new user to gallery by externalId:

function G2B_CreateG2User($GL_uid) {
    global $gallery,$_TABLES;

    /* 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']);

    $ret = GalleryEmbed::createUser($GL_uid, $args);
    if (($ret) && ($ret->getErrorCode() & ERROR_COLLISION)) {
        // 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']);

        $ret = GalleryEmbed::addExternalIdMapEntry($GL_uid, $user->getId(), 'GalleryUser');
    }

    GalleryEmbed::done();
}

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2