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
Posts: 32509
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)
Posts: 34
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>
Posts: 34
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
Posts: 32509
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.
Posts: 34
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
Posts: 32509
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.
Posts: 34
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
Posts: 34
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
Posts: 32509
nope, right now you do:
on each request. you should do it once and that's it.
also you shouldn't call ::init twice in a single request.
Posts: 34
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
Posts: 32509
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
Posts: 34
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
Posts: 32509
2) automatically? no, not yet.
1) if you mix in your own CSS, this could explain it.
Posts: 34
Ok and if i cannot do it automatically, how is the other way??
A l ot of thanks
renatto
Posts: 32509
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.
Posts: 34
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
Posts: 32509
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.
Posts: 34
OK but there is a way to add a photo or and albun using line of code. Like a class or function??
Thanks
renatto
Posts: 32509
sure there is.
modules/core/classes/GalleryCoreApi.class
http://gallery.menalto.com/node/38625
Posts: 34
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