1<?php
2/**
3 * DokuWiki Plugin facebook (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr <andi@splitbrain.org>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15
16require_once(DOKU_PLUGIN.'syntax.php');
17
18class syntax_plugin_facebook extends DokuWiki_Syntax_Plugin {
19
20    function getInfo() {
21        return confToHash(dirname(__FILE__).'/plugin.info.txt');
22    }
23
24    function getType() {
25        return 'substition';
26    }
27
28    function getPType() {
29        return 'block';
30    }
31
32    function getSort() {
33        return 155;
34    }
35
36
37    function connectTo($mode) {
38        $this->Lexer->addSpecialPattern('{{fbfanbox>[0-9]+.*?}}',$mode,'plugin_facebook');
39    }
40
41    function handle($match, $state, $pos, Doku_Handler $handler){
42
43        $data = array(
44            'type'    => 'fanbox',
45            'profile' => '52877633616',
46            'width'   => 300,
47            'height'  => 250,
48            'status'  => false,
49            'logo'    => true,
50            'fans'    => 10,
51            'align'   => 'right',
52        );
53
54        $params = explode(' ',substr(strtolower($match),4,-2));
55        list($type,$profile) = explode('>',array_shift($params));
56        $data['type']    = $type;
57        $data['profile'] = $profile;
58
59        foreach($params as $param){
60            $param = trim($param);
61            if($param === '') continue;
62
63            if($param == 'status'){
64                $data['status'] = true;
65            }elseif($param == 'nologo'){
66                $data['logo'] = false;
67            }elseif($param == 'right'){
68                $data['align'] = 'right';
69            }elseif($param == 'left'){
70                $data['align'] = 'left';
71            }elseif($param == 'center'){
72                $data['align'] = 'center';
73            }elseif(preg_match('/^\d+f$/',$param)){
74                $data['fans'] = substr($param,0,-1);
75            }elseif(preg_match('/^(\d+)x(\d+)$/',$param,$match)){
76                $data['width']  = $match[1];
77                $data['height'] = $match[2];
78            }
79        }
80
81
82
83        return $data;
84    }
85
86    function render($mode, Doku_Renderer $R, $data) {
87        if($mode != 'xhtml') return false;
88
89        if($data['align'] == 'center'){
90            $R->doc .= '<div style="width:'.$data['width'].'px; padding: 0; margin: 0.5em auto">';
91        }else{
92            $R->doc .= '<div style="width:'.$data['width'].'px; padding: 0; margin: 0.5em; float: '.$data['align'].'">';
93        }
94        $R->doc .= '<fb:fan profile_id="'.$data['profile'].'"
95                            stream="'.(($data['status'])?1:0).'"
96                            connections="'.$data['fans'].'"
97                            logobar="'.(($data['logo'])?1:0).'"
98                            width="'.$data['width'].'"
99                            height="'.$data['height'].'"></fb:fan>';
100        $R->doc .= '</div>';
101
102
103        return true;
104    }
105}
106
107// vim:ts=4:sw=4:et:enc=utf-8:
108