1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Roland Wunderling <bzfwunde@gmail.com>
5 */
6
7if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
8if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
9require_once(DOKU_PLUGIN.'syntax.php');
10
11class syntax_plugin_freechat extends DokuWiki_Syntax_Plugin {
12
13    function getInfo(){
14        return array(
15            'author' => 'Luigi micco',
16            'email'  => 'l.micco@tiscali.it',
17            'date'   => '2011-01-19',
18            'name'   => 'Freechat Plugin (syntax component)',
19            'desc'   => 'Allow to insert and use phpFreeChat on DokuWiki',
20            'url'    => 'http://www.bitlibero.com/dokuwiki/freechat-19.01.2011.zip',
21        );
22    }
23
24    function getType(){ return 'protected'; }
25    function getAllowedTypes() { return array('substition','protected','disabled','formatting'); }
26    function getSort(){ return 315; }
27    function getPType(){ return 'block'; }
28
29    function connectTo($mode) {
30        $this->Lexer->addSpecialPattern('~~CHAT~~', $mode, 'plugin_freechat');
31        $this->Lexer->addSpecialPattern('\{\{chat>[^}]*\}\}', $mode, 'plugin_freechat');
32    }
33
34    /* parse paramters (if used as {{chat>[chatid=...|rooms=...[,...]]}}) */
35    function handle($match, $state, $pos, Doku_Handler $handler) {
36        if ( $match == '~~CHAT~~' )
37            return array();
38
39        $match = substr($match, 7, -2); // strip markup
40        $params = explode('|',$match);
41        // provide easy access to parameters param=value
42        $data = array();
43        foreach ($params as $p) {
44            $splitparam = explode('=',$p);
45            if ( isset($splitparam[1]) )
46                $data[$splitparam[0]] = $splitparam[1];
47            else
48                $data[$splitparam[0]] = '';
49        }
50        return $data;
51    }
52
53    function render($mode, Doku_Renderer $renderer, $data){
54        global $conf, $USERINFO, $ID;
55
56        if(auth_quickaclcheck($ID) >= AUTH_READ) {
57            if($mode == 'xhtml'){
58
59                $renderer->info['cache'] = FALSE;
60                ob_start();
61
62                require_once DOKU_INC.'lib/plugins/freechat/phpfreechat/src/phpfreechat.class.php';
63
64                $params = array();
65
66                $params['serverid'] = md5($conf['title']);
67                if ( isset ($data['chatid'])  && $data['chatid'] != '' )
68                    $params['serverid'] = md5($data['chatid']);
69
70                $params['focus_on_connect'] = true;
71
72                $params['language'] = $this->getConf('language');
73                $params['theme'] = $this->getConf('template');
74                $params['height'] = $this->getConf('height').'px';
75                $params["title"] = $this->getConf('title');
76                if ( isset ($data['rooms']) )
77                    $params["channels"] = explode(',', $data['rooms']);
78                else
79                    $params["channels"] = explode(',', $this->getConf('channels'));
80                $params['frozen_nick'] = $this->getConf('frozen_nick');
81                $params['frozen_nick'] = !($params['frozen_nick'] == 'off'  ||  $params['frozen_nick'] == 0);
82                if ( isset ($data['locked']) )
83                    $params['frozen_channels'] = explode(',', $data['locked']);
84                else if ($this->getConf('frozen_channels') != '')
85                    $params['frozen_channels'] = explode(',', $this->getConf('frozen_channels'));
86
87                $params['isadmin']  = false;
88                if (($this->getConf('admin_group') != '') && isset($USERINFO['grps'])) {
89                    $temp = explode(',', $this->getConf('admin_group'));
90                    foreach($temp as $item) {
91                        if (in_array(trim($item),$USERINFO['grps'])) {
92                            $params['isadmin']  = true ;
93                        }
94                    }
95                }
96
97                $params['startwithsound'] = false;
98                $params['display_pfc_logo'] = true;
99                $params['showsmileys'] = false;
100
101                $params['nick'] = (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : "guest".rand(1,1000));
102                if ($this->getConf('fullname')) {
103                    if (isset($USERINFO['name']) && !empty($USERINFO['name'])) {
104                        $params['nick'] = $USERINFO['name'];
105                    }
106                }
107
108                //          $params['channels'] =  array('Generale');
109
110                $params['data_public_path']   = DOKU_INC.'data/cache/public';
111                $params['data_public_url']    = DOKU_URL.'data/cache/public';
112
113                $params['data_public_path']   = DOKU_INC.'lib/plugins/freechat/phpfreechat/data/public';
114                $params['data_public_url']    = DOKU_URL.'lib/plugins/freechat/phpfreechat/data/public';
115
116                //        $params['data_public_path']   = DOKU_INC.'data/tmp';
117                //        $params['data_public_url']    = DOKU_URL.'data/tmp';
118
119                $params['data_private_path']   = DOKU_INC.'data/cache/freechat/private';
120
121                $params['server_script_path'] = DOKU_INC.'lib/plugins/freechat/backend.php';
122                $params['server_script_url']  = DOKU_URL.'lib/plugins/freechat/backend.php';
123
124                //        $params['debug']  = true;
125
126                // store in session the parameters list for the backend script
127                @session_start();
128                $_SESSION['freechat_params_list'] = $params;
129
130                $pfc = new phpFreeChat($params);
131                $pfc->printChat();
132
133                $content = ob_get_contents();
134                ob_end_clean();
135                $renderer->doc .= $content;
136/*
137echo "<pre>";
138print_r($params);
139echo "</pre>";
140 */
141
142                return true;
143            }
144        }
145        return false;
146    }
147}
148
149//Setup VIM: ex: et ts=4 enc=utf-8 :
150