aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys/plugin_api.php
blob: 6293c2708a2d53c0b3836d1c815a3919f7fe37e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
 * File: ratatoeskr/sys/plugin_api.php
 * Plugin API contains the plugin base class and other interfaces to Ratatöskr.
 * 
 * License:
 * This file is part of Ratatöskr.
 * Ratatöskr is licensed unter the MIT / X11 License.
 * See "ratatoeskr/licenses/ratatoeskr" for more information.
 */

require_once(dirname(__FILE__) . "/models.php");

$url_handlers = array();
/*
 * Function: register_url_handler
 * Register an URL handler. See <ratatoeskr/sys/urlprocess.php> for more details.
 * 
 * Parameters:
 * 	$name - The name of the new URL
 * 	$callback - The Function to be called (see <url_process>).
 */
function register_url_handler($name, $callback)
{
	global $url_handlers;
	$url_handlers[$name] = $callback;
}

/*
 * Class: RatatoeskrPlugin
 * An abstract class to be extended in order to write your own Plugin.
 */
abstract class RatatoeskrPlugin
{
	private $id;
	
	/*
	 * Variables: Protected variables
	 *
	 * $kvstorage - The Key-Value-Storage for the Plugin.
	 * $ste - Access to the global STECore object.
	 */
	protected $kvstorage;
	protected $ste;
	
	
	/*
	 * Constructor: __construct
	 * Performing some neccessary initialisation stuff.
	 * If you are overwriting this function, you *really* should call parent::__construct!
	 * 
	 * Parameters:
	 * 	$id - The ID of the plugin (not the name).
	 */
	public function __construct($id)
	{
		global $ste;
		$this->id        = $id;
		
		$this->kvstorage = new PluginKVStorage($id);
		$this->ste       = $ste;
	}
	
	/*
	 * Functions: Some getters
	 * 
	 * get_id - get the Plugin-ID
	 * get_additional_files_dir - Path to directory with the additional files
	 * get_template_dir - Path to template directory
	 */
	final public function get_id() { return $this->id; }
	final protected function get_additional_files_dir() { return dirname(dirname(__FILE__)) . "/plugin_extradata/" . $this->id; }
	final protected function get_template_dir() { return dirname(dirname(__FILE__)) . "/templates/src/plugintemplates/" . $this->id; }
	
	/*
	 * Function: register_url_handler
	 * Easy way for register a URL handler
	 * 
	 * Parameters:
	 * 	$name - Name of URL
	 * 	$objfunction - Name of object function.
	 */
	final protected function register_url_handler($name, $objfunction)
	{
		register_url_handler($name, array($this, $objfunction));
	}
	
	/*final protected function register_settings_page($get, $validate, $set, $structure)*/
	
	/*
	 * Functions: Functions that are called at special events
	 * 
	 * init - Will be called after plugin is loaded. You should register your stuff here.
	 * install - Will be called after installation. If your plugin needs to initialize some database stuff or generate files, this is the right function.
	 * uninstall - Will be called during uninstallation. If you used the install function you should undo your custom installation stuff.
	 */
	public function init() {}
	public function install() {}
	public function uninstall() {}
}

?>