API question
stephen
Joined: 2002-11-20
Posts: 17 |
Posted: Tue, 2008-04-29 00:26 |
Hi, Can someone tell me what does the opposite of this? http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryCoreApi.html#methodfetchItemIdByPath I mean, given ItemID, returns the path to the item? I can't seem to find it... maybe I'm just blind. Thanks! |
|
Posts: 32
In the phpbb3 integration I have the ability to use a Gallery image as a forum avatar. In order for phpbb to convert the image to an avatar it must know where the source image is. Don't know if there is a better way to do this, but here is an excerpt of what I use and I think will do what you want.
Posts: 4342
GalleryItem is a subclass of GalleryFileSystemEntity which has a method fetchPath():
http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryFileSystemEntity.html#methodfetchPath
So you should probably do something like
Posts: 32
Nice...thanks Alec!
Only thing I might add is that you get an array back and the path is contained in the second element, so the actual path would be in $myItemPath[1] in your example.
Thanks again...much better way to do it.
Posts: 17
Thanks for the ideas. I haven't actually written my code yet, so I can't test to see if this will work. I asked the question to see if what I wanted to do was possible. So, for the mean time, thanks!
Posts: 4342
I don't think so. According to the docs (and also according to the code itself) the function returns
an array of (GalleryStatus status, string a path)
In my code the status is $ret, and $myItemPath is the string part. No requirement for further array dereferencing, and $myItemPath[0] would be incorrect.
Stephen: if you use this code then you should be aware (the docs make it clear) that path is only guaranteed to remain valid if the relevant locks are held.
Posts: 32
Hmm, I read the docs yesterday and was expecting a string, but was returned an array instead with element [0] empty and element [1] containing the path. I test it again today and am returned a string just as the docs say. Guess I did something wrong before :-/
Posts: 17
I should be more explicit I think...
Eventually, I would like to run my script from the command line, i.e. 'php myscript.php', where it accepts the itemID for a media file (jpg, gif, etc..) as STDIN, and outputs the full system file path as STDOUT (or at least a path I can easily convert to a full path).
I can make a php file that uses require_once('./embed.php') etc... like in numerous embedding examples, and I get my gallery page just fine. I'm a bit confused as to where to put alecmyers code in. I can browse my gallery (without rewrites on) and navigate to a photo page, and then inspect the main image on that page. In the url I have 'g2_itemId=39' so I assume that image's ID is 39. If I put something like this in my file:
I get 'Bollocks' back if I run through the web. I've tried putting it before and after the ::handleRequest, and there's no difference. If I run from the command line, I get nothing.
So I guess I have two questions now:
- What am I doing wrong? Is it not as simple as the code snippet you gave me?
- If I get this working through the web, how will I get it to work on the command line? Will I have to resort to using curl http://localhost/...?
Thanks for any additional help you can give me.
Posts: 4342
"Bollocks" ... love it.
use
instead of the bollocks lines - that'll be less fun, but more informative.
As for getting it to run from the command line - I'm not sure exactly. But one difficulty you may face is that you don't have any of the cookie/session information set up for you - Gallery code is quite tight on that kind of thing for security reasons - any you may fail on that score.
Posts: 17
alecmyers,
here's what I get from the code in my previous post using getAsHtml() :
So I put 'GalleryDerivativeImage' in place of 'GalleryItem' into loadEntitiesById, and then I get this error (the (...) is an edit by me):
where line 30 is list ($ret, $myItemPath) = $myItemArray[0]->fetchPath();.
I then changed line 30 to list ($ret, $myItemPath) = $myItemArray->fetchPath();, and now it works! So in summary, this is a working code snippet, where of course for general items 39 gets replaced by $myID or whatever:
So with respect to the command line stuff, you're probably right that it's a cookie issue. I thought I saw something somewhere about running embedded gallery2 without cookies, but it might be simpler to just accept I'll have to use curl, which I can make work, but it doesn't feel as elegant.
Thanks for help!
Posts: 4342
Great that you got it working! Once comment though:
I think that will fail if you try to get the path of a GalleryImage (i.e. an original image, not a derivative) - should you ever require to do so. If you want to cover all bases, use 'GalleryEntity', which I think is the base class for all such things.