Custom Functions
Last Modified: August 24, 2004 16:08PM
|
|
(Introduced in 0.19.0)
|
Description
Custom functions are used to extend the functionality of Mantis by integrating user written
functions into the issue processing at strategic places. This allows the system administrator to change
the functionality without re-writing parts of the internals of the code.
User versions of these functions are placed in a file called custom_functions_inc.php in the root
directory of Mantis. This is the same place that the "config_inc.php" file modifying Mantis
defaults is placed. In normal processing, Mantis will look for override functions and execute them
instead of the provided default functions.
Custom functions have names like custom_function_override_descriptive_name where descriptive name
described the particular function. The specific functions are described below. The simplest way to
create a custom function is to copy the default function, named custom_function_default_descriptive_name
from the core/custom_function_api.php file to your override file (custom_functions_inc.php), and
rename it. The specific functionality you need can then be coded into the override function.
Contents- Defined Functions
- Example Custom Function
|
User Contributed Notes Custom Functions |
|
john.pye@student.unsw.edu.au 30-Jan-2006 23:38 |
#856
|
The following is a patch that works with Mantis 1.0rc2 thru 1.0rc5. It will allow you to enter [[wikilinks]] in your mantis bug reports, bugnotes and news items, etc, and redirect them to your Wiki.
Also it will add highlighting to text like 'changeset 243' and create a link to your ViewCVS web page so that you can view the changed files.
To apply this patch, assuming your file is mantis-diff.patch and your mantis is installed in the directory ./mantis, type
$ patch -p1 -d mantis < mantis-diff.patch
Here is the patch file:
diff -uNr mantis-pre2/config_defaults_inc.php mantis-old2/config_defaults_inc.php
--- mantis-pre2/config_defaults_inc.php 2005-09-11 21:24:08.000000000 +1000
+++ mantis-old2/config_defaults_inc.php 2005-11-01 17:44:17.765625000 +1100
@@ -1053,6 +1053,9 @@
# eg: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mantisbt/mantisbt/
$g_cvs_web = '';
+ # --- Wiki linking ---
+ $g_wiki_link_url = '';
+
# --- Source Control Integration ------
# For open source projects it is expected that the notes be public, however,
diff -uNr mantis-pre2/core/string_api.php mantis-old2/core/string_api.php
--- mantis-pre2/core/string_api.php 2005-08-08 01:29:06.000000000 +1000
+++ mantis-old2/core/string_api.php 2005-12-20 10:24:53.187500000 +1100
@@ -101,6 +101,8 @@
$p_string = string_process_bug_link( $p_string );
$p_string = string_process_bugnote_link( $p_string );
$p_string = string_process_cvs_link( $p_string );
+ $p_string = string_process_wiki_link($p_string);
+ $p_string = string_process_changeset_link($p_string);
return $p_string;
}
@@ -143,6 +145,7 @@
$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 );
+ $p_string = string_process_wiki_link($p_string, false);
return $p_string;
}
@@ -192,6 +195,54 @@
$p_string );
}
+ # Process the string, returning full HTML links to a wiki, if configured.
+
+ function string_process_wiki_link($string, $fullHTML = true) {
+ if (!config_get('wiki_link_url')) return $string;
+ if ($fullHTML) return preg_replace_callback('/\[\[(([^\]]*?))\]\]/', 'string_process_wiki_link_callback_fullhtml', $string);
+ return preg_replace_callback('/\[\[(([^\]]*?))\]\]/', 'string_process_wiki_link_callback_nohtml', $string);
+
+ }
+
+ # --------------------
+ # Subsitution callback for the regexp in string_process_wiki_link(); HTML version.
+ function string_process_wiki_link_callback_fullhtml($words) {
+ $p_url_text = $words[2];
+ $p_link = config_get('wiki_link_url').$p_url_text;
+ return '<span class="bracket-link">'. "<a href=\"$p_link\" target=\"_blank\">$p_url_text</a>". '</span> ';
+ }
+
+ # --------------------
+ # Subsitution callback for the regexp in string_process_wiki_link(); plaintext version.
+ function string_process_wiki_link_callback_nohtml($words) {
+ $p_url_text = $words[2];
+ $p_link = config_get('wiki_link_url').$p_url_text;
+ return "$p_url_text ($p_link)";
+ }
+
+ # ---------------------
+ # Process 'changeset' links to ViewCVS pages
+ function string_process_changeset_link($string, $fullHTML = true) {
+ if(!config_get('changeset_link_url'))return $string;
+ $re = '/\b(version|revision|rev|changeset)\s+([0-9]+(\.[0-9]+)*)\b/';
+ if($fullHTML)return preg_replace_callback($re,'string_process_changeset_link_callback_fullhtml', $string);
+ return preg_replace_callback($re,'string_process_changeset_link_callback_nohtml', $string);
+ }
+
+ function string_process_changeset_link_callback_fullhtml($words) {
+ $p_link_text = $words[0];
+ $p_changeset = $words[2];
+ $p_url = config_get('changeset_link_url').$p_changeset;
+ return '<span class="viewcvs-link">'. "<a href=\"$p_url\">$p_link_text</a>". " [<a title=\"open in a new window\" href=\"$p_url\" target=_blank>^</a>]".'</span> ';
+ }
+
+ function string_process_changeset_link_callback_nohtml($words) {
+ $p_link_text = $words[0];
+ $p_changeset = $words[2];
+ $p_url = config_get('changeset_link_url').$p_url_text;
+ return "$p_link_text ($p_url)";
+ }
+
# --------------------
# Process $p_string, looking for bug ID references and creating bug view
# links for them. |
|
john.pye@student.unsw.edu.au 30-Jan-2006 23:39 |
#857
|
The following is a patch that works with Mantis 1.0rc2 thru 1.0rc5. It will allow you to enter [[wikilinks]] in your mantis bug reports, bugnotes and news items, etc, and redirect them to your Wiki.
Also it will add highlighting to text like 'changeset 243' and create a link to your ViewCVS web page so that you can view the changed files.
To apply this patch, assuming your file is mantis-diff.patch and your mantis is installed in the directory ./mantis, type
$ patch -p1 -d mantis < mantis-diff.patch
Here is the patch file:
diff -uNr mantis-pre2/config_defaults_inc.php mantis-old2/config_defaults_inc.php
--- mantis-pre2/config_defaults_inc.php 2005-09-11 21:24:08.000000000 +1000
+++ mantis-old2/config_defaults_inc.php 2005-11-01 17:44:17.765625000 +1100
@@ -1053,6 +1053,9 @@
# eg: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mantisbt/mantisbt/
$g_cvs_web = '';
+ # --- Wiki linking ---
+ $g_wiki_link_url = '';
+
# --- Source Control Integration ------
# For open source projects it is expected that the notes be public, however,
diff -uNr mantis-pre2/core/string_api.php mantis-old2/core/string_api.php
--- mantis-pre2/core/string_api.php 2005-08-08 01:29:06.000000000 +1000
+++ mantis-old2/core/string_api.php 2005-12-20 10:24:53.187500000 +1100
@@ -101,6 +101,8 @@
$p_string = string_process_bug_link( $p_string );
$p_string = string_process_bugnote_link( $p_string );
$p_string = string_process_cvs_link( $p_string );
+ $p_string = string_process_wiki_link($p_string);
+ $p_string = string_process_changeset_link($p_string);
return $p_string;
}
@@ -143,6 +145,7 @@
$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 );
+ $p_string = string_process_wiki_link($p_string, false);
return $p_string;
}
@@ -192,6 +195,54 @@
$p_string );
}
+ # Process the string, returning full HTML links to a wiki, if configured.
+
+ function string_process_wiki_link($string, $fullHTML = true) {
+ if (!config_get('wiki_link_url')) return $string;
+ if ($fullHTML) return preg_replace_callback('/\[\[(([^\]]*?))\]\]/', 'string_process_wiki_link_callback_fullhtml', $string);
+ return preg_replace_callback('/\[\[(([^\]]*?))\]\]/', 'string_process_wiki_link_callback_nohtml', $string);
+
+ }
+
+ # --------------------
+ # Subsitution callback for the regexp in string_process_wiki_link(); HTML version.
+ function string_process_wiki_link_callback_fullhtml($words) {
+ $p_url_text = $words[2];
+ $p_link = config_get('wiki_link_url').$p_url_text;
+ return '<span class="bracket-link">'. "<a href=\"$p_link\" target=\"_blank\">$p_url_text</a>". '</span> ';
+ }
+
+ # --------------------
+ # Subsitution callback for the regexp in string_process_wiki_link(); plaintext version.
+ function string_process_wiki_link_callback_nohtml($words) {
+ $p_url_text = $words[2];
+ $p_link = config_get('wiki_link_url').$p_url_text;
+ return "$p_url_text ($p_link)";
+ }
+
+ # ---------------------
+ # Process 'changeset' links to ViewCVS pages
+ function string_process_changeset_link($string, $fullHTML = true) {
+ if(!config_get('changeset_link_url'))return $string;
+ $re = '/\b(version|revision|rev|changeset)\s+([0-9]+(\.[0-9]+)*)\b/';
+ if($fullHTML)return preg_replace_callback($re,'string_process_changeset_link_callback_fullhtml', $string);
+ return preg_replace_callback($re,'string_process_changeset_link_callback_nohtml', $string);
+ }
+
+ function string_process_changeset_link_callback_fullhtml($words) {
+ $p_link_text = $words[0];
+ $p_changeset = $words[2];
+ $p_url = config_get('changeset_link_url').$p_changeset;
+ return '<span class="viewcvs-link">'. "<a href=\"$p_url\">$p_link_text</a>". " [<a title=\"open in a new window\" href=\"$p_url\" target=_blank>^</a>]".'</span> ';
+ }
+
+ function string_process_changeset_link_callback_nohtml($words) {
+ $p_link_text = $words[0];
+ $p_changeset = $words[2];
+ $p_url = config_get('changeset_link_url').$p_url_text;
+ return "$p_link_text ($p_url)";
+ }
+
# --------------------
# Process $p_string, looking for bug ID references and creating bug view
# links for them. |
|
gravyface@gmail.com 25-Sep-2006 15:44 |
#1265
|
I was a little confused with how to create custom functions that DO NOT override existing functions. All custom functions must have "custom_function_override_" preceed the function name, regardless of whether it overrides an existing function or not.
To create a simple hello world function that prints out to the Bug Report page, do the following:
In a newly-created file in the doc root called custom_functions_inc.php:
<?php
// my hello_world function
function custom_function_override_hello_world() {
return "Hello World!";
}
?>
in bug_report_page.php:
echo helper_call_custom_function('hello_world'); |
|
|
| Last updated: Fri, 16 May 2008 - 13:16:31 |
|
|