-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.php
More file actions
345 lines (270 loc) · 12 KB
/
print.php
File metadata and controls
345 lines (270 loc) · 12 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<form action="print.php" method="post">
<p>Rechercher: <input type="text" name="nom" /></p>
<p><input type="submit" value="OK"></p>
</form>
<a href="http://www.plafond-tendu.net/atom/print.php?action=print">
Afficher liste.
</a>
<?php
/* http://www.plafond-tendu.net/atom/print.php?action=recherche&q=mot
*/
$filename = 'tagliste.v2'; // pour créer une nouvelle liste changer le nom ici.
$action = $_GET['action'];
$index = $_GET['q'];
if (htmlspecialchars($_POST['nom']) != null){
$index = htmlspecialchars($_POST['nom']);
$action = 'recherche';
}
if ($action == 'recherche' && $filename != null){
$somecontent = jecherche($index,$filename);
}else{
if ($action == 'print'){
$somecontent = generation('',$filename);
}
}
function multiexplode ($delimiters,$string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return $launch;
}
function jecherche ($text,$filename) {
echo 'Chargement du fichier: '.$filename;
// On récupère la liste actuel:
$html = file_get_contents($filename);
// suppression des chiffres
$testexplode =ereg_replace("[0-9]","",$html);
//Suppression saut de ligne
$testexplode = strtr($testexplode, "\r\n\t\s", ",,,,");
// Création du tableau des valeurs: entre 15 et 35
$testexplode = wordwrap($testexplode, 20, ",", false);
$keywords = multiexplode(array(",",".","|",":"," ","~"),$testexplode);
// suppression des valeurs null
$keywords = array_filter($keywords);
//--------------------------------------------------------------------------------------------------------------
echo '<br>'.'Nombre de mots actuellement connus: '.count($keywords).'<br>';
// filtre des doublons
$keywords = array_unique($keywords);
$key = array_search(strtolower($text),array_map('strtolower',$keywords));
//$key = array_search($text, $keywords); // $key = 2;
echo '<br>';
if ($key == null){
echo 'valeur inconnu'.'<br>';
}else{
echo $keywords[$key].'<br>';
echo 'valeur connu'.'<br>';
print_r ($key);
}
return $key;
}
// *******************************************************************************************************************************
// *******************************************************************************************************************************
// Rechercher sur Spin
function SpinSearch($txt, $rechercher){
function filter_by_value ($array, $value){
if(is_array($array) && count($array)>0)
{
$keynew =0;
foreach(array_keys($array) as $key){
$temp[$key] = $array[$key];
//$regx = '/'.$rechercher.'/';
// if (preg_match($regx,$keywords)){
if (stristr($temp[$key], $value)){
$newarray[$keynew] = $array[$key];
$keynew = $keynew+1;
}
}
}
return $newarray;
}
$pattern = '#\{([^{}]*)\}#msi';
$test = preg_match_all($pattern, $txt, $out);
$toFind = Array();
$toReplace = Array();
foreach($out[0] AS $id => $match){
$choices = explode("~", $out[1][$id]);
// On filtre la liste de valeur:
$choices = filter_by_value($choices,$rechercher);
ksort($choices);
//$choices = array_filter($choices ,'is_string');
//print_r ($choices);
//echo "<br>";
$toFind[]=$match;
$toReplace[]=trim($choices[rand(0, count($choices)-1)]);
}
return str_replace($toFind, $toReplace, $txt);
}
// Cette fonction permet de remplacer automatique du text en fonction des mots proposés en remplacement.
function Spin($txt){
$pattern = '#\{([^{}]*)\}#msi';
$test = preg_match_all($pattern, $txt, $out);
$toFind = Array();
$toReplace = Array();
foreach($out[0] AS $id => $match){
$choices = explode("~", $out[1][$id]);
$toFind[]=$match;
$toReplace[]=trim($choices[rand(0, count($choices)-1)]);
}
return str_replace($toFind, $toReplace, $txt);
}
// ON EXCULS LES VALEURS NON DESIRER:
function valeurExclu ($element) {
$retour = true;
//Liste des mots exclus
$regex = "#luxtend|waitloading|Ã|adsense|hover|showdlg|showfullscreenset|ebay|autoclose|barrisol|maxeftv|musikprojektes|calvados|ii|displaymodefull|paylantint|topbarkeywords|preload|trackpageview|mouseover|www|clipso|copyright|enabledefaults|myform|bruno|function|ready|doctype|tooltip|var|newmat|simcity|cscript|javascript|script|pagetracker|gettracker|trackpageviewsetaccount|setdomainname|trackpageloadtime|loadingtime|gettime#";
if (preg_match($regex,$element)){
$retour = False;
}
//Régle des mots composés
//#^guitare# La chaîne doit commencer par "-"
if (preg_match("#^-#",$element)){
$retour = False;
}
//#guitare$# La chaîne ne doit pas se terminer par "-"
if (preg_match("#-$#",$element)){
$retour = False;
}
// suppression des valeurs inférieur à 3 caractères
//if (strlen($element)- substr_count($element, ' ') <= 2){
if (strlen(utf8_decode($element))<= 5){
$retour = False;
}
// On compte le nombre de blanc: si suppérieurs à 4. On exclus la valeur.
$test = explode(' ', $element);
if (count($test)>= 4){
$retour = False;
}
//suppression des valeur suppérieur à 35 max: anticonstitutionnellement
if (strlen(utf8_decode($element))>= 35){
$retour = False;
}
return $retour;
}
function antispamtexte($texte){
$retour = True;
$nombres_de_lettes_max = 3;
// les consonnes
$consonnes = array("b","c","d","f","g","h","j","k","m","n",
"p","q","r","s","t","v","w","x","z");
// les voyelles
$voyelles = array("a","e","i","o","u","y");
// les exceptions en 4 lettres (comme le $nombres_de_lettes_max)
$exceptions = array("http","aaaa","uuuu");
// votre texte
/*
$texte = "hello worrrrrdddd come to seeeee myyyy webtrhdtgrbvx
aaaaaat http://www.helloword.com siiiiite"; */
// variables
$i=0; $v=0; $c=0; $stock_consonne='';$stock_voyelle='';
while ($i<=strlen($texte)) {
// on sauvegarde le contenu de last_var pour refaire une comparaison
$last_var_sub = $last_var;
// on gere les consonnes
if (in_array($texte[$i],$consonnes))
{$stock_consonne .= $texte[$i]; $i++;$c++;$last_var='consonne';}
// on gere les voyelles
elseif (in_array($texte[$i],$voyelles))
{$stock_voyelle .= $texte[$i]; $i++; $v++; $last_var='voyelles';}
// si c'est un caratere autre on met tout a zero
else{$v=0;$c=0;$i++;$stock_consonne=''; $stock_voyelle='';}
// test sur les egalités
if ($c==$nombres_de_lettes_max) {
if (!in_array($stock_consonne,$exceptions))
//echo 'spam consonne -> '.$stock_consonne.'<br />';
$retour = false;
$v=0;$c=0;$stock_consonne='';
}
if ($v==$nombres_de_lettes_max) {
if (!in_array($stock_voyelle,$exceptions))
//echo 'spam voyelle -> '.$stock_voyelle.'<br />';
$retour = false;
$v=0;$c=0;$stock_voyelle='';
}
// si la lettre est differente on reinitialise
if ($last_var_sub != $last_var)
{$v=0;$c=0; $stock_consonne=''; $stock_voyelle='';}
}
return $retour;
}
// *******************************************************************************************************************************
function generation ($aCharger,$filename) {
echo 'Chargement du fichier: '.$filename;
// On récupère la liste actuel:
$html = file_get_contents($filename);
$url = '';
if ($aCharger != '' && $aCharger != null){
// On charge l'url à traiter:
if( false == ($str=file_get_contents((string)$aCharger))){
echo 'Erreur de chargement :'.$aCharger.'\r\n';
return null;
}else{
echo 'On charge :'.$aCharger.'<br>';
$html = $html.$str;
}
}
// On lance les regex
// 1- On vire le code entre <head> et </head> qui contient en général tout les trucs qui ne nous intéressent pas ici (feuille de style, javascript...)
// 2- On vire le javascript pour éviter les bugs au cas ou une partie nous aurait échappée
// 3- On vire les attributs de style pour les mêmes raisons
$html = preg_replace('`<head.*?/head>`', '', $html);
$html = preg_replace('`<script.*?/script>`', '', $html);
$html = preg_replace('`<style.*?/style>`', '', $html);
// ON CHARGE L ENSEMBLE DE LA PAGE A SCANNER PUIS ON SUPPRIMER TOUT LES CHARACTERES INDESIRABLES:
// suppression des commentaires: Récupération uniquement des balises html connu:
$allow = '<p><a><ul><li><b><strong><td>';
$html = strip_tags($html, $allow);
// Remplacement des caractères html pure:
$html = html_entity_decode($html);
//replace MS special characters first
$search = array('/‘/u', '/’/u', '/“/u', '/”/u', '/—/u');
$replace = array('\'', '\'', '"', '"', '-');
$html = preg_replace($search, $replace, $html);
// remplacement des caractères spéciaux:
$modif = array("®","‰","@","+","&","™","§","€","!");
$amodif = array(" "," "," "," "," "," "," "," "," ");
$newsujet = str_replace($modif,$amodif,$html);
// to en minuscul -------- et prise en charge des caractères html
$newsujet = strtolower ($newsujet);
// Flitrage complexe
$newsujet =strtr(trim(strip_tags($newsujet)), array_flip(get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES)));
// Suppression des caractères spéciaux:
$interdit=array("“","¯","Â"," ","_",">", "<","«","»", ":", "*","\\", "/", "|", "?", "}", "{", ")", "[", "]", "(","$","#","~","ª","´","¨","¢","©",".","=","%", "\"",";","…","²");
//$interdit=array("“","¯","Â"," ","_",">", "<","«","»", ":", "*","\\", "/", "|", "?", "}", "{", ")", "[", "]", "(","$","#","~","ª","´","¨","¢","©",".","=","'","%", "\"",";","…","²");
$new_array = str_replace($interdit, " ", $newsujet);
//------------------------------------------------------------------------------------------------------------
$testexplode =$new_array;
// suppression des chiffres
$testexplode =ereg_replace("[0-9]","",$testexplode);
//Suppression saut de ligne
$testexplode = strtr($testexplode, "\r\n\t\s", ",,,,");
// Création du tableau des valeurs: entre 15 et 35
$testexplode = wordwrap($testexplode, 20, ",", false);
$keywords = explode(",", $testexplode);
// suppression des valeurs null
$keywords = array_filter($keywords);
//--------------------------------------------------------------------------------------------------------------
$keywords = array_values(array_filter($keywords, "antispamtexte"));
$keywords = array_values(array_filter($keywords, "valeurExclu"));
// filtre des doublons
$keywords = array_unique($keywords);
// tri des réponses
//$keywords = ksort($keywords);
// méclange d'un tableau
shuffle($keywords);
//******************** Affichage résultat ***********************************
//Compte tous les éléments d'un tableau ou quelque chose d'un objet.
echo 'Nombre de mots actuellement connus: '.count($keywords).'<br>';
//print_r ($keywords);
$valspin= "{";
foreach ($keywords as $value) {
// trim suppression des espaces à droite et à gauche
$valspin.= trim(strtr($value,"  ",""))."~";
}
$valspin.= "Plafond}";
//echo $valspin;
//****************************************************************************
echo 'Controle Spint - Nouveau mots au hazard: '.Spin($valspin).'<br>';
echo 'On recherche la valeur Spint: '.SpinSearch($valspin, 'plafond').'<br>';
//echo 'Liste complête de mots : '.$valspin.'<br>';
return $valspin;
}
?>