Fixes #149
[akelos.git] / lib / AkConverters / AkRemoteConverter.php
blobee0f86d35f4b49381471df981462190e2d20fb0c
1 <?php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
5 // +----------------------------------------------------------------------+
6 // | Akelos Framework - http://www.akelos.org |
7 // +----------------------------------------------------------------------+
8 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez |
9 // | Released under the GNU Lesser General Public License, see LICENSE.txt|
10 // +----------------------------------------------------------------------+
12 /**
13 * @package ActiveSupport
14 * @subpackage Converters
15 * @author Bermi Ferrer <bermi a.t akelos c.om>
16 * @copyright Copyright (c) 2002-2007, Akelos Media, S.L. http://www.akelos.org
17 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
19 class AkRemoteConverter
21 function convert($from, $to, $data)
23 if(!defined('AK_REMOTE_CONVERTER_URI')){
24 return false;
26 $details = parse_url(AK_REMOTE_CONVERTER_URI);
27 if(empty($details['host'])){
28 return false;
30 $port = empty($details['port']) ? 80 : $details['port'];
31 $path = empty($details['path']) ? '' : $details['path'];
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);
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);
48 fclose($fp);
49 return $result == 'CONVERTER_NOT_AVAILABLE' ? false : $result;
51 return false;