XML Output

harry000

Joined: 2008-05-09
Posts: 6
Posted: Tue, 2008-05-13 21:21

Hi,

I want to create module that will return XML data as output.

So, for example, the URL http://mygallery.ca/main.php?g2_view=xml.GetXML should return XML data with all album ids and names and all images ids and image titles within it.

I am relatively new to Gallery development.

Do I have to use templates (somehow) for it. Or I can simply create a file that will fetch the require information and send back as XML?

- Harry

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1487
Posted: Tue, 2008-05-13 22:10

No, you don't need to use a template - you can declare a View as RenderImediate, in which case everything you echo or print gets sent straight back to the browser (you can even set your own headers.)

You will however have to write your own module, although this is less daunting than it sounds. Have a look a the simpleviewersource module for an example of doing something very similar to what you specify - it has an XML output View.

http://codex.gallery2.org/Gallery2:Modules:simpleviewersource

Login or register to post comments
harry000

Joined: 2008-05-09
Posts: 6
Posted: Thu, 2008-05-15 15:13

Thanks alecmyers for help. I finally got it working.

I have another question, its not about generating XML.

I am looking for a way to order the albums and pictures within it sorted by date.... is there any way I can do this using Gallery API.

For example, GalleryCoreApi::fetchChildItemIds($album) returns all pictures inside the album. But, is it possible to return the pictures sorted by "Date Uploaded"

Thanks

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1487
Posted: Thu, 2008-05-15 23:42

Yes of course - write yourself a comparison function that checks the dates of two items, then use php's usort() function.

Oh, you can probably start by sorting by id, since id's are generated in an increasing sequence at creation (upload) time, so the bigger ids are the newer items.

Login or register to post comments
harry000

Joined: 2008-05-09
Posts: 6
Posted: Fri, 2008-05-16 21:06

hi alecmyers..

thanks again for ur help....

now.. i have one more thing left to do.. i want to resize the images according to given width/hight.

so, like, http://mygallery/main.php?g2_view=core.DownloadItem&g2_itemId=35

will return a image with given id....

what i want is something like this:
http://mygallery/main.php?g2_view=core.DownloadItem&g2_itemId=35&width=300

and it should return the image resized to that width...

but.. i dont want to save it to the database.... just on the fly resize..

i have been looking around in API and source code for hints.

ItemEditItem.inc does kinda similar stuff... and I think i can use DownloadItem.inc code too to return the image...

any comments on what could be best option??

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1487
Posted: Fri, 2008-05-16 21:17

That sounds quite tricky. Not saving it on disc breaks the Gallery paradigm where all resizes are cached; If I were doing it I'd write my own version of core.DownloadItem (obviously under a different name but using it as a starting point) which took the extra size parameters then loaded an original, ran it through whichever image processor was configure to handle resizes (writing it to a file) and then spooled out that file before deleting it. I'm sure there are other ways, but that would be my first approach.

Login or register to post comments
harry000

Joined: 2008-05-09
Posts: 6
Posted: Mon, 2008-06-02 13:07

Hi alecmyers,

Thanks for your help before.

I have another problem that just came up. Its related with the security issues.

The problem is, if I dont give read permission to "Everyone" group, my module does not return any result until a user logs in from the browser.

So, a user with sufficient permissions must be logged in for my module to work.

Do you know any way in which I can 'by-pass' this security form my module, so that I do not need to give "Everyone" the permission to access the gallery.

Also, http://galley.com/main.php?g2_view=core.DownloadItem&g2_itemId=xxx do not return the image if the user is not logged in. I need a way to by pass this too.

Is, it possible to pass username/password somehow in the gallery query string ??

What do you suggest?

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1487
Posted: Mon, 2008-06-02 13:17

You can't put username/password in the url.

What's the problem with giving "[core]view Original" permission to Everybody? After all, if you want them to download images from Gallery without logging in, that's the correct permission - that's what it means.

Login or register to post comments
harry000

Joined: 2008-05-09
Posts: 6
Posted: Mon, 2008-06-02 13:53

If i give "[core]view Original" permission only, the gallery do not return thumbnails and resizes of the image. And if I give "[core]View all sizes" permission, then, anybody who know the URL for the gallery can view all albums and all images.

Also, from inside my module, if I get all albums using GalleryCore::fetchChildAlbumItemIds, it will not return the Items if the user logged-in in browser does not have permissions for it? Right?

Login or register to post comments
alecmyers

Joined: 2006-08-01
Posts: 1487
Posted: Mon, 2008-06-02 14:04
Quote:
If i give "[core]view Original" permission only, the gallery do not return thumbnails and resizes of the image. And if I give "[core]View all sizes" permission, then, anybody who know the URL for the gallery can view all albums and all images.

But if you're using the simpleviewersource module (for example) for users who aren't logged in (anonymous users) then anyone can do that anyway - all they have to do is look up the url from the html of your webpage. Either anonymous users can see the pictures, or else they can't; it doesn't matter whether it's via a Gallery album page, or via your module. If the pictures aren't public then the viewer has to be authenticated with Gallery.

Quote:
Also, from inside my module, if I get all albums using GalleryCore::fetchChildAlbumItemIds, it will not return the Items if the user logged-in in browser does not have permissions for it? Right?

No, I don't think that's correct. The permissions check is separate, I think.

Login or register to post comments