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