Index: trunk/extensions/TSPoll/http.func.php |
— | — | @@ -1,164 +0,0 @@ |
2 | | -<?PHP |
3 | | - |
4 | | -###Der folgende Code wurde von Marco Schuster bereit gestellt und ist unter der GPL ver�ffentlicht. Quelle: http://code.harddisk.is-a-geek.org/filedetails.php?repname=hd_bot&path=%2Fhttp.inc.php&sc=1&rev=66 |
5 | | - |
6 | | -// the HTTP wrapper class. replace this file with another for e.g. TOR/Proxy/CURL support |
7 | | -// use like $http=new http_w("de.wikipedia.org","/w/index.php"); $http->get(""); |
8 | | -// provides functions post, get |
9 | | -// result is stored in data, header. for a full HTTP response do $full=$http->header."\r\n\r\n".$http->data; |
10 | | - |
11 | | -//let's fake some browser agent to bypass MediaWiki squid block (evil!) |
12 | | -define("USERAGENT","Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"); //Mozilla Firefox |
13 | | -define("COOKIEJAR","private/cookiejar.txt"); |
14 | | -define("USE_COOKIEJAR",false); |
15 | | -class http_w { |
16 | | - public $data; |
17 | | - public $headers; |
18 | | - |
19 | | - var $server; |
20 | | - var $file; |
21 | | - var $raw; |
22 | | - |
23 | | - |
24 | | - function __construct($server, $file) { |
25 | | - global $cookies; |
26 | | - //debug(__FUNCTION__,"new instance of http_w initialized",1); |
27 | | - $this->data=""; |
28 | | - $this->headers=""; |
29 | | - $this->raw=""; |
30 | | - $this->server=$server; |
31 | | - $this->file=$file; |
32 | | - if(USE_COOKIEJAR) { |
33 | | - $fp=fopen(COOKIEJAR,"r"); |
34 | | - while (!feof($fp)) { |
35 | | - $buf.= fgets($fp,128); |
36 | | - } |
37 | | - fclose($fp); |
38 | | - $cookies=$buf; |
39 | | - } |
40 | | - } |
41 | | - |
42 | | - function get($param="", $ignore_redir=false) { |
43 | | - //debug(__FUNCTION__,"get called. param='$param', ignore_redir='$ignore_redir', server='".$this->server."', file='".$this->file."'",1); |
44 | | - |
45 | | - if($param!="") { $p="?".$param; } else { $p=""; } |
46 | | - |
47 | | - $cookies=$this->cookiestring(); |
48 | | - |
49 | | - $fp = fsockopen ($this->server, 80, $errno, $errstr, 10); |
50 | | - |
51 | | - if ($fp) { |
52 | | - $query="GET ".$this->file.$p." HTTP/1.1 |
53 | | -Host: ".$this->server." |
54 | | -Cookie: $cookies |
55 | | -User-Agent: ".USERAGENT." |
56 | | -\r\n\r\n"; |
57 | | - //debug(__FUNCTION__,$query,3); |
58 | | - fputs ($fp,$query); |
59 | | - $buf = ""; |
60 | | - while (!feof($fp)) { |
61 | | - $buf.= fgets($fp,128); |
62 | | - } |
63 | | - fclose($fp); |
64 | | - $this->raw=$buf; |
65 | | - |
66 | | - $this->headers=$this->getheaders(); |
67 | | - $this->data=$this->removeheaders(); |
68 | | - //debug(__FUNCTION__,$this->headers,3); |
69 | | - //debug(__FUNCTION__,$this->data,3); |
70 | | - |
71 | | - $this->update_cookies(); |
72 | | - preg_match('@Location: http://(.*)/(.*)\r\n@iU',$this->headers,$hit); |
73 | | - if($hit[1]!="" && (!$ignore_redir)) { |
74 | | - $this->server=$hit[1]; |
75 | | - $this->file="/".$hit[2]; |
76 | | - //debug(__FUNCTION__,"following http redirect to ".$this->server." // ".$this->file,1); |
77 | | - $this->data=$this->get(""); |
78 | | - } |
79 | | - flush(); |
80 | | - return $this->data; |
81 | | - } else { |
82 | | - echo "$errno: $errstr"; |
83 | | - } |
84 | | - } |
85 | | - |
86 | | - function post($param="", $content="", $ignore_redir=false) { |
87 | | - //debug(__FUNCTION__,"post called. param='$param', ignore_redir='$ignore_redir', server='".$this->server."', file='".$this->file."', post content='".$content["message"]."'",1); |
88 | | - |
89 | | - if($content=="") { die("thou shalt not use post without content!"); } |
90 | | - |
91 | | - if($param!="") { $p="?".$param; } else { $p=""; } |
92 | | - |
93 | | - $cookies=$this->cookiestring(); |
94 | | - |
95 | | - $fp = fsockopen ($this->server, 80, $errno, $errstr, 10); |
96 | | - |
97 | | - if ($fp) { |
98 | | - $query="POST ".$this->file.$p." HTTP/1.1 |
99 | | -Host: ".$this->server." |
100 | | -Cookie: $cookies |
101 | | -User-Agent: ".USERAGENT." |
102 | | -Content-Type: ".$content["type"]." |
103 | | -Content-Length: ".strlen($content["message"])." |
104 | | - |
105 | | -".$content["message"]." |
106 | | -\r\n\r\n"; |
107 | | - //debug(__FUNCTION__,$query,3); |
108 | | - fputs ($fp,$query); |
109 | | - while (!feof($fp)) { |
110 | | - $buf.= fgets($fp,128); |
111 | | - } |
112 | | - fclose($fp); |
113 | | - $this->raw=$buf; |
114 | | - |
115 | | - $this->headers=$this->getheaders(); |
116 | | - $this->data=$this->removeheaders(); |
117 | | - //debug(__FUNCTION__,$this->headers,3); |
118 | | - //debug(__FUNCTION__,$this->data,3); |
119 | | - $this->update_cookies(); |
120 | | - preg_match('@Location: http://(.*)/(.*)\r\n@iU',$this->headers,$hit); |
121 | | - if($hit[1]!="" && (!$ignore_redir)) { |
122 | | - $this->server=$hit[1]; |
123 | | - $this->file="/".$hit[2]; |
124 | | - //debug(__FUNCTION__,"following http redirect to ".$this->server." // ".$this->file,1); |
125 | | - $this->data=$this->post("",$content); |
126 | | - } |
127 | | - flush(); |
128 | | - return $this->data; |
129 | | - } else { |
130 | | - echo "$errno: $errstr"; |
131 | | - } |
132 | | - } |
133 | | - |
134 | | - function removeheaders() { |
135 | | - //debug(__FUNCTION__,__FUNCTION__." called",1); |
136 | | - preg_match ("/\r\n\r\n(.*)$/is",$this->raw,$hit); |
137 | | - return $hit[1]; |
138 | | - } |
139 | | - function getheaders() { |
140 | | - //debug(__FUNCTION__,__FUNCTION__." called",1); |
141 | | - preg_match ("/^(.*)\r\n\r\n/is",$this->raw,$hit); |
142 | | - return $hit[1]; |
143 | | - } |
144 | | - |
145 | | - function cookiestring() { |
146 | | - global $cookies; |
147 | | - //debug(__FUNCTION__,__FUNCTION__." called",1); |
148 | | - return $cookies; |
149 | | - } |
150 | | - function update_cookies() { |
151 | | - global $cookies; |
152 | | - //debug(__FUNCTION__,__FUNCTION__." called",1); |
153 | | - $hits=preg_match_all('@Set-Cookie: (.*)=(.*); (expires|path)(.*)@isU',$this->headers,$hit,PREG_SET_ORDER); |
154 | | - //debug(__FUNCTION__,"cookie preg hits $hits",3); |
155 | | - foreach($hit as $k=>$v) { |
156 | | - $cookies.=$v[1]."=".$v[2].";"; |
157 | | - } |
158 | | - //debug(__FUNCTION__,"cookies updated to $cookies",3); |
159 | | - if(USE_COOKIEJAR) { |
160 | | - $fp=fopen(COOKIEJAR,"w"); |
161 | | - fputs($fp,$cookies); |
162 | | - fclose($fp); |
163 | | - } |
164 | | - } |
165 | | -} |
Index: trunk/extensions/TSPoll/TSPoll.php |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | } |
43 | 43 | |
44 | 44 | $wgExtensionMessagesFiles['TSPoll'] = dirname( __FILE__ ) . '/TSPoll.i18n.php'; |
45 | | -include_once(dirname( __FILE__ ) . '/http.func.php'); |
| 45 | +include_once($IP.'/includes/HttpFunctions.php'); |
46 | 46 | |
47 | 47 | function efTSPollSetup() { |
48 | 48 | global $wgParser; |
— | — | @@ -66,8 +66,8 @@ |
67 | 67 | } |
68 | 68 | |
69 | 69 | // @todo Can't we just use the Http class? |
70 | | - $http = new http_w( 'toolserver.org', '/~jan/poll/dev/main.php?page=wiki_output&id=' . $id ); |
71 | | - $get_server = $http->get(); |
| 70 | + $http = new http(); |
| 71 | + $get_server = $http->get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); |
72 | 72 | if( $get_server != '' ) { |
73 | 73 | return $get_server; |
74 | 74 | } |