View Issue Details

IDProjectCategoryView StatusLast Update
0008766mantisbtplug-inspublic2008-04-19 04:10
Reporterjreese Assigned Tojreese  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Target Version1.2.0a1Fixed in Version1.2.0a1 
Summary0008766: Move text processing and formatting to an official plugin
Description

In order to better support the future use of plugins to customize the formatted text content in Mantis, the current text formatting system should be updated and moved to an official plugin, so it can be partially or entirely disabled in order to play nicely with other plugins.

I already have a working patch for this (attached), that I have tested with and without another plugin that enables Markdown syntax in formatted text inputs. It has three distinct functions: formatting text, formatting URLs, and processing bug/bugnote links. Each piece can be optionally disabled through the plugin config page. The patch adds a schema entry to enable the plugin by default for new installs and upgrades.

Tagspatch
Attached Files
mantis-format.2008-01-17.patch (13,668 bytes)   
diff --git a/admin/schema.php b/admin/schema.php
index fec1314..0001b80 100644
--- a/admin/schema.php
+++ b/admin/schema.php
@@ -389,4 +389,8 @@ $upgrade[] = Array( 'DropColumnSQL', Array( db_get_table( 'mantis_bug_table' ),
 $upgrade[] = Array( 'DropTableSQL', Array( db_get_table( 'mantis_project_category_table' ) ) );
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );
 
+$upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_plugin_table' ), "
+	( basename, enabled ) VALUES
+	( 'format', '1' )" ) );
+
 ?>
diff --git a/core/string_api.php b/core/string_api.php
index d5f610c..e5a64e6 100644
--- a/core/string_api.php
+++ b/core/string_api.php
@@ -106,49 +106,31 @@
 	# --------------------
 	# Prepare a multiple line string for display to HTML
 	function string_display( $p_string ) {	
-		$p_string = string_strip_hrefs( $p_string );
-		$p_string = string_html_specialchars( $p_string );
-		$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ true );
-		$p_string = string_preserve_spaces_at_bol( $p_string );
-		$p_string = string_nl2br( $p_string );
-
-		return event_signal( 'EVENT_DISPLAY_TEXT', $p_string );
+		$t_data = event_signal( 'EVENT_DISPLAY_TEXT', array( $p_string, true ) );
+		return $t_data[0];
 	}
 
 	# --------------------
 	# Prepare a single line string for display to HTML
 	function string_display_line( $p_string ) {
-		$p_string = string_strip_hrefs( $p_string );
-		$p_string = string_html_specialchars( $p_string );
-		$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ false );
-
-		return event_signal( 'EVENT_DISPLAY_TEXT', $p_string );
+		$t_data = event_signal( 'EVENT_DISPLAY_TEXT', array( $p_string, false ) );
+		return $t_data[0];
 	}
 
 	# --------------------
 	# Prepare a string for display to HTML and add href anchors for URLs, emails,
 	#  bug references, and cvs references
 	function string_display_links( $p_string ) {
-		$p_string = string_display( $p_string );
-		$p_string = string_insert_hrefs( $p_string );
-		$p_string = string_process_bug_link( $p_string );
-		$p_string = string_process_bugnote_link( $p_string );
-		$p_string = string_process_cvs_link( $p_string );
-
-		return event_signal( 'EVENT_DISPLAY_FORMATTED', $p_string );
+		$t_data = event_signal( 'EVENT_DISPLAY_FORMATTED', array( $p_string, true ) );
+		return $t_data[0];
 	}
 
 	# --------------------
 	# Prepare a single line string for display to HTML and add href anchors for 
 	# URLs, emails, bug references, and cvs references
 	function string_display_line_links( $p_string ) {
-		$p_string = string_display_line( $p_string );
-		$p_string = string_insert_hrefs( $p_string );
-		$p_string = string_process_bug_link( $p_string );
-		$p_string = string_process_bugnote_link( $p_string );
-		$p_string = string_process_cvs_link( $p_string );
-
-		return event_signal( 'EVENT_DISPLAY_FORMATTED', $p_string );
+		$t_data = event_signal( 'EVENT_DISPLAY_FORMATTED', array( $p_string, false ) );
+		return $t_data[0];
 	}
 
 	# --------------------
