1<?php
2/**
3 *  Applet Plugin
4 *
5 *  @license    GPL 2 ( http://www.gnu.org/licenses/gpl.html )
6 *  @author     Stylianos [at] Dritsas [dot] net
7 *
8 *  Description:
9 *  A very basic Java applet handling plugin.
10 *
11 *  Acknowledgments:
12 *  The draw applet author(s) for a very readable plugin
13 */
14
15if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
16if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
17require_once(DOKU_PLUGIN.'syntax.php');
18
19/**
20 *  Applet Plugin
21 */
22class syntax_plugin_applet extends DokuWiki_Syntax_Plugin {
23
24  /**
25   *  Plugin Info
26   */
27  function getInfo( ) {
28    return array(
29      'author' => 'Stylianos Dritsas',
30      'email'  => 'stylianos [at] dritsas [dot] net',
31      'date'   => '2006-03-05',
32      'name'   => 'applet',
33      'desc'   => 'Java Applet Plugin',
34      'url'    => 'https://www.dokuwiki.org/plugin:applet',
35    );
36  }
37
38  /**
39   *  Typology?
40   */
41  function getType( ) {
42		return 'substition';
43	}
44
45  /**
46   *  Sort Code?
47   */
48  function getSort( ) {
49    return 316;
50  }
51
52  /**
53   *  Pattern Matching?
54   */
55  function connectTo($mode) {
56    $this->Lexer->addSpecialPattern( '<applet.*?>', $mode, 'plugin_applet' );
57  }
58
59  /**
60   *  Parsing
61   *  1. Very rough parsing involved
62   *  2. Applet parameters not included
63   */
64  function handle( $match, $state, $pos, &$handler ) {
65    preg_match( '/width=([0-9]+)/i',            substr( $match, 6, -1 ), $match_width   );
66    preg_match( '/height=([0-9]+)/i',           substr( $match, 6, -1 ), $match_height  );
67    preg_match( '/code=([a-zA-Z_0-9.]+)/i',     substr( $match, 6, -1 ), $match_code    );
68    preg_match( '/archive=([a-zA-Z_0-9:.]+)/i', substr( $match, 6, -1 ), $match_archive );
69    return array(
70      $match_code[1],
71      $match_width[1],
72      $match_height[1],
73      $match_archive[1]
74    );
75  }
76
77  /**
78   *  Rendering
79   *  1. There is no error checking involved whatsoever
80   *  2. Assuming that all applets come in a jar or zip archive
81   *  3. The namespace to path conversion is highly ad-hoc-ish
82   */
83  function render( $mode, &$renderer, $data ) {
84    if($mode == 'xhtml'){
85      list( $code, $width, $height, $archive ) = $data;
86      //$archive = 'data/media/' . str_replace( ":", "/", $archive );
87      $archive = DOKU_BASE . 'lib/exe/fetch.php?media=' . $archive;
88      $renderer->doc .= "<applet code=\"$code\" " .
89                               "width=\"$width\" " .
90                              "height=\"$height\" " .
91                             "archive=\"$archive\"></applet>";
92      return true;
93    } else {
94      return false;
95    }
96  }
97}