Permalink
Browse files

Converted plugin system to use a class-based structure.

Updated schema and event system to match.
Updated Mantis Formatting plugin to match.
Added  config variable to simplify including plugin classes.
Hoping I didn't break trunk.


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@4961 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information...
1 parent 7f81775 commit a44abfcd6eb8df6524d20d41c8474a2c5924ae12 @jreese jreese committed Feb 6, 2008
View
@@ -394,7 +394,7 @@
$upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_plugin_table' ), "
( basename, enabled ) VALUES
- ( 'format', '1' )" ) );
+ ( 'MantisFormatting', '1' )" ) );
$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_table' ), "inherit_global I UNSIGNED NOTNULL DEFAULT '0'" ) );
$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_hierarchy_table' ), "inherit_parent I UNSIGNED NOTNULL DEFAULT '0'" ) );
View
@@ -143,6 +143,9 @@
# unless you moved the 'core' directory out of your webroot (recommended).
$g_core_path = $g_absolute_path . 'core' . DIRECTORY_SEPARATOR;
+ # Path to class files
+ $g_class_path = $g_core_path . 'classes' . DIRECTORY_SEPARATOR;
+
# Used to link to manual for User Documentation.
$g_manual_url = 'http://manual.mantisbt.org/';
View
@@ -180,6 +180,6 @@ function microtime_float() {
# Plugin initialization
require_once( $t_core_path.'plugin_api.php' );
if ( !defined( 'PLUGINS_DISABLED' ) ) {
- plugin_init_all();
+ plugin_init_installed();
}
?>
@@ -0,0 +1,81 @@
+<?php
+# Mantis - a php based bugtracking system
+
+# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
+# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.
+
+# Mantis is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Mantis is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Mantis. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Abstract class for any plugin that's modifying textual output.
+ */
+abstract class FormattingPlugin extends MantisPlugin {
+
+ /**
+ * Event hook declaration.
+ */
+ function hooks() {
+ return array(
+ 'EVENT_DISPLAY_TEXT' => 'text', # Text String Display
+ 'EVENT_DISPLAY_FORMATTED' => 'formatted', # Formatted String Display
+ 'EVENT_DISPLAY_RSS' => 'rss', # RSS String Display
+ 'EVENT_DISPLAY_EMAIL' => 'email', # Email String Display
+ );
+ }
+
+ /**
+ * Plain text processing.
+ * @param string Event name
+ * @param string Unformatted text
+ * @param boolean Multiline text
+ * @return multi Array with formatted text and multiline paramater
+ */
+ function text( $p_event, $p_string, $p_multiline = true ) {
+ return array( $p_string, $p_multiline );
+ }
+
+ /**
+ * Formatted text processing.
+ * @param string Event name
+ * @param string Unformatted text
+ * @param boolean Multiline text
+ * @return multi Array with formatted text and multiline paramater
+ */
+ function formatted( $p_event, $p_string, $p_multiline = true ) {
+ return array( $p_string, $p_multiline );
+ }
+
+ /**
+ * RSS text processing.
+ * @param string Event name
+ * @param string Unformatted text
+ * @return string Formatted text
+ */
+ function rss( $p_event, $p_string ) {
+ return $p_string;
+ }
+
+ /**
+ * Email text processing.
+ * @param string Event name
+ * @param string Unformatted text
+ * @return string Formatted text
+ */
+ function email( $p_event, $p_string ) {
+ return $p_string;
+ }
+
+}
+
+
@@ -0,0 +1,98 @@
+<?php
+# Mantis - a php based bugtracking system
+
+# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
+# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.
+
+# Mantis is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Mantis is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Mantis. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Base class that implements basic plugin functionality
+ * and integration with Mantis. See the Mantis wiki for
+ * more information.
+ */
+abstract class MantisPlugin {
+
+ public $name = null;
+ public $description = null;
+ public $page = null;
+
+ public $version = null;
+ public $requires = null;
+
+ public $author = null;
+ public $contact = null;
+ public $url = null;
+
+ abstract public function register();
+
+ public function init() {}
+
+ public function config() {
+ return array();
+ }
+
+ public function hooks() {
+ return array();
+ }
+
+ public function schema() {
+ return array();
+ }
+
+ public function install() {
+ return true;
+ }
+
+ public function upgrade( $p_schema ) {
+ return true;
+ }
+
+ public function uninstall() {
+ }
+
+ ### Core plugin functionality ###
+
+ public $basename = null;
+ final public function __construct( $p_basename ) {
+ $this->basename = $p_basename;
+ $this->register();
+ }
+
+ final public function __init() {
+ plugin_config_defaults( $this->config() );
+ plugin_event_hook_many( $this->hooks() );
+
+ $this->init();
+ }
+}
+
+/**
+ * Mantis Core Plugin
+ * Used to give other plugins a permanent core plugin to 'require' for compatibility.
+ * Can/should not be used as a base class.
+ */
+final class MantisCorePlugin extends MantisPlugin {
+ function register() {
+ $this->name = 'Mantis Core';
+ $this->description = 'Core plugin API for the Mantis Bug Tracker.';
+
+ $this->version = MANTIS_VERSION;
+
+ $this->author = 'Mantis Team';
+ $this->contact = 'mantisbt-dev@lists.sourceforge.net';
+ $this->url = 'http://www.mantisbt.org';
+ }
+}
+
View
@@ -69,7 +69,7 @@ function event_declare_many( $p_events ) {
* @param string Callback function
* @param string Plugin basename
*/
-function event_hook( $p_name, $p_callback, $p_plugin=false ) {
+function event_hook( $p_name, $p_callback, $p_plugin=0 ) {
global $g_event_cache;
if ( !isset( $g_event_cache[$p_name] ) ) {
@@ -78,15 +78,15 @@ function event_hook( $p_name, $p_callback, $p_plugin=false ) {
return null;
}
- $g_event_cache[$p_name]['callbacks'][$p_callback] = $p_plugin;
+ $g_event_cache[$p_name]['callbacks'][$p_plugin][] = $p_callback;
}
/**
* Hook multiple callback functions to multiple events.
* @param array Event name/callback pairs
* @param string Plugin basename
*/
-function event_hook_many( $p_hooks, $p_plugin=false ) {
+function event_hook_many( $p_hooks, $p_plugin=0 ) {
if ( ! is_array( $p_hooks ) ) {
return;
}
@@ -152,21 +152,25 @@ function event_signal( $p_name, $p_params=null, $p_type=null ) {
* @return multi Null if callback not found, value from callback otherwise
*/
function event_callback( $p_event, $p_callback, $p_plugin, $p_params=null ) {
- if ( $p_plugin !== false ) {
- plugin_include( $p_plugin, true );
- plugin_push_current( $p_plugin );
+ $t_value = null;
+ if ( !is_array( $p_params ) ) {
+ $p_params = array( $p_params );
}
- $t_value = null;
- if ( function_exists( $p_callback ) ) {
- if ( !is_array( $p_params ) ) {
- $p_params = array( $p_params );
+ if ( $p_plugin !== 0 ) {
+ global $g_plugin_cache;
+
+ plugin_push_current( $p_plugin );
+
+ if ( method_exists( $g_plugin_cache[$p_plugin], $p_callback ) ) {
+ $t_value = call_user_func_array( array( $g_plugin_cache[$p_plugin], $p_callback), array_merge( array( $p_event ), $p_params ) );
}
- $t_value = call_user_func_array( $p_callback, array_merge( array( $p_event ), $p_params ) );
- }
- if ( $p_plugin !== false ) {
plugin_pop_current();
+ } else {
+ if ( function_exists( $p_callback ) ) {
+ $t_value = call_user_func_array( $p_callback, array_merge( array( $p_event ), $p_params ) );
+ }
}
return $t_value;
@@ -180,8 +184,10 @@ function event_callback( $p_event, $p_callback, $p_plugin, $p_params=null ) {
* @param array Array of callback function/plugin basename key/value pairs
*/
function event_type_execute( $p_event, $p_callbacks ) {
- foreach( $p_callbacks as $t_callback => $t_plugin ) {
- event_callback( $p_event, $t_callback, $t_plugin );
+ foreach( $p_callbacks as $t_plugin => $t_callbacks ) {
+ foreach( $t_callbacks as $t_callback ) {
+ event_callback( $p_event, $t_callback, $t_plugin );
+ }
}
}
@@ -213,8 +219,10 @@ function event_type_output( $p_event, $p_callbacks, $p_params=null ) {
}
$t_output = array();
- foreach( $p_callbacks as $t_callback => $t_plugin ) {
- $t_output[] = event_callback( $p_event, $t_callback, $t_plugin, $p_params );
+ foreach( $p_callbacks as $t_plugin => $t_callbacks ) {
+ foreach( $t_callbacks as $t_callback ) {
+ $t_output[] = event_callback( $p_event, $t_callback, $t_plugin, $p_params );
+ }
}
if ( count( $p_callbacks ) > 0 ) {
echo $t_prefix, implode( $t_separator, $t_output ), $t_postfix;
@@ -233,8 +241,10 @@ function event_type_output( $p_event, $p_callbacks, $p_params=null ) {
*/
function event_type_chain( $p_event, $p_callbacks, $p_input ) {
$t_output = $p_input;
- foreach( $p_callbacks as $t_callback => $t_plugin ) {
- $t_output = event_callback( $p_event, $t_callback, $t_plugin, $t_output );
+ foreach( $p_callbacks as $t_plugin => $t_callbacks ) {
+ foreach( $t_callbacks as $t_callback ) {
+ $t_output = event_callback( $p_event, $t_callback, $t_plugin, $t_output );
+ }
}
return $t_output;
}
@@ -251,8 +261,10 @@ function event_type_chain( $p_event, $p_callbacks, $p_input ) {
*/
function event_type_default( $p_event, $p_callbacks, $p_data ) {
$t_output = array();
- foreach( $p_callbacks as $t_callback => $t_plugin ) {
- $t_output[$t_callback] = event_callback( $p_event, $t_callback, $t_plugin, $p_data );
+ foreach( $p_callbacks as $t_plugin => $t_callbacks ) {
+ foreach( $t_callbacks as $t_callback ) {
+ $t_output[$t_callback] = event_callback( $p_event, $t_callback, $t_plugin, $p_data );
+ }
}
return $t_output;
}
Oops, something went wrong.

0 comments on commit a44abfc

Please sign in to comment.