X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=www%2Fplugins-dist%2Fstatistiques%2Finc%2Freferenceurs.php;h=80a78f9c316be34472eba570617be0fb79ad2845;hb=0f3ef482e6020c572ea3221db6ab5165772c22e9;hp=11e9ea821bf3efe4d3937376589d423ac8deb841;hpb=122c920eb07e3f665789f8734965b576e6c25515;p=lhc%2Fweb%2Fwww.git diff --git a/www/plugins-dist/statistiques/inc/referenceurs.php b/www/plugins-dist/statistiques/inc/referenceurs.php index 11e9ea82..80a78f9c 100644 --- a/www/plugins-dist/statistiques/inc/referenceurs.php +++ b/www/plugins-dist/statistiques/inc/referenceurs.php @@ -3,56 +3,62 @@ /***************************************************************************\ * SPIP, Systeme de publication pour l'internet * * * - * Copyright (c) 2001-2014 * + * Copyright (c) 2001-2016 * * 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; +if (!defined("_ECRIRE_INC_VERSION")) { + return; +} /** * Recuperer la liste des moteurs de recherche depuis un fichier txt * Adaptees du code des "Visiteurs", * par Jean-Paul Dezelus (http://www.phpinfo.net/applis/visiteurs/) * - * http://doc.spip.org/@stats_load_engines + * https://code.spip.net/@stats_load_engines * * @return array */ -function stats_load_engines(){ - $arr_engines = Array(); +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){ + foreach (array_filter(preg_split("/([\r\n]|#.*)+/", $moteurs)) as $ligne) { $ligne = trim($ligne); - if (preg_match(',^\[([^][]*)\]$,S', $ligne, $regs)){ + 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); + } else { + if (preg_match(',=$,', $ligne, $regs)) { + $query = $ligne; + } else { + $arr_engines[] = array($moteur, $query, $ligne); + } + } } + return $arr_engines; } /** * Retrouver les mots cles de recherche dans une url de referer - * + * * Adaptees du code des "Visiteurs", * par Jean-Paul Dezelus (http://www.phpinfo.net/applis/visiteurs/) * - * http://doc.spip.org/@stats_show_keywords + * https://code.spip.net/@stats_show_keywords * * @param string $kw_referer * @return array */ -function stats_show_keywords($kw_referer){ +function stats_show_keywords($kw_referer) { static $arr_engines = ''; static $url_site; - if (!is_array($arr_engines)){ + if (!is_array($arr_engines)) { // Charger les moteurs de recherche $arr_engines = stats_load_engines(); @@ -61,14 +67,14 @@ function stats_show_keywords($kw_referer){ $url_site = preg_replace(",^((https?|ftp):?/?/?)?(www\.)?,", "", strtolower($url_site)); } - if ($url = @parse_url($kw_referer)){ + if ($url = @parse_url($kw_referer)) { $query = isset($url['query']) ? $url['query'] : ""; - $host = strtolower($url['host']); - $path = $url['path']; - $scheme = $url['scheme']; - } - else + $host = isset($url['host']) ? strtolower($url['host']) : ""; + $path = isset($url['path']) ? $url['path'] : ""; + $scheme = isset($url['scheme']) ? $url['scheme'] : ""; + } else { $scheme = $query = $host = $path = ''; + } // construire un array des variables directement depuis la query-string parse_str($query, $Tquery); @@ -76,29 +82,29 @@ function stats_show_keywords($kw_referer){ $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)) + 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 + } else { return array('host' => ''); - } - else { - for ($cnt = 0; $cnt0){ - if (preg_match(",".$arr_engines[$cnt][1]."([^\&]*),", $query, $vals)){ + if (!empty($keywords) AND !strlen($keywords) > 0) { + if (preg_match("," . $arr_engines[$cnt][1] . "([^\&]*),", $query, $vals)) { $keywords = urldecode($vals[2]); } } @@ -106,12 +112,14 @@ function stats_show_keywords($kw_referer){ $keywords = ""; } - if (($kw_referer_host=="Google") - || ($kw_referer_host=="AOL" && strpos($query, 'enc=iso')===false) - || ($kw_referer_host=="MSN") - ){ + 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'; + if (!isset($ie) or !$cset = $ie) { + $cset = 'utf-8'; + } $keywords = importer_charset($keywords, $cset); } $buffer["hostname"] = $kw_referer_host; @@ -122,14 +130,15 @@ function stats_show_keywords($kw_referer){ $buffer["host"] = $host; $buffer["scheme"] = $scheme; - if (!isset($buffer["hostname"]) OR !$buffer["hostname"]) + 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){ + 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); @@ -143,27 +152,30 @@ function stats_show_keywords($kw_referer){ /** * Recherche des articles pointes par le referer - * http://doc.spip.org/@referes + * https://code.spip.net/@referes * * @param $referermd5 * @param string $serveur * @return string */ -function referes($referermd5, $serveur = ''){ - $retarts = sql_allfetsel('J2.id_article, J2.titre', 'spip_referers_articles AS J1 LEFT JOIN spip_articles AS J2 ON J1.id_article = J2.id_article', "(referer_md5='$referermd5' AND J1.maj>=DATE_SUB(".sql_quote(date('Y-m-d H:i:s')).", INTERVAL 2 DAY))", '', "titre", '', '', $serveur); +function referes($referermd5, $serveur = '') { + $retarts = sql_allfetsel('J2.id_article, J2.titre', + 'spip_referers_articles AS J1 LEFT JOIN spip_articles AS J2 ON J1.id_article = J2.id_article', + "(referer_md5='$referermd5' AND J1.maj>=DATE_SUB(" . sql_quote(date('Y-m-d H:i:s')) . ", INTERVAL 2 DAY))", '', + "titre", '', '', $serveur); - foreach ($retarts as $k => $rowart){ + foreach ($retarts as $k => $rowart) { $titre = typo($rowart['titre']); - $url = generer_url_entite($rowart['id_article'], 'article', '', '', TRUE); + $url = generer_url_entite($rowart['id_article'], 'article', '', '', true); $retarts[$k] = "$titre"; } - if (count($retarts)>1) - return '→ '.join(',
→ ', $retarts); - if (count($retarts)==1) - return '→ '.array_shift($retarts); + if (count($retarts) > 1) { + return '→ ' . join(',
→ ', $retarts); + } + if (count($retarts) == 1) { + return '→ ' . array_shift($retarts); + } + return ''; } - - -?>