Fixed hook & action calls.
[viewgit.git] / inc / plugins.php
blob2193c74c08f0534c07468a665ba4c6798bc01285
1 <?php
3 /**
4 * Base class plugins should extend. This defines the public, hopefully
5 * somewhat static API plugins should be able to rely on.
7 * Plugins go to plugins/name/main.php and must contain a NamePlugin class.
8 */
9 class VGPlugin
11 /**
12 * Actions, hooks and other things must be initialized/registered here.
14 function __construct() {
18 /**
19 * Called when a registered action is triggered.
21 function action($action) {}
23 /**
24 * Display the given template.
26 function display_template($template, $with_headers = true) {
27 if ($with_headers) {
28 require 'templates/header.php';
30 require "$template";
31 if ($with_headers) {
32 require 'templates/footer.php';
36 /**
37 * Called when a registered hook is triggered.
39 * Hooks:
40 * header - before closing the head tag
41 * page_start - after body is opened
42 * footer - before closing the body tag
43 * pagenav - output() can be used to insert content into pagenav.
45 function hook($type) {}
47 /**
48 * Can be used to output xhtml.
50 function output($xhtml) {
51 echo($xhtml);
54 /**
55 * Registers the given action for this plugin.
57 function register_action($action) {
58 self::$plugin_actions[$action] = $this;
61 function register_hook($type) {
62 self::$plugin_hooks[$type][] = $this;
65 // Static members + methods
67 public static $plugin_actions = array();
68 public static $plugin_hooks = array();
70 /**
71 * Call plugin hooks of given type.
72 * @see VGPlugin::register_hook()
74 static function call_hooks($type) {
75 if (in_array($type, array_keys(self::$plugin_hooks))) {
76 foreach (self::$plugin_hooks[$type] as $class) {
77 $class->hook($type);