1
0

GoogleFunctions.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /* $Id: GoogleFunctions.php 3307 2007-12-16 22:32:03Z warion $ */
  3. /*************************************************************
  4. * TorrentFlux - PHP Torrent Manager
  5. * www.torrentflux.com
  6. **************************************************************/
  7. /*
  8. This file is part of TorrentFlux.
  9. TorrentFlux is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. TorrentFlux is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with TorrentFlux; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. // -------------------------------------------------------------------
  22. // FetchHTMLNoWaitNoFollow() method to get data from URL
  23. // uses timeout and user agent
  24. // -------------------------------------------------------------------
  25. function FetchHTMLNoWaitNoFollow( $url, $referer = "" )
  26. {
  27. global $cfg, $db;
  28. ini_set("allow_url_fopen", "1");
  29. ini_set("user_agent", $cfg['user_agent']);
  30. $url = tfb_cleanURL( $url );
  31. $domain = parse_url( $url );
  32. $getcmd = $domain["path"];
  33. if(!array_key_exists("query", $domain))
  34. {
  35. $domain["query"] = "";
  36. }
  37. $getcmd .= ( !empty( $domain["query"] ) ) ? "?" . $domain["query"] : "";
  38. $cookie = "";
  39. $rtnValue = "";
  40. // If the url already doesn't contain a passkey, then check
  41. // to see if it has cookies set to the domain name.
  42. if( ( strpos( $domain["query"], "passkey=" ) ) === false )
  43. {
  44. $sql = "SELECT c.data AS data FROM tf_cookies AS c LEFT JOIN tf_users AS u ON ( u.uid = c.uid ) WHERE u.user_id = ".$db->qstr($cfg["user"])." AND c.host = ".$db->qstr($domain['host']);
  45. $cookie = $db->GetOne( $sql );
  46. }
  47. if( !array_key_exists("port", $domain) )
  48. {
  49. $domain["port"] = 80;
  50. }
  51. if (($rtnValue == "" && function_exists("curl_init")) || /*(strpos($rtnValue, "HTTP/1.1 302") > 0 &&*/ function_exists("curl_init"))//)
  52. {
  53. // Give CURL a Try
  54. $curl = curl_init();
  55. if ($cookie != "")
  56. curl_setopt($curl, CURLOPT_COOKIE, $cookie);
  57. curl_setopt($curl, CURLOPT_PORT, $domain["port"]);
  58. curl_setopt($curl, CURLOPT_URL, $url);
  59. curl_setopt($curl, CURLOPT_VERBOSE, FALSE);
  60. curl_setopt($curl, CURLOPT_HEADER, TRUE);
  61. curl_setopt($curl, CURLOPT_USERAGENT, $cfg['user_agent']);
  62. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  63. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  64. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  65. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, FALSE);
  66. curl_setopt($curl, CURLOPT_TIMEOUT, 5);
  67. $response = curl_exec($curl);
  68. curl_close($curl);
  69. $rtnValue = substr($response, strpos($response, "d8:"));
  70. $rtnValue = rtrim($rtnValue, "\r\n");
  71. }
  72. return $rtnValue;
  73. }
  74. ?>