Extension:SignavioEmbed/code

From MediaWiki.org
Jump to navigation Jump to search

Here's the code for the current version of the Signavio Embed extension.

<?php
if (!defined('MEDIAWIKI')) die();

$sigemLinkSubDiagrams = false;

$wgExtensionCredits['parserhook'][] = array(
	'name' => 'Signavio Embed',
	'version' => '0.2',
	'author' => 'Hauke Pribnow', 
	'url' => 'http://www.mediawiki.org/wiki/Extension:SignavioEmbed', 
	'description' => 'Adds the "signavio" tag to embed Signavio Processes.'
);
 
$wgHooks['ParserFirstCallInit'][] = 'sigemParserInit';
 
function sigemParserInit( &$parser ) {
        $parser->setHook( 'signavio', 'sigemRender' );
        return true;
}
 
function sigemRender( $input, $args, $parser, $frame=null ) {
	global $sigemLinkSubDiagrams;
	
	$input=trim($input); // trim the input
	$matches=array(); // prepare the regex match array
	if(preg_match("/^([a-z0-9]+):([a-z0-9_]+)$/",$input,$matches)) { //match <signavio>modelcode:authtoken</signavio>
		return '<script type="text/javascript" src="https://editor.signavio.com/mashup/signavio.js"></script><script type="text/plain">
			{
			    url: "https://editor.signavio.com/p/model/'.$matches[1].'",
			    authToken: "'.$matches[2].'",
			    overflowX: "fit",
			    overflowY: "fit",
			    zoomSlider: true,
			    linkDiagrams: '.($sigemLinkSubDiagrams?'true':'false').'
			}
			</script>';
	} else {
		return '<b><strong class="error">'.
			htmlspecialchars("Wrong Signavio code. ".
			"Please consult the manual for information about the right code.").
			'</strong></b>';
	}
}