espace-couture-sittler.fr /spip/ecrire/inc/referenceurs.php

Language PHP Lines 245
MD5 Hash a9292604d7745ac1d04a79a176b0395b
Repository https://github.com/eyeswebcrea/espace-couture-sittler.fr.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php

if (!defined('_ECRIRE_INC_VERSION')) return;

//
// 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("maj, referer_md5, referer, $select AS vis", $table, $where, $groupby, "maj 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;
			else
				$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= " &laquo;&nbsp;$c&nbsp;&raquo;";
				} 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);
		}
		$buffer["keywords"] = trim(entites_html(urldecode(stripslashes($keywords))));
	}

	return $buffer;

}


//
// Recherche des articles pointes par le referer
//
// http://doc.spip.org/@referes
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) {
		$titre = typo($rowart['titre']);
		$url = generer_url_entite($rowart['id_article'], 'article');
		$retarts[$k] = "<a href='$url'><i>$titre</i></a>";
	}

	if (count($retarts) > 1)
		return '<br />&rarr; '.join(',<br />&rarr; ',$retarts);
	if (count($retarts) == 1)
		return '<br />&rarr; '. array_shift($retarts);
	return '';
}


?>
Back to Top