1<?php
2/*
3 * DokuWiki skype plugin
4 * 2014 Zahno Silvan
5 * Usage:
6 *
7 * {{skype>username,function}}
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the LGNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * LGNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the LGNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 */
23
24
25if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
26if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
27require_once(DOKU_PLUGIN.'syntax.php');
28
29/**
30 * All DokuWiki plugins to extend the parser/rendering mechanism
31 * need to inherit from this class
32 */
33class syntax_plugin_skype extends DokuWiki_Syntax_Plugin {
34
35    /**
36     * return some info
37     */
38    function getInfo(){
39        return array(
40            'author' => 'Zahno Silvan',
41            'email'  => 'zaswiki@gmail.com',
42            'date'   => '2014-06-16',
43            'name'   => 'Skype Plugin',
44            'desc'   => 'Skype Button',
45            'url'    => 'http://zawiki.zapto.org/doku.php/tschinz:dw_skype',
46        );
47    }
48
49    /**
50     * What kind of syntax are we?
51     */
52    function getType(){
53        return 'substition';
54    }
55
56    /**
57     * Where to sort in?
58     */
59    function getSort(){
60        return 299;
61    }
62
63
64    /**
65     * Connect pattern to lexer
66     */
67    function connectTo($mode) {
68        $this->Lexer->addSpecialPattern('\{\{skype>.*?\}\}',$mode,'plugin_skype');
69    }
70
71    /**
72     * Handle the match
73     */
74    function handle($match, $state, $pos, DOKU_Handler $handler){
75        switch ($state) {
76          case DOKU_LEXER_ENTER :
77            break;
78          case DOKU_LEXER_MATCHED :
79            break;
80          case DOKU_LEXER_UNMATCHED :
81            break;
82          case DOKU_LEXER_EXIT :
83            break;
84          case DOKU_LEXER_SPECIAL :
85            return $match;
86            break;
87        }
88        return array();
89    }
90
91    /**
92     * Create output
93     */
94    function render($mode, DOKU_Renderer $renderer, $data) {
95        if($mode == 'xhtml'){
96            $options['function']  = $this->getConf('function'); // default value
97            $options['size']      = $this->getConf('size');
98            $options['style']     = $this->getConf('style');
99
100           // strip {{skype> from start
101           $data     = substr($data,8);
102           // strip }} from end
103           $data     = substr($data,0,-2);
104
105           //get function and username
106           $var1='';
107           $var2='';
108           list($var1, $var2) = explode(',', $data, 2);
109
110           if ($var1 == 'chat' or $var1 == 'call' or $var1 == 'dropdown')
111           {
112               $options['function'] = $var1;
113               $data = $var2;
114           }
115           elseif ($var2 == 'chat' or $var2 == 'call' or $var2 == 'dropdown')
116           {
117               $options['function'] = $var2;
118               $data = $var1;
119           }
120           else
121           {
122               $data = $var1;
123           }
124
125           if (empty($data))
126           {
127               $renderer->doc .= 'No skype name given';
128               return true;
129           }
130
131           $code = '<script type="text/javascript" src="https://www.skypeassets.com/i/scom/js/skype-uri.js"></script>';
132           $code .= '<div style="display: inline" id="SkypeButton_Call_'.$data.'_1">';
133           $code .= '<script type="text/javascript">Skype.ui({';
134
135           $code .= '"name": "'.$options['function'].'",';
136
137           $code .= '"element": "SkypeButton_Call_'.$data.'_1",';
138           $code .= '"participants": ["'.$data.'"],';
139           if ($options['style'] == 'white') {
140               $code .= '"imageColor": "white",';
141           }
142           $code .= '"imageSize": '.$options['size'];
143           $code .= '});</script></div>';
144
145           $renderer->doc .= $code;
146
147           return true;
148        }
149    return false;
150    }
151}
152