Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/02/2017, 13:47
alfa18
 
Fecha de Ingreso: diciembre-2007
Mensajes: 299
Antigüedad: 17 años, 3 meses
Puntos: 2
Pregunta problemas con clase babelfish

Hola,
estoy trabajando con la clase babelfish, pero al ejecutarla obtengo un error fatal¡¡¡

Fatal error: Call to undefined function curl_init() in /..../babelfish/babelfish.class.php on line 117

Adjunto el codigo de la clase:
Código PHP:
Ver original
  1. <?php
  2. /*******************************************************************************
  3. ** Class: babelfish
  4. ** Purpose: Translate text using Altavista Babelfish
  5. ** Filename: babelfish.class.php
  6. ** Author: Vedanta Barooah
  7. ** Author Email: vedanta . barooah @ gmail . com
  8. ** Date: June 19 2005
  9. ** Last Updated: June 27 2007
  10. **
  11. ** Other Contributors:[email protected],[email protected],Nikolay Kubarelov <[email protected]>
  12. ********************************************************************************/
  13.  
  14. /* if ! PHP5 */
  15. if (!function_exists('http_build_query')) {
  16.    function http_build_query($formdata, $numeric_prefix = "")
  17.    {
  18.        $arr = array();
  19.        foreach ($formdata as $key => $val)
  20.          $arr[] = urlencode($numeric_prefix.$key)."=".urlencode($val);
  21.        return implode($arr, "&");
  22.    }
  23. }
  24. /* translate text using altavista babelfish */
  25. class babelfish{
  26.     /* array to store language names */
  27.     var $languages      =   NULL;
  28.     /* stores the altavista babelfish url*/
  29.     var $babel_url      =   NULL;
  30.     /* stores the search regex  (see readme for details) */
  31.     var $search_regex   =   NULL;
  32.     /* stores the data to be posted in an array (see readme for details) */
  33.     var $post_data      =   NULL;
  34.     /* stores the supported translation combination(s) */
  35.     var $valid_translate   =   NULL;
  36.    
  37.     /* proxy support
  38.     **
  39.     */
  40.     var $useProxy          =    FALSE;
  41.     var $proxyServer       =    NULL;
  42.     var $proxyPort         =    NULL;
  43.     var $timeOut           =    NULL;
  44.        
  45.     /* class constructor */
  46.     function babelfish($url=NULL,$postdata=NULL,$regex=NULL){
  47.         /* list of languages */
  48.         $this->languages    =       array(
  49.                                         'en'    =>  'english',
  50.                                         'zh'    =>  'chinese',
  51.                                         'zt'    =>  'chinese-traditional',
  52.                                         'nl'    =>  'dutch',
  53.                                         'fr'    =>  'french',
  54.                                         'de'    =>  'german',
  55.                                         'el'    =>  'greek',
  56.                                         'it'    =>  'italian',
  57.                                         'ja'    =>  'japanese',
  58.                                         'ko'    =>  'korean',
  59.                                         'pt'    =>  'portuguese',
  60.                                         'ru'    =>  'russian',
  61.                                         'es'    =>  'spanish'
  62.                                 );
  63.         /* list of valid translations */
  64.         $this->valid_translate=array(
  65.             'zt_en','en_zh','en_zt','en_nl','en_fr',
  66.             'en_de','en_el','en_it','en_ja','en_ko',
  67.             'en_pt','en_ru','en_es','nl_en','nl_fr',
  68.             'fr_en','fr_de','fr_el','fr_it','fr_pt',
  69.             'fr_nl','fr_es','de_en','de_fr','el_en',
  70.             'el_fr','it_en','it_fr','ja_en','ko_en',
  71.             'pt_en','pt_fr','ru_en','es_en','es_fr'
  72.         );
  73.  
  74.         /* babelfish service url */
  75.         if($url!=NULL)
  76.             $this->babel_url=$url;
  77.         else
  78.             $this->babel_url="http://babelfish.altavista.com/tr";
  79.         /* data that is posted to the babelfish site */
  80.         if($postdata!=NULL)
  81.             $this->post_data=$postdata;
  82.         else
  83.             $this->post_data=array(
  84.                         'doit'=>'done',
  85.                         'intl'=>'1',
  86.                         'tt'=>'urltext',
  87.                         'trtext'=>NULL,
  88.                         'lp'=>NULL
  89.             );
  90.         /* search for the translated text using this regex */
  91.         if($regex!=NULL)
  92.             $this->search_regex=$regex;
  93.         else
  94.              #$this->search_regex='/<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div><\/td>/';
  95.             $this->search_regex='/<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div><\/td>/sm';
  96.     }
  97.    
  98.     /* set proxy settings */
  99.     function setProxy($proxyServer, $proxyPort, $timeOut=15){
  100.         $this->useProxy = true;
  101.         $this->proxyServer = $proxyServer;
  102.         $this->proxyPort = $proxyPort;
  103.         $this->timeOut = $timeOut;
  104.     }
  105.    
  106.     /* perform babelfish translation */
  107.     function translate($text,$from_language,$to_language,$forceUTF8=true){
  108.         $f=array_search(strtolower($from_language),$this->languages);
  109.         if(!$f){die("***error: source language not found");}
  110.         $t=array_search(strtolower($to_language),$this->languages);
  111.         if(!$t){die("***error: result language not found");}
  112.         $l=$f.'_'.$t;
  113.         if(!in_array($l,$this->valid_translate)){die("***error: cant translate with given combination ($l)");}
  114.         $this->post_data['trtext']=$text;
  115.         $this->post_data['lp']=$l;
  116.         $query=http_build_query($this->post_data);
  117.         $ch=curl_init();
  118.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  119.         curl_setopt($ch, CURLOPT_URL, trim($this->babel_url));
  120.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  121.         curl_setopt($ch, CURLOPT_POST, 1);
  122.         curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
  123.         curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (babelfish.class.php)");
  124.         curl_setopt($ch,CURLOPT_ENCODING , "UTF-8");
  125.         /* use proxy if required */
  126.         if($this->useProxy){
  127.             curl_setopt($ch,CURLOPT_PROXY,$this->proxyServer.":".$this->proxyPort);
  128.             curl_setopt($ch,CURLOPT_TIMEOUT,$this->timeOut);   
  129.         }
  130.         $output = curl_exec($ch);
  131.         curl_close($ch);
  132.         $result=preg_match($this->search_regex,$output,$match);
  133.         if(count($match)!=0){
  134.             return strip_tags($match[0]);
  135.         }else{
  136.             return '** error : babelfish.class.php returned nothing';
  137.         }
  138.     }
  139. }
  140. /* end of class  */
  141. ?>

Esta claro que la funcion curl_init() no esta definida, pero ¿como puedo utilizar el metodo translate en mi codigoPHP, si este hace uso de la funcion curl_init()??

¿alguien me puede ayudar a solucionar este error?
__________________
1os pasaos con xAMP en Windows
programando en PERL