G2 into my own site

renatto

Joined: 2005-09-30
Posts: 34
Posted: Tue, 2005-10-11 20:03

HI i need some help.

Im using t his code trying to embed G2 into my site

<?php
$g2_Config['path'] = dirname(__FILE__) . '/gallery2/';
$g2_Config['embedPath'] = '/newAppp/';
$g2_Config['relativeG2Path'] = '/newApp/gallery2/';
$g2_Config['embedUri'] = 'gallery2embeded.php';

//print_r($g2_Config);
echo "aqui0";
require_once( $g2_Config['path'] . 'embed.php');

$ret = GalleryEmbed::init(array(
'embedPath' => $g2_Config['embedPath'],
'relativeG2Path' => $g2_Config['relativeG2Path'],
'embedUri' => $g2_Config['embedUri'],
'fullInit' => 'false',
'gallerySessionId' => $_COOKIE['PHPSESSID']
));
GalleryCapabilities::set('login',true);
echo "aqui1.1";
// handle the G2 request
$g2moddata = GalleryEmbed::handleRequest();

echo "aqui1.2";
// show error message if isDone is not defined
if (!isset($g2moddata['isDone']))
{
print 'isDone is not defined, something very bad must have happened.';
exit;
}

// die if it was a binary data (image) request
if ($g2moddata['isDone'])
{ echo "aqui2";
exit; /* uploads module does this too */
}

