Reddit-style Voting and plugin types
by
on 03-02-2010 at 02:38 PM (727 Views)
I've just finished an alternative to the standard voting plugin, one that works in a similar fashion to Reddit, i.e. you can vote up or down, and even change you mind. The plugin itself is nothing to shout about, but the ease in which you can swap one voting method for another is certainly worth highlighting.
Hotaru CMS is plugin-powered. If you don't like something, you can just replace it with something else. The new Up Down Voting plugin is one example of an alternative plugin. For alternative plugins like this one to work without a hitch, it uses plugin type "vote", so when any other plugin checks to see if "vote" is active, it doesn't matter which vote plugin you're using, just as long as it's of type "vote". In most cases, plugin hooks are sufficient, but this ability to specify a type makes coding much more comfortable when you don't know which plugins people will be using.
In the comment block at the top of your plugin, specify the type like this:
Other developers can then test for a "vote" plugin with the isActive function:PHP Code:* type: vote
Not all plugins need to specify a type, but it's good practice in case anyone wants to make an alternative version of your plugin. You can choose the type name yourself, or use the one of the plugin you wish to replace. The quickest way to see existing plugin types is by looking at the plugin_tpe column in the database "plugins" table. Current examples include categories, tags, base, signin, search, post, antispam and avatar.PHP Code:if $h->isActive("vote") {
// do something
}
Of course, you don't have to make alternative plugins to change the behavior of an existing plugin. Hotaru has a rather clever "extend" feature which you can use to make small changes to a plugin without having to duplicate most of its functionality in your own. Learn more about that in Extending Plugins.













Email Blog Entry