SPiFFy: Simple PHP Framework for Fedora

Customizing interfaces

The basic controller file is: index.php

The basic interface scripts are in: php/default/. Anyone of these scripts can be overridden by copying a script from that directory and placing it in the directory php/custom/

There is also a header and footer file at: php/default/inc/header.php and php/default/inc/footer.php respectively. These too can be overridden.

Developing plugins

A simple plugin is easy to write: all you have to do is create a directory with the name of the BDEF (with any ':'s converted to '_'s, as those are prohibited in many filesystems) and drop a file in there called Plugin.class.php. Inside that file, create a PHP class with the name of the BDEF (again, with any ':'s converted to '_'s). So a plugin for the BDEF "demo:DualResImage" would be named: demo_DualResImage_Plugin

Plugins require 2 methods:

class demo_DualResImage_Plugin {

    setParams(Array);

    display();

}

Plugins and text-search

If you want the object to be text searchable, create a file called Indexer.class.php that has a single method called index(). The Spiffy framework used the Zend port of the Lucene search engine to provide text search services.

class demo_DualResImage_Indexer {

   // perform indexing
   index(ObjectIndexer,Array);

}

To add an item to the index, you need to call the method addDocument() on the ObjectIndexer sent into the index() method. The Array is the same associative array of parameters sent into the Plugin. The code to add a document to the indices looks like this;

$fields = array();
$fields['FIELD_NAME'] = "[FIELD VALUE]";
// add other fields
$objectIndexer->addDocument($fields);

Note that a single object can have multiple text-search indices. (for example, a book might choose to index each page separatly). Also, since the DublinCore metadata is sent in with the parameters to the Indexer, it is easy to add those fields to the indices (note that the DublinCore title and description fields are already added.

Invoking a plugin from a search result

When a search result is returned, Spiffy uses the pid and bdef parameters that were set in the Zend_Search_Lucene_Document to invoke the plugin. Other parameters can be invoked as well, so that when a search result is clicked on, a plugin can be opened up to a particular state (such as opening a book to a particular page).

To add custom parameters to the search results that are sent in to the plugin, use this code:

$doc->addField(Zend_Search_Lucene_Field::Text('paramName1','[name]'));
$doc->addField(Zend_Search_Lucene_Field::Text('paramValue1','[value]'));
// up to ...
$doc->addField(Zend_Search_Lucene_Field::Text('paramName10','[name]'));
$doc->addField(Zend_Search_Lucene_Field::Text('paramValue10','[value]'));

When the plugin is invoked, the parameters and their values will be sent in to the plugin.