Giving my Users an album.

cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Mon, 2005-09-19 22:57

Once I have ported all my users and integrated the necessary hooks I want to further the integration.

what do I do in order to create albums for all of them?

I also have a table full of events.
How do I create an album for each of these?

I may also make it so that the albums are created on request to limit the number of empty albums.

thanks.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-09-19 23:29

the g2 useralbum module does exactly that. activate it and configure it to create a useralbum when first accessed and show the your album link.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 00:13

where do i find this useralbum module ?

What about creating an album for each event in my events table if someone has images to upload for it?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 00:30

so you didn't install the full package?
site admin -> modules. if it's not there:
http://gallery.menalto.com/downloads -> http://codex.gallery2.org/index.php/Gallery2:Download#Modules

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 00:40

My mistake.

It was there but just not installed and activated.

I've done that now.

I haven't found where to configure it yet though.
I see some of the other modules have "configure" actions in the column on the modules page but "User Albums" does not.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 00:45

once installed and activated, there's a user albums link in the site admin menu.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 04:40

Found it. Thanks.

So the album will be created when the user first accesses the gallery.

Any part of the gallery in particular?
I'm trying to figure out the API.
I have the user logging in now it seems but I actually haven't figure out yet how to let him see the pictures!

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 06:00

Ok so I got it all enabled but when I log in as one of my users in my contact point script it doesn't create a user album for me.

I am accessing through an embedded gallery with the guidelines outlines in docs/EMBEDDING.

What do i have to do in order to get the User Albums module to create an album when I log in?

or at all?

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 07:38

It did create a gallery for "Gallery Administrator" when I logged in through the main installation.

It doesn't seem to create one for the users logging in through the Embedded yet.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 09:35

you said you wanted that it doesn't create a useralbum for any user, just for those that actually want to use it. thus use the option "when first accessed". and also activate the option " Link to user album".
then you'll see a link to your user album in the top right.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 15:50

Ah Ha. So I have to click on "my album" ?

well I did that and it seems to work now. Thank you!

Is there some way for me to poll gallery to find out if a particular user has created their album yet?

I would like to dynamically link to the user's album from their profile page.

Is there a way to ask gallery for the link?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 16:02

hmm, let's see...

if you have the G2 user id (you can get it with $user->getId() if you already have a user object), you can get the information with

                global $gallery;
                $urlGenerator =& $gallery->getUrlGenerator();
		list ($ret, $albumId) =
		    GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $userId);
		if ($ret->isError()) {
		    print $ret->getAsHtml(); 
                    exit;
		}
		if (!empty($albumId)) {
                    print 'user ' . $user->getUserName() . ' has an  <a href=" . $urlGenerator->generateUrl(array('view' => 'core.ShowItem', 'itemId' => $albumId)) . ">album</a>.';
                } else {
                    print 'user ' . $user->getUserName() . ' does not have a user album.';
                }

if you only have the id of the user in your CMS, you can load the G2 user object with

                list ($ret, $user) = GalleryEmbed::loadEntityByExternalId($cmsUserId);
		if ($ret->isError()) {
		    print $ret->getAsHtml(); 
                    exit;
		}

if you want more information about the user album, you can load it with

                list ($ret, $album) = GalleryCoreApi::loadEntitiesById($albumId);
		if ($ret->isError()) {
		    print $ret->getAsHtml(); 
                    exit;
		}
 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 16:32

In my CMS i will only have the CMS userID initially.

If I use GalleryEmbed::loadEntityByExternalId($cmsUserId) to get the user object I presume the G2 UserID is in there somewhere?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 16:45

as i said, use ist ($ret, $user) = GalleryEmbed::loadEntityByExternalId($cmsUserId); and $user will be a G2 user entity. use $user->getId() to get the g2 user id.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 16:47

Can I get a link to a thumbnail of the user's main photo in their gallery?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 16:58

you mean a link to the thumbnail of the user album?
yes.
take a look at modules/core/classes/GalleryCoreApi.class there you see a long list of G2 API functions.
you need to call the fetch thumbnail function to fetch a thumbnail for the album item.
once you have the thumbnail, you can then, once you're sure it has a thumbnail (check), to generate the url to the thumbnail, use:
$imgSrc = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
'itemId' => $thumbnail->getId(),
'serialNumber' => $thumbnail->getSerialNumber()));

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-09-20 17:28

Thanks for all your help. I am really learning alot quickly and I like that.

I adapted your code above a bit..

