@@ -3,9 +3,9 @@ |
||
3 | 3 | |
4 | 4 | class myErrorHandler extends \Exception |
5 | 5 | { |
6 | - public function proc_error($errno, $errstr, $errfile, $errline) |
|
7 | - { |
|
8 | - echo "line: $errline --- ".$errstr."<br>"; |
|
6 | + public function proc_error($errno, $errstr, $errfile, $errline) |
|
7 | + { |
|
8 | + echo "line: $errline --- ".$errstr."<br>"; |
|
9 | 9 | |
10 | - } |
|
10 | + } |
|
11 | 11 | } |
@@ -3,373 +3,373 @@ discard block |
||
3 | 3 | |
4 | 4 | class CurlHttpClient |
5 | 5 | { |
6 | - var $ch ; |
|
7 | - var $debug = false; |
|
8 | - var $error_msg; |
|
6 | + var $ch ; |
|
7 | + var $debug = false; |
|
8 | + var $error_msg; |
|
9 | 9 | |
10 | - function CurlHttpClient($debug = false) |
|
11 | - { |
|
12 | - $this->debug = $debug; |
|
13 | - $this->init(); |
|
14 | - } |
|
10 | + function CurlHttpClient($debug = false) |
|
11 | + { |
|
12 | + $this->debug = $debug; |
|
13 | + $this->init(); |
|
14 | + } |
|
15 | 15 | |
16 | - function init() |
|
17 | - { |
|
18 | - // initialize curl handle |
|
19 | - $this->ch = curl_init(); |
|
20 | - //set various options |
|
21 | - //set error in case http return code bigger than 300 |
|
22 | - curl_setopt($this->ch, CURLOPT_FAILONERROR, true); |
|
23 | - // use gzip if possible |
|
24 | - curl_setopt($this->ch,CURLOPT_ENCODING , 'gzip, deflate'); |
|
25 | - // do not veryfy ssl |
|
26 | - // this is important for windows |
|
27 | - // as well for being able to access pages with non valid cert |
|
28 | - curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
29 | - } |
|
16 | + function init() |
|
17 | + { |
|
18 | + // initialize curl handle |
|
19 | + $this->ch = curl_init(); |
|
20 | + //set various options |
|
21 | + //set error in case http return code bigger than 300 |
|
22 | + curl_setopt($this->ch, CURLOPT_FAILONERROR, true); |
|
23 | + // use gzip if possible |
|
24 | + curl_setopt($this->ch,CURLOPT_ENCODING , 'gzip, deflate'); |
|
25 | + // do not veryfy ssl |
|
26 | + // this is important for windows |
|
27 | + // as well for being able to access pages with non valid cert |
|
28 | + curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Set username/pass for basic http auth |
|
33 | - * @param string user |
|
34 | - * @param string pass |
|
35 | - * @access public |
|
36 | - */ |
|
37 | - function setCredentials($username,$password) |
|
38 | - { |
|
39 | - curl_setopt($this->ch, CURLOPT_USERPWD, "$username:$password"); |
|
40 | - } |
|
31 | + /** |
|
32 | + * Set username/pass for basic http auth |
|
33 | + * @param string user |
|
34 | + * @param string pass |
|
35 | + * @access public |
|
36 | + */ |
|
37 | + function setCredentials($username,$password) |
|
38 | + { |
|
39 | + curl_setopt($this->ch, CURLOPT_USERPWD, "$username:$password"); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Set referrer |
|
44 | - * @param string referrer url |
|
45 | - * @access public |
|
46 | - */ |
|
47 | - function setReferrer($referrer_url) |
|
48 | - { |
|
49 | - curl_setopt($this->ch, CURLOPT_REFERER, $referrer_url); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Set referrer |
|
44 | + * @param string referrer url |
|
45 | + * @access public |
|
46 | + */ |
|
47 | + function setReferrer($referrer_url) |
|
48 | + { |
|
49 | + curl_setopt($this->ch, CURLOPT_REFERER, $referrer_url); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Set client's userAgent |
|
54 | - * @param string user agent |
|
55 | - * @access public |
|
56 | - */ |
|
57 | - function setUserAgent($userAgent) |
|
58 | - { |
|
59 | - curl_setopt($this->ch, CURLOPT_USERAGENT, $userAgent); |
|
60 | - } |
|
52 | + /** |
|
53 | + * Set client's userAgent |
|
54 | + * @param string user agent |
|
55 | + * @access public |
|
56 | + */ |
|
57 | + function setUserAgent($userAgent) |
|
58 | + { |
|
59 | + curl_setopt($this->ch, CURLOPT_USERAGENT, $userAgent); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Set to receive output headers in all output functions |
|
64 | - * @param boolean true to include all response headers with output, false otherwise |
|
65 | - * @access public |
|
66 | - */ |
|
67 | - function includeResponseHeaders($value) |
|
68 | - { |
|
69 | - curl_setopt($this->ch, CURLOPT_HEADER, $value); |
|
70 | - } |
|
62 | + /** |
|
63 | + * Set to receive output headers in all output functions |
|
64 | + * @param boolean true to include all response headers with output, false otherwise |
|
65 | + * @access public |
|
66 | + */ |
|
67 | + function includeResponseHeaders($value) |
|
68 | + { |
|
69 | + curl_setopt($this->ch, CURLOPT_HEADER, $value); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Set proxy to use for each curl request |
|
74 | - * @param string proxy |
|
75 | - * @access public |
|
76 | - */ |
|
77 | - function setProxy($proxy) |
|
78 | - { |
|
79 | - curl_setopt($this->ch, CURLOPT_PROXY, $proxy); |
|
80 | - } |
|
72 | + /** |
|
73 | + * Set proxy to use for each curl request |
|
74 | + * @param string proxy |
|
75 | + * @access public |
|
76 | + */ |
|
77 | + function setProxy($proxy) |
|
78 | + { |
|
79 | + curl_setopt($this->ch, CURLOPT_PROXY, $proxy); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Send post data to target URL |
|
84 | - * return data returned from url or false if error occured |
|
85 | - * @param string url |
|
86 | - * @param mixed post data (assoc array ie. $foo['post_var_name'] = $value or as string like var=val1&var2=val2) |
|
87 | - * @param string ip address to bind (default null) |
|
88 | - * @param int timeout in sec for complete curl operation (default 10) |
|
89 | - * @return string data |
|
90 | - * @access public |
|
91 | - */ |
|
92 | - function sendPostData($url, $postdata, $ip=null, $timeout=10) |
|
93 | - { |
|
94 | - //set various curl options first |
|
95 | - // set url to post to |
|
96 | - curl_setopt($this->ch, CURLOPT_URL,$url); |
|
97 | - // return into a variable rather than displaying it |
|
98 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); |
|
82 | + /** |
|
83 | + * Send post data to target URL |
|
84 | + * return data returned from url or false if error occured |
|
85 | + * @param string url |
|
86 | + * @param mixed post data (assoc array ie. $foo['post_var_name'] = $value or as string like var=val1&var2=val2) |
|
87 | + * @param string ip address to bind (default null) |
|
88 | + * @param int timeout in sec for complete curl operation (default 10) |
|
89 | + * @return string data |
|
90 | + * @access public |
|
91 | + */ |
|
92 | + function sendPostData($url, $postdata, $ip=null, $timeout=10) |
|
93 | + { |
|
94 | + //set various curl options first |
|
95 | + // set url to post to |
|
96 | + curl_setopt($this->ch, CURLOPT_URL,$url); |
|
97 | + // return into a variable rather than displaying it |
|
98 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); |
|
99 | 99 | |
100 | - //bind to specific ip address if it is sent trough arguments |
|
101 | - if($ip) { |
|
102 | - if($this->debug) |
|
103 | - { |
|
104 | - echo "Binding to ip $ip\n"; |
|
105 | - } |
|
106 | - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
107 | - } |
|
100 | + //bind to specific ip address if it is sent trough arguments |
|
101 | + if($ip) { |
|
102 | + if($this->debug) |
|
103 | + { |
|
104 | + echo "Binding to ip $ip\n"; |
|
105 | + } |
|
106 | + curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
107 | + } |
|
108 | 108 | |
109 | - //set curl function timeout to $timeout |
|
110 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
109 | + //set curl function timeout to $timeout |
|
110 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
111 | 111 | |
112 | - //set method to post |
|
113 | - curl_setopt($this->ch, CURLOPT_POST, true); |
|
114 | - // set post string |
|
115 | - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postdata); |
|
112 | + //set method to post |
|
113 | + curl_setopt($this->ch, CURLOPT_POST, true); |
|
114 | + // set post string |
|
115 | + curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postdata); |
|
116 | 116 | |
117 | - //and finally send curl request |
|
118 | - $result = curl_exec_redir($this->ch); |
|
119 | - if(curl_errno($this->ch)) { |
|
120 | - if($this->debug) { |
|
121 | - echo "Error Occured in Curl\n"; |
|
122 | - echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
123 | - echo "Error message: " .curl_error($this->ch)."\n"; |
|
124 | - } |
|
125 | - return false; |
|
126 | - } else { |
|
127 | - return $result; |
|
128 | - } |
|
129 | - } |
|
117 | + //and finally send curl request |
|
118 | + $result = curl_exec_redir($this->ch); |
|
119 | + if(curl_errno($this->ch)) { |
|
120 | + if($this->debug) { |
|
121 | + echo "Error Occured in Curl\n"; |
|
122 | + echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
123 | + echo "Error message: " .curl_error($this->ch)."\n"; |
|
124 | + } |
|
125 | + return false; |
|
126 | + } else { |
|
127 | + return $result; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * fetch data from target URL |
|
133 | - * return data returned from url or false if error occured |
|
134 | - * @param string url |
|
135 | - * @param string ip address to bind (default null) |
|
136 | - * @param int timeout in sec for complete curl operation (default 5) |
|
137 | - * @return string data |
|
138 | - * @access public |
|
139 | - */ |
|
140 | - function fetchUrl($url, $ip=null, $timeout=5) |
|
141 | - { |
|
142 | - // set url to post to |
|
143 | - curl_setopt($this->ch, CURLOPT_URL,$url); |
|
131 | + /** |
|
132 | + * fetch data from target URL |
|
133 | + * return data returned from url or false if error occured |
|
134 | + * @param string url |
|
135 | + * @param string ip address to bind (default null) |
|
136 | + * @param int timeout in sec for complete curl operation (default 5) |
|
137 | + * @return string data |
|
138 | + * @access public |
|
139 | + */ |
|
140 | + function fetchUrl($url, $ip=null, $timeout=5) |
|
141 | + { |
|
142 | + // set url to post to |
|
143 | + curl_setopt($this->ch, CURLOPT_URL,$url); |
|
144 | 144 | |
145 | - //set method to get |
|
146 | - curl_setopt($this->ch, CURLOPT_HTTPGET,true); |
|
147 | - // return into a variable rather than displaying it |
|
148 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); |
|
145 | + //set method to get |
|
146 | + curl_setopt($this->ch, CURLOPT_HTTPGET,true); |
|
147 | + // return into a variable rather than displaying it |
|
148 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); |
|
149 | 149 | |
150 | - //bind to specific ip address if it is sent trough arguments |
|
151 | - if($ip) { |
|
152 | - if($this->debug) { |
|
153 | - echo "Binding to ip $ip\n"; |
|
154 | - } |
|
150 | + //bind to specific ip address if it is sent trough arguments |
|
151 | + if($ip) { |
|
152 | + if($this->debug) { |
|
153 | + echo "Binding to ip $ip\n"; |
|
154 | + } |
|
155 | 155 | |
156 | - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
157 | - } |
|
156 | + curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
157 | + } |
|
158 | 158 | |
159 | - //set curl function timeout to $timeout |
|
160 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
159 | + //set curl function timeout to $timeout |
|
160 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
161 | 161 | |
162 | - //and finally send curl request |
|
163 | - $result = curl_exec_redir($this->ch); |
|
164 | - if(curl_errno($this->ch)) { |
|
165 | - if($this->debug) { |
|
166 | - echo "Error Occured in Curl\n"; |
|
167 | - echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
168 | - echo "Error message: " .curl_error($this->ch)."\n"; |
|
169 | - } |
|
170 | - return false; |
|
171 | - } else { |
|
172 | - return $result; |
|
173 | - } |
|
174 | - } |
|
162 | + //and finally send curl request |
|
163 | + $result = curl_exec_redir($this->ch); |
|
164 | + if(curl_errno($this->ch)) { |
|
165 | + if($this->debug) { |
|
166 | + echo "Error Occured in Curl\n"; |
|
167 | + echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
168 | + echo "Error message: " .curl_error($this->ch)."\n"; |
|
169 | + } |
|
170 | + return false; |
|
171 | + } else { |
|
172 | + return $result; |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Fetch data from target URL |
|
178 | - * and store it directly to file |
|
179 | - * @param string url |
|
180 | - * @param resource value stream resource(ie. fopen) |
|
181 | - * @param string ip address to bind (default null) |
|
182 | - * @param int timeout in sec for complete curl operation (default 5) |
|
183 | - * @return boolean true on success false othervise |
|
184 | - * @access public |
|
185 | - */ |
|
186 | - function fetchIntoFile($url, $fp, $ip=null, $timeout=5) |
|
187 | - { |
|
188 | - // set url to post to |
|
189 | - curl_setopt($this->ch, CURLOPT_URL,$url); |
|
190 | - //set method to get |
|
191 | - curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
192 | - // store data into file rather than displaying it |
|
193 | - curl_setopt($this->ch, CURLOPT_FILE, $fp); |
|
176 | + /** |
|
177 | + * Fetch data from target URL |
|
178 | + * and store it directly to file |
|
179 | + * @param string url |
|
180 | + * @param resource value stream resource(ie. fopen) |
|
181 | + * @param string ip address to bind (default null) |
|
182 | + * @param int timeout in sec for complete curl operation (default 5) |
|
183 | + * @return boolean true on success false othervise |
|
184 | + * @access public |
|
185 | + */ |
|
186 | + function fetchIntoFile($url, $fp, $ip=null, $timeout=5) |
|
187 | + { |
|
188 | + // set url to post to |
|
189 | + curl_setopt($this->ch, CURLOPT_URL,$url); |
|
190 | + //set method to get |
|
191 | + curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
192 | + // store data into file rather than displaying it |
|
193 | + curl_setopt($this->ch, CURLOPT_FILE, $fp); |
|
194 | 194 | |
195 | - //bind to specific ip address if it is sent trough arguments |
|
196 | - if($ip) { |
|
197 | - if($this->debug) { |
|
198 | - echo "Binding to ip $ip\n"; |
|
199 | - } |
|
200 | - curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
201 | - } |
|
195 | + //bind to specific ip address if it is sent trough arguments |
|
196 | + if($ip) { |
|
197 | + if($this->debug) { |
|
198 | + echo "Binding to ip $ip\n"; |
|
199 | + } |
|
200 | + curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
201 | + } |
|
202 | 202 | |
203 | - //set curl function timeout to $timeout |
|
204 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
203 | + //set curl function timeout to $timeout |
|
204 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
205 | 205 | |
206 | - //and finally send curl request |
|
207 | - $result = curl_exec_redir($this->ch); |
|
208 | - if(curl_errno($this->ch)) { |
|
209 | - if($this->debug) { |
|
210 | - echo "Error Occured in Curl\n"; |
|
211 | - echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
212 | - echo "Error message: " .curl_error($this->ch)."\n"; |
|
213 | - } |
|
206 | + //and finally send curl request |
|
207 | + $result = curl_exec_redir($this->ch); |
|
208 | + if(curl_errno($this->ch)) { |
|
209 | + if($this->debug) { |
|
210 | + echo "Error Occured in Curl\n"; |
|
211 | + echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
212 | + echo "Error message: " .curl_error($this->ch)."\n"; |
|
213 | + } |
|
214 | 214 | |
215 | - return false; |
|
216 | - } else { |
|
217 | - return true; |
|
218 | - } |
|
219 | - } |
|
215 | + return false; |
|
216 | + } else { |
|
217 | + return true; |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * Send multipart post data to the target URL |
|
223 | - * return data returned from url or false if error occured |
|
224 | - * (contribution by vule nikolic, [email protected]) |
|
225 | - * @param string url |
|
226 | - * @param array assoc post data array ie. $foo['post_var_name'] = $value |
|
227 | - * @param array assoc $file_field_array, contains file_field name = value - path pairs |
|
228 | - * @param string ip address to bind (default null) |
|
229 | - * @param int timeout in sec for complete curl operation (default 30 sec) |
|
230 | - * @return string data |
|
231 | - * @access public |
|
232 | - */ |
|
233 | - function sendMultipartPostData($url, $postdata, $file_field_array=array(), $ip=null, $timeout=30) |
|
234 | - { |
|
235 | - //set various curl options first |
|
236 | - // set url to post to |
|
237 | - curl_setopt($this->ch, CURLOPT_URL, $url); |
|
238 | - // return into a variable rather than displaying it |
|
239 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
221 | + /** |
|
222 | + * Send multipart post data to the target URL |
|
223 | + * return data returned from url or false if error occured |
|
224 | + * (contribution by vule nikolic, [email protected]) |
|
225 | + * @param string url |
|
226 | + * @param array assoc post data array ie. $foo['post_var_name'] = $value |
|
227 | + * @param array assoc $file_field_array, contains file_field name = value - path pairs |
|
228 | + * @param string ip address to bind (default null) |
|
229 | + * @param int timeout in sec for complete curl operation (default 30 sec) |
|
230 | + * @return string data |
|
231 | + * @access public |
|
232 | + */ |
|
233 | + function sendMultipartPostData($url, $postdata, $file_field_array=array(), $ip=null, $timeout=30) |
|
234 | + { |
|
235 | + //set various curl options first |
|
236 | + // set url to post to |
|
237 | + curl_setopt($this->ch, CURLOPT_URL, $url); |
|
238 | + // return into a variable rather than displaying it |
|
239 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
240 | 240 | |
241 | - //bind to specific ip address if it is sent trough arguments |
|
242 | - if($ip) { |
|
243 | - if($this->debug) { |
|
244 | - echo "Binding to ip $ip\n"; |
|
245 | - } |
|
241 | + //bind to specific ip address if it is sent trough arguments |
|
242 | + if($ip) { |
|
243 | + if($this->debug) { |
|
244 | + echo "Binding to ip $ip\n"; |
|
245 | + } |
|
246 | 246 | |
247 | - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
248 | - } |
|
247 | + curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
248 | + } |
|
249 | 249 | |
250 | - //set curl function timeout to $timeout |
|
251 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
252 | - //set method to post |
|
253 | - curl_setopt($this->ch, CURLOPT_POST, true); |
|
254 | - // disable Expect header |
|
255 | - // hack to make it working |
|
256 | - $headers = array("Expect: "); |
|
257 | - curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers); |
|
258 | - // initialize result post array |
|
259 | - $result_post = array(); |
|
260 | - //generate post string |
|
261 | - $post_array = array(); |
|
262 | - $post_string_array = array(); |
|
250 | + //set curl function timeout to $timeout |
|
251 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
252 | + //set method to post |
|
253 | + curl_setopt($this->ch, CURLOPT_POST, true); |
|
254 | + // disable Expect header |
|
255 | + // hack to make it working |
|
256 | + $headers = array("Expect: "); |
|
257 | + curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers); |
|
258 | + // initialize result post array |
|
259 | + $result_post = array(); |
|
260 | + //generate post string |
|
261 | + $post_array = array(); |
|
262 | + $post_string_array = array(); |
|
263 | 263 | |
264 | - if(!is_array($postdata)) { |
|
265 | - return false; |
|
266 | - } |
|
264 | + if(!is_array($postdata)) { |
|
265 | + return false; |
|
266 | + } |
|
267 | 267 | |
268 | - foreach($postdata as $key=>$value) { |
|
269 | - $post_array[$key] = $value; |
|
270 | - $post_string_array[] = urlencode($key)."=".urlencode($value); |
|
271 | - } |
|
268 | + foreach($postdata as $key=>$value) { |
|
269 | + $post_array[$key] = $value; |
|
270 | + $post_string_array[] = urlencode($key)."=".urlencode($value); |
|
271 | + } |
|
272 | 272 | |
273 | - $post_string = implode("&",$post_string_array); |
|
274 | - if($this->debug) { |
|
275 | - echo "Post String: $post_string\n"; |
|
276 | - } |
|
273 | + $post_string = implode("&",$post_string_array); |
|
274 | + if($this->debug) { |
|
275 | + echo "Post String: $post_string\n"; |
|
276 | + } |
|
277 | 277 | |
278 | - // set post string |
|
279 | - //curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string); |
|
280 | - // set multipart form data - file array field-value pairs |
|
281 | - if(!empty($file_field_array)) { |
|
282 | - foreach($file_field_array as $var_name => $var_value) { |
|
283 | - if(strpos(PHP_OS, "WIN") !== false) $var_value = str_replace("/", "\\", $var_value); // win hack |
|
284 | - $file_field_array[$var_name] = "@".$var_value; |
|
285 | - } |
|
286 | - } |
|
278 | + // set post string |
|
279 | + //curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string); |
|
280 | + // set multipart form data - file array field-value pairs |
|
281 | + if(!empty($file_field_array)) { |
|
282 | + foreach($file_field_array as $var_name => $var_value) { |
|
283 | + if(strpos(PHP_OS, "WIN") !== false) $var_value = str_replace("/", "\\", $var_value); // win hack |
|
284 | + $file_field_array[$var_name] = "@".$var_value; |
|
285 | + } |
|
286 | + } |
|
287 | 287 | |
288 | - // set post data |
|
289 | - $result_post = array_merge($post_array, $file_field_array); |
|
290 | - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $result_post); |
|
288 | + // set post data |
|
289 | + $result_post = array_merge($post_array, $file_field_array); |
|
290 | + curl_setopt($this->ch, CURLOPT_POSTFIELDS, $result_post); |
|
291 | 291 | |
292 | - //and finally send curl request |
|
293 | - $result = curl_exec_redir($this->ch); |
|
294 | - if(curl_errno($this->ch)) { |
|
295 | - if($this->debug) { |
|
296 | - echo "Error Occured in Curl\n"; |
|
297 | - echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
298 | - echo "Error message: " .curl_error($this->ch)."\n"; |
|
299 | - } |
|
292 | + //and finally send curl request |
|
293 | + $result = curl_exec_redir($this->ch); |
|
294 | + if(curl_errno($this->ch)) { |
|
295 | + if($this->debug) { |
|
296 | + echo "Error Occured in Curl\n"; |
|
297 | + echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
298 | + echo "Error message: " .curl_error($this->ch)."\n"; |
|
299 | + } |
|
300 | 300 | |
301 | - return false; |
|
302 | - } else { |
|
303 | - return $result; |
|
304 | - } |
|
305 | - } |
|
301 | + return false; |
|
302 | + } else { |
|
303 | + return $result; |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * Set file location where cookie data will be stored and send on each new request |
|
309 | - * @param string absolute path to cookie file (must be in writable dir) |
|
310 | - * @access public |
|
311 | - */ |
|
312 | - function storeCookies($cookie_file) |
|
313 | - { |
|
314 | - // use cookies on each request (cookies stored in $cookie_file) |
|
315 | - curl_setopt ($this->ch, CURLOPT_COOKIEJAR, $cookie_file); |
|
316 | - curl_setopt ($this->ch, CURLOPT_COOKIEFILE, $cookie_file); |
|
317 | - } |
|
307 | + /** |
|
308 | + * Set file location where cookie data will be stored and send on each new request |
|
309 | + * @param string absolute path to cookie file (must be in writable dir) |
|
310 | + * @access public |
|
311 | + */ |
|
312 | + function storeCookies($cookie_file) |
|
313 | + { |
|
314 | + // use cookies on each request (cookies stored in $cookie_file) |
|
315 | + curl_setopt ($this->ch, CURLOPT_COOKIEJAR, $cookie_file); |
|
316 | + curl_setopt ($this->ch, CURLOPT_COOKIEFILE, $cookie_file); |
|
317 | + } |
|
318 | 318 | |
319 | - /** |
|
320 | - * Set custom cookie |
|
321 | - * @param string cookie |
|
322 | - * @access public |
|
323 | - */ |
|
324 | - function setCookie($cookie) |
|
325 | - { |
|
326 | - curl_setopt ($this->ch, CURLOPT_COOKIE, $cookie); |
|
327 | - } |
|
319 | + /** |
|
320 | + * Set custom cookie |
|
321 | + * @param string cookie |
|
322 | + * @access public |
|
323 | + */ |
|
324 | + function setCookie($cookie) |
|
325 | + { |
|
326 | + curl_setopt ($this->ch, CURLOPT_COOKIE, $cookie); |
|
327 | + } |
|
328 | 328 | |
329 | - /** |
|
330 | - * Get last URL info |
|
331 | - * usefull when original url was redirected to other location |
|
332 | - * @access public |
|
333 | - * @return string url |
|
334 | - */ |
|
335 | - function getEffectiveUrl() |
|
336 | - { |
|
337 | - return curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL); |
|
338 | - } |
|
329 | + /** |
|
330 | + * Get last URL info |
|
331 | + * usefull when original url was redirected to other location |
|
332 | + * @access public |
|
333 | + * @return string url |
|
334 | + */ |
|
335 | + function getEffectiveUrl() |
|
336 | + { |
|
337 | + return curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL); |
|
338 | + } |
|
339 | 339 | |
340 | - /** |
|
341 | - * Get http response code |
|
342 | - * @access public |
|
343 | - * @return int |
|
344 | - */ |
|
345 | - function getHttpResponseCode() |
|
346 | - { |
|
347 | - return curl_getinfo($this->ch, CURLINFO_HTTP_CODE); |
|
348 | - } |
|
340 | + /** |
|
341 | + * Get http response code |
|
342 | + * @access public |
|
343 | + * @return int |
|
344 | + */ |
|
345 | + function getHttpResponseCode() |
|
346 | + { |
|
347 | + return curl_getinfo($this->ch, CURLINFO_HTTP_CODE); |
|
348 | + } |
|
349 | 349 | |
350 | - /** |
|
351 | - * Return last error message and error number |
|
352 | - * @return string error msg |
|
353 | - * @access public |
|
354 | - */ |
|
355 | - function getErrorMsg() |
|
356 | - { |
|
357 | - $err = "Error number: " .curl_errno($this->ch) ."\n"; |
|
358 | - $err .="Error message: " .curl_error($this->ch)."\n"; |
|
359 | - return $err; |
|
360 | - } |
|
350 | + /** |
|
351 | + * Return last error message and error number |
|
352 | + * @return string error msg |
|
353 | + * @access public |
|
354 | + */ |
|
355 | + function getErrorMsg() |
|
356 | + { |
|
357 | + $err = "Error number: " .curl_errno($this->ch) ."\n"; |
|
358 | + $err .="Error message: " .curl_error($this->ch)."\n"; |
|
359 | + return $err; |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
363 | - * Close curl session and free resource |
|
364 | - * Usually no need to call this function directly |
|
365 | - * in case you do you have to call init() to recreate curl |
|
366 | - * @access public |
|
367 | - */ |
|
368 | - function close() |
|
369 | - { |
|
370 | - //close curl session and free up resources |
|
371 | - curl_close($this->ch); |
|
372 | - } |
|
362 | + /** |
|
363 | + * Close curl session and free resource |
|
364 | + * Usually no need to call this function directly |
|
365 | + * in case you do you have to call init() to recreate curl |
|
366 | + * @access public |
|
367 | + */ |
|
368 | + function close() |
|
369 | + { |
|
370 | + //close curl session and free up resources |
|
371 | + curl_close($this->ch); |
|
372 | + } |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -378,58 +378,58 @@ discard block |
||
378 | 378 | */ |
379 | 379 | function curlExecRedir($ch) |
380 | 380 | { |
381 | - static $curl_loops = 0; |
|
382 | - static $curl_max_loops = 20; |
|
381 | + static $curl_loops = 0; |
|
382 | + static $curl_max_loops = 20; |
|
383 | 383 | |
384 | - if ($curl_loops++ >= $curl_max_loops) { |
|
385 | - $curl_loops = 0; |
|
386 | - return FALSE; |
|
387 | - } |
|
384 | + if ($curl_loops++ >= $curl_max_loops) { |
|
385 | + $curl_loops = 0; |
|
386 | + return FALSE; |
|
387 | + } |
|
388 | 388 | |
389 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); |
|
390 | - curl_setopt($ch, CURLOPT_HEADER, true); |
|
391 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
392 | - curl_setopt($ch, CURLOPT_VERBOSE, false); |
|
393 | - $data = curl_exec($ch); |
|
394 | - $data = str_replace("\r", "\n", str_replace("\r\n", "\n", $data)); |
|
395 | - list($header, $data) = explode("\n\n", $data, 2); |
|
396 | - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
389 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); |
|
390 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
391 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
392 | + curl_setopt($ch, CURLOPT_VERBOSE, false); |
|
393 | + $data = curl_exec($ch); |
|
394 | + $data = str_replace("\r", "\n", str_replace("\r\n", "\n", $data)); |
|
395 | + list($header, $data) = explode("\n\n", $data, 2); |
|
396 | + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
397 | 397 | |
398 | - //echo "*** Got HTTP code: $http_code ***\n"; |
|
399 | - //echo "** Got headers: \n$header\n\n"; |
|
398 | + //echo "*** Got HTTP code: $http_code ***\n"; |
|
399 | + //echo "** Got headers: \n$header\n\n"; |
|
400 | 400 | |
401 | - if ( $http_code == 301 || $http_code == 302 ) { |
|
402 | - // If we're redirected, we should revert to GET |
|
403 | - curl_setopt($ch, CURLOPT_HTTPGET,true); |
|
401 | + if ( $http_code == 301 || $http_code == 302 ) { |
|
402 | + // If we're redirected, we should revert to GET |
|
403 | + curl_setopt($ch, CURLOPT_HTTPGET,true); |
|
404 | 404 | |
405 | - $matches = array(); |
|
406 | - preg_match('/Location:\s*(.*?)(\n|$)/i', $header, $matches); |
|
407 | - $url = @parse_url(trim($matches[1])); |
|
405 | + $matches = array(); |
|
406 | + preg_match('/Location:\s*(.*?)(\n|$)/i', $header, $matches); |
|
407 | + $url = @parse_url(trim($matches[1])); |
|
408 | 408 | |
409 | - if (!$url) { |
|
410 | - //couldn't process the url to redirect to |
|
411 | - $curl_loops = 0; |
|
412 | - return $data; |
|
413 | - } |
|
409 | + if (!$url) { |
|
410 | + //couldn't process the url to redirect to |
|
411 | + $curl_loops = 0; |
|
412 | + return $data; |
|
413 | + } |
|
414 | 414 | |
415 | - $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); |
|
416 | - if (empty($url['scheme'])) |
|
417 | - $url['scheme'] = $last_url['scheme']; |
|
415 | + $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); |
|
416 | + if (empty($url['scheme'])) |
|
417 | + $url['scheme'] = $last_url['scheme']; |
|
418 | 418 | |
419 | - if (empty($url['host'])) |
|
420 | - $url['host'] = $last_url['host']; |
|
419 | + if (empty($url['host'])) |
|
420 | + $url['host'] = $last_url['host']; |
|
421 | 421 | |
422 | - if (empty($url['path'])) |
|
423 | - $url['path'] = $last_url['path']; |
|
422 | + if (empty($url['path'])) |
|
423 | + $url['path'] = $last_url['path']; |
|
424 | 424 | |
425 | - $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . (!empty($url['query'])?'?'.$url['query']:''); |
|
426 | - //echo "Being redirected to $new_url\n"; |
|
427 | - curl_setopt($ch, CURLOPT_URL, $new_url); |
|
425 | + $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . (!empty($url['query'])?'?'.$url['query']:''); |
|
426 | + //echo "Being redirected to $new_url\n"; |
|
427 | + curl_setopt($ch, CURLOPT_URL, $new_url); |
|
428 | 428 | |
429 | - return curl_exec_redir($ch); |
|
430 | - } else { |
|
431 | - $curl_loops=0; |
|
432 | - return $data; |
|
433 | - } |
|
429 | + return curl_exec_redir($ch); |
|
430 | + } else { |
|
431 | + $curl_loops=0; |
|
432 | + return $data; |
|
433 | + } |
|
434 | 434 | } |
435 | 435 | ?> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | class CurlHttpClient |
5 | 5 | { |
6 | - var $ch ; |
|
6 | + var $ch; |
|
7 | 7 | var $debug = false; |
8 | 8 | var $error_msg; |
9 | 9 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | //set error in case http return code bigger than 300 |
22 | 22 | curl_setopt($this->ch, CURLOPT_FAILONERROR, true); |
23 | 23 | // use gzip if possible |
24 | - curl_setopt($this->ch,CURLOPT_ENCODING , 'gzip, deflate'); |
|
24 | + curl_setopt($this->ch, CURLOPT_ENCODING, 'gzip, deflate'); |
|
25 | 25 | // do not veryfy ssl |
26 | 26 | // this is important for windows |
27 | 27 | // as well for being able to access pages with non valid cert |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param string pass |
35 | 35 | * @access public |
36 | 36 | */ |
37 | - function setCredentials($username,$password) |
|
37 | + function setCredentials($username, $password) |
|
38 | 38 | { |
39 | 39 | curl_setopt($this->ch, CURLOPT_USERPWD, "$username:$password"); |
40 | 40 | } |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | * @return string data |
90 | 90 | * @access public |
91 | 91 | */ |
92 | - function sendPostData($url, $postdata, $ip=null, $timeout=10) |
|
92 | + function sendPostData($url, $postdata, $ip = null, $timeout = 10) |
|
93 | 93 | { |
94 | 94 | //set various curl options first |
95 | 95 | // set url to post to |
96 | - curl_setopt($this->ch, CURLOPT_URL,$url); |
|
96 | + curl_setopt($this->ch, CURLOPT_URL, $url); |
|
97 | 97 | // return into a variable rather than displaying it |
98 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); |
|
98 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
99 | 99 | |
100 | 100 | //bind to specific ip address if it is sent trough arguments |
101 | - if($ip) { |
|
102 | - if($this->debug) |
|
101 | + if ($ip) { |
|
102 | + if ($this->debug) |
|
103 | 103 | { |
104 | 104 | echo "Binding to ip $ip\n"; |
105 | 105 | } |
106 | - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
106 | + curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | //set curl function timeout to $timeout |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | |
117 | 117 | //and finally send curl request |
118 | 118 | $result = curl_exec_redir($this->ch); |
119 | - if(curl_errno($this->ch)) { |
|
120 | - if($this->debug) { |
|
119 | + if (curl_errno($this->ch)) { |
|
120 | + if ($this->debug) { |
|
121 | 121 | echo "Error Occured in Curl\n"; |
122 | - echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
123 | - echo "Error message: " .curl_error($this->ch)."\n"; |
|
122 | + echo "Error number: ".curl_errno($this->ch)."\n"; |
|
123 | + echo "Error message: ".curl_error($this->ch)."\n"; |
|
124 | 124 | } |
125 | 125 | return false; |
126 | 126 | } else { |
@@ -137,23 +137,23 @@ discard block |
||
137 | 137 | * @return string data |
138 | 138 | * @access public |
139 | 139 | */ |
140 | - function fetchUrl($url, $ip=null, $timeout=5) |
|
140 | + function fetchUrl($url, $ip = null, $timeout = 5) |
|
141 | 141 | { |
142 | 142 | // set url to post to |
143 | - curl_setopt($this->ch, CURLOPT_URL,$url); |
|
143 | + curl_setopt($this->ch, CURLOPT_URL, $url); |
|
144 | 144 | |
145 | 145 | //set method to get |
146 | - curl_setopt($this->ch, CURLOPT_HTTPGET,true); |
|
146 | + curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
147 | 147 | // return into a variable rather than displaying it |
148 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true); |
|
148 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
149 | 149 | |
150 | 150 | //bind to specific ip address if it is sent trough arguments |
151 | - if($ip) { |
|
152 | - if($this->debug) { |
|
151 | + if ($ip) { |
|
152 | + if ($this->debug) { |
|
153 | 153 | echo "Binding to ip $ip\n"; |
154 | 154 | } |
155 | 155 | |
156 | - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
156 | + curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | //set curl function timeout to $timeout |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | |
162 | 162 | //and finally send curl request |
163 | 163 | $result = curl_exec_redir($this->ch); |
164 | - if(curl_errno($this->ch)) { |
|
165 | - if($this->debug) { |
|
164 | + if (curl_errno($this->ch)) { |
|
165 | + if ($this->debug) { |
|
166 | 166 | echo "Error Occured in Curl\n"; |
167 | - echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
168 | - echo "Error message: " .curl_error($this->ch)."\n"; |
|
167 | + echo "Error number: ".curl_errno($this->ch)."\n"; |
|
168 | + echo "Error message: ".curl_error($this->ch)."\n"; |
|
169 | 169 | } |
170 | 170 | return false; |
171 | 171 | } else { |
@@ -183,18 +183,18 @@ discard block |
||
183 | 183 | * @return boolean true on success false othervise |
184 | 184 | * @access public |
185 | 185 | */ |
186 | - function fetchIntoFile($url, $fp, $ip=null, $timeout=5) |
|
186 | + function fetchIntoFile($url, $fp, $ip = null, $timeout = 5) |
|
187 | 187 | { |
188 | 188 | // set url to post to |
189 | - curl_setopt($this->ch, CURLOPT_URL,$url); |
|
189 | + curl_setopt($this->ch, CURLOPT_URL, $url); |
|
190 | 190 | //set method to get |
191 | 191 | curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
192 | 192 | // store data into file rather than displaying it |
193 | 193 | curl_setopt($this->ch, CURLOPT_FILE, $fp); |
194 | 194 | |
195 | 195 | //bind to specific ip address if it is sent trough arguments |
196 | - if($ip) { |
|
197 | - if($this->debug) { |
|
196 | + if ($ip) { |
|
197 | + if ($this->debug) { |
|
198 | 198 | echo "Binding to ip $ip\n"; |
199 | 199 | } |
200 | 200 | curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | |
206 | 206 | //and finally send curl request |
207 | 207 | $result = curl_exec_redir($this->ch); |
208 | - if(curl_errno($this->ch)) { |
|
209 | - if($this->debug) { |
|
208 | + if (curl_errno($this->ch)) { |
|
209 | + if ($this->debug) { |
|
210 | 210 | echo "Error Occured in Curl\n"; |
211 | - echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
212 | - echo "Error message: " .curl_error($this->ch)."\n"; |
|
211 | + echo "Error number: ".curl_errno($this->ch)."\n"; |
|
212 | + echo "Error message: ".curl_error($this->ch)."\n"; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return false; |
216 | - } else { |
|
216 | + } else { |
|
217 | 217 | return true; |
218 | 218 | } |
219 | 219 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @return string data |
231 | 231 | * @access public |
232 | 232 | */ |
233 | - function sendMultipartPostData($url, $postdata, $file_field_array=array(), $ip=null, $timeout=30) |
|
233 | + function sendMultipartPostData($url, $postdata, $file_field_array = array(), $ip = null, $timeout = 30) |
|
234 | 234 | { |
235 | 235 | //set various curl options first |
236 | 236 | // set url to post to |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
240 | 240 | |
241 | 241 | //bind to specific ip address if it is sent trough arguments |
242 | - if($ip) { |
|
243 | - if($this->debug) { |
|
242 | + if ($ip) { |
|
243 | + if ($this->debug) { |
|
244 | 244 | echo "Binding to ip $ip\n"; |
245 | 245 | } |
246 | 246 | |
247 | - curl_setopt($this->ch,CURLOPT_INTERFACE,$ip); |
|
247 | + curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | //set curl function timeout to $timeout |
@@ -261,26 +261,26 @@ discard block |
||
261 | 261 | $post_array = array(); |
262 | 262 | $post_string_array = array(); |
263 | 263 | |
264 | - if(!is_array($postdata)) { |
|
264 | + if (!is_array($postdata)) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - foreach($postdata as $key=>$value) { |
|
268 | + foreach ($postdata as $key=>$value) { |
|
269 | 269 | $post_array[$key] = $value; |
270 | 270 | $post_string_array[] = urlencode($key)."=".urlencode($value); |
271 | 271 | } |
272 | 272 | |
273 | - $post_string = implode("&",$post_string_array); |
|
274 | - if($this->debug) { |
|
273 | + $post_string = implode("&", $post_string_array); |
|
274 | + if ($this->debug) { |
|
275 | 275 | echo "Post String: $post_string\n"; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // set post string |
279 | 279 | //curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string); |
280 | 280 | // set multipart form data - file array field-value pairs |
281 | - if(!empty($file_field_array)) { |
|
282 | - foreach($file_field_array as $var_name => $var_value) { |
|
283 | - if(strpos(PHP_OS, "WIN") !== false) $var_value = str_replace("/", "\\", $var_value); // win hack |
|
281 | + if (!empty($file_field_array)) { |
|
282 | + foreach ($file_field_array as $var_name => $var_value) { |
|
283 | + if (strpos(PHP_OS, "WIN")!==false) $var_value = str_replace("/", "\\", $var_value); // win hack |
|
284 | 284 | $file_field_array[$var_name] = "@".$var_value; |
285 | 285 | } |
286 | 286 | } |
@@ -291,11 +291,11 @@ discard block |
||
291 | 291 | |
292 | 292 | //and finally send curl request |
293 | 293 | $result = curl_exec_redir($this->ch); |
294 | - if(curl_errno($this->ch)) { |
|
295 | - if($this->debug) { |
|
294 | + if (curl_errno($this->ch)) { |
|
295 | + if ($this->debug) { |
|
296 | 296 | echo "Error Occured in Curl\n"; |
297 | - echo "Error number: " .curl_errno($this->ch) ."\n"; |
|
298 | - echo "Error message: " .curl_error($this->ch)."\n"; |
|
297 | + echo "Error number: ".curl_errno($this->ch)."\n"; |
|
298 | + echo "Error message: ".curl_error($this->ch)."\n"; |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | return false; |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | function storeCookies($cookie_file) |
313 | 313 | { |
314 | 314 | // use cookies on each request (cookies stored in $cookie_file) |
315 | - curl_setopt ($this->ch, CURLOPT_COOKIEJAR, $cookie_file); |
|
316 | - curl_setopt ($this->ch, CURLOPT_COOKIEFILE, $cookie_file); |
|
315 | + curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookie_file); |
|
316 | + curl_setopt($this->ch, CURLOPT_COOKIEFILE, $cookie_file); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | */ |
324 | 324 | function setCookie($cookie) |
325 | 325 | { |
326 | - curl_setopt ($this->ch, CURLOPT_COOKIE, $cookie); |
|
326 | + curl_setopt($this->ch, CURLOPT_COOKIE, $cookie); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -354,8 +354,8 @@ discard block |
||
354 | 354 | */ |
355 | 355 | function getErrorMsg() |
356 | 356 | { |
357 | - $err = "Error number: " .curl_errno($this->ch) ."\n"; |
|
358 | - $err .="Error message: " .curl_error($this->ch)."\n"; |
|
357 | + $err = "Error number: ".curl_errno($this->ch)."\n"; |
|
358 | + $err .= "Error message: ".curl_error($this->ch)."\n"; |
|
359 | 359 | return $err; |
360 | 360 | } |
361 | 361 | |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | static $curl_loops = 0; |
382 | 382 | static $curl_max_loops = 20; |
383 | 383 | |
384 | - if ($curl_loops++ >= $curl_max_loops) { |
|
384 | + if ($curl_loops++>=$curl_max_loops) { |
|
385 | 385 | $curl_loops = 0; |
386 | 386 | return FALSE; |
387 | 387 | } |
@@ -398,9 +398,9 @@ discard block |
||
398 | 398 | //echo "*** Got HTTP code: $http_code ***\n"; |
399 | 399 | //echo "** Got headers: \n$header\n\n"; |
400 | 400 | |
401 | - if ( $http_code == 301 || $http_code == 302 ) { |
|
401 | + if ($http_code==301 || $http_code==302) { |
|
402 | 402 | // If we're redirected, we should revert to GET |
403 | - curl_setopt($ch, CURLOPT_HTTPGET,true); |
|
403 | + curl_setopt($ch, CURLOPT_HTTPGET, true); |
|
404 | 404 | |
405 | 405 | $matches = array(); |
406 | 406 | preg_match('/Location:\s*(.*?)(\n|$)/i', $header, $matches); |
@@ -422,13 +422,13 @@ discard block |
||
422 | 422 | if (empty($url['path'])) |
423 | 423 | $url['path'] = $last_url['path']; |
424 | 424 | |
425 | - $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . (!empty($url['query'])?'?'.$url['query']:''); |
|
425 | + $new_url = $url['scheme'].'://'.$url['host'].$url['path'].(!empty($url['query']) ? '?'.$url['query'] : ''); |
|
426 | 426 | //echo "Being redirected to $new_url\n"; |
427 | 427 | curl_setopt($ch, CURLOPT_URL, $new_url); |
428 | 428 | |
429 | 429 | return curl_exec_redir($ch); |
430 | 430 | } else { |
431 | - $curl_loops=0; |
|
431 | + $curl_loops = 0; |
|
432 | 432 | return $data; |
433 | 433 | } |
434 | 434 | } |
@@ -280,7 +280,10 @@ discard block |
||
280 | 280 | // set multipart form data - file array field-value pairs |
281 | 281 | if(!empty($file_field_array)) { |
282 | 282 | foreach($file_field_array as $var_name => $var_value) { |
283 | - if(strpos(PHP_OS, "WIN") !== false) $var_value = str_replace("/", "\\", $var_value); // win hack |
|
283 | + if(strpos(PHP_OS, "WIN") !== false) { |
|
284 | + $var_value = str_replace("/", "\\", $var_value); |
|
285 | + } |
|
286 | + // win hack |
|
284 | 287 | $file_field_array[$var_name] = "@".$var_value; |
285 | 288 | } |
286 | 289 | } |
@@ -413,14 +416,17 @@ discard block |
||
413 | 416 | } |
414 | 417 | |
415 | 418 | $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); |
416 | - if (empty($url['scheme'])) |
|
417 | - $url['scheme'] = $last_url['scheme']; |
|
419 | + if (empty($url['scheme'])) { |
|
420 | + $url['scheme'] = $last_url['scheme']; |
|
421 | + } |
|
418 | 422 | |
419 | - if (empty($url['host'])) |
|
420 | - $url['host'] = $last_url['host']; |
|
423 | + if (empty($url['host'])) { |
|
424 | + $url['host'] = $last_url['host']; |
|
425 | + } |
|
421 | 426 | |
422 | - if (empty($url['path'])) |
|
423 | - $url['path'] = $last_url['path']; |
|
427 | + if (empty($url['path'])) { |
|
428 | + $url['path'] = $last_url['path']; |
|
429 | + } |
|
424 | 430 | |
425 | 431 | $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . (!empty($url['query'])?'?'.$url['query']:''); |
426 | 432 | //echo "Being redirected to $new_url\n"; |
@@ -3,9 +3,9 @@ |
||
3 | 3 | |
4 | 4 | class Metric |
5 | 5 | { |
6 | - const EUCLIDEAN = 1; //measures point to point distance as a straight line |
|
7 | - const MANHATTAN = 2; //measures point to point distance as taxicab geometry line |
|
8 | - const GEODESIC = 3; //measures point to point distance approximating curvature of the earth |
|
9 | - const MATRIX = 4; //measures point to point distance by traversing the actual road network |
|
10 | - const EXACT_2D = 5; //measures point to point distance using 2d rectilinear distance |
|
6 | + const EUCLIDEAN = 1; //measures point to point distance as a straight line |
|
7 | + const MANHATTAN = 2; //measures point to point distance as taxicab geometry line |
|
8 | + const GEODESIC = 3; //measures point to point distance approximating curvature of the earth |
|
9 | + const MATRIX = 4; //measures point to point distance by traversing the actual road network |
|
10 | + const EXACT_2D = 5; //measures point to point distance using 2d rectilinear distance |
|
11 | 11 | } |
@@ -3,34 +3,34 @@ |
||
3 | 3 | |
4 | 4 | class ActivityTypes |
5 | 5 | { |
6 | - const AREA_REMOVED = 'area-removed'; |
|
7 | - const AREA_ADDED = 'area-added'; |
|
8 | - const AREA_UPDATED = 'area-updated'; |
|
9 | - const DELETE_DESTINATION = 'delete-destination'; |
|
10 | - const INSERT_DESTINATION = 'insert-destination'; |
|
11 | - const DESTINATION_OUT_SEQUENCE = 'destination-out-sequence'; |
|
12 | - const DRIVER_ARRIVED_EARLY = 'driver-arrived-early'; |
|
13 | - const DRIVER_ARRIVED_LATE = 'driver-arrived-late'; |
|
14 | - const DRIVER_ARRIVED_ON_TIME = 'driver-arrived-on-time'; |
|
15 | - const GEOFENCE_LEFT = 'geofence-left'; |
|
16 | - const GEOFENCE_ENTERED = 'geofence-entered'; |
|
17 | - const MARK_DESTINATION_DEPARTED = 'mark-destination-departed'; |
|
18 | - const MARK_DESTINATION_VISITED = 'mark-destination-visited'; |
|
19 | - const MEMBER_CREATED = 'member-created'; |
|
20 | - const MEMBER_DELETED = 'member-deleted'; |
|
21 | - const MEMBER_MODIFIED = 'member-modified'; |
|
22 | - const MOVE_DESTINATION = 'move-destination'; |
|
23 | - const NOTE_INSERT = 'note-insert'; |
|
24 | - const ROUTE_DELETE = 'route-delete'; |
|
25 | - const ROUTE_OPTIMIZED = 'route-optimized'; |
|
26 | - const ROUTE_OWNER_CHANGED = 'route-owner-changed'; |
|
27 | - const ROUTE_DUPLICATE = 'route-duplicate'; |
|
28 | - const UPDATE_DESTINATIONS = 'update-destinations'; |
|
29 | - const USER_MESSAGE = 'user_message'; |
|
6 | + const AREA_REMOVED = 'area-removed'; |
|
7 | + const AREA_ADDED = 'area-added'; |
|
8 | + const AREA_UPDATED = 'area-updated'; |
|
9 | + const DELETE_DESTINATION = 'delete-destination'; |
|
10 | + const INSERT_DESTINATION = 'insert-destination'; |
|
11 | + const DESTINATION_OUT_SEQUENCE = 'destination-out-sequence'; |
|
12 | + const DRIVER_ARRIVED_EARLY = 'driver-arrived-early'; |
|
13 | + const DRIVER_ARRIVED_LATE = 'driver-arrived-late'; |
|
14 | + const DRIVER_ARRIVED_ON_TIME = 'driver-arrived-on-time'; |
|
15 | + const GEOFENCE_LEFT = 'geofence-left'; |
|
16 | + const GEOFENCE_ENTERED = 'geofence-entered'; |
|
17 | + const MARK_DESTINATION_DEPARTED = 'mark-destination-departed'; |
|
18 | + const MARK_DESTINATION_VISITED = 'mark-destination-visited'; |
|
19 | + const MEMBER_CREATED = 'member-created'; |
|
20 | + const MEMBER_DELETED = 'member-deleted'; |
|
21 | + const MEMBER_MODIFIED = 'member-modified'; |
|
22 | + const MOVE_DESTINATION = 'move-destination'; |
|
23 | + const NOTE_INSERT = 'note-insert'; |
|
24 | + const ROUTE_DELETE = 'route-delete'; |
|
25 | + const ROUTE_OPTIMIZED = 'route-optimized'; |
|
26 | + const ROUTE_OWNER_CHANGED = 'route-owner-changed'; |
|
27 | + const ROUTE_DUPLICATE = 'route-duplicate'; |
|
28 | + const UPDATE_DESTINATIONS = 'update-destinations'; |
|
29 | + const USER_MESSAGE = 'user_message'; |
|
30 | 30 | |
31 | - static function getConstants() { |
|
32 | - $atc = new \ReflectionClass('Route4Me\\Enum\\ActivityTypes'); |
|
33 | - return $atc->getConstants(); |
|
34 | - } |
|
31 | + static function getConstants() { |
|
32 | + $atc = new \ReflectionClass('Route4Me\\Enum\\ActivityTypes'); |
|
33 | + return $atc->getConstants(); |
|
34 | + } |
|
35 | 35 | } |
36 | 36 |
@@ -3,9 +3,9 @@ |
||
3 | 3 | |
4 | 4 | class TravelMode |
5 | 5 | { |
6 | - const DRIVING = 'Driving'; |
|
7 | - const WALKING = 'Walking'; |
|
8 | - const TRUCKING = 'Trucking'; |
|
9 | - const CYCLING = 'Cycling'; |
|
10 | - const TRANSIT = 'Transit'; |
|
6 | + const DRIVING = 'Driving'; |
|
7 | + const WALKING = 'Walking'; |
|
8 | + const TRUCKING = 'Trucking'; |
|
9 | + const CYCLING = 'Cycling'; |
|
10 | + const TRANSIT = 'Transit'; |
|
11 | 11 | } |
@@ -3,26 +3,26 @@ |
||
3 | 3 | |
4 | 4 | class StatusUpdateType |
5 | 5 | { |
6 | - const PICKUP = 'pickup'; |
|
7 | - const DROPOFF = 'dropoff'; |
|
8 | - const NOANSWER = 'noanswer'; |
|
9 | - const NOTFOUND = 'notfound'; |
|
10 | - const NOTPAID = 'notpaid'; |
|
11 | - const PAID = 'paid'; |
|
12 | - const WRONGDELIVERY = 'wrongdelivery'; |
|
13 | - const WRONGADDRESSRECIPIENT = 'wrongaddressrecipient'; |
|
14 | - const NOTPRESENT = 'notpresent'; |
|
15 | - const PARTS_MISSING = 'parts_missing'; |
|
16 | - const SERVICE_RENDERED = 'service_rendered'; |
|
17 | - const FOLLOW_UP = 'follow_up'; |
|
18 | - const LEFT_INFORMATION = 'left_information'; |
|
19 | - const SPOKE_WITH_DECISION_MAKER = 'spoke_with_decision_maker'; |
|
20 | - const SPOKE_WITH_DECISION_INFLUENCER = 'spoke_with_decision_influencer'; |
|
21 | - const SPOKE_WITH_DECISION_INFLUENCER = 'spoke_with_decision_influencer'; |
|
22 | - const COMPETITIVE_ACCOUNT = 'competitive_account'; |
|
23 | - const SCHEDULED_FOLLOW_UP_MEETING = 'scheduled_follow_up_meeting'; |
|
24 | - const SCHEDULED_LUNCH = 'scheduled_lunch'; |
|
25 | - const SCHEDULED_PRODUCT_DEMO = 'scheduled_product_demo'; |
|
26 | - const SCHEDULED_CLINICAL_DEMO = 'scheduled_clinical_demo'; |
|
27 | - const NO_OPPORTUNITY = 'no_opportunity'; |
|
6 | + const PICKUP = 'pickup'; |
|
7 | + const DROPOFF = 'dropoff'; |
|
8 | + const NOANSWER = 'noanswer'; |
|
9 | + const NOTFOUND = 'notfound'; |
|
10 | + const NOTPAID = 'notpaid'; |
|
11 | + const PAID = 'paid'; |
|
12 | + const WRONGDELIVERY = 'wrongdelivery'; |
|
13 | + const WRONGADDRESSRECIPIENT = 'wrongaddressrecipient'; |
|
14 | + const NOTPRESENT = 'notpresent'; |
|
15 | + const PARTS_MISSING = 'parts_missing'; |
|
16 | + const SERVICE_RENDERED = 'service_rendered'; |
|
17 | + const FOLLOW_UP = 'follow_up'; |
|
18 | + const LEFT_INFORMATION = 'left_information'; |
|
19 | + const SPOKE_WITH_DECISION_MAKER = 'spoke_with_decision_maker'; |
|
20 | + const SPOKE_WITH_DECISION_INFLUENCER = 'spoke_with_decision_influencer'; |
|
21 | + const SPOKE_WITH_DECISION_INFLUENCER = 'spoke_with_decision_influencer'; |
|
22 | + const COMPETITIVE_ACCOUNT = 'competitive_account'; |
|
23 | + const SCHEDULED_FOLLOW_UP_MEETING = 'scheduled_follow_up_meeting'; |
|
24 | + const SCHEDULED_LUNCH = 'scheduled_lunch'; |
|
25 | + const SCHEDULED_PRODUCT_DEMO = 'scheduled_product_demo'; |
|
26 | + const SCHEDULED_CLINICAL_DEMO = 'scheduled_clinical_demo'; |
|
27 | + const NO_OPPORTUNITY = 'no_opportunity'; |
|
28 | 28 | } |
@@ -3,7 +3,7 @@ |
||
3 | 3 | |
4 | 4 | class OptimizationType |
5 | 5 | { |
6 | - const DISTANCE = 'Distance'; |
|
7 | - const TIME = 'Time'; |
|
8 | - const TIME_WITH_TRAFFIC = 'timeWithTraffic'; |
|
6 | + const DISTANCE = 'Distance'; |
|
7 | + const TIME = 'Time'; |
|
8 | + const TIME_WITH_TRAFFIC = 'timeWithTraffic'; |
|
9 | 9 | } |
@@ -3,10 +3,10 @@ |
||
3 | 3 | |
4 | 4 | class OptimizationStates |
5 | 5 | { |
6 | - const INITIAL = 1; |
|
7 | - const MATRIX_PROCESSING = 2; |
|
8 | - const OPTIMIZING = 3; |
|
9 | - const OPTIMIZED = 4; |
|
10 | - const ERROR = 5; |
|
11 | - const COMPUTING_DIRECTIONS = 6; |
|
6 | + const INITIAL = 1; |
|
7 | + const MATRIX_PROCESSING = 2; |
|
8 | + const OPTIMIZING = 3; |
|
9 | + const OPTIMIZED = 4; |
|
10 | + const ERROR = 5; |
|
11 | + const COMPUTING_DIRECTIONS = 6; |
|
12 | 12 | } |
@@ -3,7 +3,7 @@ |
||
3 | 3 | |
4 | 4 | class TerritoryTypes |
5 | 5 | { |
6 | - const CIRCLE = 'circle'; |
|
7 | - const POLY = 'poly'; |
|
8 | - const RECT = 'rect'; |
|
6 | + const CIRCLE = 'circle'; |
|
7 | + const POLY = 'poly'; |
|
8 | + const RECT = 'rect'; |
|
9 | 9 | } |