Flip-Gallery 0.2 – a gallery plugin for WordPress

My gallery plugin for WordPress Flip-Gallery is finally ready, and you can download it from here.

Flip-Gallery uses a tewaked version of Thickbox, the UI display widget built on the jQuery JavaScript Library.

Flip-Gallery is a simple image gallery. You can configure and use it entirely through the WordPress admin interface. It consists of two main parts: a collection of images and a collection of galleries. You can create as many galleries as you want and include as many images as you want in each gallery. An image can be displayed in more than one gallery.

Flip-Gallery has 3 modes of use:

  • HTML mode – nothing fancy just plain URLs
  • Thickbox Image mode – images are displayed in Thickbox overlays
  • AJAX mode – html pages are loaded in an AJAX overlay

If you don’t have JavaScript enabled – don’t worry, it should just degrade nicely.

Download, change it, play with it, break it… give me some feedback and I’ll make it better.

Modified Muliple Checkbox Helper

I’ve been getting some very odd results with Joshua McFarrens excellent checkbox helper and ended up having to modify it slightly to get it to work. Here is my revised version:

'Text' pairs) 
     * @param array $selected Selected checkboxes 
     * @param string $inbetween String that separates the checkboxes. 
     * @param array $htmlAttributes Array of HTML options 
     * @param  boolean $return         Whether this method should return a value 
     * @return string List of checkboxes 
    function checkboxMultiple($fieldName, $options, $selected = null, $inbetween = null, $htmlAttributes = null, $return = false) 
       		 if ($this->tagIsInvalid($this->model, $this->field)) 
            		if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") 
                			$htmlAttributes['class'] .= ' form_error'; 
                			$htmlAttributes['class'] = 'form_error'; 
        if (!is_array($options)) 
            	return null; 
        if (!isset($selected)) 
				$selected = $this->tagValue($fieldName); 
		while(list($key, $name) = each($options))
				$optionsHere = $htmlAttributes; 
				if(in_array($key, $selected))
						$optionsHere['checked'] = 'checked'; 
				$optionsHere['value'] = $key; 
            	$checkbox[] = "
  • " . sprintf($this->tags['checkboxmultiple'], $this->model, $this->field, $this->parseHtmlOptions($optionsHere), $name) . "
  • \n"; } return "\n" . sprintf($this->tags['hiddenmultiple'], $this->model, $this->field, null, $name) . "\n
      \n" . $this->output(implode($checkbox), $return) . "
    \n"; } } ?>

    (The difference between this and the original version is that the foreach loop has been replaced with a while(list loop that works in slightly different way.)

    HABTM / Checkbox working example

    Reading the CakePHP group messages, a lot of people seem to run into problems with creating HABTM relationships and changing from the default multipleSelect to using a series of checkboxes. In an app I was building I ran into a brick wall where I just wasn’t able to find out waht was wrong so I just decided to bake a quick example that I could use as a reference.

    This is for Cake 1.1.x.x

    I used a slightly modified copy of the SQL from the manual and used  Josh McFarren’s checkbox helper.

    -- Table structure for table `posts`
    CREATE TABLE `posts` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `title` varchar(50) default NULL,
      `body` text,
      `created` datetime default NULL,
      `modified` datetime default NULL,
      `status` tinyint(1) NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) TYPE=MyISAM;
    -- --------------------------------------------------------
    -- Table structure for table `posts_tags`
    CREATE TABLE `posts_tags` (
      `post_id` int(10) unsigned NOT NULL default '0',
      `tag_id` int(10) unsigned NOT NULL default '0',
      PRIMARY KEY  (`post_id`,`tag_id`)
    ) TYPE=MyISAM;
    -- --------------------------------------------------------
    -- Table structure for table `tags`
    CREATE TABLE `tags` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `name` varchar(100) default NULL,
      PRIMARY KEY  (`id`)
    ) TYPE=MyISAM;

    I have made two changes to the SQL above:

    1. Removed the user_id field in ‘posts’ (to simplify the example)
    2. Changed ‘tag’ to ‘name’ in ‘tags’ – I changed this because generateList was not working and the $tags array geneated for the view did not contain the tag name ‘tag’ – only the ‘tag_id’ value.

    You can download my working example, it contains all of the files that I create in bake and the files added and changed to use the checkboxHelper. To install the example:

    1. Bake a new application
    2. Connect to database
    3. Paste files from zip example to replace the newly baked files
    4. Create database tables using the SQL


    Session Error in Cake App

    I have spent the past 24 hours pulling my hair out over a very odd error in a CakePHP application I have been developing.
    I had an app called training, so my directory structure looked like this (the training app was generated using bake)

    Dreamweaver Screenshot

    I had copied large amounts of code from another cake site that I am also developing including a simple login system to password protect the admin routes.

    I noticed that as I was browsing the site and tried to login, I would login successfully into the admin area and then as soon as I tried to access any controller method in the admin section I would be logged out.

    I echoed all my POST and SESSION variables to the screen in the layout using:


    So I knew that I was being logged in successfully.

    Session Screenshot

    When I tried to access another controller action e.g. /admin/courses/index I would be logged out and asked to login again. Eventually I noticed that when I logged in I was being redirected to /training/admin/homes/index instead of the expected /admin/homes/index which is why I was being logged out.

    I examined all the releveant files in my working application and my broken one and discovered that the only difference was that the working application was called /app/ and the broken one was called /training/ I re-named training to /app/ uploaded the site and it all worked again.

    I am not sure at the moment whether this is the result of something I have misunderstood or if it is a bug, anyway I’ll stick it on trac when I get the chance.