Plugin Development
osDate v2 introduces a mechanism to create your own plugins. A plugin is a small system which works as a separate function, but which interfaces with osDate to integrate with it. This uses the data stored in osDate in collaboration with data specific to the plugin.
If you've made a good plugin that you would be willing to share freely with the osDate community, please share it on the forum or the osDate Code Depot. Or, if you'd like to earn some $ for your efforts, you may be able to sell your plugin to the osDate development team. Please keep in mind that would permit us full copyright control over your plugin, including the ability to sell your plugin on TUFaT.com as an osDate add-on.
How does it work?
osDate v2 introduces two classes - plugin class and modPlugin class. The plugin class (/libs/plugin.php) work like a wrapper class for plugins. This manages all plugin interactions: installation, management and execution.
modPlugin (/libs/mosOsDate/modPlugin.php) provides functions to extract information from osDate tables.
Combining these two, you can create your own plugin with access to most of osDate's core features. If there is something that you need to do with your plugin that is clearly impossible using these files, please let the osDate development team know so that we can improve modPlugin and plugin.php. Do that before attempting to create a "hack" that solves the problem in some other way.
We have provided some sample plugins for your use, in addition to serving as a guide for new plugin development.
How do I develop a new plugin?
Create a new directory in the /plugin directory. This should be your plugin name and plugin class name. Please follow the example of existing plugins.
Then create sub-directories, as given in sample plugins.
Create your plugin Class, templates for displaying, and language files with definition of captions for the plugin. DO NOT HARD CODE ANY CAPTIONS INTO THE PLUGIN, THEY MUST BE IN LANGUAGE FILE. It's likely that some osDate user somewhere in the world will wish to translate your plugin to another language; let's make it easy to do that by sticking with the language file for all captions.
Now test your plugin.
You can see various plugins and understand the way in which they are written.
YOU MUST FOLLOW SAME STRUCTURE AND STYLE as existing plugins. Please note that the functions defined in sample plugins should be available in the plugin you create. Specifically, these functions should ALWAYS be present in the plugin:
displayPluginPage()
displayPluginContent()
displayLeftCol()
displayMain()
displayPluginAdminPage()
Example
Suppose you want to create a plugin named testPlugin.
The directory name of the testPlugin plugin should be /plugins/testPlugin
(Note the directory name should exactly match the plugin name)
The plugin file name is therefore /plugins/testPlugin/libs/testPlugin.php
(note the file name should be same as plugin name)
The contents of testPlugin.php should resemble the code below. The spacing & indentation is irrelvant for actual code execution, but please try as much as possible to make your code well-organized and easy to read & modify... comments are always appreciated!
<?php
include_once(MODOSDATE_DIR . 'modPlugin.php');
class testPlugin extends modPlugin {
/**
* Holds the language phrases
*
* @access private
*/
var $lang;
/**
* The name name of the plugin class.
*
* @access private
*/
var $plugin_class_name = "testPlugin";
/**
* The text that appears in the admin plugin list
*
* @access private
*/
var $display_name = "Test Plugin";
/**
* The link text that appears on the user's menu
*
* @access private
*/
var $user_menu_text = "Test Plugin";
/**
* Appear on users menu (true or false)
*
* @access private
*/
var $user_menu_appear = true;
/**
* The link text that appears on the admin's menu
*
* @access private
*/
var $admin_menu_text = "Test Plugin";
/**
* Appear on admin's menu (true or false)
*
* @access private
*/
var $admin_menu_appear = true;
/**
* Constructor
*
* @return
* @access public
*/
function testPlugin( )
{
$this->modPlugin();
$pluginDir = dirname(__FILE__).'/../';
$this->lang = $this->modLoadLang($pluginDir);
$this->user_menu_text=$this->modGetLang('user_title');
$this->display_name = $this->admin_menu_text=$this->modGetLang('admin_title');
} // end of member method pluginClass
/**
* Does the processing to display a user page. Called from plugin.php
*
* @return array
* @access public
*/
function displayPluginPage() {
$this->modSmartyAssign('lang', $this->modGetLang() );
// This is what makes the template display on the page
//
return $this->modSmartyFetch('testplugin.tpl');
}
/**
* WARNING: USER IS NOT VALIDATED HERE. BE CAREFUL
* Does the processing to display 100% plugin content. Called from pluginraw.php
*
* @return array
* @access public
*/
function displayPluginContent() {
}
/**
* Returns the content that will appear in the left column of a page. Designed to be overridden by plugins
*
* @return array
* @access public
*/
function displayLeftCol() {
$this->modSmartyAssign('lang', $this->modGetLang() );
// This is what makes the template display on the page
//
return $this->modSmartyFetch('testpluginleft.tpl');
}
/**
* Returns the content that will appear in the main content area of the page. This content will appear after the existing main content. Designed to be overridden by plugins
*
* @return array
* @access public
*/
function displayMain() {
$this->modSmartyAssign('lang', $this->modGetLang() );
// This is what makes the template display on the page
//
return $this->modSmartyFetch('testpluginmain.tpl');
}
/**
* Does the processing to display a admin page. Called from plugin.php
*
* @return array
* @access public
*/
function displayPluginAdminPage() {
$this->modSmartyAssign('lang', $this->modGetLang() );
// This is what makes the template display on the page
//
return $this->modSmartyFetch('admin/testplugin.tpl');
}
}
?>