PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/googlemini/code/trunk/administrator/components/com_artofgm/libraries/joomla/client/http/fopen.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 83 lines | 41 code | 13 blank | 29 comment | 4 complexity | 94ebca8640f53dbcaa5234715daed183 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: fopen.php 518 2011-01-07 06:36:43Z eddieajau $
  4. * @package Jentla
  5. * @subpackage com_jentlacert
  6. * @copyright Copyright 2011 New Life in IT Pty Ltd. All rights reserved.
  7. * @copyright Copyright 2010 Jentla Pty Ltd. All rights reserved.
  8. * @license GNU General Public License version 2 or later.
  9. * @link http://www.jentla.com
  10. * @author Andrew Eddie <andrew.eddie@newlifeinit.com>
  11. */
  12. // no direct access
  13. defined('_JEXEC') or die;
  14. /**
  15. * @package Jentla
  16. * @subpackage com_jentlacert
  17. * @since 1.0
  18. */
  19. class JHTTPfopen extends JHTTP
  20. {
  21. /**
  22. * Get a URL via the fopen method.
  23. *
  24. * @param string $url The URL to get.
  25. * @param string $fileName TODO (the file to save the buffer).
  26. *
  27. * @return string Returns a buffer if no filename specified.
  28. * @since 1.0
  29. */
  30. public function get($url, $fileName = '')
  31. {
  32. $httpOptions = array(
  33. 'method' => 'GET',
  34. 'user_agent' => 'Mozilla/5.0'
  35. );
  36. if ($this->proxy_host) {
  37. $httpOptions['proxy'] = 'tcp://'.$this->proxy_host.':'.$this->proxy_port;
  38. // Play nicely with squid
  39. $httpOptions['request_fulluri'] = 'true';
  40. if ($this->proxy_user) {
  41. $credentials = base64_encode($this->proxy_user.':'.$this->proxy_pass);
  42. $httpOptions['header'] .= "Proxy-Authorization: Basic $credentials\r\n";
  43. }
  44. }
  45. if ($this->timeout) {
  46. $httpOptions['timeout'] = $this->timeout;
  47. }
  48. $context = stream_context_create(
  49. array(
  50. 'http' => $httpOptions
  51. )
  52. );
  53. // Reset the error message variable.
  54. $php_errormsg = '';
  55. // Set track errors.
  56. $track_errors = ini_set('track_errors',true);
  57. $buffer = @file_get_contents($url, false, $context);
  58. // Reset track errors.
  59. ini_set('track_errors',$track_errors);
  60. if ($buffer === false) {
  61. throw new Exception(
  62. "Failed to connect to URL: $url".
  63. "\nError: $php_errormsg".
  64. ($this->proxy_host ? "\nUsing proxy" : '')
  65. );
  66. }
  67. ini_set('track_errors', $track_errors);
  68. return $buffer;
  69. }
  70. }