15a8d6e48SMichael Große<?php 25a8d6e48SMichael Große 35a8d6e48SMichael Große 45a8d6e48SMichael Großenamespace dokuwiki\HTTP; 55a8d6e48SMichael Große 65a8d6e48SMichael Große 75a8d6e48SMichael Große/** 85a8d6e48SMichael Große * Adds DokuWiki specific configs to the HTTP client 95a8d6e48SMichael Große * 105a8d6e48SMichael Große * @author Andreas Goetz <cpuidle@gmx.de> 118a10b6f0SElan Ruusamäe * @link https://www.dokuwiki.org/devel:httpclient 125a8d6e48SMichael Große */ 13*a3b08db5SAndreas Gohrclass DokuHTTPClient extends HTTPClient 14*a3b08db5SAndreas Gohr{ 155a8d6e48SMichael Große 165a8d6e48SMichael Große /** 175a8d6e48SMichael Große * Constructor. 185a8d6e48SMichael Große * 195a8d6e48SMichael Große * @author Andreas Gohr <andi@splitbrain.org> 205a8d6e48SMichael Große */ 21*a3b08db5SAndreas Gohr public function __construct() 22*a3b08db5SAndreas Gohr { 235a8d6e48SMichael Große global $conf; 245a8d6e48SMichael Große 255a8d6e48SMichael Große // call parent constructor 265a8d6e48SMichael Große parent::__construct(); 275a8d6e48SMichael Große 285a8d6e48SMichael Große // set some values from the config 295a8d6e48SMichael Große $this->proxy_host = $conf['proxy']['host']; 305a8d6e48SMichael Große $this->proxy_port = $conf['proxy']['port']; 315a8d6e48SMichael Große $this->proxy_user = $conf['proxy']['user']; 325a8d6e48SMichael Große $this->proxy_pass = conf_decodeString($conf['proxy']['pass']); 335a8d6e48SMichael Große $this->proxy_ssl = $conf['proxy']['ssl']; 345a8d6e48SMichael Große $this->proxy_except = $conf['proxy']['except']; 355a8d6e48SMichael Große 365a8d6e48SMichael Große // allow enabling debugging via URL parameter (if debugging allowed) 375a8d6e48SMichael Große if ($conf['allowdebug']) { 385a8d6e48SMichael Große if ( 395a8d6e48SMichael Große isset($_REQUEST['httpdebug']) || 405a8d6e48SMichael Große ( 415a8d6e48SMichael Große isset($_SERVER['HTTP_REFERER']) && 425a8d6e48SMichael Große strpos($_SERVER['HTTP_REFERER'], 'httpdebug') !== false 435a8d6e48SMichael Große ) 445a8d6e48SMichael Große ) { 455a8d6e48SMichael Große $this->debug = true; 465a8d6e48SMichael Große } 475a8d6e48SMichael Große } 485a8d6e48SMichael Große } 495a8d6e48SMichael Große 505a8d6e48SMichael Große 515a8d6e48SMichael Große /** 525a8d6e48SMichael Große * Wraps an event around the parent function 535a8d6e48SMichael Große * 545a8d6e48SMichael Große * @triggers HTTPCLIENT_REQUEST_SEND 555a8d6e48SMichael Große * @author Andreas Gohr <andi@splitbrain.org> 565a8d6e48SMichael Große */ 575a8d6e48SMichael Große /** 585a8d6e48SMichael Große * @param string $url 595a8d6e48SMichael Große * @param string|array $data the post data either as array or raw data 605a8d6e48SMichael Große * @param string $method 615a8d6e48SMichael Große * @return bool 625a8d6e48SMichael Große */ 63*a3b08db5SAndreas Gohr public function sendRequest($url, $data = '', $method = 'GET') 64*a3b08db5SAndreas Gohr { 65*a3b08db5SAndreas Gohr $httpdata = [ 66*a3b08db5SAndreas Gohr 'url' => $url, 675a8d6e48SMichael Große 'data' => $data, 68*a3b08db5SAndreas Gohr 'method' => $method 69*a3b08db5SAndreas Gohr ]; 705a8d6e48SMichael Große $evt = new \Doku_Event('HTTPCLIENT_REQUEST_SEND', $httpdata); 715a8d6e48SMichael Große if ($evt->advise_before()) { 725a8d6e48SMichael Große $url = $httpdata['url']; 735a8d6e48SMichael Große $data = $httpdata['data']; 745a8d6e48SMichael Große $method = $httpdata['method']; 755a8d6e48SMichael Große } 765a8d6e48SMichael Große $evt->advise_after(); 775a8d6e48SMichael Große unset($evt); 785a8d6e48SMichael Große return parent::sendRequest($url, $data, $method); 795a8d6e48SMichael Große } 805a8d6e48SMichael Große 815a8d6e48SMichael Große} 82