Subversion Repositories Sites.tela-botanica.org

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 david 1
<?php
2
 
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2005                                                *
7
 *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
8
 *                                                                         *
9
 *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
10
 *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11
\***************************************************************************/
12
 
13
 
14
//
15
// Ce fichier ne sera execute qu'une fois
16
if (defined("_INC_STATS")) return;
17
define("_INC_STATS", "1");
18
 
19
function ecrire_stats() {
20
	global $id_article, $id_breve, $id_rubrique;
21
 
22
	if ($GLOBALS['HTTP_X_FORWARDED_FOR'])
23
		$log_ip = $GLOBALS['HTTP_X_FORWARDED_FOR'];
24
	else
25
		$log_ip = $GLOBALS['REMOTE_ADDR'];
26
 
27
	if ($log_id_num = intval($id_rubrique))
28
		$log_type = "rubrique";
29
	else if ($log_id_num = intval($id_article))
30
		$log_type = "article";
31
	else if ($log_id_num = intval($id_breve))
32
		$log_type = "breve";
33
	else
34
		$log_type = "autre";
35
 
36
	// Conversion IP 4 octets -> entier 32 bits
37
	if (ereg("^(::ffff:)?([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$", $log_ip, $r)) {
38
		$log_ip = sprintf("0x%02x%02x%02x%02x", $r[2], $r[3], $r[4], $r[5]);
39
	}
40
	else return;
41
 
42
	//
43
	// Loguer la visite dans la base si possible
44
	//
45
	if ($log_type != "autre") {
46
		$query = "INSERT IGNORE INTO spip_visites_temp (ip, type, id_objet) ".
47
			"VALUES ($log_ip, '$log_type', $log_id_num)";
48
		spip_query($query);
49
	}
50
 
51
	//
52
	// Loguer le referer
53
	//
54
	$url_site_spip = lire_meta('adresse_site');
55
	$url_site_spip = eregi_replace("^((https?|ftp)://)?(www\.)?", "", $url_site_spip);
56
	$log_referer = $GLOBALS['HTTP_REFERER'];
57
	if (($url_site_spip<>'') AND strpos('-'.strtolower($log_referer), strtolower($url_site_spip)) AND !$GLOBALS['var_recherche']) $log_referer = "";
58
	if ($log_referer) {
59
		$referer_md5 = '0x'.substr(md5($log_referer), 0, 15);
60
		$query = "INSERT IGNORE INTO spip_referers_temp (ip, referer, referer_md5, type, id_objet) ".
61
			"VALUES ($log_ip, '".texte_script($log_referer)."', $referer_md5, '$log_type', $log_id_num)";
62
		spip_query($query);
63
	}
64
}
65
 
66
 
67
function afficher_raccourci_stats($id_article) {
68
	$query = "SELECT visites, popularite FROM spip_articles WHERE id_article=$id_article AND statut='publie'";
69
	$result = spip_query($query);
70
	if ($row = @spip_fetch_array($result)) {
71
		$visites = intval($row['visites']);
72
		$popularite = ceil($row['popularite']);
73
 
74
		$query = "SELECT COUNT(DISTINCT ip) AS c FROM spip_visites_temp WHERE type='article' AND id_objet=$id_article";
75
		$result = spip_query($query);
76
		if ($row = @spip_fetch_array($result)) {
77
			$visites = $visites + $row['c'];
78
		}
79
 
80
		return array('visites' => $visites, 'popularite' => $popularite);
81
	}
82
}
83
 
84
?>