if ($ret->isError())
{echo "aqui3";
print $ret->getAsHtml();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<?php
$headHtml = $g2moddata['headHtml'];
//$headHtml = str_ireplace('</title>', ' -- ' . 'My Site' . '</title>', $headHtml);
echo "html :".$headHtml;
?>
<style type="text/css"> <!-- /*#gsHeader { display : none; } #gsFooter { display: none; }*/ --> </style>
</head>

<body class="gallery">
<?php
echo $g2moddata['bodyHtml'];
?>
</body>
</html>

But dont apear anything, i notice the problem is the $g2moddata['isDone'] is true so it exit dont showing anithing, but i dont know how tio correct this.

Thanks
Renatto

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-10-11 20:46
$g2_Config['relativeG2Path'] = '/newApp/gallery2/';

is wrong.
relativeG2Path should be a .... relative path. relative paths don't start with a slash /. rather with ./ or ../

'gallerySessionId' => $_COOKIE['PHPSESSID']
isn't really necessary.
but you missed activeUserId

have you actually looked at the example wrapper in the sticky Embedding and integration topic? (first post of the thread)

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Thu, 2005-10-13 05:58

I fix the problem but now i have

Error (ERROR_MISSING_OBJECT) : 1 GalleryUser

* in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 138 (gallerystatus::error)
* in modules/core/classes/GalleryCoreApi.class at line 2225 (galleryentityhelper_simple::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 184 (gallerycoreapi::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 94 (galleryembed::checkactiveuser)
* in /discos/d/Documentos/renatto/www/newApp/gallery2embeded.php at line 19 (galleryembed::init)

This is my code
<?php
$g2_Config['path'] = dirname(__FILE__) . '/gallery2/';
$g2_Config['embedPath'] = '/newApp/';
$g2_Config['relativeG2Path'] = 'gallery2';
$g2_Config['embedUri'] = 'gallery2embeded.php';

//print_r($g2_Config);

require_once( $g2_Config['path'] . 'embed.php');

$ret = GalleryEmbed::init(array(
'embedPath' => $g2_Config['embedPath'],
'relativeG2Path' => $g2_Config['relativeG2Path'],
'embedUri' => $g2_Config['embedUri'],
'activeUserId' => '1',
'fullInit' => 'false',
));

if ($ret->isError())
{
print $ret->getAsHtml();
}
GalleryCapabilities::set('login',true);

// handle the G2 request
$g2moddata = GalleryEmbed::handleRequest();

// show error message if isDone is not defined
if (!isset($g2moddata['isDone']))
{
print 'isDone is not defined, something very bad must have happened.';
exit;
}

// die if it was a binary data (image) request
if ($g2moddata['isDone'])
{ echo "aqui2";
exit; /* uploads module does this too */
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<?php
$headHtml = $g2moddata['headHtml'];
//$headHtml = str_ireplace('</title>', ' -- ' . 'My Site' . '</title>', $headHtml);
echo "html :".$headHtml;
?>
<style type="text/css"> <!-- /*#gsHeader { display : none; } #gsFooter { display: none; }*/ --> </style>
</head>

<body class="gallery">
<?php
echo $g2moddata['bodyHtml'];
?>
</body>
</html>

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Thu, 2005-10-13 06:38

Thanks for ur answers Valiant. I read teh documentation but i didn't get this:
return value contains 'isDone'=>true if output has already been sent
* (redirect, or output from G2 immediate view like core.DownloadItem)

Because when i try to use the guest user ( 'activeUserId' => '',) it aleways sent me to the isDone=true so i cant see anything

Thanks a lot

renatto

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-10-13 11:25

i've updated the sample wrapper attached to the first post on:

http://gallery.menalto.com/node/24126

look at sample file, only exit if isDone == true. isset is not the same as == true.

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Thu, 2005-10-13 17:00

I make it work but im not sure how use the GalleryEmbed::init and the GalleryEmbed::addExternalIdMapEntry.

Because when i use GalleryEmbed::addExternalIdMapEntry first nothing happen, and when i use GalleryEmbed::init i have the error

* in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 138 (gallerystatus::error)
* in modules/core/classes/GalleryCoreApi.class at line 2225 (galleryentityhelper_simple::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 184 (gallerycoreapi::loadentitybyexternalid)
* in modules/core/classes/GalleryEmbed.class at line 94 (galleryembed::checkactiveuser)
* in /discos/d/Documentos/renatto/www/newApp/gallery2embeded.php at line 19 (galleryembed::init)

there which steps i have to follow?

A lot of thanks

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-10-13 17:16

it seems to call GalleryEmbed::init with activeUserId which is not '' (empty string), but forgot to add the mapping first.

what G2 does when you give it a activeUserId = $activeUserId is:
- look in the database table externalIdMap if there's an entry for externalId = $activeUserId
- if so, good: it uses the entityId associated with this externalId and loads the corresponding g2 user
- if there's no such entry, bad: you forgot to add the entry first

that's why you get an error.

you have to first map the user Ids of your website with the user ids of G2. then you can call GalleryEmbed::init with the existing activeUserIds.

how do you do that? with GalleryEmbed::createUser and / or GalleryEmbed::addexternalidmap

see docs/EMBEDDING and modules/core/classes/GalleryEmbed.class for the usage etc.

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Fri, 2005-10-14 04:04

OK so to correct what u trhe problem i did that and works, but i wanna know if i do the correct way

<?php

require_once(dirname(__FILE__).'/gallery2/embed.php');

$usr_id = '2';

$ret = GalleryEmbed::init(array( 'embedUri' => 'gallery2.php',
'embedPath' => '/newApp/',
'relativeG2Path' => 'gallery2',
'loginRedirect' => './index.php',
'activeUserId' => ''));

GalleryEmbed::addExternalIdMapEntry($usr_id, '6', 'GalleryUser');

$ret = GalleryEmbed::init(array( 'embedUri' => 'gallery2.php',
'embedPath' => '/newApp/',
'relativeG2Path' => 'gallery2',
'loginRedirect' => './index.php',
'activeUserId' => $usr_id));

if ($ret->isError()) {

print $ret->getAsHtml(); //has error details..
exit;
}

GalleryCapabilities::set('login',true);

$g2data = GalleryEmbed::handleRequest();

if ($g2data['isDone']) {

exit; // Gallery 2 has already sent output (redirect or binary data)
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<?php
echo $g2data['headHtml'];
?>
<style type="text/css"></style>
</head>
<body class="gallery">

<?php
echo $g2data['bodyHtml'];
?>

</body>
</html>

Thanks
Renatto

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Fri, 2005-10-14 05:46

Please another question: ok now im logged in Gallery, how i can return to my site again, passing the ssesion vars or the id of the user i was logged in, in to my site.

Thanks

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-10-14 09:17

nope, right now you do:

Quote:
GalleryEmbed::addExternalIdMapEntry($usr_id, '6', 'GalleryUser');

on each request. you should do it once and that's it.

also you shouldn't call ::init twice in a single request.

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Sat, 2005-10-15 22:33

OK Valiant thanks, but when i call GalleryEmbed::addExternalIdMapEntry($usr_id, '6', 'GalleryUser'); before the ::init Nothing happens.

Another Quetion how i can return from gallery to my aplication keeping my aplication user id and other vars.

Also How i can make this: When a user login and get inside the gallery show him a particular album. In the main page?

Thansk a lot

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2005-10-16 14:49
Quote:
OK Valiant thanks, but when i call GalleryEmbed::addExternalIdMapEntry($usr_id, '6', 'GalleryUser'); before the ::init Nothing happens.

well, why do you do that?
i'm aware that we better need to describe how you should use the methods of GalleryEmbed, we need more docs.
- you should not call any GalleryEmbed function before calling ::init.
- you should not call addExternalMapEntry on each request.

this won't help you that much, it just explains that you're doing it incorrectly at the moment. i recommend taking a look at the code of the WP and the joomla integration to see how it should be done.

@sessions:
as long as you're using cookies, and 99% of all users are, this shouldn't be an issue. else you can use the session argument of ::init

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Tue, 2005-10-18 07:21

A lot of thanks Valiant. I get it and now i make it work in correct way.

But i have 2 more questions:

1) I pharse the header as is explained in the main.php u post. But teh gallery code seems not aplied all the css because the leters type is bigger than teh normal ones.

2) There is a way when some user geristers i can direct him to an especific album (not necesary teh user album) any other album i choose.

Thanks Again

renatto

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-10-18 08:36

2) automatically? no, not yet.

1) if you mix in your own CSS, this could explain it.

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Tue, 2005-10-18 15:44

Ok and if i cannot do it automatically, how is the other way??

A l ot of thanks

renatto

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-10-18 16:03

2) what's the question? if not automatically, then hand-craft the url yourself...

given an album name or an album id, you can generate a url to it with the g2 urlgenerator.

for examples of the urlgenerator, please try the forum search function or the g2 source code.

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Thu, 2005-10-20 05:51

thOK thans i solve the pronbelm my site is working pretty cool right now.

But sorry im continue asking morequestions.

there is a way to add photos to an Album using a link. For example have a button add to favorites and when i click it in a photo i cna add this to the personal album of a member?

Thanks a lot again.

Renatto

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-10-20 11:36

there's no "favorites" feature in g2 yet. yesterday, someone said he'd start such a module. the related topic is either in the development or in the customization forum.

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Sat, 2005-10-22 20:24

OK but there is a way to add a photo or and albun using line of code. Like a class or function??

Thanks

renatto

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2005-10-23 01:57

sure there is.
modules/core/classes/GalleryCoreApi.class

http://gallery.menalto.com/node/38625

 
renatto

Joined: 2005-09-30
Posts: 34
Posted: Mon, 2005-10-24 18:11

Im doing a test scrip to add new items in an album.

I start doing this but when i use the GalleryCoreApi class seems that it not works. These code was only for test if i can use teh classes well the GalleryUtilities class works fine as i can see teh result of teh extension. But the Mime type using the GallerrycoreApi didnt work.

<?php
echo "INICIAMOS<br>";
require_once(dirname(__FILE__).'/gallery2/modules/core/classes/GalleryCoreApi.class');
require_once(dirname(__FILE__).'/gallery2/modules/core/classes/GalleryUtilities.class');
echo "Terminamos de cargar clases<br>";

$file = "/discos/d/Documentos/renatto/www/newApp/fotos/samurai.jpg";

$fileName = basename($file);

$title = 'mi foto';
$summary = 'Esta es mi primera foto';
$description = 'Esta es una foto agregada via link';

echo $file."<br>";
echo $parentId."<br>";
echo $fileName."<br>";

list ($base, $extension) = GalleryUtilities::getFileNameComponents($fileName);
echo "Tomamos la extension: ".$extension."<br>";

list ($ret, $mimeType) = GalleryCoreApi::convertExtensionToMime($extension);
echo "Tomamos el mimetype: ".$mimeType."<br>";

if ($ret->isError()) {
return $ret->wrap(__FILE__, __LINE__);
}

echo "FIN";
?>

The out put of mi code is this:

INICIAMOS
Terminamos de cargar clases
/discos/d/Documentos/renatto/www/newApp/fotos/samurai.jpg
118
samurai.jpg
Tomamos la extension: jpg

A lot of thanks Renatto