hi,
i would like to add a "lightbox" functionality to zenphoto. i mean a lightbox in the photographic way. basically it would allow user to select pictures to put in their lightbox for later review. from within the lightbox the user could then refine and remove unwanted images before saving the lightbox and getting a url pointing to it.
i'd like to do that as a plugin but like i said in one of my other posts, i am not a php developper and hardly a php coder. anyway i think it could be something nice to get me started.
i have read the recommandations on how to write a plugin but i still have questions. from what i've read so far, i will need php session variable to track the user and its lightbox. is this possible to do that in a plugin. or should i use some global variables in that case how do i make sure they will be known everywhere.
do you have any plugin in mind that uses the same idea and which i could look at to get started.
well thanks for your tips and avices.
frank.
Comments
We have no plugin that does similar things. The rating is similar however it saves into the database and is not really user dependend.
looking how to implement this lightbox manager. i need to identify the user by the session id number so that he can only add/remove images to his/her lightbox. for that i guess i need the `session_start();` instruction almost on all pages. yet it seems to me that sessions are started only if we go through the admin.php page. where should i place the instruction so that sessions are started for any user ?
also, this "lightbox" manager requires a new table in the database to store the information relative to the lightbox (id, user_id, image_id's). i could create the table through my phpadmin page but i'd like the table creation to be done when we activate the plugin. is this possible ? if yes where should i place the mysql_query ?
thanks for your help.
frank.
Regarding the table: You could place that MySQL query on the beginning of your plugin file: If it does not exist create it otherwise do nothing. Note that Zenphoto uses the filename and the album (folder) name are the unique values to identify an element, not the id. Using those two will help you with displaying the actual selected items since you should use the object model for that.
Also take a look at the documenation as we have some functions for databases.
well thanks for your help and i am waiting for sbillard comment on starting the session.
trying to find my way with the object model without lots of success so far.
what i did so far is create the table in the database to store the information about the images that are selected to be in the lightbox. i wrote couple functions already (addImage, deleteImage, ...) and a function that reads this table and get all the info (basically image filename and folder it belongs to) and put that in a `$images` array.
for what i understood, going to the object model will allow me to use the `next_image()` function for instance and therefore loop through all images in the lightbox to display them. the thing is i'm a bit confused on how to move from my `$images` array to the object model.
if i want to create a "new" album that will hold the lightbox images i guess i should do something like this:
`$lightbox = new Album($gal, 'name')'
do i have to create a new gallery too or can i just put $_zp_gallery in there ? yet the major problem is that this "lightbox" album has no real existence and i am not sure i can do it this way.
assuming i have a folder to hold my images, do i have simply to loop through my `$images` array and instanciate a newImage object for each entry?
thanks for your help and pointing me to the right direction because i've the feeling i am losing it !
i'll let you know.
$_zp_gallery is as a global object for the gallery always available on teh theme files. Just take a look at other plugins how they use it.
i still have a little problem. basically i have 2 files. `zLiteBox.php` is the plugin file where i have defined all my function (addImage, removeImage, countImage, getImages and so on) and `lightbox.php` is my custom page where i show what is currently in the lightbox.
in the custom lightbox.php file i have done some thing like this:
`$images = getLiteBoxImages();` to get the raay with the image info (filename, folder)
and later on
`
<?php $c++; } while ($c < $total); ?>
`<?php do {
$img = $images[$c];
$obj = newImage(new Album($_zp_gallery, $img['folder']), $img['filename']);
?>
getImageLink());?>" title="<?php echo gettext('Detail Page: '); ?><?php echo $obj->getTitle(); ?>">
getThumb(); ?>" alt="<?php echo $obj->getTitle(); ?>" width="75" height="75" />
<?php echo $obj->getTitle(); ?>
<?php printLiteBoxForm('removeImage', 'Delete from Lightbox'); ?>i don't know if that's the way to do it. yet in the printLiteBoxForm function (which is in the plugin file) i need to know the filename of the image to be deleted but `$obj->getFileName()` is not known. how do i make the two files to know the `$obj` image ??
i am not sure if this is clear, hopefully it is.
thanks.
the lightbox manager is kind of working. i would like to add some pagination to it and i was wondering if i have to hard code it in my "display" page or if i could turn the selected images into a "virtual" album and use the build-in function `getNextPageURL()` and so on. i looked in the documentation but couldn't find how to create a dynamic album and if it would be the solution at all.
thanks.
frank.
however i wanted to add the "lightbox +" button to each image in a search result. and this is where i have the problem. the `header("Location: "...);` instruction sends me back to page/search which is empty. the result of the search are lost with this relocation. i guess i could a bit of javascript and the `history.back()` function but in that case the user will have to revalidate the form. is there another way to relocate people to the search result page ??
thanks.
So without a search this won't probably work. Regarding pagination, that is not really that hard to do via MySQL and PHP directly.
Regarding images in searches. Search and other things works with contexts. That is why it is lost if you redirect. Maybe it would be an idea to open the lightbox manager in a Colorbox window directly without leaving the page at all?
`header("Location: " . $_SERVER['HTTP_REFERER'] . $_SESSION['lastsearch'] . " ");` instruction.
it does work, though it might not be the best way to do it.
and for the pagination, i'll work on it.
got the pagination working. thanks for giving me directions. i have a question about session id's. i want to use this to identify a user so that he/she can only add images to the lightbox he/she has created. for now i am developping the website on a local server. basically i work on a mac with mamp installed. for now i am the only user and no matter what i do i always the same session id. i thought i should get a new one when i close the browser and open it again. but this is not the case. is it normal ?? is it an issue with safari that i use ?
thanks.
I just got the idea that you might not need sessions at all. You can always get the currently logged in user, so if you create the table entries assigned to that currently logged in user as a field you might be able to work without them.
There is a global object available `$_zp_authority`. Look at the `zp-core/lib-auth.php` that has several methods (this requires the nightly or the soon release 1.3).
i also keep in the table the date of creation of each lightbox with the idea to be able to delete old ones from the admin panel by setting an number of days and click a button to delete everything that is older than that.
thanks for your tips,
frank.
How to do that is described on our user guide: http://www.zenphoto.org/2010/04/zenphoto-plugin-architecture/
i've got my plugin to work. it may not be optimized as i am far from a real php developer but so far so good it does the basic things i wanted (add/remove images to/from the lightbox, save/clear the current lightbox, read a previoulsy created lightbox).
as i said i'd like to have a quick read of how many lightboxes exist in the admin overview page. is there a way to do that without editing and "hacking" the admin.php file ?
if not i guess i need to add an `if ( getOption('zp_plugin_zLiteBox') )` in the file and call a function that will return the number of lightboxes in the database. is this the way to go.
whatever the answer is it will be the same to add a "delete expired lightboxes" in the same overview page.
thanks for your answer.
frank.