I’ve been meaning to write this up for a while. Adding custom blocks to Ushahidi is a fairly common request
but generally requires a developer, or at least some basic coding skills. However for some basic use cases
it should be possible to add a block with a bit of cut and paste scripting.
To add a block you’ll need to create a plugin. This is actually less complicated than it sounds.
In your Ushahidi install find the directory ‘plugins’ and create a new folder. The structure is like this:
In more complicated plugins we might also have libraries, controllers, helpers or anything else that exists
in the usual Kohana module structure. But for this simple case lets still to just hooks and views.
The readme file is required for Ushahidi to pick up the plugin at all. The first section of this file is parsed for plugin name, description and other details used in the Ushahidi admin.
=== About ===
name: Category Block
description: Adds custom category blocks
tested up to: 2.5
author: Ushahidi Team
author website: http://www.ushahidi.com
Add any other docs here
So how does this work?
The hook ‘register_category_blocks.php’ is included by Ushahidi (and Kohana). This hook registers the ‘Wildlife Reports’ block with Ushahidi core by calling blocks::register().
The array passed to blocks::register() tells Ushahidi the plugin name, description, and where to find the plugin content.
When the plugin is rendered, Ushahidi will call category_wildlife_blocks::block().
This loads the view blocks/category_wildlife_block.php and passes it a list of incidents: the last 10 incidents with category ID = 7.
Change the category ID - just change line 24 of register_category_blocks.php. You might also want to change the name and class for the block too.
Change the html in category_wildlife_block.php - if you want to tweak the output slightly you can easily change it here
Filter the incidents by something else - change where() call on line 30 of register_category_blocks.php
Load images or similar - I’ll post an example for this in the new year…