1 <?php
2 /**
3  * Plugin Facebook comments on Dokuwiki
4  *
5  * Syntax: <TEST> - will be replaced with "Hello World!"
6  *
7  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8  * @author     Christopher Smith <chris@jalakai.co.uk>
9  */
10 
11 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
12 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13 require_once(DOKU_PLUGIN.'syntax.php');
14 require_once(DOKU_INC.'inc/auth.php');
15 
16 class syntax_plugin_fbcomments extends DokuWiki_Syntax_Plugin {
17 
18    /**
19     * Plugin Info
20     */
21     function getInfo(){
22         return array(
23                       'author' => 'Greatdays',
24                       'email'  => 'greatedays@gmail.com',
25                       'date'   => '2011-04-03',
26                       'name'   => 'Facebook comments box',
27                       'desc'   => 'Add Facebook comments box',
28                       'url'    => 'http://juice.linuxstudy.pe.kr/wiki/facebook_comments_for_dokuwiki',
29                     );
30     }
31 
32   /*
33    * Get the type of syntax this plugin defines.
34    */
35    function getType(){
36       return 'container';
37    }
38 
39    function getPType(){
40       return 'block';
41    }
42 
43    function getSort(){
44       return FXIME;
45    }
46 
47    function connectTo($mode) {
48 //      $this->Lexer->addSpecialPattern('\{\{fbc[^}]*\}\}',$mode,'plugin_fbcomments');
49       $this->Lexer->addSpecialPattern('\{\{fbc>[^}]*\}\}',$mode,'plugin_fbcomments');
50    }
51 
52    function handle($match, $state, $pos, &$handler){
53       if (isset($_REQUEST['comment'])) return false;
54 
55       $match= substr($match, 6, -2);
56       $data = array();
57 
58       $params = explode('|',$match);
59       foreach($params as $param){
60 
61         $splitparam = explode('=',$param);
62         if($splitparam[0] == num)
63           $splitparam[0]= 'num_posts';
64 
65         $splitparam[0] = FB_. $splitparam[0];
66         $data[$splitparam[0]] = $splitparam[1];
67       }
68 
69         return $data;
70    }
71 
72    function render($mode, &$renderer, $data){
73      if($mode == 'xhtml'){
74        $renderer->doc .= $this->_commentsBox($data);
75 
76        return true;
77      }
78        return false;
79    }
80 
81    protected function _commentsBox($data){
82      global $ID;
83      global $conf;
84      $this ->data= $data;
85 
86      if($data['FB_like'] == 'y' or $data['FB_like'] == 'Y'){
87         $fblike =  '<!-- Fcaebook Like Button -->'
88                   .'<fb:like href="'. wl($ID, '', true) .'"'
89                   .'show_faces="true" width="'. $this->_fbsetting('FB_width', $conf) .'" action="like" font="">'
90                   .'</fb:like>'
91                   .'<!-- Facebook Like Button end -->';
92      }
93         else $fblike = '<!-- Fcaebook Like Button --> '
94                       .'<!-- Facebook Like Button end -->';
95 
96      if(!empty($conf['plugin']['fbcomments']['FB_AppID'])){
97 
98           $box=  '<!-- Facebook Script -->'
99                 .'<div id="fb-root"> </div>'
100                 .'<script src="http://connect.facebook.net/'. $this->getLang('fb_langs')
101                 .'/all.js#appId='. $this->getConf('FB_AppID') .'&amp;xfbml=1">'
102                 .'</script>'
103                 . $fblike
104                 .'<!-- Facbebook Comments Box start -->'
105                 .'<fb:comments href="'. wl($ID, '', true)
106                 .'" num_posts="'. $this->_fbsetting('FB_num_posts', $conf)
107                 .'" width="'. $this->_fbsetting('FB_width', $conf)
108                 .'"></fb:comments>'
109                 .'<!-- Facebook Comments Box end -->';
110       }
111         else $box= 'Empty Facebook App ID';
112 
113     return $box;
114    }
115 
116    protected function _fbsetting($name, $fbconf) {
117       include dirname(__FILE__).'/conf/default.php';
118 
119       if(empty($this->data[$name])){
120         if(!empty($fbconf['plugin']['fbcomments'][$name]))
121           return $fbconf['plugin']['fbcomments'][$name];
122             else return $conf[$name];
123       }
124         return hsc($this->data[$name]);
125    }
126 
127 }
128 ?>