[Question] Gallery 2 embedding in our own CMS

s.smid

Joined: 2005-06-21
Posts: 16
Posted: Tue, 2005-06-21 14:51

First of all I'd like to thank the devs for creating and maintaing this nice piece of software. I've been using this for more then a year now and I'm still a very pleased gallery user.

In my spare time I've created with a friend of mine a CMS application in which we'd like to make use of some of the gallery 2 options. Since this version was designed with intergration in mind this seems to be the best solution. We've looked at the docs/EMBEDDING and embed.php files but we've didn't quite know what to do with this information. We also checked some the existing "xaraya" intergration, templates files and the main.php file but those didn't help much either. Let me explain what we want to do and perhaps someone here has some pointers how to do something like this.

We want two views on gallery. One will be used in the 'normal' view of the website. The other will be used in our CMS. Both views show gallery embedded in a view_page.php kind of file in which we'll add our own headers, footers. menus etc.

The normal view:
If possible we'd like to only show some of the options that gallery has. For instance no login function, cart funtion or photo of the month. Only an album overview or pictures of an album.

The CMS view:
Here we want to embed gallery in our own CMS. We'd like to make sure that the logged in user in our CMS doesn't have to login again for gallery. The user can upload files and do other gallery admin options.

Do I need to create a smarty template for both of these views or can I do all of this by php code? If I want to include a gallery in my own php file what classes and functions do I need to create or call?

San

 
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Tue, 2005-06-21 15:11

You dont need any smart knowledge, or create any template to embedd Gallery. Gallery uses smarty for it's internal template engine. The embedded class handles Gallery requests and return the raw xhtml as a string for you to display in your CMS. The only Gallery class you should be concered with is GalleryEmbed (modules/core/classes/GalleryEmbed.class). In your 'view_page.php' you include embed.php and call GalleryEmbed::init(...) or other methods of that class.

I dont know if we yet support more than one CMS per Gallery, but since you don't want users for the normal view I think it might be possible. Valiant is the embed wiz, he might straighten this one out for you. All I know is that if you plan to use URL Rewrite (short URLs) you have to set the param 'embedPath' when calling GalleryEmbed::init() for both embedded versions.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-06-21 17:35

i don't see here the need for embedding g2 with more than one CMS. it's the same CMS in both cases. and in the "normal view", i guess, you don't even want users to be able to login.

