Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] problemas con clase babelfish

Estas en el tema de problemas con clase babelfish en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 13/02/2017, 13:47
 
Fecha de Ingreso: diciembre-2007
Mensajes: 299
Antigüedad: 16 años, 4 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
  #2 (permalink)  
Antiguo 13/02/2017, 15:38
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: problemas con clase babelfish

Lo mas probable es que no tengas habilitada la extensión para curl
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #3 (permalink)  
Antiguo 15/02/2017, 17:03
 
Fecha de Ingreso: diciembre-2007
Mensajes: 299
Antigüedad: 16 años, 4 meses
Puntos: 2
Respuesta: problemas con clase babelfish

Cita:
Iniciado por hhs Ver Mensaje
Lo mas probable es que no tengas habilitada la extensión para curl
Y en linux(XAMPP), ¿como cargo la extension curl?
__________________
1os pasaos con xAMP en Windows
programando en PERL
  #4 (permalink)  
Antiguo 15/02/2017, 17:27
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: problemas con clase babelfish

Información para instalar: http://php.net/manual/es/curl.installation.php

Para activar, edita php.ini y quita el punto y coma en:
Código:
; extension=php_curl.so
Reinica apache y todo debería funcionar correctamente.
__________________
- León, Guanajuato
- GV-Foto
  #5 (permalink)  
Antiguo 15/02/2017, 17:32
 
Fecha de Ingreso: diciembre-2007
Mensajes: 299
Antigüedad: 16 años, 4 meses
Puntos: 2
Respuesta: problemas con clase babelfish

Cita:
Iniciado por Triby Ver Mensaje
Para activar, edita php.ini y quita el punto y coma.
En windows es asi, pero en linux(que yo sepa) no existe php.ini ¿Entonces como hago en linux?
__________________
1os pasaos con xAMP en Windows
programando en PERL
  #6 (permalink)  
Antiguo 16/02/2017, 03:06
 
Fecha de Ingreso: noviembre-2003
Ubicación: Zaragoza, España
Mensajes: 1.257
Antigüedad: 20 años, 5 meses
Puntos: 154
Respuesta: problemas con clase babelfish

Hola alfa18,

¿Que no existe en linux?

https://clouding.io/kb/encontrar-php-ini-en-linux/
  #7 (permalink)  
Antiguo 16/02/2017, 08:22
 
Fecha de Ingreso: diciembre-2007
Mensajes: 299
Antigüedad: 16 años, 4 meses
Puntos: 2
Respuesta: problemas con clase babelfish

Cita:
Iniciado por Triby Ver Mensaje
Para activar, edita php.ini y quita el punto y coma en:
Código:
; extension=php_curl.so
Gracias por la iinfo @rbczgz, no se porque pensaba que el php.ini solo era de windows.
Sin embargo, en mi php.ini no aparecen extesiones ,¿como la activo entonces?
Código:
[user@mail Desktop]$ grep curl /etc/php5/apache2/php.ini 
[curl]
;curl.cainfo =
__________________
1os pasaos con xAMP en Windows
programando en PERL
  #8 (permalink)  
Antiguo 17/02/2017, 05:26
 
Fecha de Ingreso: octubre-2010
Ubicación: España
Mensajes: 1.007
Antigüedad: 13 años, 6 meses
Puntos: 123
Respuesta: problemas con clase babelfish

En el manual lo explica fácilmente para debian


Ejemplo para instalar curl php 5 en debían.
Cita:
apt-get install php5-curl
__________________
Unset($vida['malRollo']);
  #9 (permalink)  
Antiguo 17/02/2017, 06:05
 
Fecha de Ingreso: diciembre-2007
Mensajes: 299
Antigüedad: 16 años, 4 meses
Puntos: 2
Respuesta: problemas con clase babelfish

Gracias @xerifandtomas, tambien vale para derivdos tipo ubuntu??

he activado la extension curl en mi php.ini, y esto es lo que obtengo: Frenh: ** error : babelfish.class.php returned nothing,¿alguien puede decirme el error?
__________________
1os pasaos con xAMP en Windows
programando en PERL

Última edición por alfa18; 17/02/2017 a las 13:38
  #10 (permalink)  
Antiguo 17/02/2017, 13:39
 
Fecha de Ingreso: septiembre-2015
Mensajes: 142
Antigüedad: 8 años, 7 meses
Puntos: 13
Respuesta: problemas con clase babelfish

en ubuntu debe ser lo mismo :

