
commit
0d46ac67ef
28 changed files with 6269 additions and 0 deletions
@ -0,0 +1,28 @@
|
||||
* text=auto !eol |
||||
base/delete_statistiques.php -text |
||||
base/stats.php -text |
||||
base/stats_upgrade.php -text |
||||
/engines-list.txt -text |
||||
exec/statistiques_lang.php -text |
||||
exec/statistiques_referers.php -text |
||||
exec/statistiques_repartition.php -text |
||||
exec/statistiques_visites.php -text |
||||
formulaires/configurer_compteur.html -text |
||||
formulaires/configurer_compteur.php -text |
||||
genie/popularites.php -text |
||||
genie/visites.php -text |
||||
inc/referenceurs.php -text |
||||
inc/statistiques.php -text |
||||
javascript/excanvas.js -text |
||||
javascript/jquery.flot.js -text |
||||
javascript/jquery.tflot.js -text |
||||
/plugin.xml -text |
||||
prive/bouton/statistiques.html -text |
||||
prive/configurer/compteur.html -text |
||||
prive/images/statistiques-48.png -text |
||||
prive/stats/visites.html -text |
||||
prive/style_prive_plugin_stats.html -text |
||||
public/stats.php -text |
||||
/stats_autoriser.php -text |
||||
/stats_options.php -text |
||||
/stats_pipelines.php -text |
@ -0,0 +1,34 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2009 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; // securiser |
||||
|
||||
// faudrait plutot recuperer dans inc_serialbase et inc_auxbase |
||||
// mais il faudra prevenir ceux qui affectent les globales qui s'y trouvent |
||||
// Afficher la liste de ce qu'on va detruire et demander confirmation |
||||
// ca vaudrait mieux |
||||
|
||||
// http://doc.spip.org/@base_delete_statistiques_dist |
||||
function base_delete_statistiques_dist($titre='', $reprise='') |
||||
{ |
||||
if (!$titre) return; // anti-testeur automatique |
||||
sql_delete("spip_visites"); |
||||
sql_delete("spip_visites_articles"); |
||||
sql_delete("spip_referers"); |
||||
sql_delete("spip_referers_articles"); |
||||
sql_update("spip_articles", array('visites'=>0, 'referers'=>0, 'popularite'=>0)); |
||||
|
||||
// un pipeline pour detruire les tables de stats installees par les plugins |
||||
pipeline('delete_statistiques', ''); |
||||
spip_log("raz des stats operee redirige vers " . _request('redirect')); |
||||
} |
||||
?> |
@ -0,0 +1,65 @@
|
||||
<?php |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
|
||||
function stats_declarer_tables_auxiliaires($tables_auxiliaires){ |
||||
|
||||
$spip_visites = array( |
||||
"date" => "DATE NOT NULL", |
||||
"visites" => "int UNSIGNED DEFAULT '0' NOT NULL", |
||||
"maj" => "TIMESTAMP"); |
||||
|
||||
$spip_visites_key = array( |
||||
"PRIMARY KEY" => "date"); |
||||
|
||||
$spip_visites_articles = array( |
||||
"date" => "DATE NOT NULL", |
||||
"id_article" => "int UNSIGNED NOT NULL", |
||||
"visites" => "int UNSIGNED DEFAULT '0' NOT NULL", |
||||
"maj" => "TIMESTAMP"); |
||||
|
||||
$spip_visites_articles_key = array( |
||||
"PRIMARY KEY" => "date, id_article"); |
||||
|
||||
|
||||
|
||||
$spip_referers = array( |
||||
"referer_md5" => "bigint UNSIGNED NOT NULL", |
||||
"date" => "DATE NOT NULL", |
||||
"referer" => "VARCHAR (255)", |
||||
"visites" => "int UNSIGNED NOT NULL", |
||||
"visites_jour" => "int UNSIGNED NOT NULL", |
||||
"visites_veille"=> "int UNSIGNED NOT NULL", |
||||
"maj" => "TIMESTAMP"); |
||||
|
||||
$spip_referers_key = array( |
||||
"PRIMARY KEY" => "referer_md5"); |
||||
|
||||
$spip_referers_articles = array( |
||||
"id_article" => "int UNSIGNED NOT NULL", |
||||
"referer_md5" => "bigint UNSIGNED NOT NULL", |
||||
"referer" => "VARCHAR (255) DEFAULT '' NOT NULL", |
||||
"visites" => "int UNSIGNED NOT NULL", |
||||
"maj" => "TIMESTAMP"); |
||||
|
||||
$spip_referers_articles_key = array( |
||||
"PRIMARY KEY" => "id_article, referer_md5", |
||||
"KEY referer_md5" => "referer_md5"); |
||||
|
||||
$tables_auxiliaires['spip_visites'] = array( |
||||
'field' => &$spip_visites, |
||||
'key' => &$spip_visites_key); |
||||
$tables_auxiliaires['spip_visites_articles'] = array( |
||||
'field' => &$spip_visites_articles, |
||||
'key' => &$spip_visites_articles_key); |
||||
$tables_auxiliaires['spip_referers'] = array( |
||||
'field' => &$spip_referers, |
||||
'key' => &$spip_referers_key); |
||||
$tables_auxiliaires['spip_referers_articles'] = array( |
||||
'field' => &$spip_referers_articles, |
||||
'key' => &$spip_referers_articles_key); |
||||
|
||||
return $tables_auxiliaires; |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,33 @@
|
||||
<?php |
||||
|
||||
|
||||
function stats_upgrade($nom_meta_base_version,$version_cible){ |
||||
$current_version = 0.0; |
||||
if ( (!isset($GLOBALS['meta'][$nom_meta_base_version]) ) |
||||
|| (($current_version = $GLOBALS['meta'][$nom_meta_base_version])!=$version_cible)){ |
||||
|
||||
if ($current_version==0.0){ |
||||
include_spip('base/stats'); |
||||
include_spip('base/create'); |
||||
// creer les tables |
||||
creer_base(); |
||||
// mettre les metas par defaut |
||||
$config = charger_fonction('config','inc'); |
||||
$config(); |
||||
ecrire_meta($nom_meta_base_version,$current_version=$version_cible); |
||||
} |
||||
} |
||||
} |
||||
|
||||
function stats_vider_tables($nom_meta_base_version) { |
||||
sql_drop_table("spip_visites"); |
||||
sql_drop_table("spip_visites_articles"); |
||||
sql_drop_table("spip_referers"); |
||||
sql_drop_table("spip_referers_articles"); |
||||
|
||||
effacer_meta("activer_statistiques"); |
||||
effacer_meta("activer_captures_referers"); |
||||
|
||||
effacer_meta($nom_meta_base_version); |
||||
} |
||||
?> |
@ -0,0 +1,274 @@
|
||||
# ----------------------------------------------------------------------------- |
||||
# Les Visiteurs - Engines List |
||||
# ----------------------------------------------------------------------------- |
||||
# [Engine Name] |
||||
# word= | word => query | directory |
||||
# host 1 |
||||
# host 2 |
||||
# hots ... |
||||
# ----------------------------------------------------------------------------- |
||||
# sort the list according your visits (see your referrers). |
||||
# ----------------------------------------------------------------------------- |
||||
|
||||
[IP] |
||||
rien= |
||||
[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ |
||||
|
||||
[Google] |
||||
(^q|\&q|as_q)= |
||||
(www\.|ww\.|maps\.)?(google|gogole)\.(.*) |
||||
(web|www).toile.com |
||||
www\.cegetel\.net |
||||
search\.conduit\.com |
||||
search\.sweetim\.com |
||||
chello\.fr |
||||
|
||||
[Voila] |
||||
(kw|rdata)= |
||||
(search|moteur)(.*)\.voila\.(fr|com) |
||||
|
||||
[Yahoo!] |
||||
p= |
||||
(.*)(search|ink|dir|google)\.yahoo\.([a-z]+)$ |
||||
|
||||
[AltaVista] |
||||
q= |
||||
(.*)altavista\.com |
||||
|
||||
[Ask] |
||||
q= |
||||
(.*)\.ask\.com |
||||
|
||||
[HotBot] |
||||
query= |
||||
www\.hotbot\.com |
||||
|
||||
[Freeserve] |
||||
q= |
||||
search\.freeserve\.com |
||||
|
||||
[Skeech] |
||||
query= |
||||
skeech\.com |
||||
|
||||
[Dogpile] |
||||
query= |
||||
(.*)dogpile\.com |
||||
|
||||
[Metacrawler] |
||||
query= |
||||
metacrawler\.com |
||||
|
||||
[Mirago] |
||||
qry= |
||||
www.mirago\.([a-z]+)$ |
||||
|
||||
[Nomade] |
||||
s= |
||||
(.*)\.nomade\.fr |
||||
(.*)\.nomade\.tiscali\.fr |
||||
(.*)\.nomade\.aliceadsl\.fr |
||||
|
||||
[Alice] |
||||
qs= |
||||
\.aliceadsl\. |
||||
|
||||
[Lycos] |
||||
query= |
||||
search\.lycos\.com |
||||
vachercher\.lycos\.fr |
||||
|
||||
[Francite] |
||||
name= |
||||
recherche\.francite\.com |
||||
|
||||
[MSN] |
||||
(q|s)= |
||||
search(.*)\.msn\.([a-z.]+)$ |
||||
leguide(.*)\.msn\.([a-z]+)$ |
||||
search\.ninemsn\.com\.au |
||||
|
||||
[Live] |
||||
q= |
||||
search\.live\.com |
||||
|
||||
[Excite] |
||||
search= |
||||
www\.excite\.fr |
||||
(.*)\.excite\.co\.jp |
||||
|
||||
[AOL France] |
||||
(query|q|r)= |
||||
(.*)recherchet?\.aol\.fr |
||||
|
||||
[AOLsearch] |
||||
query= |
||||
(.*)search\.aol\.(.*) |
||||
|
||||
[AllTheWeb] |
||||
q= |
||||
www\.alltheweb\.com |
||||
|
||||
[ixquick] |
||||
query= |
||||
ixquick\.com |
||||
|
||||
[Netscape] |
||||
search= |
||||
search-intl\.netscape\.com |
||||
search\.netscape\.com |
||||
www\.netscape\.fr |
||||
|
||||
[Free] |
||||
q= |
||||
search(.*)\.free\.fr |
||||
|
||||
[9online] |
||||
query= |
||||
www\.9online\.fr |
||||
|
||||
[Naver] |
||||
query= |
||||
search\.naver\.com |
||||
|
||||
[Club Internet] |
||||
q= |
||||
recherche\.club-internet\.fr |
||||
|
||||
[Sympatico] |
||||
query= |
||||
search\.sli\.sympatico\.ca |
||||
|
||||
[Overture] |
||||
Keywords= |
||||
www\.overture\.com |
||||
|
||||
[moteur-recherche.net] |
||||
keyword= |
||||
www\.moteur-recherche\.net |
||||
|
||||
[Reacteur.com] |
||||
kw= |
||||
www\.reacteur\.com |
||||
|
||||
[francesurf] |
||||
q= |
||||
www\.francesurf\.net |
||||
|
||||
[n9uf] |
||||
((K|k)eywords|query)= |
||||
(www\.)?neuf\.fr |
||||
|
||||
[MozBot] |
||||
q= |
||||
www\.mozbot\.([a-z]+)$ |
||||
|
||||
[Cegetel] |
||||
q= |
||||
(www\.)?cegetel\.([a-z]+)$ |
||||
|
||||
[MyWay] |
||||
searchfor= |
||||
kf\.mysearch\.myway\.com |
||||
www\.mywebsearch\.com |
||||
(.*)\.mysearch\.com |
||||
|
||||
[MonGenie] |
||||
Keywords= |
||||
www\.mongenie\.com |
||||
|
||||
[Need2Find] |
||||
searchfor= |
||||
kx\.search\.need2find\.com |
||||
|
||||
[Exalead] |
||||
q= |
||||
www\.exalead\.fr |
||||
www\.exalead\.com |
||||
|
||||
[Virgilio.it] |
||||
qs= |
||||
search\.virgilio\.it |
||||
|
||||
[Libero.it] |
||||
query= |
||||
arianna\.libero\.it |
||||
|
||||
[LemmeFind] |
||||
t= |
||||
www\.lemmefind\.fr |
||||
|
||||
[NovoNeo] |
||||
q= |
||||
www\.novoneo\.com |
||||
|
||||
[MyWebSearch] |
||||
searchfor= |
||||
search\.mywebsearch\.com |
||||
|
||||
[Copernic] |
||||
query= |
||||
find\.copernic\.com |
||||
|
||||
[Seek] |
||||
qry_str= |
||||
\.seek\.fr |
||||
|
||||
[Orange, le moteur] |
||||
rdata= |
||||
www\.lemoteur\.fr |
||||
|
||||
[alOt] |
||||
q= |
||||
search\.alot\.com |
||||
|
||||
# |
||||
# Dmoz |
||||
# |
||||
[dmoz.org] |
||||
rien= |
||||
(.*\.)?dmoz\.org |
||||
|
||||
[FoxRef] |
||||
key= |
||||
www\.foxref\.org |
||||
|
||||
[OneBigWorld] |
||||
Keywords= |
||||
fr\.onebigworld\.com |
||||
|
||||
[BlueWin] |
||||
query= |
||||
search\.bluewin\.ch |
||||
|
||||
[EO] |
||||
q= |
||||
www\.eo\.st |
||||
|
||||
[HooSeek] |
||||
recherche= |
||||
(www\.)?hooseek\.com |
||||
|
||||
[Lost] |
||||
x_query= |
||||
(www\.)?lo\.st |
||||
|
||||
[Babylon] |
||||
q= |
||||
search\.babylon\.com |
||||
|
||||
# |
||||
# Services de mail |
||||
# |
||||
|
||||
[(email)] |
||||
rien= |
||||
imp(.*)\.free\.fr |
||||
fc\.kayenta\.com |
||||
courrielweb\.cmaisonneuve\.qc\.ca |
||||
(.*)mail\.(.*)\.([a-z]+)$ |
||||
webmail([0-9]*)\.wanadoo\.fr |
||||
www\.laposte\.net |
||||
mail([0-9]*)\.voila\.fr |
||||
\/(web)?mail\/ |
||||
|
@ -0,0 +1,123 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2009 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
|
||||
include_spip('inc/presentation'); |
||||
|
||||
// http://doc.spip.org/@exec_statistiques_lang_dist |
||||
function exec_statistiques_lang_dist() |
||||
{ |
||||
if (!autoriser('voirstats')) { |
||||
include_spip('inc/minipres'); |
||||
echo minipres(); |
||||
} else statistiques_lang_ok(); |
||||
} |
||||
|
||||
// http://doc.spip.org/@statistiques_lang_ok |
||||
function statistiques_lang_ok() |
||||
{ |
||||
global $spip_ecran, $spip_lang_right; |
||||
|
||||
$commencer_page = charger_fonction('commencer_page', 'inc'); |
||||
echo $commencer_page(_T('onglet_repartition_lang'), "statistiques_visites", "repartition-langues"); |
||||
|
||||
if ($spip_ecran == "large") { |
||||
$largeur_table = 974; |
||||
} else { |
||||
$largeur_table = 750; |
||||
} |
||||
$taille = $largeur_table - 200; |
||||
echo "<table class='centered' width='$largeur_table'><tr><td style='width: $largeur_table" . "px; text-align:center;' class='verdana2'>"; |
||||
|
||||
echo gros_titre(_T('onglet_repartition_lang'),'', false); |
||||
|
||||
echo barre_onglets("statistiques", "statistiques_lang"); |
||||
|
||||
if ($critere == "debut") { |
||||
$critere = "visites"; |
||||
echo "<a href='".generer_url_ecrire('statistiques_lang')."'>"._T('icone_repartition_actuelle').'</a>'; |
||||
echo " | <strong>"._T('onglet_repartition_debut').'</strong>'; |
||||
} |
||||
else { |
||||
$critere = "popularite"; |
||||
echo "<strong>"._T('icone_repartition_actuelle').'</strong>'; |
||||
echo " | <a href='".generer_url_ecrire('statistiques_lang','critere=debut')."'>"._T('onglet_repartition_debut').'</a>'; |
||||
} |
||||
|
||||
|
||||
// |
||||
// Statistiques par langue |
||||
// |
||||
|
||||
|
||||
echo debut_cadre_enfonce("langues-24.gif", true); |
||||
|
||||
$r = sql_fetsel("SUM($critere) AS total_visites", "spip_articles"); |
||||
|
||||
$visites = 1; |
||||
if ($r) |
||||
$total_visites = $r['total_visites']; |
||||
else |
||||
$total_visites = 1; |
||||
|
||||
$result = sql_select("lang, SUM(".$critere.") AS cnt", "spip_articles", "statut='publie' ", "lang"); |
||||
|
||||
echo "\n<table cellpadding='2' cellspacing='0' border='0' width='100%' style='border: 1px solid #aaaaaa;'>"; |
||||
$ifond = 1; |
||||
|
||||
$visites_abs = 0; |
||||
while ($row = sql_fetch($result)) { |
||||
|
||||
$lang = $row['lang']; |
||||
if ($row['cnt']) { |
||||
$visites = round($row['cnt'] / $total_visites * $taille); |
||||
$pourcent = round($row['cnt'] / $total_visites * 100); |
||||
} |
||||
|
||||
if ($visites > 0) { |
||||
|
||||
if ($ifond==0){ |
||||
$ifond=1; |
||||
$couleur="white"; |
||||
}else{ |
||||
$ifond=0; |
||||
$couleur="eeeeee"; |
||||
} |
||||
|
||||
echo "\n<tr style='background-color: $couleur'>"; |
||||
$dir=lang_dir($lang,'',' dir="rtl"'); |
||||
echo "<td style='width: 100%; border-bottom: 1px solid #cccccc;'><span class='verdana2'$dir><span style='float: $spip_lang_right;'>$pourcent%</span>".traduire_nom_langue($lang)."</span></td>"; |
||||
|
||||
echo "<td style='border-bottom: 1px solid #cccccc;'>"; |
||||
echo "\n<table cellpadding='0' cellspacing='0' border='0' width='".($taille+5)."'>"; |
||||
echo "\n<tr><td style='align:$spip_lang_right; background-color: #eeeeee; border: 1px solid #999999; white-space: nowrap;'>"; |
||||
if ($visites_abs > 0) echo "<img src='" . chemin_image('rien.gif') . "' width='$visites_abs' height='8' alt=' ' />"; |
||||
if ($visites>0) echo "<img src='" . chemin_image('rien.gif') . "' class='couleur_langue' style='border: 0px;' width='$visites' height='8' alt=' ' />"; |
||||
echo "</td></tr></table>\n"; |
||||
|
||||
echo "</td>"; |
||||
echo "</tr>"; |
||||
$visites_abs += $visites; |
||||
} |
||||
} |
||||
echo "</table>\n"; |
||||
|
||||
|
||||
//echo "<p><span class='verdana1 spip_medium'>"._T('texte_signification')."</span>"; |
||||
|
||||
echo fin_cadre_enfonce(true); |
||||
|
||||
echo "</td></tr></table>"; |
||||
echo fin_page(); |
||||
} |
||||
?> |
@ -0,0 +1,77 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2009 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
|
||||
include_spip('inc/presentation'); |
||||
|
||||
// http://doc.spip.org/@exec_statistiques_referers_dist |
||||
function exec_statistiques_referers_dist() |
||||
{ |
||||
$jour = _request('jour'); |
||||
$limit = _request('limit'); |
||||
// nombre de referers a afficher |
||||
$limit = intval($limit); //secu |
||||
if (!autoriser('voirstats','article')) { |
||||
include_spip('inc/minipres'); |
||||
echo minipres(); |
||||
} else { |
||||
|
||||
if ($limit == 0) $limit = 100; |
||||
if ($jour<>'veille') $jour='jour'; |
||||
|
||||
$referenceurs = charger_fonction('referenceurs', 'inc'); |
||||
$res = $referenceurs (0, "SUM(visites_$jour)", 'spip_referers', "visites_$jour>0", "referer", $limit); |
||||
|
||||
$n = count($res); |
||||
$args = "jour=$jour@limit=" . strval($limit+200); |
||||
$plus = generer_url_ecrire('statistiques_visites', $args); |
||||
|
||||
if ($plus) { |
||||
$plus = ($limit == $n) |
||||
? "<div style='text-align:right;'><b><a href='$plus'>+++</a></b></div>" |
||||
: ''; |
||||
} |
||||
|
||||
$titre = _T('titre_liens_entrants') |
||||
. " ($n " |
||||
. ($n <= 1 ? _T('info_site') : _T('info_sites')) |
||||
. ")"; |
||||
|
||||
$commencer_page = charger_fonction('commencer_page', 'inc'); |
||||
|
||||
echo $commencer_page(_T('titre_page_statistiques_referers'), "statistiques_visites", "referers"); |
||||
|
||||
echo gros_titre($titre,'', false); |
||||
echo debut_gauche('', true); |
||||
echo debut_boite_info(true); |
||||
echo "<p style='font-size:small; text-align:left;' class='verdana1'>"; |
||||
echo _T('info_gauche_statistiques_referers'); |
||||
echo "</p>"; |
||||
echo fin_boite_info(true); |
||||
echo debut_droite('', true); |
||||
echo barre_onglets("stat_referers", $jour . '_referers'); // attention a pas avoir le meme id d'onglet... |
||||
|
||||
if ($res) { |
||||
echo "<br /><div style='font-size:small;' class='verdana1'>"; |
||||
echo "<ul class='referers'><li>"; |
||||
echo join("</li><li>\n", $res); |
||||
echo "</li></ul>"; |
||||
echo $plus; |
||||
} |
||||
echo "</div><br />"; |
||||
|
||||
echo fin_gauche(), fin_page(); |
||||
} |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,180 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2009 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
|
||||
include_spip('inc/presentation'); |
||||
|
||||
// http://doc.spip.org/@enfants |
||||
function enfants($id_parent, $critere){ |
||||
global $nombre_vis, $nombre_abs; |
||||
|
||||
$result = sql_select("id_rubrique", "spip_rubriques", "id_parent=$id_parent"); |
||||
|
||||
$nombre = 0; |
||||
|
||||
while($row = sql_fetch($result)) { |
||||
$id_rubrique = $row['id_rubrique']; |
||||
|
||||
$visites = intval(sql_getfetsel("SUM(".$critere.")", "spip_articles", "id_rubrique=$id_rubrique")); |
||||
$nombre_abs[$id_rubrique] = $visites; |
||||
$nombre_vis[$id_rubrique] = $visites; |
||||
$nombre += $visites + enfants($id_rubrique, $critere); |
||||
} |
||||
if (!isset($nombre_vis[$id_parent])) $nombre_vis[$id_parent]=0; |
||||
$nombre_vis[$id_parent] += $nombre; |
||||
return $nombre; |
||||
} |
||||
|
||||
|
||||
// http://doc.spip.org/@enfants_aff |
||||
function enfants_aff($id_parent,$decalage, $critere, $gauche=0) { |
||||
|
||||
global $niveau; |
||||
global $nombre_vis; |
||||
global $nombre_abs; |
||||
global $spip_lang_right, $spip_lang_left; |
||||
global $abs_total; |
||||
global $taille; |
||||
$visites_abs = 0; |
||||
|
||||
$result = sql_select("id_rubrique, titre, descriptif", "spip_rubriques", "id_parent=$id_parent",'', '0+titre,titre'); |
||||
|
||||
while($row = sql_fetch($result)){ |
||||
$id_rubrique = $row['id_rubrique']; |
||||
$titre = typo($row['titre']); |
||||
$descriptif = attribut_html(couper(typo($row['descriptif']),80)); |
||||
|
||||
if ($nombre_vis[$id_rubrique]>0 OR $nombre_abs[$id_rubrique]>0){ |
||||
$largeur_rouge = floor(($nombre_vis[$id_rubrique] - $nombre_abs[$id_rubrique]) * $taille / $abs_total); |
||||
$largeur_vert = floor($nombre_abs[$id_rubrique] * $taille / $abs_total); |
||||
|
||||
if ($largeur_rouge+$largeur_vert>0){ |
||||
|
||||
if ($niveau == 0) { |
||||
$couleur="#cccccc"; |
||||
} |
||||
|
||||
else if ($niveau == 1) { |
||||
$couleur="#eeeeee"; |
||||
} |
||||
else { |
||||
$couleur="white"; |
||||
} |
||||
echo "<table cellpadding='2' cellspacing='0' border='0' width='100%'>"; |
||||
echo "\n<tr style='background-color: $couleur'>"; |
||||
echo "\n<td style='border-bottom: 1px solid #aaaaaa; padding-$spip_lang_left: ".($niveau*20+5)."px;'>"; |
||||
|
||||
|
||||
if ( $largeur_rouge > 2) |
||||
echo bouton_block_depliable("<a href='" . generer_url_ecrire("naviguer","id_rubrique=$id_rubrique") . "' style='color: black;' title=\"$descriptif\">$titre</a>","incertain", "stats$id_rubrique"); |
||||
else |
||||
echo "<div class='verdana1' style='padding-left: 18px; padding-top: 4px; padding-bottom: 3px;'>", |
||||
"<a href='" . generer_url_ecrire("naviguer","id_rubrique=$id_rubrique") . "' style='color: black;' title=\"$descriptif\">$titre</a>", |
||||
"</div>"; |
||||
echo "</td>"; |
||||
|
||||
|
||||
if ($niveau==0 OR 1==1){ |
||||
$pourcent = round($nombre_vis[$id_rubrique]/$abs_total*1000)/10; |
||||
echo "\n<td class='verdana1' style='text-align: $spip_lang_right; width: 40px; border-bottom: 1px solid #aaaaaa;'>$pourcent%</td>"; |
||||
} |
||||
else { echo "<td style='width: 10px; border-bottom: 1px solid #aaaaaa;'></td>"; } |
||||
|
||||
|
||||
echo "\n<td align='right' style='border-bottom: 1px solid #aaaaaa; width:" . ($taille+5) ."px'>"; |
||||
|
||||
|
||||
echo "\n<table cellpadding='0' cellspacing='0' border='0' width='".($decalage+1+$gauche)."'>"; |
||||
echo "\n<tr>"; |
||||
if ($gauche > 0) echo "<td style='width: " .$gauche."px'></td>"; |
||||
echo "\n<td style='border: 0px; white-space: nowrap;'>"; |
||||
echo "<div style='border: 1px solid #999999; background-color: #dddddd; height: 12px; padding: 0px; margin: 0px;'>"; |
||||
if ($visites_abs > 0) echo "<img src='" . chemin_image('rien.gif') . "' style='vertical-align: top; height: 12px; border: 0px; width: ".$visites_abs."px;' alt= ' '/>"; |
||||
if ($largeur_rouge>0) echo "<img src='" . chemin_image('rien.gif') . "' class='couleur_cumul' style='vertical-align: top; height: 12px; border: 0px; width: " . $largeur_rouge . "px;' alt=' ' />"; |
||||
if ($largeur_vert>0) echo "<img src='" . chemin_image('rien.gif') . "' class='couleur_nombre' style='vertical-align: top; width: " . $largeur_vert ."px; height: 12px; border: 0px' alt=' ' />"; |
||||
echo "</div>"; |
||||
echo "</td></tr></table>\n"; |
||||
echo "</td></tr></table>"; |
||||
} |
||||
} |
||||
|
||||
if (isset($largeur_rouge) && ($largeur_rouge > 0)) { |
||||
$niveau++; |
||||
echo debut_block_depliable(false,"stats$id_rubrique"); |
||||
enfants_aff($id_rubrique,$largeur_rouge, $critere, $visites_abs+$gauche); |
||||
echo fin_block(); |
||||
$niveau--; |
||||
} |
||||
$visites_abs = $visites_abs + round($nombre_vis[$id_rubrique]/$abs_total*$taille); |
||||
} |
||||
} |
||||
|
||||
// http://doc.spip.org/@exec_statistiques_repartition_dist |
||||
function exec_statistiques_repartition_dist() |
||||
{ |
||||
|
||||
global $abs_total, $nombre_vis, $taille, $spip_ecran; |
||||
|
||||
if (!autoriser('voirstats')) { |
||||
include_spip('inc/minipres'); |
||||
echo minipres(); |
||||
} else { |
||||
|
||||
$taille = _request('taille'); |
||||
$commencer_page = charger_fonction('commencer_page', 'inc'); |
||||
echo $commencer_page(_T('titre_page_statistiques'), "statistiques_visites", "repartition"); |
||||
|
||||
echo debut_grand_cadre(true); |
||||
echo gros_titre(_T('titre_page_statistiques'),'',false); |
||||
|
||||
echo barre_onglets("statistiques", "statistiques_repartition"); |
||||
|
||||
if ($spip_ecran == "large") { |
||||
$largeur_table = 974; |
||||
$taille = 550; |
||||
} else { |
||||
$largeur_table = 750; |
||||
$taille = 400; |
||||
} |
||||
|
||||
echo "\n<br /><br /><table width='$largeur_table'><tr><td class='verdana2' style='text-align: center; width: $largeur_table" . "px;'>"; |
||||
$critere = _request('critere'); |
||||
|
||||
if ($critere == "debut") { |
||||
$critere = "visites"; |
||||
echo "<a href='".generer_url_ecrire('statistiques_repartition')."'>"._T('icone_repartition_actuelle').'</a>'; |
||||
echo " | <strong>"._T('onglet_repartition_debut').'</strong>'; |
||||
} |
||||
else { |
||||
$critere = "popularite"; |
||||
echo "<strong>"._T('icone_repartition_actuelle').'</strong>'; |
||||
echo " | <a href='".generer_url_ecrire('statistiques_repartition','critere=debut')."'>"._T('onglet_repartition_debut').'</a>'; |
||||
} |
||||
|
||||
$abs_total=enfants(0, $critere); |
||||
if ($abs_total<1) $abs_total=1; |
||||
$nombre_vis[0] = 0; |
||||
|
||||
echo debut_cadre_relief("statistiques-24.gif",true); |
||||
echo "<div style='border: 1px solid #aaaaaa; border-bottom: 0px;'>"; |
||||
enfants_aff(0,$taille, $critere); |
||||
echo "</div><br />", |
||||
"<div class='verdana3' style='text-align: left;'>", |
||||
_T('texte_signification'), |
||||
"</div>"; |
||||
echo fin_cadre_relief(true); |
||||
echo "</td></tr></table>"; |
||||
echo fin_grand_cadre(true),fin_page(); |
||||
} |
||||
} |
||||
?> |
@ -0,0 +1,179 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2009 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
|
||||
include_spip('inc/presentation'); |
||||
include_spip('inc/statistiques'); |
||||
|
||||
// http://doc.spip.org/@exec_statistiques_visites_dist |
||||
function exec_statistiques_visites_dist() |
||||
{ |
||||
$id_article = intval(_request('id_article')); |
||||
$type = _request('type'); |
||||
if (!preg_match('/^\w+$/', $type)) $type = 'day'; |
||||
$duree = intval(_request('duree')); |
||||
if (!$duree) $duree = 1825; |
||||
$interval = intval(_request('interval')); |
||||
if (!$interval) { |
||||
if ($type == 'day') |
||||
$interval = 3600*24; |
||||
else $interval = 3600; |
||||
} |
||||
|
||||
// nombre de referers a afficher |
||||
$limit = intval(_request('limit')); |
||||
if ($limit == 0) $limit = 100; |
||||
|
||||
if (!autoriser('voirstats', $id_article ? 'article':'', $id_article)) { |
||||
include_spip('inc/minipres'); |
||||
echo minipres(); |
||||
} else exec_statistiques_visites_args($id_article, $duree, $interval, $type, $limit); |
||||
} |
||||
|
||||
|
||||
// http://doc.spip.org/@exec_statistiques_visites_args |
||||
function exec_statistiques_visites_args($id_article, $duree, $interval, $type, $limit,$serveur='') |
||||
{ |
||||
$titre = $pourarticle = ""; |
||||
|
||||
if ($id_article){ |
||||
$row = sql_fetsel("titre, visites, popularite", "spip_articles", "statut='publie' AND id_article=$id_article",'','','','',$serveur); |
||||
|
||||
if ($row) { |
||||
$titre = typo($row['titre']); |
||||
$total_absolu = $row['visites']; |
||||
$val_popularite = round($row['popularite']); |
||||
} |
||||
} else { |
||||
$row = sql_fetsel("SUM(visites) AS total_absolu", "spip_visites",'','','','','',$serveur); |
||||
$total_absolu = $row ? $row['total_absolu'] : 0; |
||||
$val_popularite = 0; |
||||
} |
||||
|
||||
if ($titre) $pourarticle = " "._T('info_pour')." « $titre »"; |
||||
if ($serveur) { |
||||
if ($row = sql_fetsel('valeur','spip_meta',"nom='nom_site'",'','','','',$serveur)){ |
||||
$titre = $row['valeur'].($titre?" / $titre":""); |
||||
} |
||||
} |
||||
|
||||
$commencer_page = charger_fonction('commencer_page', 'inc'); |
||||
echo $commencer_page(_T('titre_page_statistiques_visites').$pourarticle, "statistiques_visites", "statistiques"); |
||||
echo gros_titre(_T('titre_evolution_visite')."<html>".aide("confstat")."</html>",'', false); |
||||
// barre_onglets("statistiques", "evolution"); |
||||
if ($titre) echo gros_titre($titre,'', false); |
||||
|
||||
echo barre_onglets("statistiques", "statistiques_visites"); |
||||
|
||||
echo debut_gauche('', true); |
||||
echo "<br />"; |
||||
echo "<div class='iconeoff' style='padding: 5px;'>"; |
||||
echo "<div class='verdana1 spip_x-small'>"; |
||||
echo typo(_T('info_afficher_visites')); |
||||
echo "<ul>"; |
||||
|
||||
if ($id_article>0) { |
||||
echo "<li><b><a href='" . generer_url_ecrire("statistiques_visites","") . "'>"._T('info_tout_site')."</a></b></li>"; |
||||
} else { |
||||
echo "<li><b>"._T('titre_page_articles_tous')."</b></li>"; |
||||
} |
||||
|
||||
echo "</ul>"; |
||||
echo "</div>"; |
||||
echo "</div>"; |
||||
|
||||
$classement = array(); |
||||
$liste = 0; |
||||
echo aff_statistique_visites_popularite($serveur, $id_article, $classement, $liste); |
||||
|
||||
// Par visites depuis le debut |
||||
$result = aff_statistique_visites_par_visites($serveur, $id_article, $classement); |
||||
|
||||
if ($result OR $id_article) |
||||
echo creer_colonne_droite('', true); |
||||
|
||||
if ($id_article) { |
||||
echo bloc_des_raccourcis(icone_horizontale(_T('icone_retour_article'), generer_url_ecrire("articles","id_article=$id_article"), "article-24.gif","rien.gif", false)); |
||||
} |
||||
echo $result; |
||||
|
||||
echo debut_droite('', true); |
||||
|
||||
if ($id_article) { |
||||
$table = "spip_visites_articles"; |
||||
$table_ref = "spip_referers_articles"; |
||||
$where = "id_article=$id_article"; |
||||
|
||||
} else { |
||||
$table = "spip_visites"; |
||||
$table_ref = "spip_referers"; |
||||
$where = ""; |
||||
} |
||||
|
||||
$order = "date"; |
||||
|
||||
$where2 = $duree ? "$order > DATE_SUB(".sql_quote(date('Y-m-d H:i:s')).",INTERVAL $duree $type)": ''; |
||||
if ($where) $where2 = $where2 ? "$where2 AND $where" : $where; |
||||
$log = statistiques_collecte_date('visites', "(CEIL(UNIX_TIMESTAMP($order) / $interval) * $interval)", $table, $where2, $serveur); |
||||
|
||||
|
||||
if ($log) |
||||
$res = statistiques_tous($log, $id_article, $table, $where, $order, $serveur, $duree, $interval, $total_absolu, $val_popularite, $liste, $classement); |
||||
|
||||
// installer les js |
||||
echo recuperer_fond('prive/stats/visites'); |
||||
echo cadre_stat($res, $table, $id_article); |
||||
|
||||
if ($id_article) { |
||||
$signatures = charger_fonction('signatures', 'statistiques'); |
||||
echo $signatures($duree, $interval, $type, $id_article, $serveur); |
||||
/* |
||||
Il faudra optimiser les requetes de ces stats c'est vraiment trop horrible : |
||||
plusieurs secondes d'attente sur un site comme contrib. |
||||
par ailleurs, l'affichage presente des defauts : |
||||
cf http://trac.rezo.net/trac/spip/ticket/1598 |
||||
$forums = charger_fonction('forums', 'statistiques'); |
||||
echo $forums($duree, $interval, $type, $id_article, $serveur); |
||||
*/ |
||||
} |
||||
|
||||
|
||||
$referenceurs = charger_fonction('referenceurs', 'inc'); |
||||
$res = $referenceurs($id_article, "visites", $table_ref, $where, '', $limit); |
||||
|
||||
if ($res) { |
||||
|
||||
// Le lien pour en afficher "plus" |
||||
$args = ($id_article?"id_article=$id_article&" : '') . "limit=" . strval($limit+200); |
||||
$n = count($res); |
||||
$plus = generer_url_ecrire('statistiques_visites', $args); |
||||
if ($plus) { |
||||
$plus = ($limit == $n) |
||||
? "<div style='text-align:right;'><b><a href='$plus'>+++</a></b></div>" |
||||
: ''; |
||||
} |
||||
$titre = _T("onglet_origine_visites") |
||||
. " ($n " |
||||
. ($n == 1 ? _T('info_site') : _T('info_sites')) |
||||
. ")"; |
||||
echo gros_titre($titre,'', false); |
||||
echo "<div style='overflow:hidden;' class='verdana1 spip_small'><br />"; |
||||
echo "<ul class='referers'><li>"; |
||||
echo join("</li><li>\n",$res); |
||||
echo "</li></ul>"; |
||||
echo $plus; |
||||
echo "<br /></div>"; |
||||
} |
||||
echo fin_gauche(), fin_page(); |
||||
} |
||||
?> |
@ -0,0 +1,42 @@
|
||||
<div class='formulaire_spip formulaire_configurer formulaire_configurer_compteur' id='formulaire_configurer_compteur'> |
||||
<h3 class='titrem'>[(#CHEMIN{images/statistiques-24.gif}|balise_img{'',cadre-icone})]<:info_forum_statistiques:> #AIDER{confstat}</h3> |
||||
|
||||
[<p class="reponse_formulaire reponse_formulaire_ok">(#ENV*{message_ok})</p>] |
||||
[<p class="reponse_formulaire reponse_formulaire_erreur">(#ENV*{message_erreur})</p>] |
||||
<form action="#ENV{action}#formulaire_configurer_compteur" method="post" enctype='multipart/form-data'><div> |
||||
[(#ACTION_FORMULAIRE{#ENV{action}})] |
||||
<ul> |
||||
<li class='configurer_activer_statistiques[ (#ENV**{erreurs}|table_valeur{activer_statistiques}|oui)erreur]'> |
||||
<label><:info_question_gerer_statistiques:></label> |
||||
[<span class='erreur_message'>(#ENV**{erreurs}|table_valeur{activer_statistiques})</span>] |
||||
<div class='choix'> |
||||
<input class='checkbox' type="checkbox" name="activer_statistiques" value='oui' [checked="(#ENV{activer_statistiques}|=={oui}|?{checked})"] id="activer_statistiques"/> |
||||
<label for="activer_statistiques"><:item_gerer_statistiques:></label> |
||||
</div> |
||||
</li> |
||||
<li class='configurer_activer_captures_referers[ (#ENV**{erreurs}|table_valeur{activer_captures_referers}|oui)erreur]'> |
||||
<div class='explication'><:info_question_vignettes_referer:></div> |
||||
[<span class='erreur_message'>(#ENV**{erreurs}|table_valeur{activer_captures_referers})</span>] |
||||
<div class='choix'> |
||||
<input class='checkbox' type="checkbox" name="activer_captures_referers" value='oui' [checked="(#ENV{activer_captures_referers}|=={oui}|?{checked})"] id="activer_captures_referers"/> |
||||
<label for="activer_captures_referers"><:info_question_vignettes_referer_oui:></label> |
||||
</div> |
||||
</li> |
||||
|
||||
</ul> |
||||
<p class='boutons'><input class='submit' type="submit" name="ok" value="<:bouton_enregistrer:>"/></p> |
||||
</div></form> |
||||
|
||||
</div> |
||||
<script type='text/javascript'> |
||||
function actualise_capture_referers(){ |
||||
if (jQuery('#activer_statistiques').attr('checked')) |
||||
jQuery('#formulaire_configurer_compteur li.configurer_activer_captures_referers').show(); |
||||
else |
||||
jQuery('#formulaire_configurer_compteur li.configurer_activer_captures_referers').hide(); |
||||
} |
||||
jQuery(document).ready(function(){ |
||||
jQuery('#activer_statistiques').bind('change',actualise_capture_referers); |
||||
actualise_capture_referers(); |
||||
}); |
||||
</script> |
@ -0,0 +1,44 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2009 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
|
||||
function formulaires_configurer_compteur_charger_dist(){ |
||||
|
||||
$valeurs = array(); |
||||
|
||||
$valeurs['activer_statistiques'] = $GLOBALS['meta']['activer_statistiques']; |
||||
$valeurs['activer_captures_referers'] = $GLOBALS['meta']['activer_captures_referers']; |
||||
|
||||
return $valeurs; |
||||
|
||||
} |
||||
|
||||
function formulaires_configurer_compteur_verifier_dist(){ |
||||
$erreurs = array(); |
||||
|
||||
// les checkbox |
||||
foreach(array('activer_statistiques','activer_captures_referers') as $champ) |
||||
if (_request($champ)!='oui') |
||||
set_request($champ,'non'); |
||||
|
||||
return $erreurs; |
||||
} |
||||
|
||||
function formulaires_configurer_compteur_traiter_dist(){ |
||||
include_spip('inc/config'); |
||||
appliquer_modifs_config(); |
||||
|
||||
return array('message_ok'=>_T('config_info_enregistree')); |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,83 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2009 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
|
||||
// |
||||
// Popularite, modele logarithmique |
||||
// |
||||
function genie_popularite_constantes($duree){ |
||||
// duree de demi-vie d'une visite dans le calcul de la popularite (en jours) |
||||
$demivie = 0.5; |
||||
// periode de reference en jours |
||||
$periode = 1; |
||||
// $a est le coefficient d'amortissement depuis la derniere mesure |
||||
$a = pow(2, - $duree / ($demivie * 24 * 3600)); |
||||
// $b est la constante multiplicative permettant d'avoir |
||||
// une visite par jour (periode de reference) = un point de popularite |
||||
// (en regime stationnaire) |
||||
// or, magie des maths, ca vaut log(2) * duree journee/demi-vie |
||||
// si la demi-vie n'est pas trop proche de la seconde ;) |
||||
$b = log(2) * $periode / $demivie; |
||||
|
||||
return array($a,$b); |
||||
} |
||||
|
||||
// http://doc.spip.org/@genie_popularites_dist |
||||
function genie_popularites_dist($t) { |
||||
|
||||
// Si c'est le premier appel, ne pas calculer |
||||
$t = $GLOBALS['meta']['date_popularites']; |
||||
ecrire_meta('date_popularites', time()); |
||||
|
||||
if (!$t) |
||||
return 1; |
||||
|
||||
$duree = time() - $t; |
||||
list($a,$b) = genie_popularite_constantes($duree); |
||||
|
||||
// du passe, faisons table (SQL) rase |
||||
sql_update('spip_articles', array('maj'=>'maj', 'popularite' => "popularite * $a")); |
||||
|
||||
// enregistrer les metas... |
||||
$row = sql_fetsel('MAX(popularite) AS max, SUM(popularite) AS tot', "spip_articles"); |
||||
ecrire_meta("popularite_max", $row['max']); |
||||
ecrire_meta("popularite_total", $row['tot']); |
||||
|
||||
|
||||
// Une fois par jour purger les referers du jour ; qui deviennent |
||||
// donc ceux de la veille ; au passage on stocke une date_statistiques |
||||
// dans spip_meta - cela permet au code d'etre "reentrant", ie ce cron |
||||
// peut etre appele par deux bases SPIP ne partageant pas le meme |
||||
// _DIR_TMP, sans tout casser... |
||||
|
||||
$aujourdhui = date("Y-m-d"); |
||||
if (($d = $GLOBALS['meta']['date_statistiques']) != $aujourdhui) { |
||||
spip_log("Popularite: purger referer depuis $d"); |
||||
ecrire_meta('date_statistiques', $aujourdhui); |
||||
#spip_query("UPDATE spip_referers SET visites_veille=visites_jour, visites_jour=0"); |
||||
// version 3 fois plus rapide, mais en 2 requetes |
||||
#spip_query("ALTER TABLE spip_referers CHANGE visites_jour visites_veille INT( 10 ) UNSIGNED NOT NULL DEFAULT '0',CHANGE visites_veille visites_jour INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'"); |
||||
#spip_query("UPDATE spip_referers SET visites_jour=0"); |
||||
// version 4 fois plus rapide que la premiere, en une seule requete |
||||
sql_alter("TABLE spip_referers DROP visites_veille, |
||||
CHANGE visites_jour visites_veille INT(10) UNSIGNED NOT NULL DEFAULT '0', |
||||
ADD visites_jour INT(10) UNSIGNED NOT NULL DEFAULT '0'"); |
||||
} |
||||
|
||||
// et c'est fini pour cette fois-ci |
||||
return 1; |
||||
|
||||
} |
||||
|
||||
?> |
||||
|
@ -0,0 +1,224 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2009 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
@define('_CRON_LOT_FICHIERS_VISITE',100); |
||||
|
||||
### Pour se debarrasser du md5, comment faire ? Un index sur 'referer' ? |
||||
### ou alors la meme notion, mais sans passer par des fonctions HEX ? |
||||
|
||||
// |
||||
// prendre en compte un fichier de visite |
||||
// |
||||
// http://doc.spip.org/@compte_fichier_visite |
||||
function compte_fichier_visite($fichier, &$visites, &$visites_a, &$referers, &$referers_a) { |
||||
|
||||
// Noter la visite du site (article 0) |
||||
$visites ++; |
||||
|
||||
$content = array(); |
||||
if (lire_fichier($fichier, $content)) |
||||
$content = @unserialize($content); |
||||
if (!is_array($content)) return; |
||||
|
||||
foreach ($content as $source => $num) { |
||||
list($log_type, $log_id_num, $log_referer) |
||||
= preg_split(",\t,", $source, 3); |
||||
|
||||
// Noter le referer |
||||
if ($log_referer) |
||||
$referers[$log_referer]++; |
||||
|
||||
// S'il s'agit d'un article, noter ses visites |
||||
if ($log_type == 'article' |
||||
AND $id_article = intval($log_id_num)) { |
||||
$visites_a[$id_article] ++; |
||||
if ($log_referer) |
||||
$referers_a[$id_article][$log_referer]++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
// http://doc.spip.org/@calculer_visites |
||||
function calculer_visites($t) { |
||||
include_spip('base/abstract_sql'); |
||||
|
||||
// Initialisations |
||||
$visites = array(); # visites du site |
||||
$visites_a = array(); # tableau des visites des articles |
||||
$referers = array(); # referers du site |
||||
$referers_a = array(); # tableau des referers des articles |
||||
|
||||
// charger un certain nombre de fichiers de visites, |
||||
// et faire les calculs correspondants |
||||
|
||||
// Traiter jusqu'a 100 sessions datant d'au moins 30 minutes |
||||
$sessions = preg_files(sous_repertoire(_DIR_TMP, 'visites')); |
||||
|
||||
$compteur = _CRON_LOT_FICHIERS_VISITE; |
||||
$date_init = time()-30*60; |
||||
foreach ($sessions as $item) { |
||||
if (($d=@filemtime($item)) < $date_init) { |
||||
if (!$d) $d = $date_init; // si le fs ne donne pas de date, on prend celle du traitement, mais tout cela risque d'etre bien douteux |
||||
$d = date("Y-m-d",$d); |
||||
spip_log("traite la session $item"); |
||||
compte_fichier_visite($item, |
||||
$visites[$d], $visites_a[$d], $referers[$d], $referers_a[$d]); |
||||
spip_unlink($item); |
||||
if (--$compteur <= 0) |
||||
break; |
||||
} |
||||
#else spip_log("$item pas vieux"); |
||||
} |
||||
if (!count($visites)) |
||||
return; |
||||
|
||||
include_spip('genie/popularites'); |
||||
list($a,$b) = genie_popularite_constantes(24*3600); |
||||
|
||||
// Maintenant on dispose de plusieurs tableaux qu'il faut ventiler dans |
||||
// les tables spip_visites, spip_visites_articles, spip_referers |
||||
// et spip_referers_articles ; attention a affecter tout ca a la bonne |
||||
// date (celle de la visite, pas celle du traitement) |
||||
foreach(array_keys($visites) as $date) |
||||
if ($visites[$date]) { |
||||
|
||||
// 1. les visites du site (facile) |
||||
if (!sql_countsel('spip_visites', "date='$date'")) |
||||
sql_insertq('spip_visites', |
||||
array('date' => $date, 'visites' => $visites[$date])); |
||||
else |
||||
sql_update('spip_visites', array('visites' => "visites+".intval($visites[$date])), "date='$date'"); |
||||
|
||||
// 2. les visites des articles |
||||
if ($visites_a[$date]) { |
||||
$ar = array(); # tableau num -> liste des articles ayant num visites |
||||
foreach($visites_a[$date] as $id_article => $n) { |
||||
if (!sql_countsel('spip_visites_articles', |
||||
"id_article=$id_article AND date='$date'")){ |
||||
sql_insertq('spip_visites_articles', |
||||
array('id_article' => $id_article, |
||||
'visites' => 0, |
||||
'date' => $date)); |
||||
} |
||||
$ar[$n][] = $id_article; |
||||
} |
||||
foreach ($ar as $n => $liste) { |
||||
$tous = sql_in('id_article', $liste); |
||||
sql_update('spip_visites_articles', |
||||
array('visites' => "visites+$n"), |
||||
"date='$date' AND $tous"); |
||||
|
||||
$ref = $noref = array(); |
||||
foreach($liste as $id) { |
||||
if (isset($referers_a[$id])) |
||||
$ref[]= $id ; |
||||
else $noref[]=$id; |
||||
} |
||||
// il faudrait ponderer la popularite ajoutee ($n) par son anciennete eventuelle |
||||
// sur le modele de ce que fait genie/popularites |
||||
if (count($noref)) |
||||
sql_update('spip_articles', |
||||
array('visites' => "visites+$n", |
||||
'popularite' => "popularite+".round($n*$b,2), |
||||
'maj' => 'maj'), |
||||
sql_in('id_article',$noref)); |
||||
|
||||
if (count($ref)) |
||||
sql_update('spip_articles', |
||||
array('visites' => "visites+".($n+1), |
||||
'popularite' => "popularite+".round($n*$b,2), |
||||
'maj' => 'maj'), |
||||
sql_in('id_article',$ref)); |
||||
|
||||
## Ajouter un JOIN sur le statut de l'article ? |
||||
} |
||||
} |
||||
// 3. Les referers du site |
||||
// insertion pour les nouveaux, au tableau des increments sinon |
||||
if ($referers[$date]) { |
||||
$ar = array(); |
||||
$trouver_table = charger_fonction('trouver_table', 'base'); |
||||
$desc = $trouver_table('referers'); |
||||
$n = preg_match('/(\d+)/',$desc['field']['referer'], $r); |
||||
$n = $n ? $r[1] : 255; |
||||
foreach ($referers[$date] as $referer => $num) { |
||||
$referer_md5 = sql_hex(substr(md5($referer), 0, 15)); |
||||
$referer = substr($referer,0,$n); |
||||
if (!sql_countsel('spip_referers', "referer_md5=$referer_md5")) |
||||
sql_insertq('spip_referers', |
||||
array('visites' => $num, |
||||
'visites_jour' => $num, |
||||
'visites_veille' => $num, |
||||
'date' => $date, |
||||
'referer' => $referer, |
||||
'referer_md5' => $referer_md5)); |
||||
else $ar[$num][] = $referer_md5; |
||||
} |
||||
|
||||
// appliquer les increments sur les anciens |
||||
// attention on appelle sql_in en mode texte et pas array |
||||
// pour ne pas passer sql_quote() sur les '0x1234' de referer_md5, cf #849 |
||||
foreach ($ar as $num => $liste) { |
||||
sql_update('spip_referers', array('visites' => "visites+$num", 'visites_jour' => "visites_jour+$num"), sql_in('referer_md5',join(', ', $liste))); |
||||
} |
||||
} |
||||
|
||||
// 4. Les referers d'articles |
||||
if ($referers_a[$date]) { |
||||
$ar = array(); |
||||
$insert = array(); |
||||
// s'assurer d'un slot pour chacun |
||||
foreach ($referers_a[$date] as $id_article => $referers) |
||||
foreach ($referers as $referer => $num) { |
||||
$referer_md5 = sql_hex(substr(md5($referer), 0, 15)); |
||||
$prim = "(id_article=$id_article AND referer_md5=$referer_md5)"; |
||||
if (!sql_countsel('spip_referers_articles', $prim)) |
||||
sql_insertq('spip_referers_articles', |
||||
array('visites' => $num, |
||||
'id_article' => $id_article, |
||||
'referer' => $referer, |
||||
'referer_md5' => $referer_md5)); |
||||
else $ar[$num][] = $prim; |
||||
} |
||||
// ajouter les visites |
||||
foreach ($ar as $num => $liste) { |
||||
sql_update('spip_referers_articles', array('visites' => "visites+$num"), join(" OR ", $liste)); |
||||
## Ajouter un JOIN sur le statut de l'article ? |
||||
} |
||||
} |
||||
} |
||||
|
||||
// S'il reste des fichiers a manger, le signaler pour reexecution rapide |
||||
if ($compteur==0) { |
||||
spip_log("il reste des visites a traiter..."); |
||||
return -$t; |
||||
} |
||||
} |
||||
|
||||
// |
||||
// Calcule les stats en plusieurs etapes |
||||
// |
||||
// http://doc.spip.org/@genie_visites_dist |
||||
function genie_visites_dist($t) { |
||||
$encore = calculer_visites($t); |
||||
|
||||
// Si ce n'est pas fini on redonne la meme date au fichier .lock |
||||
// pour etre prioritaire lors du cron suivant |
||||
if ($encore) |
||||
return (0 - $t); |
||||
|
||||
return 1; |
||||
} |
||||
?> |
@ -0,0 +1,241 @@
|
||||
<?php |
||||
|
||||
// |
||||
// Afficher les referers d'un article (ou du site) |
||||
// |
||||
|
||||
// http://doc.spip.org/@inc_referenceurs_dist |
||||
function inc_referenceurs_dist ($id_article, $select, $table, $where, $groupby, $limit, $serveur='') { |
||||
|
||||
$nbvisites = $lescriteres = array(); |
||||
|
||||
$result = sql_select("referer_md5, referer, $select AS vis", $table, $where, $groupby, "vis DESC", $limit,'',$serveur); |
||||
while ($row = sql_fetch($result,$serveur)) { |
||||
$referer = interdire_scripts($row['referer']); |
||||
$buff = stats_show_keywords($referer, $referer); |
||||
|
||||
if ($buff["host"]) { |
||||
$numero = $buff["hostname"]; |
||||
$visites = $row['vis']; |
||||
$referermd5 = $row['referer_md5']; |
||||
$lesreferermd5[$numero] = $referermd5; |
||||
$lesliens[$numero] = $referer; |
||||
$lesurls[$numero] = $buff["host"]; |
||||
if (!isset($nbvisites[$numero])) |
||||
$nbvisites[$numero] = $visites; |
||||
$nbvisites[$numero] += $visites; |
||||
if (!isset($lesreferers[$numero])) |
||||
$lesreferers[$numero] = array(); |
||||
if (!isset($lesliensracine[$numero])) |
||||
$lesliensracine[$numero]=0; |
||||
|
||||
if (isset($buff["keywords"]) |
||||
AND $c = $buff["keywords"]) { |
||||
if (!isset($lescriteres[$numero][$c])) { |
||||
$lescriteres[$numero][$c] = true; |
||||
$tmp= " « $c »"; |
||||
} else $tmp = ""; |
||||
} else { |
||||
$tmp = $buff["path"]; |
||||
if ($buff["query"]) |
||||
$tmp .= "?".$buff['query']; |
||||
if (strlen($tmp) > 18) |
||||
$tmp = "/".substr($tmp, 0, 15)."..."; |
||||
else if (strlen($tmp) > 0) |
||||
$tmp = "/$tmp"; |
||||
} |
||||
if ($tmp) { |
||||
$lesreferers[$numero][] = "<a href=\"".attribut_html($referer)."\">".quote_amp(urldecode($tmp))."</a>" . (($visites > 1)?" ($visites)":""). ($id_article ? '' : referes($referermd5)); |
||||
} else $lesliensracine[$numero] += $visites; |
||||
} |
||||
} |
||||
|
||||
if (!count($nbvisites)) return array(); |
||||
arsort($nbvisites); |
||||
return referers_group($nbvisites, $id_article, $lesliensracine, $lesreferermd5, $lesreferers, $lesurls); |
||||
} |
||||
|
||||
function referers_group($nbvisites, $id_article, $lesliensracine, $lesreferermd5, $lesreferers, $lesurls) |
||||
{ |
||||
global $spip_lang_right, $source_vignettes; |
||||
$vign = ((strlen($source_vignettes) > 0) && |
||||
$GLOBALS['meta']["activer_captures_referers"]!='non'); |
||||
$aff = array(); |
||||
foreach($nbvisites as $numero => $visites) { |
||||
if (!$numero) next; |
||||
$referermd5 = $lesreferermd5[$numero]; |
||||
$bouton = $ret = ""; |
||||
|
||||
if ($vign) |
||||
$ret = "\n<a href=\"http://".$lesurls[$numero]."\"><img src=\"$source_vignettes".rawurlencode($lesurls[$numero])."\"\nstyle=\"float: $spip_lang_right; margin-bottom: 3px; margin-left: 3px;\" alt='' /></a>"; |
||||
|
||||
if ($visites > 5) $bouton .= "<span class='visites visites3'>$visites "._T('info_visites')."</span> "; |
||||
else if ($visites > 1) $bouton .= "<span class='visites visites2'>$visites "._T('info_visites')."</span> "; |
||||
else $bouton .= "<span class='visites visites1'>$visites "._T('info_visite')."</span> "; |
||||
|
||||
if ($numero == "(email)") { |
||||
$ret .= $bouton . "<b>".$numero."</b>"; |
||||
} else { |
||||
$n = count($lesreferers[$numero]); |
||||
if (($n > 1) || ($n > 0 && substr(supprimer_tags($lesreferers[$numero][0]),0,1) != '/')) { |
||||
$rac = $lesliensracine[$numero]; |
||||
$bouton .= "<a href=\"http://".attribut_html($lesurls[$numero])."\" style='font-weight: bold;'>".$numero."</a>" |
||||
. (!$rac ? '': (" <span class='spip_x-small'>(" . $rac .")</span>")); |
||||
$ret .= bouton_block_depliable($bouton,false) |
||||
. debut_block_depliable(false) |
||||
. "\n<ul><li>" |
||||
. join ("</li><li>",$lesreferers[$numero]) |
||||
. "</li></ul>" |
||||
. fin_block(); |
||||
} else { |
||||
$ret .= $bouton; |
||||
$lien = $n ? $lesreferers[$numero][0] : ''; |
||||
if (preg_match(",^(<a [^>]+>)([^ ]*)( \([0-9]+\))?,i", $lien, $regs)) { |
||||
$lien = quote_amp($regs[1]).$numero.$regs[2]; |
||||
if (!strpos($lien, '</a>')) $lien .= '</a>'; |
||||
} else |
||||
$lien = "<a href=\"http://".attribut_html($numero)."\">".$numero."</a>"; |
||||
$ret .= "<b>".quote_amp($lien)."</b>" |
||||
. ($id_article ? '' : referes($referermd5)); |
||||
} |
||||
} |
||||
$aff[]= $ret; |
||||
} |
||||
return $aff; |
||||
} |
||||
|
||||
// Les deux fonctions suivantes sont adaptees du code des "Visiteurs", |
||||
// par Jean-Paul Dezelus (http://www.phpinfo.net/applis/visiteurs/) |
||||
|
||||
// http://doc.spip.org/@stats_load_engines |
||||
function stats_load_engines() { |
||||
$arr_engines = Array(); |
||||
lire_fichier(find_in_path('engines-list.txt'), $moteurs); |
||||
foreach (array_filter(preg_split("/([\r\n]|#.*)+/", $moteurs)) as $ligne) { |
||||
$ligne = trim($ligne); |
||||
if (preg_match(',^\[([^][]*)\]$,S', $ligne, $regs)) { |
||||
$moteur = $regs[1]; |
||||
$query = ''; |
||||
} else if (preg_match(',=$,', $ligne, $regs)) |
||||
$query = $ligne; |
||||
else |
||||
$arr_engines[] = array($moteur,$query,$ligne); |
||||
} |
||||
return $arr_engines; |
||||
} |
||||
|
||||
// http://doc.spip.org/@stats_show_keywords |
||||
function stats_show_keywords($kw_referer, $kw_referer_host) { |
||||
static $arr_engines = ''; |
||||
static $url_site; |
||||
|
||||
if (!is_array($arr_engines)) { |
||||
// Charger les moteurs de recherche |
||||
$arr_engines = stats_load_engines(); |
||||
|
||||
// initialiser la recherche interne |
||||
$url_site = $GLOBALS['meta']['adresse_site']; |
||||
$url_site = preg_replace(",^((https?|ftp):?/?/?)?(www\.)?,", "", strtolower($url_site)); |
||||
} |
||||
|
||||
if ($url = @parse_url( $kw_referer )) { |
||||
$query = isset($url['query'])?$url['query']:""; |
||||
$host = strtolower($url['host']); |
||||
$path = $url['path']; |
||||
} else $query = $host = $path =''; |
||||
|
||||
// Cette fonction affecte directement les variables selon la query-string ! |
||||
parse_str($query); |
||||
|
||||
$keywords = ''; |
||||
$found = false; |
||||
|
||||
if (!empty($url_site)) { |
||||
if (strpos('-'.$kw_referer, $url_site)!==false) { |
||||
if (preg_match(",(s|search|r|recherche)=([^&]+),i", $kw_referer, $regs)) |
||||
$keywords = urldecode($regs[2]); |
||||
|
||||
|
||||
else |
||||
return array('host' => ''); |
||||
} else |
||||
for ($cnt = 0; $cnt < sizeof($arr_engines) && !$found; $cnt++) |
||||
{ |
||||
if ( $found = preg_match(','.$arr_engines[$cnt][2].',', $host) |
||||
OR $found = preg_match(','.$arr_engines[$cnt][2].',', $path)) |
||||
{ |
||||
$kw_referer_host = $arr_engines[$cnt][0]; |
||||
|
||||
if (strpos($arr_engines[$cnt][1],'=')!==false) { |
||||
|
||||
// Fonctionnement simple: la variable existe |
||||
$v = str_replace('=', '', $arr_engines[$cnt][1]); |
||||
$keywords = isset($$v)?$$v:""; |
||||
|
||||
// Si on a defini le nom de la variable en expression reguliere, chercher la bonne variable |
||||
if (! strlen($keywords) > 0) { |
||||
if (preg_match(",".$arr_engines[$cnt][1]."([^\&]*),", $query, $vals)) { |
||||
$keywords = urldecode($vals[2]); |
||||
} |
||||
} |
||||
} else { |
||||
$keywords = ""; |
||||
} |
||||
|
||||
if (( ($kw_referer_host == "Google") |
||||
|| ($kw_referer_host == "AOL" && strpos($query,'enc=iso')===false) |
||||
|| ($kw_referer_host == "MSN") |
||||
)) { |
||||
include_spip('inc/charsets'); |
||||
if (!isset($ie) OR !$cset = $ie) $cset = 'utf-8'; |
||||
$keywords = importer_charset($keywords,$cset); |
||||
} |
||||
$buffer["hostname"] = $kw_referer_host; |
||||
} |
||||
} |
||||
} |
||||
|
||||
$buffer["host"] = $host; |
||||
if (!isset($buffer["hostname"]) OR !$buffer["hostname"]) |
||||
$buffer["hostname"] = $host; |
||||
|
||||
$buffer["path"] = substr($path, 1, strlen($path)); |
||||
$buffer["query"] = $query; |
||||
|
||||
if ($keywords != '') |
||||
{ |
||||
if (strlen($keywords) > 150) { |
||||
$keywords = spip_substr($keywords, 0, 148); |
||||
// supprimer l'eventuelle entite finale mal coupee |
||||
$keywords = preg_replace('/&#?[a-z0-9]*$/', '', $keywords); |
||||
} |
||||