1 | <?php |
---|
2 | |
---|
3 | function statsjs_affichage_final($page) { |
---|
4 | |
---|
5 | if (!$GLOBALS['html']) return $page; |
---|
6 | |
---|
7 | // Identification de l'element |
---|
8 | foreach($GLOBALS['contexte'] as $k => &$v) { |
---|
9 | if (preg_match(',^id_(\w+)$,S', $k, $r) |
---|
10 | AND ($id = intval($v))>0 |
---|
11 | ) { |
---|
12 | $identifier = $r[1].$id; |
---|
13 | } |
---|
14 | } |
---|
15 | |
---|
16 | if (isset($identifier)) { |
---|
17 | $page = preg_replace(',</head>,i', |
---|
18 | "\n".'<meta name="SPIP.identifier" content="'.$identifier.'" />'."\n".'\0', |
---|
19 | $page, 1); |
---|
20 | } |
---|
21 | |
---|
22 | if (!strpos($page, '<!-- MOUCHARD STATS SPIP -->')) |
---|
23 | $page = preg_replace(',</body>,i', statsjs_mouchard()."\n".'\0', $page, 1); |
---|
24 | |
---|
25 | |
---|
26 | return $page; |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | // Remplacer la balise spip_cron, qui ne sert plus a rien si on active les stats |
---|
31 | if (!function_exists('balise_SPIP_CRON')) { |
---|
32 | function balise_SPIP_CRON ($p) { |
---|
33 | $p->code = _q(""); |
---|
34 | $p->interdire_scripts = false; |
---|
35 | return $p; |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | function statsjs_mouchard() { |
---|
41 | $urljs = generer_url_public('stats.js'); |
---|
42 | $urlhit = generer_url_action('stats'); |
---|
43 | $mouchard = " |
---|
44 | <!-- MOUCHARD STATS SPIP --> |
---|
45 | <script type='text/javascript'> |
---|
46 | $(function(){setTimeout(function(){ |
---|
47 | $.ajax({url: '${urljs}', dataType: 'script', cache: true, |
---|
48 | success: function() { |
---|
49 | var obj = ($('meta[name=\"SPIP.identifier\"]').attr('content')||''); |
---|
50 | try { |
---|
51 | var piwikTracker = Piwik.getTracker('${urlhit}\\x26obj='+obj); |
---|
52 | piwikTracker.setDocumentTitle(document.title); |
---|
53 | piwikTracker.trackPageView(); |
---|
54 | } catch( err ) {} |
---|
55 | } |
---|
56 | }); |
---|
57 | }, 100);}); |
---|
58 | </script> |
---|
59 | <noscript><p><img src='${urlhit}' style='border:0' alt='' /></p></noscript> |
---|
60 | <!-- / MOUCHARD -->\n"; |
---|
61 | |
---|
62 | return $mouchard; |
---|
63 | } |
---|