User Tools

  • Logged in as: anonymous (anonymous)
  • Log Out

Site Tools


mantisbt:plugins_sample

This is an old revision of the document!


Sample Plugins

Super Cow Powers

This is a very minimal plugin that does nothing but increase your site's Geek Factor.

Directory Structure

mantis/
  plugins/
    supercow/
      register.php
      events.php

plugins/supercow/register.php

<?php
 
/**
 * Return plugin details to the API.
 * @return array Plugin details
 */
function plugin_callback_supercow_info() {
  return array(
    'name' => 'Super Cow Powers',
    'description' => 'Gives your Mantis installation super cow powers.',
    'version' => '1.0',
    'author' => 'John Reese',
    'contact' => 'jreese@leetcode.net',
    'url' => 'http://leetcode.net',
    'page' => '',
    'requires' => array(),
  );
}
 
/**
 * Intitialize the plugin.
 */
function plugin_callback_supercow_init() {
  plugin_event_hook( 'EVENT_PLUGIN_INIT', 'header' );
}

plugins/supercow/events.php

<?php
 
/**
 * Handle the EVENT_PLUGIN_INIT callback.
 */
function plugin_event_supercow_header() {
  header( 'X-Mantis: This Mantis has super cow powers.' );
}

This is a plugin that detects svn:123 and hyperlinks it to the ViewVC web page that contains all the details of the changeset.

plugins/svnlinks/register.php

<?php
 
/**
 * Return plugin details to the API.
 * @return array Plugin details
 */
function plugin_callback_svnlinks_info() {
  return array(
    'name' => 'SVN Links',
    'description' => 'Detects references to SVN changesets and hyperlinks them.',
    'version' => '1.0',
    'author' => 'Victor Boctor',
    'contact' => 'vboctor -at- users.sourceforge.net',
    'url' => 'http://www.mantisbt.org',
  );
}
 
/**
 * Intitialize the plugin.
 */
function plugin_callback_svnlinks_init() {
	plugin_event_hook( 'EVENT_TEXT_LINKS', 'string_display_links' );
}

plugins/svnlinks/events.php

<?php
 
# Configuration:
# $g_plugin_svnlinks_svn_changeset_link = 'http://mantisbt.svn.sourceforge.net/viewvc/mantisbt?view=rev&revision=%s';

/**
 * Handle the EVENT_PLUGIN_INIT callback.
 */
function plugin_event_svnlinks_string_display_links( $p_event, $p_string ) {
	$t_svn_changeset_link_format = config_get( 'plugin_svnlinks_svn_changeset_link', '' );
	if ( is_blank( $t_svn_changeset_link_format ) ) {
		return $p_string;
	}
 
	$t_svn_changeset_link = sprintf( $t_svn_changeset_link_format, '\\1' );
 
	$t_replace_with = '<a href="'. $t_svn_changeset_link . '" target="_new">svn:\\1</a>';
 
	return preg_replace( '/svn\:([[:digit:]]+)/i',
						 $t_replace_with,
						 $p_string );
}
mantisbt/plugins_sample.1194211760.txt.gz · Last modified: 2008/10/29 04:31 (external edit)

Driven by DokuWiki