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 // +----------------------------------------------------------------------+
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')){
26 $details = parse_url(AK_REMOTE_CONVERTER_URI
);
27 if(empty($details['host'])){
30 $port = empty($details['port']) ?
80 : $details['port'];
31 $path = empty($details['path']) ?
'' : $details['path'];
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");
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]));
46 $result = join("\n",$result);
49 return $result == 'CONVERTER_NOT_AVAILABLE' ?
false : $result;