Quote:
require_once('../phpgallery/embed.php');

$galleryActiveUser = '';

$ret = GalleryEmbed::init(array(
'embedUri' => "profile.php", embedPath => "/directory", 'relativeG2Path' => "../phpgallery",
'loginRedirect' => "{$_SERVER[QUERY_STRING]}&login=1", 'activeUserId' => $galleryActiveUser));
if ($ret->isError()) {
print $ret->getAsHtml(); #has error details..
exit;
}

list ($ret, $galleryuser) = GalleryCoreApi::loadEntityByExternalId($user->uid,'GalleryUser');
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

$gmessage = 'something failed to load';

global $gallery;

$urlGenerator =& $gallery->getUrlGenerator();
list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $galleryuser);
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
if (!empty($albumId)) {

$gmessage = 'user ' . $galleryuser->getUserName() . ' has an <a href="' . $urlGenerator->generateUrl(array('view' => 'core.ShowItem', 'itemId' => $albumId)) . '">album</a>.';

} else {

$gmessage = 'user ' . $galleryuser->getUserName() . ' does not have a user album.';

}

But I'm now getting a strange storage error?

Quote:
Error (ERROR_STORAGE_FAILURE)

* in modules/core/classes/GalleryStorage/DatabaseStorage.class at line 1166 (gallerystatus::error)
* in modules/core/classes/GalleryStorage.class at line 245 (mysqldatabasestorage::search)
* in modules/core/classes/Gallery.class at line 223 (gallerystorage::search)
* in modules/core/classes/helpers/GalleryPluginHelper_simple.class at line 300 (gallery::search)
* in modules/core/classes/helpers/GalleryPluginHelper_simple.class at line 241 (gallerypluginhelper_simple::fetchallparameters)
* in modules/core/classes/GalleryCoreApi.class at line 216 (gallerypluginhelper_simple::getparameter)
* in /var/www/rheo/neotribes.net/website/directory/profile.php at line 57 (gallerycoreapi::getpluginparameter)

any ideas?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-09-20 17:55

cool :)

change:
list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $galleryuser);
to
list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $galleryuser->getId());

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Fri, 2005-09-23 08:21
Quote:
you need to call the fetch thumbnail function to fetch a thumbnail for the album item.
once you have the thumbnail, you can then, once you're sure it has a thumbnail (check), to generate the url to the thumbnail, use:
$imgSrc = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
'itemId' => $thumbnail->getId(),
'serialNumber' => $thumbnail->getSerialNumber()));

I put something together that seems to do the trick.
But some reason the generated URL points back to my install G2 directory instead of to my Embeded G2 access point.

This is what I hacked together.

Quote:

require_once('../phpgallery/embed.php');

$galleryActiveUser = 6;

$ret = GalleryEmbed::init(array(
'embedUri' => "main.php", embedPath => "/gallery", 'relativeG2Path' => "../phpgallery", 'fullInit' => true,
'loginRedirect' => "{$_SERVER[QUERY_STRING]}&login=1", 'activeUserId' => $galleryActiveUser));
if ($ret->isError()) {
print $ret->getAsHtml(); #has error details..
exit;
}

list ($ret, $galleryuser) = GalleryCoreApi::loadEntityByExternalId($uo->uid,'GalleryUser');
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

global $gallery;

list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $galleryuser->getId());
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

print "AlbumID: $albumId \n<br>";

$Ids= array($albumId);

if (!empty($albumId)) {

$Ids= array($albumId);

list ($ret,$thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds($Ids);
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

list($id,$thumbnail)=each($thumbnails);

print "<pre>";
print_r($thumbnail);
print "thumbid: " . $thumbnail->getId();
print "</pre>";

$urlGenerator =& $gallery->getUrlGenerator();

$imgSrc = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
'itemId' => $thumbnail->getId(),
'serialNumber' => $thumbnail->getSerialNumber()));
} else {

$imgSrc = 0;

}
##

print $imgSrc;

Any ideas why this would happen?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-23 12:23

where's your CMS / application installed (url to access it, url to access the frontpage of embedded g2 ?, filesystem path?)
where's your G2 installed ? url and filesystem path

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Fri, 2005-09-23 16:53

> CMS / application installed (url to access it, url to access the frontpage of embedded g2 ?,

/gallery/main.php

>filesystem path

/pathtodocumentroot/gallery

> where's your G2 installed ?
> url

/phpgallery

> filesystem path

/pathtodocumentroot/phpgallery

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-23 17:46
cosmicelf wrote:
> CMS / application installed (url to access it, url to access the frontpage of embedded g2 ?,

/gallery/main.php

>filesystem path

/pathtodocumentroot/gallery

> where's your G2 installed ?
> url

/phpgallery

> filesystem path

/pathtodocumentroot/phpgallery

correct values:

embedUri => 'main.php'
embedPath => '/gallery/'
relativeG2Path => '../phpgallery/'

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-23 17:47

which is what you already had.

but what i don't get is: your profile, or event page, they are not accessed with /gallery/main.php, right?
there you'll have to use other parameter values in ::init().

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Fri, 2005-09-23 17:56

I'm not sure I understand.

What is the embed script?

whatever script is calling the GalleryEmbed::init at that time?

or the actual access point to the gallery?

I have one main access point that I made at /gallery/main.php

but the scripts that call the api are varied and all over.

this particlular one is in /lib/gallery.inc which is in turn called by /directory/profile.php

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-23 19:12

note: core.DownloadUrl urls always point to the G2 installation, never to embedded G2.

reason: performance and it doesn't make sense to route all image download requests through an external application.

core.ShowItem and pretty much everything else points to the embedded G2.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-28 16:51

In my case, and I imagine in other cases, I would like to keep the base code installation somewhat secret.

I don't want my users accessing the gallery through /phpgallery.

With all the links being directed to there there seems no way for me to keep my users out of there.

is there?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-28 21:18

you can set embed.mode.only = true in config.php and then they won't be able to access g2 standalone.
but this will also disable the gallery remote / upload applet features ( gotta fix that once).

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-09-28 21:54

i think people are already liking the upload feature.

is this something that will be fixed soon?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-29 01:07

fixed in cvs, mode.embed.only = true works now with GR, upload applet and slideshowapplet.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-09-29 01:25

i guess that's pretty soon.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Tue, 2005-12-20 11:25

Many of my users have now created albums by accessing their gallery for the first time.

Many of my users still have not however.

I happen to have a long list of URLs that point to one image per user for many of the users who have not yet created an album.

How can I create an album for these users as if they created them for themselves?
Will I have to pay special attention to permissions to make sure the user owns their own album?

Once the album is created how do I tell it to add an image by an URL that I specify?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-12-20 12:16

see modules/useralbum/UserAlbum.inc function handlerequest.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-12-21 07:01

ok.. that tells me how to create the user album right ?

Will that assure that it has the proper permissions?

also I am wondering once the album is created how do I insert the first Item from an URL and make sure the thumbnail is generated?
is that in modules/useralbum/UserAlbum.inc as well?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-12-21 09:12

just take a look at this UserAlbumController::handleRequest.
yes, permissions are set there.
how to add an item: see modules/core/ItemAddFrom...inc + ItemAdd.inc how it uses GalleryCoreApi::addItemToAlbum etc

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-12-21 09:47

I see this code which seems would do the trick?

Quote:
$platform = $gallery->getPlatform();
/* Copy the file locally */
$tmpDir = $gallery->getConfig('data.gallery.tmp');
$tmpFile = $platform->tempnam($tmpDir, 'add');

list ($successfullyCopied, $response, $headers) = GalleryCoreApi::fetchWebFile($tribeImageUrl, $tmpFile);

if ($successfullyCopied && strpos($response, '404 Not Found') === false) {
/* Add it */
list ($ret, $mimeType, $fileName) = $this->_getMimeType($url, $headers, true);
if ($ret->isError()) {
return array($ret->wrap(__FILE__, __LINE__), null, null);
}

list ($base) = GalleryUtilities::getFileNameComponents($fileName);
$title = $base;
$summary = '';
$description = '';

list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($tmpFile,
$fileName,
$title,
$summary,
$description,
$mimeType,
$item->getId());
if ($ret->isError()) {
print "<pre>";
print_r($ret->wrap(__FILE__, __LINE__), null);
print "</pre>";
}

$status['addedFiles'][] = array('fileName' => $url,
'id' => $newItem->getId(),
'warnings' => array());
}
@$platform->unlink($tmpFile);

how important is the list $mimeType ?
is there a way I could get the same results of this from within my script?

" $this->_getMimeType($url, $headers, true); "

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-12-21 10:27

if the file is already on the same server, there's no need to call ::fetchWebFile .
addItemToAlbum requires the mimetype, period.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-12-21 15:58

it isn't already on the same server. it's on a remote web server.

So how do i get the mime type would you say?

copy and paste the whole getMimeType() function into my own script?

or is there a way to obtain the needed information through the embed API ?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-12-21 16:19

see ItemAddFromWeb.inc function handlerequest.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-12-21 19:18

Ok. I copy and pasted the getMimeType() function to my script and that aspect seems to work..

However now I am getting another strange error.. soemthing about an "ERROR_LOCK_REQUIRED" ??

Quote:
GalleryCoreApi::addItemToAlbum('/var/www/website/gallerydata/tmp/addC5f8nf', '3e9051dc-f7ba-487c-8e17-b0289a29763c', '3e9051dc-f7ba-487c-8e17-b0289a29763c','' ,'' , "image/jpeg", "8370")
Error (ERROR_LOCK_REQUIRED)

* in modules/core/classes/GalleryDataItem.class at line 137 (gallerystatus::error)
* in modules/core/classes/GalleryPhotoItem.class at line 126 (gallerydataitem::create)
* in modules/core/classes/helpers/GalleryItemHelper_medium.class at line 190 (galleryphotoitem::create)
* in modules/core/classes/GalleryCoreApi.class at line 1499 (galleryitemhelper_medium::additemtoalbum)
* in /var/www/website/directory/foafspider.php at line 186 (gallerycoreapi::additemtoalbum)

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-12-21 20:40

ok.. i figured the lock thing out.

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Wed, 2005-12-21 21:38

now how do i get it to create the thumbnail at the same time as I add it to the gallery?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-12-22 00:18

see modules/core/CreateThumbnailOption.inc

 
cosmicelf

Joined: 2005-08-21
Posts: 153
Posted: Thu, 2005-12-22 09:03

so basically just this?

GalleryCoreApi::rebuildDerivativeCacheIfNotCurrent($thumbnail->getId())

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-12-22 15:44

yep. and don't forget to check the returned $ret status as usual :)

 
tomsawyer123
tomsawyer123's picture

Joined: 2002-07-24
Posts: 81
Posted: Tue, 2007-05-29 08:48

hi,

I am using Joomla and I would like the user to have a thumbnails of each a their album in their profil.

Does your code enable that?

can you give me some explaination on how to use it. G2 is already integrated in my CMS.

tks

florian

cosmicelf wrote:
Quote:
you need to call the fetch thumbnail function to fetch a thumbnail for the album item.
once you have the thumbnail, you can then, once you're sure it has a thumbnail (check), to generate the url to the thumbnail, use:
$imgSrc = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
'itemId' => $thumbnail->getId(),
'serialNumber' => $thumbnail->getSerialNumber()));

