<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
abstract class PLModule
{
- abstract function handlers();
+ /** Path of the includes of the module
+ * Internal use only.
+ */
+ private $modIncludePath;
+
+ /** Return an array associating pathes to the corresponding hook.
+ * array( '/my/path' => make_hook(...),
+ * ...);
+ * @ref make_hook
+ */
+ abstract public function handlers();
/** Register a hook
* @param fun name of the handler (the exact name will be handler_$fun)
*/
public function make_hook($fun, $auth, $perms = 'user', $type = DO_AUTH)
{
- return array('hook' => array($this, 'handler_'.$fun),
- 'auth' => $auth,
- 'perms' => $perms,
- 'type' => $type);
+ return new PlStdHook(array($this, 'handler_' . $fun),
+ $auth, $perms, $type);
+ }
+
+ /** Register a hook that points to a wiki page.
+ */
+ public function make_wiki_hook($auth = AUTH_PUBLIC, $perms = 'user', $type = DO_AUTH)
+ {
+ return new PlWikiHook($auth, $perms, $type);
+ }
+
+ /** Include a 'module-specific' file.
+ * Module specific includes must be in the in the path modules/{modulename}.
+ */
+ public function load($file)
+ {
+ require_once $this->modIncludePath . $file;
}
/* static functions */
- public static function factory($modname)
+ public static function path($modname)
{
global $globals;
if ($modname == 'core') {
- $mod_path = $globals->spoolroot . '/core/modules/' . $modname . '.php';
+ $mod_path = $globals->spoolroot . '/core/modules/' . $modname;
} else {
- $mod_path = $globals->spoolroot . '/modules/' . $modname . '.php';
+ $mod_path = $globals->spoolroot . '/modules/' . $modname;
}
+ return $mod_path;
+ }
+
+ public static function factory($modname)
+ {
+ $mod_path = self::path($modname);
$class = ucfirst($modname) . 'Module';
- require_once $mod_path;
- return new $class();
+ require_once $mod_path . '.php';
+ $module = new $class();
+ $module->modIncludePath = $mod_path . '/';
+ return $module;
}
}