How To Write A Plugin

This tutorial assumes that you have some basic understanding of programming/scripting. This is not a beginner level task.

We'll break this tutorial into four sections:

1 - how plugins work
2 - creating the plugin file
3 - creating the function
4 - some additional tips

1. How Plugins Work

When a webpage is presented the template and it's contents are parsed by Indexhibit. The parser searches for system variables* and plugins and replaces them with their according variable and/or plugin. For instance, if a plugin is called "ndxz_users" the parser will look for an actual file in your plugins folder called 'plugin.ndxz_users.php' and the accompanying function. If the file does not exist the parser will return nothing.

2. Creating the Plugin File

Creating the plugin file is quite simple - just name the file the same as you wish the plugin to be called in your code. As in the previous example, if your plugin is called "ndxz_users" then you would name your file "plugin.ndxz_users.php" and save the file to your plugins directory.

3. Creating the Function

Your file is called "plugin.ndxz_users.php" and your plugin is executed as "ndxz_users" so now you need to have a function in your file which should be called "function ndxz_users() { }". Be sure that you include your opening and closing php tags.

That's the basics of creating a function. What you make happen with your function is up to you.

4. Some Additional Tips

These are sort of random helper notes - I'll add to these as I think of new ones.

You can include variables in your function, like:

<plug:ndxz_users limit='12' />

As many as you need. You can also include system variables in them as well:

<plug:ndxz_users limit='<%ID%>', other='true' />

DO NOT echo results from your functions, return them only. Echoing will produce error messages.

If you peruse the sample plugins included with Indexhibit you will find examples of database queries, etc. The important thing to know here is that the database library can be accessed globally via this command:

$OBJ =&amp; get_instance();

And then accessed like:

$OBJ->db->fetchArray( query in here... );

There are some really nice database tools that can be found in the /ndxz-studio/db/ folder. We'll write a more detailed tutorial about these later. For now, the sample code contains the basics for usage.

*System Variables: here is a short list of some of the more important ones. But anything that comes out in the page query is automatically turned into a system variable.

You can access system variables in your functions with "global $rs;". When you use them in a template you wrap them like:

<%system_variable_name%>

id = page id number
url = page url
title = page title
content = page text
pdate = published date (comes in the form 0000-00-00 00:00:00)
section_id = section id corresponding to sections table
sec_desc = section description/name

If you would like a full rundown just look up the ndxz_objects and ndxz_sections tables.