RSS: use gmdate() instead of date().
[viewgit.git] / inc / plugins.php
blob16683cb53d758df42c522f3de6b67fb02f806904
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 * Display the given template.
39 function display_plugin_template($template, $with_headers = true) {
40 $name = 'plugins/'. $this->get_name() .'/templates/'. $template .'.php';
41 $this->display_template($name, $with_headers);
44 /**
45 * Return the name of this plugin, for example: "hello".
47 function get_name() {
48 $name = get_class($this);
49 return strtolower(str_replace('Plugin', '', $name));
52 /**
53 * Called when a registered hook is triggered.
55 * Hooks:
56 * header - before closing the head tag
57 * summary - add to summary page
58 * page_start - after body is opened
59 * footer - before closing the body tag
60 * pagenav - $page['links'] can be modified to add more pagenav links, see templates/header.php
62 function hook($type) {}
64 /**
65 * Can be used to output xhtml.
67 function output($xhtml) {
68 echo($xhtml);
71 /**
72 * Registers the given action for this plugin.
74 function register_action($action) {
75 self::$plugin_actions[$action] = $this;
78 function register_hook($type) {
79 self::$plugin_hooks[$type][] = $this;
82 // Static members + methods
84 public static $plugin_actions = array();
85 public static $plugin_hooks = array();
87 /**
88 * Call plugin hooks of given type.
89 * @see VGPlugin::register_hook()
91 static function call_hooks($type) {
92 if (in_array($type, array_keys(self::$plugin_hooks))) {
93 foreach (self::$plugin_hooks[$type] as $class) {
94 $class->hook($type);