You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

80 lines
2.1 KiB

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