DokuHTTPClient.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace dokuwiki\HTTP;
  3. /**
  4. * Adds DokuWiki specific configs to the HTTP client
  5. *
  6. * @author Andreas Goetz <cpuidle@gmx.de>
  7. */
  8. class DokuHTTPClient extends HTTPClient {
  9. /**
  10. * Constructor.
  11. *
  12. * @author Andreas Gohr <andi@splitbrain.org>
  13. */
  14. public function __construct(){
  15. global $conf;
  16. // call parent constructor
  17. parent::__construct();
  18. // set some values from the config
  19. $this->proxy_host = $conf['proxy']['host'];
  20. $this->proxy_port = $conf['proxy']['port'];
  21. $this->proxy_user = $conf['proxy']['user'];
  22. $this->proxy_pass = conf_decodeString($conf['proxy']['pass']);
  23. $this->proxy_ssl = $conf['proxy']['ssl'];
  24. $this->proxy_except = $conf['proxy']['except'];
  25. // allow enabling debugging via URL parameter (if debugging allowed)
  26. if($conf['allowdebug']) {
  27. if(
  28. isset($_REQUEST['httpdebug']) ||
  29. (
  30. isset($_SERVER['HTTP_REFERER']) &&
  31. strpos($_SERVER['HTTP_REFERER'], 'httpdebug') !== false
  32. )
  33. ) {
  34. $this->debug = true;
  35. }
  36. }
  37. }
  38. /**
  39. * Wraps an event around the parent function
  40. *
  41. * @triggers HTTPCLIENT_REQUEST_SEND
  42. * @author Andreas Gohr <andi@splitbrain.org>
  43. */
  44. /**
  45. * @param string $url
  46. * @param string|array $data the post data either as array or raw data
  47. * @param string $method
  48. * @return bool
  49. */
  50. public function sendRequest($url,$data='',$method='GET'){
  51. $httpdata = array('url' => $url,
  52. 'data' => $data,
  53. 'method' => $method);
  54. $evt = new \Doku_Event('HTTPCLIENT_REQUEST_SEND',$httpdata);
  55. if($evt->advise_before()){
  56. $url = $httpdata['url'];
  57. $data = $httpdata['data'];
  58. $method = $httpdata['method'];
  59. }
  60. $evt->advise_after();
  61. unset($evt);
  62. return parent::sendRequest($url,$data,$method);
  63. }
  64. }