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