Frustation with MiniGallery

I was working on the next release of MiniGallery today, adding some new features and ironing out some issues from the previous release.  The project is still officially in beta, which means I’m still ironing out bugs and to a certain extent relying on other people to tell me what needs changing, so it was useful to demonstrate the system to friends and family over the weekend – it highlighted where work still needs to be done!  I was down Gloucester way for a long weekend, seeing Ellie’s parents, my parents, various grandparents, and a few others, and the opportunity came up to share some photos from recent events here in Wiv, so up came my PhotoLounge!  Using it in front of other people made me realised just how badly structured the whole project is.

Version 0.5Beta made heavy use of sessions to store the information that needed to be passed from one page to the next.  This is something I’d not used before, so it was useful to experiment and learn about this sort of technology, old though it might be.  However, my implementation was far from perfect and wasn’t exactly fool-proof.  For some reason I had decided to put navigation into the session too, and although that works fine in normal operation it had knock-on complications if you wanted to have two instances in your browser at once, say one in each tab for different folders of images.  Because there was no differentiation between one and the other, the navigation and stored information from one instance interfered with the other, leading to some rather unwanted results!

The other problem with having navigation implemented using sessions was that hitting the Back button in the browser didn’t take you back a page, because the session information was not stored for the previous instance of the page.  Not the best approach then.

So today I sat down and re-thought the whole structure of the project, and introduced a global settings file (which would hold values for site-wide parameters such as which theme to use, what the gallery is called, etc.) and another settings file for each theme (with parameters that would need to be set differently depending on what was needed for the theme style).  I also removed the drop down box allowing visitors to change the number of images shown on each page, partly to make it simpler to program and partly because it’s not really all that necessary; in fact one could argue that it should be up to the theme designer to ensure a suitable number of images are displayed on a page, not the user.

Of course, there were problems in the development process, which were frustratingly difficult to pin down.  I would have three class variables, I’d set each one of them to something different, but when I’d try to access them they’d all three have the same value.  It was as if the variables had suddenly and inexplicably become referenced rather than explicit, which is something I don’t think PHP4 does anyway.  After a lot (and I mean a LOT) of googling and fiddling and debugging and testing, I finally realised that the problem lay in the way I was using the class variables – I had been using $this->$album instead of $this->album.  It was just an extra $ sign, but it made all the difference!  So after going through the whole gallery file and fixing all of those variables, it finally started to work.

My next challenge will be watermarking images.  As far as I know this should be fairly straightforward, as there are already routines built into PHP that should allow the combining of two images, I just need to research that tomorrow and see if I can produce a pain-free implementation of it.  The idea of watermarking just means that people using MiniGallery will be able to quickly and easily apply a logo or copyright notice to every image without needing to edit each individual file before uploading.

I was also pleased to note that the main gallery script still only takes up 10KB.  Not bad for a (nearly) fully functional photo gallery system!  The key here is that the main script only deals with the generation and output of the gallery, not the layout or styling – everything to do with colour, images, layout, style, is all determined by the stylesheet in the theme folder, which not only makes it more flexible and more powerful but also much smaller.  Bring on the CSS!

3 thoughts on “Frustation with MiniGallery

  1. I quite like the ‘number of images to display’ drop-down. Seriously, I hate it when there’s a gallery with a lot of images and I keep on having to click “Next”. Obviously if there aren’t that many images then it doesn’t make that much difference.

    By the way, it’s probably not a good idea to set permissions on your web server to 777, 755 should be enough 🙂

  2. [note: the above comment was referring to point #3 of your howto… I seem to be posting double comments a lot, sorry about that!]

  3. I’ve made some more progress today, getting close to the next release! Got watermarking and image scaling sorted (after a lot of messing around with htmlspecialchars() and stripslashes() to make it work).

    Yes Phill, it is a shame to be losing the drop down box, but I just don’t have time to add that into this release and still have it work, maybe I’ll put it back in in a subsequent release.

    As for the permissions, all I need really is for the server to be able to save files into a directory it’s created. True, 777 isn’t the safest, maybe I’ll change that too…

    Thanks for your comments though, nice to know someone actually reads this stuff!!

Leave a Reply

Your email address will not be published. Required fields are marked *