PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 92 lines | 37 code | 17 blank | 38 comment | 4 complexity | e6b4094bbd6037d20e8c8c471aff3454 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: curl.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 JHTTPcurl 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. if (!function_exists('curl_init')) {
  33. throw new Exception(JText::_('JLIB_ERROR_CURL_UNSUPPORTED'));
  34. }
  35. // Set up the user agent.
  36. if (empty($this->user_agent)) {
  37. $ua = 'Mozilla/5.0';
  38. }
  39. else {
  40. $ua = $this->user_agent;
  41. }
  42. // Reset the error message variable.
  43. $php_errormsg = '';
  44. // Set track errors.
  45. $track_errors = ini_set('track_errors',true);
  46. // Create a new cURL resource
  47. $ch = curl_init();
  48. //
  49. // Set URL and other appropriate options
  50. //
  51. // Set the download URL
  52. curl_setopt($ch, CURLOPT_URL, $url);
  53. // Don't include the header in the output
  54. curl_setopt($ch, CURLOPT_HEADER, false);
  55. // Set the user agent
  56. curl_setopt($ch, CURLOPT_USERAGENT, $ua);
  57. // follow redirects (required for Joomla!)
  58. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  59. // 10 maximum redirects
  60. curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  61. // We only want the result, not the output.
  62. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  63. $buffer = curl_exec($ch);
  64. curl_close($ch);
  65. if ($buffer === false) {
  66. throw new Exception(
  67. "Failed to connect to URL: $url".
  68. "\nError: $php_errormsg".
  69. ($this->proxy_host ? "\nUsing proxy" : '')
  70. );
  71. }
  72. ini_set('track_errors', $track_errors);
  73. return $buffer;
  74. }
  75. }