lightbox manager plugin

frankm Member
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

  • acrylian Administrator, Developer
    That's quite a task if you are not a php developer.... Global variables would not work as they are dependend in instances that need to be setup. A session/cookie would be the best I think and I see no reason why that would not work with a plugin.

    We have no plugin that does similar things. The rating is similar however it saves into the database and is not really user dependend.
  • frankm Member
    hi,

    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.
  • acrylian Administrator, Developer
    I will pass the question about the session stuff to my collegue sbillard.

    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.
  • frankm Member
    thanks. i have already looked into function-db.php to see what were the zenphoto functions for databases and i'm working from that. your remark on the filenames being the unique values to identify an element confuses me a bit. do you mean the image filename is the unique value ? because reading the documentation i found the `getImageID()` function that i thought was returning a unique id number that i could use to identify the images in the lightbox. so far that's what i am using. are you saying i should change for the image filename instead ?

    well thanks for your help and i am waiting for sbillard comment on starting the session.
  • acrylian Administrator, Developer
    Yes, there is an unique id of course. But since you probably want to show the images selected in the lightbox manager you will need to use the object model to do that (at least I recommend not to query via the db) and that does not use the id but the album name and filename (as images and albums are filesystem based). Using the object model saves a little work. Take a look at the object model tutorial.
  • Zenphoto will create front-end sessions if you set the gallery session option. You would need to use `session_id()` for the id of the session.
  • frankm Member
    hi,

    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 !
  • frankm Member
    i think i'm back on track. hopefully i'll get something working very soon and maybe then i'll need some comments on how to make the code better.

    i'll let you know.
  • acrylian Administrator, Developer
    The object model is not specififially for the next_image() loop only. It is a good way to get other info of an image like the filename, title, date, tags or whatever. YOu can do all this via the db but the object model is quite easier and cleaner to use (once you got it).

    $_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.
  • frankm Member
    hi,

    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

    ` `
    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.
  • acrylian Administrator, Developer
    Looks good so far. To get `printLiteBoxFrom()` to know about `$obj` you have to pass it via a parameter.
  • frankm Member
    thanks. that's what i was thinking to do at the end having found no other method.
  • acrylian Administrator, Developer
    Another way would have been to declare $obj global but passing as a parameter seems to be the best.
  • frankm Member
    hi,

    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.
  • frankm Member
    i have an issue. basically what i do right now when some click the "add to lightbox" button is to run the addImage function which as the end send me back to where i come from through the `header("Location: " . $_SERVER['HTTP_REFERER'] . " ");` instruction. it ok if we add an image from an album page.

    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.
  • acrylian Administrator, Developer
    Dynamic albums are generated from search results (http://www.zenphoto.org/2008/09/how-to-use-the-dynamic-albums-feature/).

    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?
  • frankm Member
    concerning the last point what i have done is save the $_POST['words'] in a $_SESSION variable that keeps the last search and if i add image from a search i redirect the script with the
    `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.
  • frankm Member
    hi,

    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.
  • acrylian Administrator, Developer
    I am also doing bascially all developing on MAMP. Regarding the session, you are always the same IP/computer so that sounds logical for me. (Not the expert on sessions stuff though).

    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).
  • frankm Member
    i guess it will require each user that want to create a lightbox to register first, correct ?
  • acrylian Administrator, Developer
    Yes, true. if you don't want that you would in indeed have to use sessions.
  • frankm Member
    also, is there a way to have on the admin panel the number of lightboxes currently in the table just like we have some info on how many images, comments, news (and so on) we have in the gallery.

    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.
  • acrylian Administrator, Developer
    It is possible to add main admin tabs via a filter (like the menu manager or Zenpage do) but I think creating an admin overview page utility for that like the gallery statistics would be fitting as well. The main tabs get a little wide especially in languages that use longer terms than English.
    How to do that is described on our user guide: http://www.zenphoto.org/2010/04/zenphoto-plugin-architecture/
  • You can set up user registration to be automatic if you want. (No intervention from you needed.) I do not understand why you would like the general public to be able to make changes to your site (create light boxes.) That would certainly be subject to hacking/spammer attack.
  • frankm Member
    hi,

    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.
  • acrylian Administrator, Developer
    No need for hacking any files. As I already said above you will have to provide a admin utility plugin, either as a separate file or within the main plugin file. See the plugin tutorial about that.
  • frankm Member
    sorry about that. i guess i haven't looked in details how it was done. i'll go back to the tutorial and the examples.
Sign In or Register to comment.