@@ -157,16 +139,6 @@
 		# rss can not start with   which spaces will be replaced into by string_display().
 		$t_string = trim( $p_string );
 
-		# same steps as string_display_links() without the preservation of spaces since   is undefined in XML.
-		$t_string = string_strip_hrefs( $t_string );
-		$t_string = string_html_specialchars( $t_string );
-		$t_string = string_restore_valid_html_tags( $t_string );
-		$t_string = string_nl2br( $t_string );
-		$t_string = string_insert_hrefs( $t_string );
-		$t_string = string_process_bug_link( $t_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
-		$t_string = string_process_bugnote_link( $t_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
-		$t_string = string_process_cvs_link( $t_string );
-
 		$t_string = event_signal( 'EVENT_DISPLAY_RSS', $t_string );
 
 		# another escaping to escape the special characters created by the generated links
@@ -185,12 +157,7 @@
 	# Prepare a string for plain text display in email and add URLs for bug
 	#  links and cvs links
 	function string_email_links( $p_string ) {
-		$p_string = string_email( $p_string );
-		$p_string = string_process_bug_link( $p_string, false );
-		$p_string = string_process_bugnote_link( $p_string, false );
-		$p_string = string_process_cvs_link( $p_string, false );
-
-		return $p_string;
+		return event_signal( 'EVENT_DISPLAY_EMAIL', $p_string );
 	}
 
 
diff --git a/plugins/format/events.php b/plugins/format/events.php
new file mode 100644
index 0000000..13913ca
--- /dev/null
+++ b/plugins/format/events.php
@@ -0,0 +1,104 @@
+<?php
+
+/**
+ * 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 plugin_event_format_text( $p_event, $p_string, $p_multiline = true ) {
+	if ( ON == plugin_config_get( 'process_text' ) ) {
+		$p_string = string_strip_hrefs( $p_string );
+		$p_string = string_html_specialchars( $p_string );
+		$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ true );
+
+		if ( $p_multiline ) {
+			$p_string = string_preserve_spaces_at_bol( $p_string );
+			$p_string = string_nl2br( $p_string );
+		}
+	}
+
+	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 plugin_event_format_formatted( $p_event, $p_string, $p_multiline = true ) {
+	if ( ON == plugin_config_get( 'process_text' ) ) {
+		$p_string = string_strip_hrefs( $p_string );
+		$p_string = string_html_specialchars( $p_string );
+		$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ true );
+
+		if ( $p_multiline ) {
+			$p_string = string_preserve_spaces_at_bol( $p_string );
+			$p_string = string_nl2br( $p_string );
+		}
+	}
+
+	if ( ON == plugin_config_get( 'process_urls' ) ) {
+		$p_string = string_insert_hrefs( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_buglinks' ) ) {
+		$p_string = string_process_bug_link( $p_string );
+		$p_string = string_process_bugnote_link( $p_string );
+		$p_string = string_process_cvs_link( $p_string );
+	}
+
+	return array( $p_string, $p_multiline );
+}
+
+/**
+ * RSS text processing.
+ * @param string Event name
+ * @param string Unformatted text
+ * @return string Formatted text
+ */
+function plugin_event_format_rss( $p_event, $p_string ) {
+	if ( ON == plugin_config_get( 'process_text' ) ) {
+		$p_string = string_strip_hrefs( $p_string );
+		$p_string = string_html_specialchars( $p_string );
+		$p_string = string_restore_valid_html_tags( $p_string );
+		$p_string = string_nl2br( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_urls' ) ) {
+		$p_string = string_insert_hrefs( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_buglinks' ) ) {
+		$p_string = string_process_bug_link( $p_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
+		$p_string = string_process_bugnote_link( $p_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
+		$p_string = string_process_cvs_link( $p_string );
+	}
+ 
+	return $p_string;
+}
+
+/**
+ * Email text processing.
+ * @param string Event name
+ * @param string Unformatted text
+ * @return string Formatted text
+ */
+function plugin_event_format_email( $p_event, $p_string ) {
+	if ( ON == plugin_config_get( 'process_text' ) ) {
+		$p_string = string_strip_hrefs( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_buglinks' ) ) {
+		$p_string = string_process_bug_link( $p_string, false );
+		$p_string = string_process_bugnote_link( $p_string, false );
+		$p_string = string_process_cvs_link( $p_string, false );
+	}
+
+	return $p_string;
+}
+
+
diff --git a/plugins/format/lang/strings_english.txt b/plugins/format/lang/strings_english.txt
new file mode 100644
index 0000000..68d2ba9
--- /dev/null
+++ b/plugins/format/lang/strings_english.txt
@@ -0,0 +1,13 @@
+<?php
+
+$s_plugin_format_title = 'Mantis Formatting';
+$s_plugin_format_description = 'Standard text processing and formatting plugin for the Mantis Bug Tracker.';
+
+$s_plugin_format_config = 'Configuration';
+$s_plugin_format_process_text = 'Text Processing';
+$s_plugin_format_process_urls = 'URL Processing';
+$s_plugin_format_process_buglinks = 'Mantis Links ( Bug/Bugnote )';
+
+$s_plugin_format_on = 'On';
+$s_plugin_format_off = 'Off';
+$s_plugin_format_save = 'Save Configuration';
diff --git a/plugins/format/pages/config.php b/plugins/format/pages/config.php
new file mode 100644
index 0000000..7868331
--- /dev/null
+++ b/plugins/format/pages/config.php
@@ -0,0 +1,76 @@
+<?php
+
+auth_reauthenticate();
+access_ensure_global_level( config_get( 'manage_plugin_threshold' ) );
+
+html_page_top1( lang_get( 'plugin_format_title' ) );
+html_page_top2();
+
+print_manage_menu();
+
+?>
+
+<br/>
+<form action="<?php echo plugin_page( 'config_edit' ) ?>" method="post">
+<table align="center" class="width50" cellspacing="1">
+
+<tr>
+	<td class="form-title" colspan="3">
+		<?php echo lang_get( 'plugin_format_title' ) . ': ' . lang_get( 'plugin_format_config' ) ?>
+	</td>
+</tr>
+
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category" width="60%">
+		<?php echo lang_get( 'plugin_format_process_text' ) ?>
+	</td>
+	<td class="center" width="20%">
+		<label><input type="radio" name="process_text" value="1" <?php echo ( ON == plugin_config_get( 'process_text' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'plugin_format_on' ) ?></label>
+	</td>
+	<td class="center" width="20%">
+		<label><input type="radio" name="process_text" value="0" <?php echo ( OFF == plugin_config_get( 'process_text' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'plugin_format_off' ) ?></label>
+	</td>
+</tr>
+
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'plugin_format_process_urls' ) ?>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_urls" value="1" <?php echo ( ON == plugin_config_get( 'process_urls' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'plugin_format_on' ) ?></label>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_urls" value="0" <?php echo ( OFF == plugin_config_get( 'process_urls' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'plugin_format_off' ) ?></label>
+	</td>
+</tr>
+
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'plugin_format_process_buglinks' ) ?>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_buglinks" value="1" <?php echo ( ON == plugin_config_get( 'process_buglinks' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'plugin_format_on' ) ?></label>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_buglinks" value="0" <?php echo ( OFF == plugin_config_get( 'process_buglinks' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'plugin_format_off' ) ?></label>
+	</td>
+</tr>
+
+<tr>
+	<td class="center" colspan="3">
+		<input type="submit" class="button" value="<?php echo lang_get( 'plugin_format_save' ) ?>" />
+	</td>
+</tr>
+
+</table>
+<form>
+
+<?php
+html_page_bottom1( __FILE__ );
+
diff --git a/plugins/format/pages/config_edit.php b/plugins/format/pages/config_edit.php
new file mode 100644
index 0000000..2ce6e5a
--- /dev/null
+++ b/plugins/format/pages/config_edit.php
@@ -0,0 +1,23 @@
+<?php
+
+auth_reauthenticate();
+access_ensure_global_level( config_get( 'manage_plugin_threshold' ) );
+
+$f_process_text = gpc_get_int( 'process_text', ON );
+$f_process_urls = gpc_get_int( 'process_urls', ON );
+$f_process_mantis_links = gpc_get_int( 'process_buglinks', ON );
+
+if ( plugin_config_get( 'process_text' ) != $f_process_text ) {
+	plugin_config_set( 'process_text', $f_process_text );
+}
+
+if ( plugin_config_get( 'process_urls' ) != $f_process_urls ) {
+	plugin_config_set( 'process_urls', $f_process_urls );
+}
+
+if ( plugin_config_get( 'process_buglinks' ) != $f_process_buglinks ) {
+	plugin_config_set( 'process_buglinks', $f_process_buglinks );
+}
+
+print_successful_redirect( plugin_page( 'config' ) );
+
diff --git a/plugins/format/register.php b/plugins/format/register.php
new file mode 100644
index 0000000..1a7bab7
--- /dev/null
+++ b/plugins/format/register.php
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * Plugin information.
+ */
+function plugin_callback_format_info() {
+	return array(
+		'name' => lang_get( 'plugin_format_title' ),
+		'description' => lang_get( 'plugin_format_description' ),
+		'version' => '0.1',
+		'author' => 'Mantis Team',
+		'contact' => 'mantisbt-dev@lists.sourceforge.net',
+		'url' => 'http://www.mantisbt.org',
+		'page' => 'config',
+		'requires' => array(
+			'mantis' => '1.2.0',
+		),
+	);
+}
+
+/**
+ * Default plugin configuration.
+ */
+function plugin_callback_format_config() {
+	return array(
+		'process_text' => ON,
+		'process_urls' => ON,
+		'process_buglinks' => ON,
+	);
+}
+
+/**
+ * Event hook declaration.
+ */
+function plugin_callback_format_hook() {
+	return array(
+		
+		# Text String Display
+		'EVENT_DISPLAY_TEXT' => 'text',	
+
+		# Formatted String Display
+		'EVENT_DISPLAY_FORMATTED' => 'formatted',
+
+		# RSS String Display
+		'EVENT_DISPLAY_RSS' => 'rss',
+
+		# Email String Display
+		'EVENT_DISPLAY_EMAIL' => 'email',
+
+	);
+}
mantis-format.2008-01-17.patch (13,668 bytes)   
mantis-format.2008-01-18.patch (14,555 bytes)   
diff --git a/admin/schema.php b/admin/schema.php
index fec1314..0001b80 100644
--- a/admin/schema.php
+++ b/admin/schema.php
@@ -389,4 +389,8 @@ $upgrade[] = Array( 'DropColumnSQL', Array( db_get_table( 'mantis_bug_table' ),
 $upgrade[] = Array( 'DropTableSQL', Array( db_get_table( 'mantis_project_category_table' ) ) );
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );
 
+$upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_plugin_table' ), "
+	( basename, enabled ) VALUES
+	( 'format', '1' )" ) );
+
 ?>
diff --git a/core/string_api.php b/core/string_api.php
index d5f610c..e5a64e6 100644
--- a/core/string_api.php
+++ b/core/string_api.php
@@ -106,49 +106,31 @@
 	# --------------------
 	# Prepare a multiple line string for display to HTML
 	function string_display( $p_string ) {	
-		$p_string = string_strip_hrefs( $p_string );
-		$p_string = string_html_specialchars( $p_string );
-		$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ true );
-		$p_string = string_preserve_spaces_at_bol( $p_string );
-		$p_string = string_nl2br( $p_string );
-
-		return event_signal( 'EVENT_DISPLAY_TEXT', $p_string );
+		$t_data = event_signal( 'EVENT_DISPLAY_TEXT', array( $p_string, true ) );
+		return $t_data[0];
 	}
 
 	# --------------------
 	# Prepare a single line string for display to HTML
 	function string_display_line( $p_string ) {
-		$p_string = string_strip_hrefs( $p_string );
-		$p_string = string_html_specialchars( $p_string );
-		$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ false );
-
-		return event_signal( 'EVENT_DISPLAY_TEXT', $p_string );
+		$t_data = event_signal( 'EVENT_DISPLAY_TEXT', array( $p_string, false ) );
+		return $t_data[0];
 	}
 
 	# --------------------
 	# Prepare a string for display to HTML and add href anchors for URLs, emails,
 	#  bug references, and cvs references
 	function string_display_links( $p_string ) {
-		$p_string = string_display( $p_string );
-		$p_string = string_insert_hrefs( $p_string );
-		$p_string = string_process_bug_link( $p_string );
-		$p_string = string_process_bugnote_link( $p_string );
-		$p_string = string_process_cvs_link( $p_string );
-
-		return event_signal( 'EVENT_DISPLAY_FORMATTED', $p_string );
+		$t_data = event_signal( 'EVENT_DISPLAY_FORMATTED', array( $p_string, true ) );
+		return $t_data[0];
 	}
 
 	# --------------------
 	# Prepare a single line string for display to HTML and add href anchors for 
 	# URLs, emails, bug references, and cvs references
 	function string_display_line_links( $p_string ) {
-		$p_string = string_display_line( $p_string );
-		$p_string = string_insert_hrefs( $p_string );
-		$p_string = string_process_bug_link( $p_string );
-		$p_string = string_process_bugnote_link( $p_string );
-		$p_string = string_process_cvs_link( $p_string );
-
-		return event_signal( 'EVENT_DISPLAY_FORMATTED', $p_string );
+		$t_data = event_signal( 'EVENT_DISPLAY_FORMATTED', array( $p_string, false ) );
+		return $t_data[0];
 	}
 
 	# --------------------
@@ -157,16 +139,6 @@
 		# rss can not start with &nbsp; which spaces will be replaced into by string_display().
 		$t_string = trim( $p_string );
 
-		# same steps as string_display_links() without the preservation of spaces since &nbsp; is undefined in XML.
-		$t_string = string_strip_hrefs( $t_string );
-		$t_string = string_html_specialchars( $t_string );
-		$t_string = string_restore_valid_html_tags( $t_string );
-		$t_string = string_nl2br( $t_string );
-		$t_string = string_insert_hrefs( $t_string );
-		$t_string = string_process_bug_link( $t_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
-		$t_string = string_process_bugnote_link( $t_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
-		$t_string = string_process_cvs_link( $t_string );
-
 		$t_string = event_signal( 'EVENT_DISPLAY_RSS', $t_string );
 
 		# another escaping to escape the special characters created by the generated links
@@ -185,12 +157,7 @@
 	# Prepare a string for plain text display in email and add URLs for bug
 	#  links and cvs links
 	function string_email_links( $p_string ) {
-		$p_string = string_email( $p_string );
-		$p_string = string_process_bug_link( $p_string, false );
-		$p_string = string_process_bugnote_link( $p_string, false );
-		$p_string = string_process_cvs_link( $p_string, false );
-
-		return $p_string;
+		return event_signal( 'EVENT_DISPLAY_EMAIL', $p_string );
 	}
 
 
diff --git a/plugins/format/events.php b/plugins/format/events.php
new file mode 100644
index 0000000..e936d15
--- /dev/null
+++ b/plugins/format/events.php
@@ -0,0 +1,113 @@
+<?php
+
+/**
+ * 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 plugin_event_format_text( $p_event, $p_string, $p_multiline = true ) {
+	if ( ON == plugin_config_get( 'process_text' ) ) {
+		$p_string = string_strip_hrefs( $p_string );
+		$p_string = string_html_specialchars( $p_string );
+		$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ true );
+
+		if ( $p_multiline ) {
+			$p_string = string_preserve_spaces_at_bol( $p_string );
+			$p_string = string_nl2br( $p_string );
+		}
+	}
+
+	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 plugin_event_format_formatted( $p_event, $p_string, $p_multiline = true ) {
+	if ( ON == plugin_config_get( 'process_text' ) ) {
+		$p_string = string_strip_hrefs( $p_string );
+		$p_string = string_html_specialchars( $p_string );
+		$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ true );
+
+		if ( $p_multiline ) {
+			$p_string = string_preserve_spaces_at_bol( $p_string );
+			$p_string = string_nl2br( $p_string );
+		}
+	}
+
+	if ( ON == plugin_config_get( 'process_urls' ) ) {
+		$p_string = string_insert_hrefs( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_buglinks' ) ) {
+		$p_string = string_process_bug_link( $p_string );
+		$p_string = string_process_bugnote_link( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_vcslinks' ) ) {
+		$p_string = string_process_cvs_link( $p_string );
+	}
+
+	return array( $p_string, $p_multiline );
+}
+
+/**
+ * RSS text processing.
+ * @param string Event name
+ * @param string Unformatted text
+ * @return string Formatted text
+ */
+function plugin_event_format_rss( $p_event, $p_string ) {
+	if ( ON == plugin_config_get( 'process_text' ) ) {
+		$p_string = string_strip_hrefs( $p_string );
+		$p_string = string_html_specialchars( $p_string );
+		$p_string = string_restore_valid_html_tags( $p_string );
+		$p_string = string_nl2br( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_urls' ) ) {
+		$p_string = string_insert_hrefs( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_buglinks' ) ) {
+		$p_string = string_process_bug_link( $p_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
+		$p_string = string_process_bugnote_link( $p_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
+	}
+
+	if ( ON == plugin_config_get( 'process_vcslinks' ) ) {
+		$p_string = string_process_cvs_link( $p_string );
+	}
+ 
+	return $p_string;
+}
+
+/**
+ * Email text processing.
+ * @param string Event name
+ * @param string Unformatted text
+ * @return string Formatted text
+ */
+function plugin_event_format_email( $p_event, $p_string ) {
+	if ( ON == plugin_config_get( 'process_text' ) ) {
+		$p_string = string_strip_hrefs( $p_string );
+	}
+
+	if ( ON == plugin_config_get( 'process_buglinks' ) ) {
+		$p_string = string_process_bug_link( $p_string, false );
+		$p_string = string_process_bugnote_link( $p_string, false );
+	}
+
+	if ( ON == plugin_config_get( 'process_vcslinks' ) ) {
+		$p_string = string_process_cvs_link( $p_string, false );
+	}
+
+	return $p_string;
+}
+
+
diff --git a/plugins/format/lang/strings_english.txt b/plugins/format/lang/strings_english.txt
new file mode 100644
index 0000000..b7e5ef2
--- /dev/null
+++ b/plugins/format/lang/strings_english.txt
@@ -0,0 +1,10 @@
+<?php
+
+$s_plugin_format_title = 'Mantis Formatting';
+$s_plugin_format_description = 'Standard text processing and formatting plugin for the Mantis Bug Tracker.';
+
+$s_plugin_format_config = 'Configuration';
+$s_plugin_format_process_text = 'Text Processing';
+$s_plugin_format_process_urls = 'URL Processing';
+$s_plugin_format_process_buglinks = 'Mantis Links ( Bug/Bugnote )';
+$s_plugin_format_process_vcslinks = 'VCS Links';
diff --git a/plugins/format/pages/config.php b/plugins/format/pages/config.php
new file mode 100644
index 0000000..225d710
--- /dev/null
+++ b/plugins/format/pages/config.php
@@ -0,0 +1,90 @@
+<?php
+
+auth_reauthenticate();
+access_ensure_global_level( config_get( 'manage_plugin_threshold' ) );
+
+html_page_top1( lang_get( 'plugin_format_title' ) );
+html_page_top2();
+
+print_manage_menu();
+
+?>
+
+<br/>
+<form action="<?php echo plugin_page( 'config_edit' ) ?>" method="post">
+<table align="center" class="width50" cellspacing="1">
+
+<tr>
+	<td class="form-title" colspan="3">
+		<?php echo lang_get( 'plugin_format_title' ) . ': ' . lang_get( 'plugin_format_config' ) ?>
+	</td>
+</tr>
+
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category" width="60%">
+		<?php echo lang_get( 'plugin_format_process_text' ) ?>
+	</td>
+	<td class="center" width="20%">
+		<label><input type="radio" name="process_text" value="1" <?php echo ( ON == plugin_config_get( 'process_text' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'on' ) ?></label>
+	</td>
+	<td class="center" width="20%">
+		<label><input type="radio" name="process_text" value="0" <?php echo ( OFF == plugin_config_get( 'process_text' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'off' ) ?></label>
+	</td>
+</tr>
+
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'plugin_format_process_urls' ) ?>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_urls" value="1" <?php echo ( ON == plugin_config_get( 'process_urls' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'on' ) ?></label>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_urls" value="0" <?php echo ( OFF == plugin_config_get( 'process_urls' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'off' ) ?></label>
+	</td>
+</tr>
+
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'plugin_format_process_buglinks' ) ?>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_buglinks" value="1" <?php echo ( ON == plugin_config_get( 'process_buglinks' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'on' ) ?></label>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_buglinks" value="0" <?php echo ( OFF == plugin_config_get( 'process_buglinks' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'off' ) ?></label>
+	</td>
+</tr>
+
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'plugin_format_process_vcslinks' ) ?>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_vcslinks" value="1" <?php echo ( ON == plugin_config_get( 'process_vcslinks' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'on' ) ?></label>
+	</td>
+	<td class="center">
+		<label><input type="radio" name="process_vcslinks" value="0" <?php echo ( OFF == plugin_config_get( 'process_vcslinks' ) ) ? 'checked="checked" ' : ''?>/>
+			<?php echo lang_get( 'off' ) ?></label>
+	</td>
+</tr>
+
+<tr>
+	<td class="center" colspan="3">
+		<input type="submit" class="button" value="<?php echo lang_get( 'change_configuration' ) ?>" />
+	</td>
+</tr>
+
+</table>
+<form>
+
+<?php
+html_page_bottom1( __FILE__ );
+
diff --git a/plugins/format/pages/config_edit.php b/plugins/format/pages/config_edit.php
new file mode 100644
index 0000000..48b1df4
--- /dev/null
+++ b/plugins/format/pages/config_edit.php
@@ -0,0 +1,28 @@
+<?php
+
+auth_reauthenticate();
+access_ensure_global_level( config_get( 'manage_plugin_threshold' ) );
+
+$f_process_text = gpc_get_int( 'process_text', ON );
+$f_process_urls = gpc_get_int( 'process_urls', ON );
+$f_process_buglinks = gpc_get_int( 'process_buglinks', ON );
+$f_process_vcslinks = gpc_get_int( 'process_vcslinks', ON );
+
+if ( plugin_config_get( 'process_text' ) != $f_process_text ) {
+	plugin_config_set( 'process_text', $f_process_text );
+}
+
+if ( plugin_config_get( 'process_urls' ) != $f_process_urls ) {
+	plugin_config_set( 'process_urls', $f_process_urls );
+}
+
+if ( plugin_config_get( 'process_buglinks' ) != $f_process_buglinks ) {
+	plugin_config_set( 'process_buglinks', $f_process_buglinks );
+}
+
+if ( plugin_config_get( 'process_vcslinks' ) != $f_process_vcslinks ) {
+	plugin_config_set( 'process_vcslinks', $f_process_vcslinks );
+}
+
+print_successful_redirect( plugin_page( 'config' ) );
+
diff --git a/plugins/format/register.php b/plugins/format/register.php
new file mode 100644
index 0000000..fff2696
--- /dev/null
+++ b/plugins/format/register.php
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * Plugin information.
+ */
+function plugin_callback_format_info() {
+	return array(
+		'name' => lang_get( 'plugin_format_title' ),
+		'description' => lang_get( 'plugin_format_description' ),
+		'version' => '0.1',
+		'author' => 'Mantis Team',
+		'contact' => 'mantisbt-dev@lists.sourceforge.net',
+		'url' => 'http://www.mantisbt.org',
+		'page' => 'config',
+		'requires' => array(
+			'mantis' => '1.2.0',
+		),
+	);
+}
+
+/**
+ * Default plugin configuration.
+ */
+function plugin_callback_format_config() {
+	return array(
+		'process_text' => ON,
+		'process_urls' => ON,
+		'process_buglinks' => ON,
+		'process_vcslinks' => ON,
+	);
+}
+
+/**
+ * Event hook declaration.
+ */
+function plugin_callback_format_hook() {
+	return array(
+		
+		# Text String Display
+		'EVENT_DISPLAY_TEXT' => 'text',	
+
+		# Formatted String Display
+		'EVENT_DISPLAY_FORMATTED' => 'formatted',
+
+		# RSS String Display
+		'EVENT_DISPLAY_RSS' => 'rss',
+
+		# Email String Display
+		'EVENT_DISPLAY_EMAIL' => 'email',
+
+	);
+}
mantis-format.2008-01-18.patch (14,555 bytes)   

Activities

vboctor

vboctor

2008-01-18 02:03

manager   ~0016710

Hi John, here is my first take on it:

  • Within a function, don't assign values to $p variables. This was in the old code, but if we are refactoring, then we should fix that. Use $t*.

  • In my mind the core linking plugin should only include hyperlinking email addresses, http addresses, issue #s, issue note #s. However, I think the links for cvs / svn should be a separate plugin. And if we keep the legacy CVS support in this plugin, then it should have a separate configuration variable.

  • $s_plugin_format_process_buglinks - use issue terminology.

  • $s_plugin_format_on - I believe the plugin ON and OFF strings should be in Mantis standard strings. Otherwise, we will end up with a cocktail of translations for the same thing. Probably save confirmation is also a good candidate for sharing.

  • I am thinking we should rename the version of the 1.2 branch in code, bug tracker and the plugin requirement to 1.2.0a1. In code, it will be 1.2.0a1-SVN. The plugin infrastructure will hopefully be able to handle suffixes like a1 and a1-svn and compare them to rc1, no suffix, etc.

  • I am expecting that if you turn off process_text and turn ON process URLs, you will get some interesting results when there are URLs in the text. However, not sure.

  • Shouldn't methods like string_strip_hrefs(), string_html_specialchars(), etc be moved to the plug-in. Are we using them elsewhere? Are we leaving some of them so that they can be used by other plugins? I think the APIs should only include the ones we use in Mantis core code. Whatever we move to the plugin should be renamed to something that is plugin-specific.

  • The main issue we want to make sure we are handling with having multiple formatting plugins is to make sure that one plugin doesn't scramble the formatting of another. For example, image plugin 1 changes 0000001 to a hyperlink with 1 as the text and an href pointing to a URL. Now another plugin may take the hyper link the href and hyperlink it, or re-format it in a way so that it becomes verbatim text rather than HTML.

  • Did we end up defining a way where the order of executing such plugins can be controlled?

jreese

jreese

2008-01-18 09:45

reporter   ~0016715

  • I'll cleanup the $p vs $t, as of now, the plugin is mostly just using a cut/paste of the old code, so I'll take care of updating it.

  • I'd rather keep the legacy CVS/SVN links in the same plugin, but you are correct that it should be a separate configuration option.

  • I'm not quite sure what you mean by this.

  • Will do.

  • The plugin version version check code will handle this, but I think the version change is unnecessary and unrelated to this discussion.

  • This is not an issue. Each piece of text/url processing happens independently and can be turned on or off in any combination without issue.

  • Most of these methods are used by the rest of the API throughout Mantis. None of it is really specific to the plugin, except perhaps the buglinks code. However, for simplicity sake, I think we should just leave the code in the String API for the time being.

  • I think this should be a matter of plugin authors knowing what plugins they are or aren't compatible with, etc, rather than putting too much power and logic in the plugin manager. For an example, my Markdown plugin knows to disable the text and url processing of this plugin before it installs (prompting the user first of course), so that conflicts don't arrise. Otherwise, plugins can have a list of plugins they aren't compatible with, which should include any plugins that offer the same or conflicting functionality.

  • The only order defined is based on the dependency hierarchy. Setting plugin priorities would generally only result in every plugin saying they are the most important, and there's no real perfect way of solving the issue without making the plugin manager a lot heavier and slower, and the benefit is mostly minimal.

jreese

jreese

2008-01-18 10:30

reporter   ~0016716

Added a new patch with changes suggested by Victor.

jreese

jreese

2008-01-28 09:30

reporter   ~0016858

Changeset has been committed to trunk, SVN r4933.