summaryrefslogtreecommitdiff
blob: 1270698f42ad083a6c216c6539045223ef1c2a52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

class ExtPipeEsc {
	private static $parserFunctions = array('!' => 'pipeChar');

	public static function setup( &$parser ) {
		// register each hook
		foreach( self::$parserFunctions as $hook => $function )
			$parser->setFunctionHook( $hook,
				array( __CLASS__, $function ), Parser::SFH_OBJECT_ARGS );
		return true;
	}

	public static function pipeChar( &$parser, $frame, $args ) {
		$output = array_shift( $args );
		// no parameters means we're done.  spit out an empty string
		if ( !isset( $output ) )
			return '';
		// expand the first argument
		$output = $frame->expand( $output );
		// get the rest of the arguments, expand each one, prefix each expansion
		// with a pipe character, and append it to the output string.
		for ( $arg = array_shift( $args );
			isset( $arg );
			$arg = array_shift( $args ) )
		{
			$output .= '|' . $frame->expand( $arg );
		}
		//return '<pre><nowiki>'. trim( $output ) . '</nowiki></pre>';
		return trim( $output );
	}
}