in the normal view, you need to call
include('embed.php');
GalleryEmbed::init(array('embedPath' => ..., 'embedUri' => ..., 'relativeG2Path' => ..., 'activeUserId' => '', ...));
(important is the activeUserId => '', that's how you set it to anonymous user aka guest. of course, the other params need to be correct too.
You can turn off things with GalleryCapabilities (login, ...).

then you generate the page with
GalleryEmbed::handleRequest();

@cms view:
almost the same, use 'activeUserId' => $userId (user id from your cms application).
- you need to create cms users in g2 with GalleryEmbed::createUser($cmsUserId, $data); and you can map the special accounts / already existing accounts with GalleryEmbed::addExternalIdMap(...);
- set different capabilities
- report capabilities that you miss

problems:
- i guess we can't deactivate the cart module just for a single request (normal vs. cms view)
- i guess you'd like to have different templates for the 2 different views. that's also impossible at the moment.
- you're free to modify the code / propose changes that could be backported to G2
- maybe there are other approaches

moving the topic to the g2 integrations forum.

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Tue, 2005-06-21 19:53

This seems to be working thanks for the fast replies!

Indeed in the normal view I only want to show a basic version of gallery2 without any login or memberlist functions.
I do think that I want indeed two diffrent templates for each view. The view files will be two different files like view_page.php and edit_page.php. Can't I define which template to use in each of those files?

I still have some trouble but this seems more like a general bug. When I include gallery everything seems to be working okay. I can view albums and pictures. But when I'm viewing a single picture and I click on the gallery link just below the Welcome, Guest I get an error

Welcome, Guest

    * Gallery <-- this one
    * Picturename

Error:
Warning: Cannot modify header information - headers already sent by (output started at /blablabla/webroot/view_page.php:3) in /blablabla/webroot/gallery2/main.php on line 460

Perhaps this is caused by some wrong paths or something in the init function but the other stuff seems to work so I doubt it... look into this tomorrow.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-06-21 21:35

@warning: read the warning... output started at /blablabla/webroot/view_page.php:3
what do you do there on line 3? fix it...

you also have to check for isDone and exit if it is true etc. see the existing integrations.

@templates: i wouldn't invest too much time in it right now, the whole layout / template system will change in a week or so.

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Mon, 2005-06-27 10:27

Thanks for you replies! Things are working quite nicely now.. the only two problems I encountered where the following.

1. When I link our CMS login with the gallery2 login this works for added users. But when I try to do the same for the gallery2 admin user I get an error from the "GalleryEmbed::init" function. Perhaps you guys simply don't allow admin login in the embed mode..?

2. When I want to use some of the java functions, for instance the slideshow or the upload applet, I get an error because those applets think that gallery is installed in the same path where the embed "view_page.php" is located. This leads to some errors. I've set the paths correctly in the init function and except for the java applets everything seems to work okay. Even file upload with php...

- san

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-06-27 10:30

1. you have to map the CMS admin id with the G2 admin id. see the db table g2_externalIdMap for existing maps

2. use the current g2 version (core 0.9.25 or newer) and don't forget embedUri, embedPath, and relativeG2Path in the GalleryEmbed::init call.

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Thu, 2005-08-04 17:47

Hi,

I just installed beta 4 and I must admit that I'm impressed. The code I write looks so simple compared to yours ;) I do have a question about the search function in gallery2. Something like this would be nice for a site I'm designing. I was wondering if I can use the searchbar from the sidebar without using the actual sidebar or do I need to use the search functions provided in GalleryEmbed.class. And if I do the latter how can I get the actual image / album from the array. I know I get the "itemID" in the array but I'm a bit clueless how to use this to link to the album or show the albumpreview. Perhaps you have some pointers.

Btw I think I found a bug in the "Site Admin" -> "Blocks" -> "Random/Popular" page. When I choose some "Image blocks" and press save the page says that the settings are saved but the result is a list with unselected selectboxes so I guess stuff isn't saved.

Cheers,
san aka s.smid

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-08-04 17:52

for your bug:
please open a new topic in the support forum. screenshots would help.

@search:
yeah, we need some docs for that.
the easiest thing: just copy the whole html form from the g2 page to your own page. then when they search, they get a g2 result page.

if you want to integrate searching in G2 in your existing CMS search function, you'll have to use GalleryEmbed and
global $gallery;
$urlGenerator = $gallery->getUrlgenerator;
foreach ($itemIds as $itemId) {
$urls[] = $urlGenerator->generateUrl(array('itemId' => $itemId, 'view' => 'core.ShowItem'));
}

or view => core.DownloadItem for the image url itself

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Sun, 2005-08-07 17:46

Thanks for your fast reply once again. I've now updated to the lastest version (RC1) but for some reason the code you posted doesn't seem to work. I changed it a bit but the general idea is the same. The file I included this code is a page that has the gallery2 init function and works with showing albums and pictures. The only thing that goes wrong is searching.

This is my code ($array[$key]['itemId'] is the itemId of a found item):

global $gallery;					
$urlGenerator = $gallery->getUrlgenerator;
$url = $urlGenerator->generateUrl(array('itemId' => $array[$key]['itemId'], 'view' => 'core.DownloadItem'));
echo $url;

The error I get is:
Fatal error: Call to a member function on a non-object in /opt/guide/www.blablabla.com/somepath/myCMS/modules/view_gallery2.php on line 170

I'm not sure if this is a bug in gallery2 or if it's a mistake on my side. I hope you guys can help me out.

Thanks in advantage,
san

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Mon, 2005-08-08 17:51

Valiant: You asked in the other topic, which I'll use for some more questions about the G2 Api, if I did a GalleryEmbed::init() before this code. Well I do so. I show an embedded version of gallery2 in that page so gallery2 has been succesfully initialized.

I'm wondering what I'm doing wrong or if this is a bug..

Cheers,
San

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Tue, 2005-08-09 18:23

Well I got this going.. I get the results of my search and from the images I can show already an image. Now I have a problem with albums. How can I determine if the result is an album or an image. And if it's an album is there a way to get the selected highlight (the album preview picture)? I haven't seen it in the "GalleryAlbumItem" documentation ( http://gallery.menalto.com/modules/GalleryAPI/apidoc/GalleryCore/Classes/GalleryAlbumItem_core.html )

Cheers,
san

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-08-09 23:11

s.smid, please either discuss this here or in the other topic.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-08-10 23:44

@headers:
should be fixed in tomorrows nightly snapshot.

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Thu, 2005-08-11 11:45
valiant wrote:
@headers:
should be fixed in tomorrows nightly snapshot.

What do you mean by headers?

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Thu, 2005-08-11 12:42

I'm still trying to get the highlighted galleryPhotoItem from an album but I clueless how to get it. I seached though quite a few files which appeared to have something to do with this "galleryalbumitem". I tried galleryalbumitem_core class, some parent classes, the helper dir with the filesystem files but all without any luck. When I print_r out the object I get the following but none of it seem to link to a PhotoItem or something like that. I hope you can, once more, help me out here.

galleryalbumitem Object
(
    [_theme] => 
    [_orderBy] => 
    [_orderDirection] => asc
    [_canContainChildren] => 1
    [_description] => 
    [_keywords] => 
    [_ownerId] => 16
    [_summary] => Serie over asielzoekers op Ameland.
    [_title] => Allemaal Amelanders
    [_viewedSinceTimestamp] => 1122462350
    [_originationTimestamp] => 1122462350
    [_pathComponent] => Allemaal Amelanders
    [_id] => 131
    [_creationTimestamp] => 1122462350
    [_isLinkable] => 0
    [_linkId] => 
    [_linkedEntity] => 
    [_modificationTimestamp] => 1122463090
    [_serialNumber] => 4
    [_entityType] => GalleryAlbumItem
    [_onLoadHandlers] => 
    [_persistentStatus] => stdClass Object
        (
            [flags] => 0
            [modified] => Array
                (
                )

            [originalValue] => Array
                (
                )

        )

    [_parentId] => 7
)

Thanks,
san

PS. I'm not sure if anyone is interessted but I've written my own random image function for gallery2 which can return an array loaded with, all diffrent, (photo)items. If you'd like the source I'd be a happy to share :)

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-08-11 12:56

just get the thumbnail for the albumId...
see GalleryCoreApi, there's a method to get the thumbs.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-08-11 12:57

Warning: Cannot modify header information - headers already sent by (output started at /blablabla/webroot/view_page.php:3) in /blablabla/webroot/gallery2/main.php on line 460

there was also a g2 issue involved which could have been the reason for that warning, that's what i mean with @headers.

 
s.smid

Joined: 2005-06-21
Posts: 16
Posted: Thu, 2005-08-11 13:58

You're right.. it works the same as getting a image for an regular item. Weird, I thouhgt I tried that.. well anyways it works now..

And about that header problem; it was fixed by placing some of our own code a bit lower. No clue why that did the trick since we don't output anything (jsut some sessopm stuff) but thanks.. I'll think I'll wait for RC2 instead of checking out nightly builds.. but thanks again!