]> git.mxchange.org Git - friendica.git/blob - addon/piwik/piwik.php
Update info comments in all plugins
[friendica.git] / addon / piwik / piwik.php
1 <?php
2 /**
3  * Name: Piwik Analytics
4  * Description: Piwik Analytics Plugin for Friendika
5  * Version: 1.0
6  * Author: Tobias Diekershoff <https://diekershoff.homeunix.net/friendika/profile/tobias>
7  */
8  
9
10 /*   Piwik Analytics Plugin for Friendika
11  *
12  *   Author: Tobias Diekershoff
13  *           tobias.diekershoff@gmx.net
14  *
15  *   License: 3-clause BSD license (same as Friendika)
16  *
17  *   Configuration:
18  *     Add the following two lines to your .htconfig.php file:
19  *
20  *     $a->config['piwik']['baseurl'] = 'www.example.com/piwik/';
21  *     $a->config['piwik']['sideid'] = '1';
22  *     $a->config['piwik']['optout'] = true;  // set to false to disable
23  *
24  *     Change the sideid to the ID that the Piwik tracker for your Friendika
25  *     installation has. Alter the baseurl to fit your needs, don't care
26  *     about http/https but beware to put the trailing / at the end of your
27  *     setting.
28  *
29  *     Documentation see http://diekershoff.homeunix.net/redmine/wiki/friendikaplugin/Piwik_Plugin
30  */
31
32 function piwik_install() {
33         register_hook('page_end', 'addon/piwik/piwik.php', 'piwik_analytics');
34
35         logger("installed piwik plugin");
36 }
37
38 function piwik_uninstall() {
39         unregister_hook('page_end', 'addon/piwik/piwik.php', 'piwik_analytics');
40
41         logger("uninstalled piwik plugin");
42 }
43
44 function piwik_analytics($a,&$b) {
45
46         /*
47          *   styling of every HTML block added by this plugin is done in the
48          *   associated CSS file. We just have to tell Friendika to get it
49          *   into the page header.
50          */
51         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/piwik/piwik.css' . '" media="all" />' . "\r\n";
52
53         /*
54          *   Get the configuration variables from the .htconfig file.
55          */
56         $baseurl = get_config('piwik','baseurl');
57         $sideod  = get_config('piwik','sideid');
58         $optout  = get_config('piwik','optout');
59
60         /*
61          *   Add the Piwik code for the side.
62          */
63         $b .= "<div id='piwik-code-block'> <!-- Piwik -->\r\n <script type=\"text/javascript\">\r\n var pkBaseURL = ((\"https:\" == document.location.protocol) ? \"https://".$baseurl."\" : \"http://".$baseurl."\");\r\n document.write(unescape(\"%3Cscript src='\" + pkBaseURL + \"piwik.js' type='text/javascript'%3E%3C/script%3E\"));\r\n </script>\r\n<script type=\"text/javascript\">\r\n try {\r\n var piwikTracker = Piwik.getTracker(pkBaseURL + \"piwik.php\", 8);\r\n piwikTracker.trackPageView();\r\n piwikTracker.enableLinkTracking();\r\n }\r\n catch( err ) {}\r\n </script>\r\n<noscript><p><img src=\"http://".$baseurl."/piwik.php?idsite=8\" style=\"border:0\" alt=\"\" /></p></noscript>\r\n <!-- End Piwik Tracking Tag --> </div>";
64         /*
65          *   If the optout variable is set to true then display the notice
66          *   otherwise just include the above code into the page.
67          */
68         if ($optout) {
69                 $b .= "<div id='piwik-optout-link'>This website is tracked using the <a href='http://www.piwik.org'>Piwik</a> analytics tool. If you do not want that your visits are logged this way you <a href='http://". $baseurl ."index.php?module=CoreAdminHome&action=optOut'>can set a cookie to prevent Piwik from tracking further visits of the site</a> (opt-out).</div>";
70         }
71
72 }
73