SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | // парсер ключевых слов | |
| 3 | // © [email protected] 19.05.2017 | |
| 4 | ||
| 5 | $error=1; | |
| 6 | if($error==1){error_reporting(E_ALL);ini_set('display_errors', 'on');}
| |
| 7 | else {error_reporting(0);ini_set('display_errors', 'off');}
| |
| 8 | ||
| 9 | $tema=isset($_GET['tema'])?strip_tags($_GET['tema']):"test"; | |
| 10 | $tm=isset($_GET['tema'])?"&tema=$tema":""; | |
| 11 | $tmg=isset($_GET['tema'])?"?tema=$tema":""; | |
| 12 | if(!file_exists($tema)){mkdir($tema, 0700);echo "<meta http-equiv=\"refresh\" content=\"1; url=$tmg\">";}
| |
| 13 | ||
| 14 | $_db="$tema/$tema.db"; | |
| 15 | $files=array("key","bad");
| |
| 16 | foreach($files as $line) | |
| 17 | {
| |
| 18 | $fil[$line]=$tema.'/'.$line.'_'.$tema.'.txt'; | |
| 19 | if (!file_exists($fil[$line])) | |
| 20 | {
| |
| 21 | $fp = fopen($fil[$line], "w"); | |
| 22 | fwrite($fp, ""); | |
| 23 | fclose($fp); | |
| 24 | } | |
| 25 | $arfil[$line]=file($fil[$line]); | |
| 26 | } | |
| 27 | $p=isset($_GET['p'])?$_GET['p']:0; | |
| 28 | $st=isset($_GET['stop'])?"&stop=":""; | |
| 29 | $p20=$p*20; | |
| 30 | $p2020=$p20+20; | |
| 31 | if (isset($_GET['feed'])) | |
| 32 | {
| |
| 33 | if (!file_exists($_db)) | |
| 34 | {
| |
| 35 | $db = new SQLite3($_db); | |
| 36 | $db->busyTimeout(5000); | |
| 37 | $db->exec('PRAGMA journal_mode=WAL;');
| |
| 38 | $db->exec('CREATE TABLE IF NOT EXISTS pages (id INTEGER PRIMARY KEY, key TEXT UNIQUE);');
| |
| 39 | $db->close(); | |
| 40 | } | |
| 41 | else | |
| 42 | {
| |
| 43 | $db = new SQLite3($_db); | |
| 44 | $db->busyTimeout(5000); | |
| 45 | $db->exec('PRAGMA journal_mode=WAL;');
| |
| 46 | if(isset($_POST['key'])) | |
| 47 | {
| |
| 48 | $ar=explode("\n",strip_tags($_POST['key']));
| |
| 49 | $db->exec('BEGIN IMMEDIATE;');
| |
| 50 | foreach($ar as $key) | |
| 51 | {
| |
| 52 | if(empty($key)) continue; | |
| 53 | $lin = $db->escapeString(trim($key)); | |
| 54 | @$db->exec("INSERT INTO pages (key) VALUES ('".$lin."');");
| |
| 55 | } | |
| 56 | $db->exec('COMMIT;');
| |
| 57 | } | |
| 58 | $lh = $db->query("SELECT * FROM pages ORDER BY id ASC LIMIT $p20,20;");
| |
| 59 | $count = $db->querySingle('SELECT count(*) FROM pages;');
| |
| 60 | ||
| 61 | while ($echo = $lh->fetchArray()) | |
| 62 | {
| |
| 63 | $arkey[]=$echo['key']; | |
| 64 | } | |
| 65 | if ($_GET['feed'] == 'gen') | |
| 66 | {
| |
| 67 | foreach($arkey as $key) | |
| 68 | {
| |
| 69 | $key = mb_strtolower($key, 'utf-8'); | |
| 70 | $keyu=preg_replace("/ /",'+',$key);
| |
| 71 | $keyu=urlencode($keyu); | |
| 72 | ||
| 73 | ////////////////////// ---------- ////////////////////// | |
| 74 | ||
| 75 | $url="http://sgs.sputnik.ru/?format=xml&type=web&query=$keyu"; | |
| 76 | $xml = simplexml_load_file($url); | |
| 77 | $offer=$xml->item; | |
| 78 | foreach($offer as $line){$attr=$line->attributes();$keys[]=$attr['header'];}
| |
| 79 | ||
| 80 | $url="http://suggests.go.mail.ru/ie8?q=$keyu"; | |
| 81 | $xml = simplexml_load_file($url); | |
| 82 | $offer=$xml->Section->Item; | |
| 83 | foreach($offer as $line)$keys[]=$line->Text; | |
| 84 | ||
| 85 | $url="http://autocomplete.nigma.ru/complete/query_help.php?suggest=true&q=$keyu"; | |
| 86 | $fff=file_get_contents($url); | |
| 87 | $response = json_decode($fff, true); | |
| 88 | foreach($response[1] as $lin)$keys[]=$lin; | |
| 89 | ||
| 90 | $url="https://suggest.yandex.ru/suggest-ff.cgi?part=$keyu&uil=ru&sn=50"; | |
| 91 | $fff=file_get_contents($url); | |
| 92 | $response = json_decode($fff, true); | |
| 93 | foreach($response[1] as $lin)$keys[]=$lin; | |
| 94 | ||
| 95 | $url="https://search.yahoo.com/sugg/gossip/gossip-us-fp/?nresults=20&command=$keyu"; | |
| 96 | $fff=file_get_contents($url); | |
| 97 | $fff=preg_replace("/fxsearch\((.*)\,\[\]\,\[\](\])\)/",'\1\2',$fff);
| |
| 98 | $response = json_decode($fff, true); | |
| 99 | foreach($response[1] as $lin)$keys[]=$lin; | |
| 100 | /* | |
| 101 | $url="https://clients1.google.com/s?client=opera&q=$keyu"; | |
| 102 | $fff=file_get_contents($url); | |
| 103 | $response = json_decode($fff, true); | |
| 104 | foreach($response[1] as $lin)$keys[]=$lin; | |
| 105 | */ | |
| 106 | $url="http://ss.ask.com/query?li=ff&sstype=prefix&num=20&q=$keyu"; | |
| 107 | $fff=file_get_contents($url); | |
| 108 | $response = json_decode($fff, true); | |
| 109 | foreach($response[1] as $lin)$keys[]=$lin; | |
| 110 | ||
| 111 | ////////////////////// ---------- ////////////////////// | |
| 112 | ||
| 113 | $keys=array_unique($keys); | |
| 114 | ||
| 115 | $db->exec('BEGIN IMMEDIATE;');
| |
| 116 | foreach($keys as $k=>$line) | |
| 117 | {
| |
| 118 | $rr=""; | |
| 119 | foreach ($arfil['bad'] as $black) | |
| 120 | {
| |
| 121 | $black = trim($black); | |
| 122 | preg_match("/$black/",$line,$re);
| |
| 123 | if(!empty($re)) $rr.=$re[0]; | |
| 124 | } | |
| 125 | if(!empty($rr)) continue; | |
| 126 | $lin = $db->escapeString(trim($line)); | |
| 127 | @$db->exec("INSERT INTO pages (key) VALUES ('$lin');");
| |
| 128 | } | |
| 129 | $db->exec('COMMIT;');
| |
| 130 | } | |
| 131 | $p++; | |
| 132 | if($count<$p20) {echo "Все"; exit;}
| |
| 133 | echo "feed=gen&p=$p$tm$st<br>с $p20 по $p2020<br>"; | |
| 134 | ||
| 135 | if(!empty($st)) | |
| 136 | {
| |
| 137 | echo " | |
| 138 | <form action=\"index.php\" target=\"generator\" method=\"get\"> | |
| 139 | <input type=\"hidden\" name=\"feed\" value=\"gen\"/> | |
| 140 | <input type=\"hidden\" name=\"tema\" value=\"$tema\"/> | |
| 141 | <input type=\"text\" name=\"p\" value=\"$p\" size=\"2\" /> | |
| 142 | <input type=\"submit\"> | |
| 143 | </form>"; | |
| 144 | } | |
| 145 | else | |
| 146 | {
| |
| 147 | echo " | |
| 148 | <A HREF=\"?feed=gen&p=$p$tm&stop=\" target=\"generator\">стоп</A> | |
| 149 | <meta http-equiv=\"refresh\" content=\"1; url=?feed=gen&p=$p$tm$st\">"; | |
| 150 | } | |
| 151 | } | |
| 152 | ||
| 153 | if ($_GET['feed'] == 'html') | |
| 154 | {
| |
| 155 | $list = $db->query('SELECT id, key FROM pages ORDER BY id DESC LIMIT 3000;');
| |
| 156 | echo "<A HREF=\"?feed=html$tm\">обновить</A><br>"; | |
| 157 | while ($echo = $list->fetchArray()) | |
| 158 | {
| |
| 159 | echo $echo['id'].' '.$echo['key'].'<br>'; | |
| 160 | } | |
| 161 | } | |
| 162 | ||
| 163 | if ($_GET['feed'] == 'txt') | |
| 164 | {
| |
| 165 | $list = $db->query('SELECT key FROM pages;');
| |
| 166 | echo "Сохранено: $count ключей $tema"; | |
| 167 | $file = fopen ("$tema/$tema.txt","w+");
| |
| 168 | while ($echo = $list->fetchArray()) | |
| 169 | {
| |
| 170 | fputs($file,$echo['key']."\n"); | |
| 171 | } | |
| 172 | fclose ($file); | |
| 173 | } | |
| 174 | ||
| 175 | foreach($files as $k=>$fk) | |
| 176 | {
| |
| 177 | $line=$fil[$fk]; | |
| 178 | if ($_GET['feed'] == $fk) | |
| 179 | {
| |
| 180 | if(isset($_POST[$fk])) | |
| 181 | {
| |
| 182 | file_put_contents($line, strip_tags($_POST[$fk])); | |
| 183 | echo "<meta http-equiv=\"refresh\" content=\"1; url=?feed=$fk$tm\">"; | |
| 184 | } | |
| 185 | $bf[$k]=@file_get_contents($line); | |
| 186 | echo "$line<br/> | |
| 187 | <form action=\"index.php?feed=$fk$tm\" method=\"post\"> | |
| 188 | <textarea rows=\"42\" cols=\"24\" name=\"$fk\">$bf[$k]</textarea><br/> | |
| 189 | <input type=\"submit\"> | |
| 190 | </form> | |
| 191 | "; | |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 | $db->close(); | |
| 196 | } | |
| 197 | } | |
| 198 | else | |
| 199 | {
| |
| 200 | header('Content-Type: text/html; charset=UTF-8');
| |
| 201 | echo " | |
| 202 | <table> | |
| 203 | <tr> | |
| 204 | <td colspan=2> | |
| 205 | <A HREF=\"/\">главная</A> | | |
| 206 | <A HREF=\"?feed=gen$tm&p=$p\" target=\"generator\">пуск</A> | | |
| 207 | <A HREF=\"?feed=txt$tm\" target=\"keytxt\">сохранить</A> | | |
| 208 | <A HREF=\"$tema/$tema.txt\" target=\"keytxt\">скачать</A></td> | |
| 209 | <td colspan=2> | |
| 210 | <form action=\"/\" method=\"get\"> | |
| 211 | <input type=\"text\" name=\"tema\" value=\"$tema\" maxlength=\"10\" /> | |
| 212 | <input type=\"submit\"> | |
| 213 | </form></td> | |
| 214 | </tr> | |
| 215 | <tr> | |
| 216 | <td><iframe src=\"?feed=key$tm\" width=\"220\" height=\"700\" frameborder=\"0\" scrolling=\"yes\"></iframe></td> | |
| 217 | <td><iframe src=\"?feed=bad$tm\" width=\"220\" height=\"700\" frameborder=\"0\" scrolling=\"yes\"></iframe></td> | |
| 218 | <td><iframe src=\"?feed=html$tm\" width=\"500\" height=\"700\" frameborder=\"0\" scrolling=\"yes\"></iframe></td> | |
| 219 | <td><iframe name=\"generator\" width=\"500\" height=\"400\" frameborder=\"0\" scrolling=\"yes\"></iframe><br> | |
| 220 | <iframe name=\"keytxt\" width=\"500\" height=\"300\" frameborder=\"0\" scrolling=\"yes\"></iframe></td> | |
| 221 | </tr> | |
| 222 | </table>"; | |
| 223 | } | |
| 224 | ?> |