I put something together that seems to do the trick.
But some reason the generated URL points back to my install G2 directory instead of to my Embeded G2 access point.

This is what I hacked together.

Quote:

require_once('../phpgallery/embed.php');

$galleryActiveUser = 6;

$ret = GalleryEmbed::init(array(
'embedUri' => "main.php", embedPath => "/gallery", 'relativeG2Path' => "../phpgallery", 'fullInit' => true,
'loginRedirect' => "{$_SERVER[QUERY_STRING]}&login=1", 'activeUserId' => $galleryActiveUser));
if ($ret->isError()) {
print $ret->getAsHtml(); #has error details..
exit;
}

list ($ret, $galleryuser) = GalleryCoreApi::loadEntityByExternalId($uo->uid,'GalleryUser');
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

global $gallery;

list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $galleryuser->getId());
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

print "AlbumID: $albumId \n<br>";

$Ids= array($albumId);

if (!empty($albumId)) {

$Ids= array($albumId);

list ($ret,$thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds($Ids);
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}

list($id,$thumbnail)=each($thumbnails);

print "<pre>";
print_r($thumbnail);
print "thumbid: " . $thumbnail->getId();
print "</pre>";

$urlGenerator =& $gallery->getUrlGenerator();

$imgSrc = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem',
'itemId' => $thumbnail->getId(),
'serialNumber' => $thumbnail->getSerialNumber()));
} else {

$imgSrc = 0;

}
##

print $imgSrc;

Any ideas why this would happen?

 
tomsawyer123
tomsawyer123's picture

Joined: 2002-07-24
Posts: 81
Posted: Wed, 2007-05-30 10:08

I have try to copy the code in a useralbum.php, when I run the page on my server I have a blank page. Could you send me your file please. Or give me some imput on how to do it.

tks a lot

Florian