1<?php
2/**
3 * DokuWiki Plugin facebook (Action 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.'action.php');
17
18class action_plugin_facebook extends DokuWiki_Action_Plugin {
19
20    function getInfo() {
21        return confToHash(dirname(__FILE__).'/plugin.info.txt');
22    }
23
24    function register(Doku_Event_Handler $controller) {
25
26       $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_tpl_metaheader_output');
27
28    }
29
30    function handle_tpl_metaheader_output(&$event, $param) {
31        global $conf;
32
33        // match our language against available FaceBook languages
34        $fblocales =  ' af_ZA sq_AL ar_AR az_AZ eu_ES bn_IN bs_BA bg_BG ca_ES'.
35                      ' zh_CN zh_HK zh_TW hr_HR cs_CZ kw_GB da_DK nl_NL en_US'.
36                      ' en_GB en_PI eo_EO et_EE fo_FO tl_PH fi_FI fr_FR fr_CA'.
37                      ' gl_ES ka_GE de_DE el_GR he_IL hi_IN hu_HU is_IS id_ID'.
38                      ' ga_IE it_IT ja_JP ko_KR la_VA lv_LV lt_LT mk_MK ms_MY'.
39                      ' ml_IN ne_NP nb_NO nn_NO fa_IR pl_PL pt_PT pt_BR pa_IN'.
40                      ' ro_RO ru_RU sr_RS sk_SK sl_SI es_LA es_ES sw_KE sv_SE'.
41                      ' ta_IN te_IN th_TH tr_TR uk_UA vi_VN cy_GB ';
42
43        $lc = $conf['lang'];
44        $lc = str_replace('-','_',$lc);
45        $lc = str_replace('_pirate','_PI',$lc);
46
47        if(preg_match('/ ('.$lc.') /i',$fblocales,$match)){
48            $loc = $match[1];
49        }elseif(preg_match('/ ('.$lc.'_..) /i',$fblocales,$match)){
50            $loc = $match[1];
51        }else{
52            $loc = 'en_US';
53        }
54
55
56        $event->data['script'][] = array(
57              'type'  => 'text/javascript',
58              'src'   => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/'.$loc,
59              '_data' => '',
60        );
61        $event->data['script'][] = array(
62              'type'  => 'text/javascript',
63              '_data' => 'FB.init("9ec02de6127d88bbcc6103da6a44a6b0");',
64        );
65
66    }
67
68}
69
70// vim:ts=4:sw=4:et:enc=utf-8:
71