|
Revision 1397, 2.1 kB
(checked in by bermi, 6 months ago)
|
COnverting converters to PHP5
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class AkRemoteConverter |
|---|
| 20 |
{ |
|---|
| 21 |
public function convert($from, $to, $data) |
|---|
| 22 |
{ |
|---|
| 23 |
if(!defined('AK_REMOTE_CONVERTER_URI')){ |
|---|
| 24 |
return false; |
|---|
| 25 |
} |
|---|
| 26 |
$details = parse_url(AK_REMOTE_CONVERTER_URI); |
|---|
| 27 |
if(empty($details['host'])){ |
|---|
| 28 |
return false; |
|---|
| 29 |
} |
|---|
| 30 |
$port = empty($details['port']) ? 80 : $details['port']; |
|---|
| 31 |
$path = empty($details['path']) ? '' : $details['path']; |
|---|
| 32 |
|
|---|
| 33 |
$data = "data=$data"; |
|---|
| 34 |
if ($fp = fsockopen($details['host'], $port)) { |
|---|
| 35 |
fwrite($fp, "POST $path/{$_SERVER['SERVER_NAME']}/{$from}_to_{$to} HTTP/1.1\r\n". |
|---|
| 36 |
"Host: webservices.akelos.com\r\nContent-type: application/x-www-form-urlencoded\r\n". |
|---|
| 37 |
"User-Agent: Mozilla 4.0\r\nContent-length: ".strlen($data)."\r\nConnection: close\r\n\r\n$data"); |
|---|
| 38 |
$result = ''; |
|---|
| 39 |
while (!feof($fp)) { |
|---|
| 40 |
$result .= fgets($fp, 1024); |
|---|
| 41 |
} |
|---|
| 42 |
if(preg_match('/\n\n.*/ms',str_replace("\r\n","\n",$result),$match)){ |
|---|
| 43 |
$result = explode("\n",trim($match[0])); |
|---|
| 44 |
array_pop($result); |
|---|
| 45 |
array_shift($result); |
|---|
| 46 |
$result = join("\n",$result); |
|---|
| 47 |
} |
|---|
| 48 |
fclose($fp); |
|---|
| 49 |
return $result == 'CONVERTER_NOT_AVAILABLE' ? false : $result; |
|---|
| 50 |
} |
|---|
| 51 |
return false; |
|---|
| 52 |
} |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
?> |
|---|