root/trunk/lib/AkConverters/AkRemoteConverter.php

Revision 1397, 2.1 kB (checked in by bermi, 6 months ago)

COnverting converters to PHP5

Line 
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
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 // +----------------------------------------------------------------------+
11
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>
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 ?>
Note: See TracBrowser for help on using the browser.