*/
// must be run within Dokuwiki
if ( !defined( 'DOKU_INC' ) ) die();
if ( !defined( 'DOKU_PLUGIN' ) ) define( 'DOKU_PLUGIN', DOKU_INC.'lib/plugins/' );
require_once DOKU_PLUGIN.'syntax.php';
class syntax_plugin_clippy extends DokuWiki_Syntax_Plugin {
/**
*
*
* @return string Syntax mode type
*/
public function gettype() {
return 'substition';
}
/**
*
*
* @return string Paragraph type
*/
public function getPType() {
return 'block';
}
/**
*
*
* @return int Sort order - Low numbers go before high numbers
*/
public function getSort() {
return 999;
}
/**
* Connect lookup pattern to lexer.
*
* @param string $mode Parser mode
*/
public function connectTo( $mode ) {
$this->Lexer->addSpecialPattern( '.*?', $mode, 'plugin_clippy' );
// $this->Lexer->addSpecialPattern( '[clippy.*?]', $mode, 'plugin_clippy' );
}
// public function postConnect() {
// $this->Lexer->addExitPattern( '', 'plugin_clippy' );
// }
/**
* Handle matches of the clippy syntax
*
* @param string $match The match of the syntax
* @param int $state The state of the handler
* @param int $pos The position in the document
* @param Doku_Handler $handler The handler
* @return array Data for the renderer
*/
public function handle( $match, $state, $pos, Doku_Handler $handler ) {
//
if ( preg_match( '/\(.*)\<\/clippy\>/is', $match, $result ) === 1 ) {
$text = $result[1];
}
elseif ( preg_match( '/\[clippy\s(.*)\]/is', $match, $result ) === 1 ) {
$text = $result[1];
}
else {
return $data;
}
$data = array(
'width' => 110,
'height' => 14,
'allowScriptAccess' => 'always',
'quality' => 'high',
'scale' => 'noscale',
'bgcolor' => '#FFFFFF',
'text' => $text,
);
return $data;
}
/**
* Render xhtml output or metadata
*
* @param string $mode Renderer mode (supported modes: xhtml)
* @param Doku_Renderer $renderer The renderer
* @param array $data The data from the handler() function
* @return bool If rendering was successful.
*/
public function render( $mode, Doku_Renderer $renderer, $data ) {
if ( $mode != 'xhtml' ) return false;
$movie = "lib/clippy.swf";
$flashvars = array( "text" => $data['text'] );
unset( $data['text'] );
$renderer->doc .= html_flashobject( DOKU_BASE.'lib/plugins/clippy/'.$movie, $data['width'], $data['height'], $data, $flashvars );
return true;
}
}
// vim:ts=4:sw=4:et: