Tuesday, November 24, 2009

Lightbox

So, following on from the last post i've added a simple Lightbox. This needs to allow users to:

  • Add images to lightbox at various places

  • View images in their lightbox and remove one or more



At the moment a user will have a single lightbox; it's not designed to be a galleries type of system; its simply a 'bucket' to add images to in readiness for buying and downloading them.

So, its relatively straightforward; i added a component with one page and a couple of tasks; all the tasks result in the user being presented with their lightbox; the tasks them selves define whether an image (or images) are added to the lightbox or removed. The default task simply bypasses the processing and goes to the lightbox view/page.

Session
The one wrinkle is that a lightbox can be created in session by guest users OR if logged in the lightbox is saved and persists across sessions. This means that the processing has to check at various stages whether the current user is logged in. This is achieved by this code:


$user =& JFactory::getUser();
if (!$user->guest){
...
}


This 'if' block will run for logged in users. So all we do at each stage is to check if the user's logged in and then add to d/b and session (or just session) accordingly.

Both cases put the list of lightbox items in the session:


$session =& JFactory::getSession();
$session->set('PJ_IMAGES',$images);


where '$images' is an array of image 'objects'.

This object list is created from a SQL statement and the array built using
$rows = $db->loadObjectList();
; it also uses some JoomGallery helper functions.

Parameters
One thing I needed to add is the use of component parameters; these are global parameters and will beused to hold how much various images cost and need to be available in the Admin interface.

To add these is simple:


  • Add a 'config.xml' file describing the parameters

  • Add a toolbar button



the 'config.xml' file I put into the 'admin' folder (and added to the list of files in the component XML descriptor file:


<?xml version="1.0" encoding="utf-8"?>
<root>
<params>
<param type="text" name="sml_image_price" size="3" label="Small Image Price:" description="Please enter the new price" />
<param type="text" name="med_image_price" size="3" label="Medium Image Price:" description="Please enter the new price" />
<param type="text" name="lrg_image_price" size="3" label="Large Image Price:" description="Please enter the new price" />
</params>
</root>


The toolbar button is added programatically. If you dont have a default admin landing page already, create on, in the 'admin' folder root called COMPONENT_NAME.php and add this code:


<?php
JToolBarHelper::preferences( 'com_COMPONENT_NAME' );
?>


And that's it; go to the component in the admin interface and hit the Parameters button.

Friday, November 06, 2009

JoomGallery & Image Selection

Given the use of JommGallery for image handling and processing, the next step is to allow users, when they find images they like, to add them to a 'lightroom' or 'lightbox'.

Essentially the user willbuild a list of selected images and then needs to be able to manage that list of images.

I feel a new component coming on. Use cases are


  • User searches, finds image(s) and selects one or more to add to lightroom

  • User wants to view lightroom

  • User wants to remove images from lightroom

  • User wants to buy & download images from lightroom

Thursday, November 05, 2009

Thumbnails and JoomGallery

so, with JoomGallery working well, i now need a way to create multiple thumbnails.

JoomGallery automatically creates one thumbnail on upload; i want to intercept that and create 3.

So, there are a couple of ways of doing that;

  • amend the JoomGallery code and add the extra code

  • amend the JoomGallery code to trigger and event and write a plugin to create the thumbnails



The latter is more appealing; we can control/maintain the image sizes by adding parameters to the Plugin and then use those in the code.

Update: Part One
added this to classes/upload.class.php:


$dispatcher =& JDispatcher::getInstance();
//$results = $dispatcher->trigger('onJoomCreateThumbnail', $params);


So, need to populate 'params' and the write the plugin to handle it. Beauty is we can re-use JoomGallery's functionality to create the thumbnails for us.

Tuesday, November 03, 2009

Uploads, Files, Components and Permissions

There's an underlying issue when you have a hosted Joomla.

The host invariably runs your site as the Apache account owner (apache or httpd).

You log in to manage your account using your own site using a different account.

When you install components (by default) Joomla's set up to use file uploads, i.e. the new folders etc are created as using the Apache account which differs (possibly) to the account the Joomla installation is crested under.

This has given me issues amending single files in components/plugins that i've installed via the Admin interface.

So, i've just installed joomlaXplorer and i have to say, it rocks.

I've left the ownership alone so that i can uninstall etc, but i can mod file permissions so that i can at least amend files.