Skip to content

Commit a44abfc

Browse files
committedFeb 6, 2008
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
1 parent 7f81775 commit a44abfc

18 files changed

+619
-628
lines changed
 

‎admin/schema.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@
394394

395395
$upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_plugin_table' ), "
396396
( basename, enabled ) VALUES
397-
( 'format', '1' )" ) );
397+
( 'MantisFormatting', '1' )" ) );
398398

399399
$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_table' ), "inherit_global I UNSIGNED NOTNULL DEFAULT '0'" ) );
400400
$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_hierarchy_table' ), "inherit_parent I UNSIGNED NOTNULL DEFAULT '0'" ) );

‎config_defaults_inc.php

+3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@
143143
# unless you moved the 'core' directory out of your webroot (recommended).
144144
$g_core_path = $g_absolute_path . 'core' . DIRECTORY_SEPARATOR;
145145

146+
# Path to class files
147+
$g_class_path = $g_core_path . 'classes' . DIRECTORY_SEPARATOR;
148+
146149
# Used to link to manual for User Documentation.
147150
$g_manual_url = 'http://manual.mantisbt.org/';
148151

‎core.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,6 @@ function microtime_float() {
180180
# Plugin initialization
181181
require_once( $t_core_path.'plugin_api.php' );
182182
if ( !defined( 'PLUGINS_DISABLED' ) ) {
183-
plugin_init_all();
183+
plugin_init_installed();
184184
}
185185
?>
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
# Mantis - a php based bugtracking system
3+
4+
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
5+
# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.
6+
7+
# Mantis is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# Mantis is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with Mantis. If not, see <http://www.gnu.org/licenses/>.
19+
20+
/**
21+
* Abstract class for any plugin that's modifying textual output.
22+
*/
23+
abstract class FormattingPlugin extends MantisPlugin {
24+
25+
/**
26+
* Event hook declaration.
27+
*/
28+
function hooks() {
29+
return array(
30+
'EVENT_DISPLAY_TEXT' => 'text', # Text String Display
31+
'EVENT_DISPLAY_FORMATTED' => 'formatted', # Formatted String Display
32+
'EVENT_DISPLAY_RSS' => 'rss', # RSS String Display
33+
'EVENT_DISPLAY_EMAIL' => 'email', # Email String Display
34+
);
35+
}
36+
37+
/**
38+
* Plain text processing.
39+
* @param string Event name
40+
* @param string Unformatted text
41+
* @param boolean Multiline text
42+
* @return multi Array with formatted text and multiline paramater
43+
*/
44+
function text( $p_event, $p_string, $p_multiline = true ) {
45+
return array( $p_string, $p_multiline );
46+
}
47+
48+
/**
49+
* Formatted text processing.
50+
* @param string Event name
51+
* @param string Unformatted text
52+
* @param boolean Multiline text
53+
* @return multi Array with formatted text and multiline paramater
54+
*/
55+
function formatted( $p_event, $p_string, $p_multiline = true ) {
56+
return array( $p_string, $p_multiline );
57+
}
58+
59+
/**
60+
* RSS text processing.
61+
* @param string Event name
62+
* @param string Unformatted text
63+
* @return string Formatted text
64+
*/
65+
function rss( $p_event, $p_string ) {
66+
return $p_string;
67+
}
68+
69+
/**
70+
* Email text processing.
71+
* @param string Event name
72+
* @param string Unformatted text
73+
* @return string Formatted text
74+
*/
75+
function email( $p_event, $p_string ) {
76+
return $p_string;
77+
}
78+
79+
}
80+
81+

‎core/classes/MantisPlugin.class.php

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
# Mantis - a php based bugtracking system
3+
4+
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
5+
# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.
6+
7+
# Mantis is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# Mantis is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with Mantis. If not, see <http://www.gnu.org/licenses/>.
19+
20+
/**
21+
* Base class that implements basic plugin functionality
22+
* and integration with Mantis. See the Mantis wiki for
23+
* more information.
24+
*/
25+
abstract class MantisPlugin {
26+
27+
public $name = null;
28+
public $description = null;
29+
public $page = null;
30+
31+
public $version = null;
32+
public $requires = null;
33+
34+
public $author = null;
35+
public $contact = null;
36+
public $url = null;
37+
38+
abstract public function register();
39+
40+
public function init() {}
41+
42+
public function config() {
43+
return array();
44+
}
45+
46+
public function hooks() {
47+
return array();
48+
}
49+
50+
public function schema() {
51+
return array();
52+
}
53+
54+
public function install() {
55+
return true;
56+
}
57+
58+
public function upgrade( $p_schema ) {
59+
return true;
60+
}
61+
62+
public function uninstall() {
63+
}
64+
65+
### Core plugin functionality ###
66+
67+
public $basename = null;
68+
final public function __construct( $p_basename ) {
69+
$this->basename = $p_basename;
70+
$this->register();
71+
}
72+
73+
final public function __init() {
74+
plugin_config_defaults( $this->config() );
75+
plugin_event_hook_many( $this->hooks() );
76+
77+
$this->init();
78+
}
79+
}
80+
81+
/**
82+
* Mantis Core Plugin
83+
* Used to give other plugins a permanent core plugin to 'require' for compatibility.
84+
* Can/should not be used as a base class.
85+
*/
86+
final class MantisCorePlugin extends MantisPlugin {
87+
function register() {
88+
$this->name = 'Mantis Core';
89+
$this->description = 'Core plugin API for the Mantis Bug Tracker.';
90+
91+
$this->version = MANTIS_VERSION;
92+
93+
$this->author = 'Mantis Team';
94+
$this->contact = 'mantisbt-dev@lists.sourceforge.net';
95+
$this->url = 'http://www.mantisbt.org';
96+
}
97+
}
98+

‎core/event_api.php

+33-21
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function event_declare_many( $p_events ) {
6969
* @param string Callback function
7070
* @param string Plugin basename
7171
*/
72-
function event_hook( $p_name, $p_callback, $p_plugin=false ) {
72+
function event_hook( $p_name, $p_callback, $p_plugin=0 ) {
7373
global $g_event_cache;
7474

7575
if ( !isset( $g_event_cache[$p_name] ) ) {
@@ -78,15 +78,15 @@ function event_hook( $p_name, $p_callback, $p_plugin=false ) {
7878
return null;
7979
}
8080

81-
$g_event_cache[$p_name]['callbacks'][$p_callback] = $p_plugin;
81+
$g_event_cache[$p_name]['callbacks'][$p_plugin][] = $p_callback;
8282
}
8383

8484
/**
8585
* Hook multiple callback functions to multiple events.
8686
* @param array Event name/callback pairs
8787
* @param string Plugin basename
8888
*/
89-
function event_hook_many( $p_hooks, $p_plugin=false ) {
89+
function event_hook_many( $p_hooks, $p_plugin=0 ) {
9090
if ( ! is_array( $p_hooks ) ) {
9191
return;
9292
}
@@ -152,21 +152,25 @@ function event_signal( $p_name, $p_params=null, $p_type=null ) {
152152
* @return multi Null if callback not found, value from callback otherwise
153153
*/
154154
function event_callback( $p_event, $p_callback, $p_plugin, $p_params=null ) {
155-
if ( $p_plugin !== false ) {
156-
plugin_include( $p_plugin, true );
157-
plugin_push_current( $p_plugin );
155+
$t_value = null;
156+
if ( !is_array( $p_params ) ) {
157+
$p_params = array( $p_params );
158158
}
159159

160-
$t_value = null;
161-
if ( function_exists( $p_callback ) ) {
162-
if ( !is_array( $p_params ) ) {
163-
$p_params = array( $p_params );
160+
if ( $p_plugin !== 0 ) {
161+
global $g_plugin_cache;
162+
163+
plugin_push_current( $p_plugin );
164+
165+
if ( method_exists( $g_plugin_cache[$p_plugin], $p_callback ) ) {
166+
$t_value = call_user_func_array( array( $g_plugin_cache[$p_plugin], $p_callback), array_merge( array( $p_event ), $p_params ) );
164167
}
165-
$t_value = call_user_func_array( $p_callback, array_merge( array( $p_event ), $p_params ) );
166-
}
167168

168-
if ( $p_plugin !== false ) {
169169
plugin_pop_current();
170+
} else {
171+
if ( function_exists( $p_callback ) ) {
172+
$t_value = call_user_func_array( $p_callback, array_merge( array( $p_event ), $p_params ) );
173+
}
170174
}
171175

172176
return $t_value;
@@ -180,8 +184,10 @@ function event_callback( $p_event, $p_callback, $p_plugin, $p_params=null ) {
180184
* @param array Array of callback function/plugin basename key/value pairs
181185
*/
182186
function event_type_execute( $p_event, $p_callbacks ) {
183-
foreach( $p_callbacks as $t_callback => $t_plugin ) {
184-
event_callback( $p_event, $t_callback, $t_plugin );
187+
foreach( $p_callbacks as $t_plugin => $t_callbacks ) {
188+
foreach( $t_callbacks as $t_callback ) {
189+
event_callback( $p_event, $t_callback, $t_plugin );
190+
}
185191
}
186192
}
187193

@@ -213,8 +219,10 @@ function event_type_output( $p_event, $p_callbacks, $p_params=null ) {
213219
}
214220

215221
$t_output = array();
216-
foreach( $p_callbacks as $t_callback => $t_plugin ) {
217-
$t_output[] = event_callback( $p_event, $t_callback, $t_plugin, $p_params );
222+
foreach( $p_callbacks as $t_plugin => $t_callbacks ) {
223+
foreach( $t_callbacks as $t_callback ) {
224+
$t_output[] = event_callback( $p_event, $t_callback, $t_plugin, $p_params );
225+
}
218226
}
219227
if ( count( $p_callbacks ) > 0 ) {
220228
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 ) {
233241
*/
234242
function event_type_chain( $p_event, $p_callbacks, $p_input ) {
235243
$t_output = $p_input;
236-
foreach( $p_callbacks as $t_callback => $t_plugin ) {
237-
$t_output = event_callback( $p_event, $t_callback, $t_plugin, $t_output );
244+
foreach( $p_callbacks as $t_plugin => $t_callbacks ) {
245+
foreach( $t_callbacks as $t_callback ) {
246+
$t_output = event_callback( $p_event, $t_callback, $t_plugin, $t_output );
247+
}
238248
}
239249
return $t_output;
240250
}
@@ -251,8 +261,10 @@ function event_type_chain( $p_event, $p_callbacks, $p_input ) {
251261
*/
252262
function event_type_default( $p_event, $p_callbacks, $p_data ) {
253263
$t_output = array();
254-
foreach( $p_callbacks as $t_callback => $t_plugin ) {
255-
$t_output[$t_callback] = event_callback( $p_event, $t_callback, $t_plugin, $p_data );
264+
foreach( $p_callbacks as $t_plugin => $t_callbacks ) {
265+
foreach( $t_callbacks as $t_callback ) {
266+
$t_output[$t_callback] = event_callback( $p_event, $t_callback, $t_plugin, $p_data );
267+
}
256268
}
257269
return $t_output;
258270
}

0 commit comments

Comments
 (0)
Please sign in to comment.