1<?php
2/**
3 * DokuWiki Plugin socialshareprivacy (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Frank Schiebel <frank@linuxmuster.net>
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_socialshareprivacy extends DokuWiki_Action_Plugin {
19
20    public function register(Doku_Event_Handler $controller) {
21
22       $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_tpl_metaheader_output');
23    }
24
25    public function handle_tpl_metaheader_output(Doku_Event $event, $param) {
26        global $conf;
27
28        $options = array(
29                "global_info_link",
30                "global_txt_help",
31                "global_settings_perma",
32                "global_cookie_expires",
33                "facebook_status",
34                "facebook_txt_info",
35                "facebook_perma_option",
36                "facebook_display_name",
37                "facebook_language",
38                "facebook_action",
39                "twitter_status",
40                "twitter_txt_info",
41                "twitter_perma_option",
42                "twitter_display_name",
43                "twitter_language",
44                "gplus_status",
45                "gplus_txt_info",
46                "gplus_perma_option",
47                "gplus_display_name",
48                "gplus_language"
49                );
50
51        foreach($options as $opt) {
52                $opt_value=$this->getConf("$opt");
53                $parts = explode("_", $opt, 2);
54                if ( $parts[1] == "status" && $opt_value == "1") { $opt_value = "on"; }
55                if ( $parts[1] == "status" && $opt_value == "0") { $opt_value = "off"; }
56                if ( $parts[1] == "perma_option" && $opt_value == "1") { $opt_value = "on"; }
57                if ( $parts[1] == "perma_option" && $opt_value == "0") { $opt_value = "off"; }
58                if ( $opt_value != "" ) {
59                    $jsopt["$parts[0]"] .= "'" . $parts[1] . "' : " . "'" .$opt_value . "',";
60                }
61        }
62
63        $dummyImgPath = DOKU_BASE . "lib/plugins/socialshareprivacy/images/";
64        $dummyFB = $dummyImgPath . str_replace(".png", "_".$conf['lang'] . ".png", "dummy_facebook.png");
65        $dummyTWIT = $dummyImgPath . "dummy_twitter.png";
66        $dummyGP = $dummyImgPath . "dummy_gplus.png";
67
68        $scriptstring  = '   jQuery(document).ready(function($){ ' . DOKU_LF;
69        $scriptstring .= "        if($('#socialshareprivacy').length > 0){ " .DOKU_LF;
70        $scriptstring .= "           $('#socialshareprivacy').socialSharePrivacy({ ". DOKU_LF;
71        $scriptstring .= "              services : { " .DOKU_LF;
72        $scriptstring .= "                  facebook : { " .DOKU_LF;
73        $scriptstring .= "                     ". $jsopt["facebook"] . DOKU_LF;
74        $scriptstring .= "                      'dummy_img' : '". $dummyFB  ."' " .DOKU_LF;
75        $scriptstring .= "                  },  " .DOKU_LF;
76        $scriptstring .= "                  twitter : { " .DOKU_LF;
77        $scriptstring .= "                     ". $jsopt["twitter"] .DOKU_LF;
78        $scriptstring .= "                      'dummy_img' : '". $dummyTWIT  ."' " .DOKU_LF;
79        $scriptstring .= "                  }, " .DOKU_LF;
80        $scriptstring .= "                  gplus : { " .DOKU_LF;
81        $scriptstring .= "                     ". $jsopt["gplus"] . DOKU_LF;
82        $scriptstring .= "                      'dummy_img' : '". $dummyGP  ."' " .DOKU_LF;
83        $scriptstring .= "                  } ".DOKU_LF;
84        $scriptstring .= "              }, ".DOKU_LF;
85        $scriptstring .= "              ". $jsopt["global"];
86        $scriptstring .= "              'css_path' : '' ".DOKU_LF;
87        $scriptstring .= '     })' .DOKU_LF;
88        $scriptstring .= "    }" .DOKU_LF;
89        $scriptstring .= '   });' .DOKU_LF;
90
91        // Output
92        $event->data["script"][] = array (
93                "type" => "text/javascript",
94                "charset" => "utf-8",
95                "_data" => "",
96                "src" => DOKU_BASE."lib/plugins/socialshareprivacy/jquery.socialshareprivacy.min.js"
97                );
98
99        $event->data["script"][] = array (
100                "type" => "text/javascript",
101                "_data" => $scriptstring
102                );
103
104    }
105
106}
107
108// vim:ts=4:sw=4:et:
109