Advertisement
tikaszvince

remote_http_get.patch

Feb 19th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.51 KB | None | 0 0
  1. Index: class-admin.php
  2. ===================================================================
  3. --- class-admin.php (revision 670456)
  4. +++ class-admin.php (working copy)
  5. @@ -191,7 +191,8 @@
  6.                 <tr valign="top"><th scope="row"><label for="language">Language</label></th>
  7.                     <td><?php
  8.   $dom_object = new DOMDocument();
  9. - $dom_object->load("http://www.facebook.com/translations/FacebookLocales.xml");
  10. + $content = fbcomments_remote_http_get("http://www.facebook.com/translations/FacebookLocales.xml");
  11. + $dom_object->loadXML( str_replace("<?xml version='1.0'?>", '', $content) );
  12.  $langfeed = $dom_object->getElementsByTagName("locale");
  13.  
  14.                  echo '<select name="fbcomments[language]">';
  15. @@ -353,4 +354,65 @@
  16.  <?php
  17.  }
  18.  
  19. +
  20. +function fbcomments_remote_http_get($url) {
  21. +  $url_stuff = parse_url($url);
  22. +  $port = isset($url_stuff['port']) ? $url_stuff['port'] : 80;
  23. +  $fp = fsockopen($url_stuff['host'], $port);
  24. +
  25. +  if (!$fp) {
  26. +    return false;
  27. +  }
  28. +  $query  = 'GET '.$url_stuff['path'].'?'.$url_stuff['query']." HTTP/1.1\r\n";
  29. +  $query .= 'Host: '.$url_stuff['host']."\r\n";
  30. +  $query .= 'Connection: close'."\r\n";
  31. +  $query .= 'Cache-Control: no'."\r\n";
  32. +  $query .= 'Accept-Ranges: bytes'."\r\n";
  33. +  //$query .= 'Referer: http:/...'."\r\n";
  34. +  //$query .= 'User-Agent: myphp'."\r\n";
  35. +  $query .= "\r\n";
  36. +
  37. +  fwrite($fp, $query);
  38. +
  39. +  $chunksize = 1*(1024*1024);
  40. +  $headersfound = false;
  41. +  $buffer = '';
  42. +
  43. +  while (!feof($fp) && !$headersfound) {
  44. +    $buffer .= fread($fp, 1);
  45. +    if (preg_match('/HTTP\/[0-9]\.[0-9][ ]+([0-9]{3}).*\r\n/', $buffer, $matches)) {
  46. +      $headers['HTTP'] = $matches[1];
  47. +      $buffer = '';
  48. +    }
  49. +    elseif (preg_match('/([^:][A-Za-z_-]+):[ ]+(.*)\r\n/', $buffer, $matches)) {
  50. +      $headers[$matches[1]] = $matches[2];
  51. +      $buffer = '';
  52. +    }
  53. +    elseif (preg_match('/^\r\n/', $buffer)) {
  54. +      $headersfound = true;
  55. +      $buffer = '';
  56. +    }
  57. +
  58. +    if (strlen($buffer) >= $chunksize) {
  59. +      return false;
  60. +    }
  61. +  }
  62. +
  63. +  if (preg_match('/4[0-9]{2}/', $headers['HTTP'])) {
  64. +    return false;
  65. +  }
  66. +  elseif (preg_match('/3[0-9]{2}/', $headers['HTTP']) && !empty($headers['Location'])) {
  67. +    $url = $headers['Location'];
  68. +    return _fifingerprint_remote_http_get($url, $range);
  69. +  }
  70. +  $_content = array();
  71. +  while (!feof($fp) && $headersfound) {
  72. +    $buffer = fread($fp, $chunksize);
  73. +    $_content[] = $buffer;
  74. +  }
  75. +  $status = fclose($fp);
  76. +
  77. +  return join("\n", $_content);
  78. +}
  79. +
  80.  ?>
  81. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement