1<?php
2/**
3 * DokuWiki Plugin Doku Clippy (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Derek Chafin <infomaniac50@gmail.com>
7 */
8
9// must be run within Dokuwiki
10if ( !defined( 'DOKU_INC' ) ) die();
11
12if ( !defined( 'DOKU_PLUGIN' ) ) define( 'DOKU_PLUGIN', DOKU_INC.'lib/plugins/' );
13require_once DOKU_PLUGIN.'syntax.php';
14
15class syntax_plugin_clippy extends DokuWiki_Syntax_Plugin {
16  /**
17   *
18   *
19   * @return string Syntax mode type
20   */
21  public function gettype() {
22    return 'substition';
23  }
24  /**
25   *
26   *
27   * @return string Paragraph type
28   */
29  public function getPType() {
30    return 'block';
31  }
32  /**
33   *
34   *
35   * @return int Sort order - Low numbers go before high numbers
36   */
37  public function getSort() {
38    return 999;
39  }
40
41  /**
42   * Connect lookup pattern to lexer.
43   *
44   * @param string  $mode Parser mode
45   */
46  public function connectTo( $mode ) {
47    $this->Lexer->addSpecialPattern( '<clippy>.*?</clippy>', $mode, 'plugin_clippy' );
48    // $this->Lexer->addSpecialPattern( '[clippy.*?]', $mode, 'plugin_clippy' );
49  }
50
51  // public function postConnect() {
52  //   $this->Lexer->addExitPattern( '</clippy>', 'plugin_clippy' );
53  // }
54
55  /**
56   * Handle matches of the clippy syntax
57   *
58   * @param string  $match   The match of the syntax
59   * @param int     $state   The state of the handler
60   * @param int     $pos     The position in the document
61   * @param Doku_Handler $handler The handler
62   * @return array Data for the renderer
63   */
64  public function handle( $match, $state, $pos, Doku_Handler $handler ) {
65    // <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="110" height="14" class="clippy" >
66    //   <param name="movie" value="lib/clippy.swf"/>
67    //   <param name="allowScriptAccess" value="always" />
68    //   <param name="quality" value="high" />
69    //   <param name="scale" value="noscale" />
70    //   <param NAME="FlashVars" value="text={$text}">
71    //   <param name="bgcolor" value="#FFFFFF">
72    //   <embed src="lib/clippy.swf"
73    //     width="110"
74    //     height="14"
75    //     name="clippy"
76    //     quality="high"
77    //     allowScriptAccess="always"
78    //     type="application/x-shockwave-flash"
79    //     pluginspage="http://www.macromedia.com/go/getflashplayer"
80    //     FlashVars="text={$text}"
81    //     bgcolor="#FFFFFF"
82    //   />
83    // </object>
84    if ( preg_match( '/\<clippy\>(.*)\<\/clippy\>/is', $match, $result ) === 1 ) {
85      $text = $result[1];
86    }
87    elseif ( preg_match( '/\[clippy\s(.*)\]/is', $match, $result ) === 1 ) {
88      $text = $result[1];
89    }
90    else {
91      return $data;
92    }
93
94    $data = array(
95      'width'  => 110,
96      'height' => 14,
97      'allowScriptAccess' => 'always',
98      'quality' => 'high',
99      'scale' => 'noscale',
100      'bgcolor' => '#FFFFFF',
101      'text' => $text,
102    );
103
104    return $data;
105  }
106
107  /**
108   * Render xhtml output or metadata
109   *
110   * @param string  $mode     Renderer mode (supported modes: xhtml)
111   * @param Doku_Renderer $renderer The renderer
112   * @param array   $data     The data from the handler() function
113   * @return bool If rendering was successful.
114   */
115  public function render( $mode, Doku_Renderer $renderer, $data ) {
116    if ( $mode != 'xhtml' ) return false;
117    $movie = "lib/clippy.swf";
118    $flashvars = array( "text" => $data['text'] );
119
120    unset( $data['text'] );
121    $renderer->doc .= html_flashobject( DOKU_BASE.'lib/plugins/clippy/'.$movie, $data['width'], $data['height'], $data, $flashvars );
122    return true;
123  }
124}
125
126// vim:ts=4:sw=4:et:
127