1<?php
2/**
3 * DokuWiki Plugin slidesharewp (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Hanson  Kim <sng2nara@gmail.com>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12class syntax_plugin_slidesharewp_slidesharewp extends DokuWiki_Syntax_Plugin {
13    /**
14     * @return string Syntax mode type
15     */
16    public function getType() {
17        return 'substition';
18    }
19    /**
20     * @return string Paragraph type
21     */
22    public function getPType() {
23        return 'block';
24    }
25    /**
26     * @return int Sort order - Low numbers go before high numbers
27     */
28    public function getSort() {
29        return 159;
30    }
31
32    /**
33     * Connect lookup pattern to lexer.
34     *
35     * @param string $mode Parser mode
36     */
37    public function connectTo($mode) {
38        $this->Lexer->addSpecialPattern('\[slideshare id=.+?&doc=.+?\]',$mode,'plugin_slidesharewp_slidesharewp');
39    }
40
41//    public function postConnect() {
42//        $this->Lexer->addExitPattern('</FIXME>','plugin_slidesharewp_slidesharewp');
43//    }
44
45    /**
46     * Handle matches of the slidesharewp syntax
47     *
48     * @param string $match The match of the syntax
49     * @param int    $state The state of the handler
50     * @param int    $pos The position in the document
51     * @param Doku_Handler    $handler The handler
52     * @return array Data for the renderer
53     */
54    public function handle($match, $state, $pos, Doku_Handler &$handler){
55        $pm = preg_match_all('/\[slideshare id=(.+?)&doc=(.+?)\]/', $match, $result);
56        $id = $result[1][0];
57        $doc = $result[2][0];
58        return array($id, $doc);
59    }
60
61    /**
62     * Render xhtml output or metadata
63     *
64     * @param string         $mode      Renderer mode (supported modes: xhtml)
65     * @param Doku_Renderer  $renderer  The renderer
66     * @param array          $data      The data from the handler() function
67     * @return bool If rendering was successful.
68     */
69    public function render($mode, Doku_Renderer &$renderer, $data) {
70        if($mode != 'xhtml') return false;
71        list($id, $doc) = $data;
72        $id = urlencode($id);
73        $renderer->doc .= "<iframe src=\"http://www.slideshare.net/slideshow/embed_code/$id\"
74        width=\"425\" height=\"355\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"
75        style=\"border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%%;\" allowfullscreen></iframe>";
76        $renderer->doc .= NL;
77        return true;
78    }
79}
80
81// vim:ts=4:sw=4:et:
82