Cita:
sudo apt-get install php5-curl
, luego que se instale reinicia apache. y listo
  #11 (permalink)  
Antiguo 17/02/2017, 13:39
 
Fecha de Ingreso: octubre-2010
Ubicación: España
Mensajes: 1.007
Antigüedad: 13 años, 6 meses
Puntos: 123
Respuesta: problemas con clase babelfish

Si. Debería valer para Ubuntu ya que este esta basado en debian.
__________________
Unset($vida['malRollo']);
  #12 (permalink)  
Antiguo 21/02/2017, 08:43
 
Fecha de Ingreso: diciembre-2007
Mensajes: 299
Antigüedad: 16 años, 4 meses
Puntos: 2
Respuesta: problemas con clase babelfish

OK xerifandtomas, he activado la extension curl, y esto es lo que obtengo: Frenh(/Dutch/Japanese/...): ** error : babelfish.class.php returned nothing,¿alguien puede decirme el error?

No creo que se deba a errores en el codigo pues no es mio, ¿entonces?¿por que no obtengo el mensaje ?
__________________
1os pasaos con xAMP en Windows
programando en PERL
  #13 (permalink)  
Antiguo 21/02/2017, 13:54
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: problemas con clase babelfish

Parece que tu librería es muy antigua; incluso ya no existe la URL donde intentas conectarte.
__________________
- León, Guanajuato
- GV-Foto
  #14 (permalink)  
Antiguo 22/02/2017, 06:20
 
Fecha de Ingreso: octubre-2010
Ubicación: España
Mensajes: 1.007
Antigüedad: 13 años, 6 meses
Puntos: 123
Respuesta: problemas con clase babelfish

Intenta actualizar tu sistema.

Cita:
sudo apt-get update
Cita:
sudo apt-get upgrade
Edito:

Vale, no he dicho nada. Como dice triby, tu problema está en la librería de babelfish, que seguramente esta obsoleta.
__________________
Unset($vida['malRollo']);
  #15 (permalink)  
Antiguo 23/02/2017, 00:44
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: problemas con clase babelfish

Código PHP:
Ver original
  1. $result=preg_match($this->search_regex,$output,$match);
  2.         if(count($match)!=0){
  3.             return strip_tags($match[0]);
  4.         }else{
  5.             return '** error : babelfish.class.php returned nothing';
  6.         }
En esa linea esta el problema no esta haciendo match o esta marcando error, te aconsejo que habilites el reporte de errores
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #16 (permalink)  
Antiguo 23/02/2017, 04:24
 
Fecha de Ingreso: octubre-2010
Ubicación: España
Mensajes: 1.007
Antigüedad: 13 años, 6 meses
Puntos: 123
Respuesta: problemas con clase babelfish

Buenos días Hhs.

Es verdad que el error salta ahí, pero si te fijas en la clase que paso el compañero veras que apunta a
"http://babelfish.altavista.com/tr" y esta redirecciona a yahoo, por lo que esa clase que parece que fue actualizada en 2007 ya no es válida.

La verdad que en 10 años, cambian, mueren y nacen muchos proyectos. Por lo que yo animaría al compañero a buscar algo más reciente.
__________________
Unset($vida['malRollo']);
  #17 (permalink)  
Antiguo 23/02/2017, 11:16
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: problemas con clase babelfish

Es correcto el servicio ya no esta funcionando y por lo mismo no hace match la expresión regular creo que van a necesitar buscar otra opción
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #18 (permalink)  
Antiguo 26/02/2017, 14:02
 
Fecha de Ingreso: diciembre-2007
Mensajes: 299
Antigüedad: 16 años, 4 meses
Puntos: 2
Respuesta: problemas con clase babelfish

Gracias a todos por vuestra ayuda, demasiado obvio: el servicio babelfish de yahoo ya no existe, lo k no entiendo es por que mantienen esta libreria en PHPclasses

Gracias a todos:D
__________________
1os pasaos con xAMP en Windows
programando en PERL

Última edición por alfa18; 26/02/2017 a las 14:46
  #19 (permalink)  
Antiguo 26/02/2017, 15:00
 
Fecha de Ingreso: noviembre-2003
Ubicación: Zaragoza, España
Mensajes: 1.257
Antigüedad: 20 años, 5 meses
Puntos: 154
Respuesta: problemas con clase babelfish

Cita:
Iniciado por alfa18 Ver Mensaje
... lo k no entiendo es por que mantienen esta libreria en PHPclasses...
Pues quizá porque no sepan que ya no funciona... se me ocurre...

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:10.