Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Парсер торент раздач, проблема с кодировкой
Форумы портала PHP.SU » » Кодировки и все смежное » Парсер торент раздач, проблема с кодировкой

Страниц (1): [1]
 

1. D0Gmatist - 12 Августа, 2012 - 00:27:38 - перейти к сообщению
Здравствуйте ... для DLE есть модуль парсера раздач.

Работает отлично ...

У меня сайт в UTF-8

и тут возникает беда с русским языком

помогите как решить эту беду

PHP:
скопировать код в буфер обмена
  1.  
  2. <?PHP
  3.  
  4.  
  5.  
  6. @error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);
  7. @ini_set('display_errors', false);
  8. @ini_set('html_errors', false);
  9. @ini_set('error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE);
  10.  
  11. define('DATALIFEENGINE', true);
  12.  
  13. $member_id = false;
  14. $is_logged = false;
  15.  
  16. define('ROOT_DIR', dirname(__FILE__).'/../..');
  17. define('ENGINE_DIR', ROOT_DIR.'/engine');
  18.  
  19. @include (ENGINE_DIR.'/data/config.php');
  20. require_once ENGINE_DIR.'/classes/mysql.php';
  21. require_once ENGINE_DIR.'/data/dbconfig.php';
  22. require_once ENGINE_DIR.'/modules/functions.php';
  23.  
  24. function UTF8toCP1251($str)
  25. {
  26.         static $table = array("\xD0\x81" => "\xA8", // Ё
  27.     "\xD1\x91" => "\xB8", // ё
  28.     // украинские символы
  29.     "\xD0\x8E" => "\xA1", // Ў (У)
  30.     "\xD1\x9E" => "\xA2", // ў (у)
  31.     "\xD0\x84" => "\xAA", // Є (Э)
  32.     "\xD0\x87" => "\xAF", // Ї (I..)
  33.     "\xD0\x86" => "\xB2", // I (I)
  34.     "\xD1\x96" => "\xB3", // i (i)
  35.     "\xD1\x94" => "\xBA", // є (э)
  36.     "\xD1\x97" => "\xBF", // ї (i..)
  37.     // чувашские символы
  38.     "\xD3\x90" => "\x8C", // &#1232; (А)
  39.     "\xD3\x96" => "\x8D", // &#1238; (Е)
  40.     "\xD2\xAA" => "\x8E", // &#1194; (С)
  41.     "\xD3\xB2" => "\x8F", // &#1266; (У)
  42.     "\xD3\x91" => "\x9C", // &#1233; (а)
  43.     "\xD3\x97" => "\x9D", // &#1239; (е)
  44.     "\xD2\xAB" => "\x9E", // &#1195; (с)
  45.     "\xD3\xB3" => "\x9F", // &#1267; (у)
  46.         );
  47.         return preg_replace('#([\xD0-\xD1])([\x80-\xBF])#se', 'isset($table["$0"]) ? $table["$0"] :
  48.                       chr(ord("$2")+("$1" == "\xD0" ? 0x30 : 0x70))
  49.                      ', $str
  50.         );
  51. }
  52.  
  53. function search_torrent($query)
  54. {
  55.  
  56.  
  57.         $query = str_replace(" ", "+", $query);
  58.  
  59.         $querys = "POST http://rutor.org/search/0/0/100/0/$query HTTP/1.0\r\n".
  60.                 "Referer: http \r\n".
  61.                 "User-Agent: Mozilla/4.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20036725 Firefox/2.0.0.1\r\n".
  62.                 "Host: rutor.org\r\n".
  63.                 "Accept: text/html;q=0.1\r\n".
  64.                 "Accept-Language: ru,en;q=0.9\r\n".
  65.                 "Accept-Charset: windows-1251;q=0.6, *;q=0.1\r\n".
  66.                 "Proxy-Connection: close\r\n".
  67.                 "Content-Type: application/x-www-form-urlencoded\r\n".
  68.                 "Content-Length: "."1"."\r\n\r\n".
  69.                 $posts."\r\n\r\n";
  70.         $socket = fsockopen('rutor.org', 80, $errno, $errstr, 120);
  71.  
  72.         fwrite($socket, $querys);
  73.         while (!feof($socket)) {
  74.                 $s.=fgets($socket);
  75.         }
  76.         fclose($socket);
  77.         $result = $s;
  78.  
  79.         $result = UTF8toCP1251($result);
  80.  
  81.         $find2 = "";
  82.  
  83.         $p1 = strpos($result, "<table width=\"100%\"><tr class=\"backgr\">");
  84.         $p2 = strpos($result, "</table><b>Страницы");
  85.         $result = substr($result, $p1, $p2 - $p1);
  86.  
  87.  
  88.  
  89.        
  90. preg_match_all('#<a class="downgif" href="http://d.rutor.org/download/(.[0-9]*)"><img src="http://s.rutor.org/i/d.gif" alt="D" /></a>(.*)<a href="/torrent/(.*)">(.*)</a></td>(.*)<td align="right">([0-9]*..?[0-9]+.?) (.[A-Z]*)</td><td align="center"><span class="green"><img src="http://s.rutor.org/t/arrowup.gif" alt="S" /> (.[0-9]*)</span> <img src="http://s.rutor.org/t/arrowdown.gif" alt="L" /><span class="red"> (.[0-9]*)</span></td></tr>#Uis', $result, $find);
  91.  
  92.  
  93.         $count = intval(count($find['1']));
  94.         $i = -1;
  95.         $find2 = "";
  96.         while ($i < $count - 1) {
  97.         if($is==5)break;
  98.                 $i++;
  99.                 $find['2'][$i] = str_replace("http://s.rutor.org/i/m.png", "/magnet.png", $find['2'][$i]);
  100.                 $find['2'][$i] = str_replace("magnet:", "magnet:", $find['2'][$i]);
  101.                 $is = $i + 1;
  102.                 $find2 .= <<<HTML
  103. <tr>
  104. <th><center>{$is}<center></th>
  105. <th>{$find['4'][$i]} <a href="http://rutor.org/download/{$find['1'][$i]}"><img title="Скачать без регистрации торрент" src="/download.png" alt="Скачать без регистрации торрент"></a> {$find['2'][$i]}</th>
  106. <th>{$find['6'][$i]} {$find['7'][$i]}</th>
  107. <th>{$find['8'][$i]}</th>
  108. <th>{$find['9'][$i]}</th>
  109. </tr>
  110.  
  111. HTML;
  112.         }
  113.  
  114. // $find2 = $result;
  115.  
  116.         if (!$find2 or $find2 == "") {
  117.                 $finds = "<br><br><p style=\"text-align: center;\"><span style=\"font-size: medium;\"><strong><span style=\"color: #ff0000;\">Внимание:</span></strong> Не удалось отобразить раздачу! Обновите страницу!</span></p><br><br>";
  118.         } else {
  119.                 $finds = <<<HTML
  120.  
  121.  
  122.  
  123.  
  124. <style type="text/css">
  125.  
  126.  
  127. .restable {
  128.  
  129.        
  130.         border-left: 1px solid #ebebeb;
  131.         border-right: 1px solid #ebebeb;
  132. }
  133.  
  134. .restable th {
  135.         width: 100px;
  136.         padding: 6px;
  137.         text-align: left;
  138. }
  139.  
  140. .restable thead tr {
  141.        
  142.         cursor: pointer;
  143.         background: #97d234;
  144.         border: 1px solid #5ea007;
  145.         border-radius: 5px;
  146.         color: #fff;
  147.         text-shadow: 1px 1px 2px black;
  148. }
  149.  
  150. .restable a {
  151.         text-decoration:none;
  152. }
  153.  
  154. .restable a:hover {
  155.         text-decoration:underline;
  156. }
  157.  
  158. .restable tr:nth-child(2n) {
  159.         background-color:#f7f7f7;
  160. }
  161.  
  162. .restable tr {
  163.         background-color:#fefefe;
  164. }
  165.  
  166. .restable tbody tr:hover {
  167.         background-color:#e7e7e7;
  168. }
  169.  
  170. .restable td {
  171.         padding:6px;
  172.         vertical-align:middle;
  173.         border-bottom: 1px solid #cccccc;
  174.         color: #333333;
  175.         font-size:12px;
  176. }
  177.  
  178. #pselect {
  179.         display: inline;
  180.         padding: 5px 12px;
  181.         background: #ebebeb;
  182.         border-bottom: 1px solid rgba(0, 0, 0, 0.251);
  183.         cursor: pointer;
  184.         border-radius: 5px;
  185.         color: #808080;
  186.         text-shadow: white 0px 1px 2px;
  187.         margin: 3px;
  188.         font-size: 15px;
  189. }
  190.  
  191. #pselect.active, #pselect:hover {
  192.         background: #97d234 !important;
  193.         border-bottom: 1px solid rgba(0, 0, 0, 0.251);
  194.         text-shadow: 1px 1px 2px black;
  195.         color: #fff !important;
  196. }
  197.  
  198. .restable th {
  199.        
  200.         white-space: inherit;
  201. }
  202.  
  203. .restable th > span {
  204.     background: url("/img/nosorted.gif") 0px 50% no-repeat;
  205.         padding-left: 8px;
  206. }
  207. .restable .up > span {
  208.     background: url("/img/down.gif") 0px 50% no-repeat;
  209.         padding-left: 8px;
  210. }
  211. .restable .down > span {
  212.     background: url("/img/up.gif") 0px 50% no-repeat;
  213.         padding-left: 8px;
  214. }
  215.  
  216.  
  217.  
  218.  
  219. .restable b {
  220.         background: #e4ffb5;
  221. }
  222.  
  223. .restable a:hover {
  224.         color: #5f8f0b;
  225. }
  226.  
  227.  
  228.  
  229. </style>
  230.        
  231.  
  232.         <table style="width:100%;" class="restable">
  233.  
  234.                 <thead>
  235.                         <tr>
  236.                                 <th style="width:30px;text-align:center;">№<span>  </span></th>
  237.                                 <th style="width:500px;">Название торрент раздачи<span>  </span></th>
  238.                                 <th style="width:40px;">Размер <span>  </span></th>
  239.                                 <th style="width:50px;">Сиды <span>  </span></th>
  240.  
  241.                                 <th style="width:50px;">Пиры <span>  </span></th>
  242.                                
  243.                         </tr>
  244.                 </thead>
  245.                
  246.                 <tbody>
  247. {$find2}
  248.                 </tbody>
  249.         </table>
  250.  
  251.  
  252.  
  253. HTML;
  254.         }
  255.  
  256.         return ($finds);
  257. }
  258.  
  259.  
  260. $title = trim(strip_tags($_POST['title']));
  261.  
  262. @header("Content-type: text/html; charset=".$config['charset']);
  263. echo search_torrent($title);
  264.  

 

Powered by ExBB FM 1.0 RC1