Foros del Web » Programando para Internet » PHP »

Ayuda con traducir SpellChecker PHP

Estas en el tema de Ayuda con traducir SpellChecker PHP en el foro de PHP en Foros del Web. Hola, trabajo en una empresa desarolladora de software... en la cual me pidieron que haga un codigo php a el lenguaje que nosotros estamos creando! ...
  #1 (permalink)  
Antiguo 14/08/2008, 08:41
 
Fecha de Ingreso: abril-2008
Mensajes: 11
Antigüedad: 16 años
Puntos: 0
De acuerdo Ayuda con traducir SpellChecker PHP

Hola, trabajo en una empresa desarolladora de software... en la cual me pidieron que haga un codigo php a el lenguaje que nosotros estamos creando!
Si alguien me puede decir que hace el codigo o que es lo que tengo que hacer yo para suplantar ese codigo con el mio!?

SPELLCHECKER
Código:
<?php
header('Content-type: text/html; charset=utf-8');

// The following variables values must reflect your installation needs.

$aspell_prog	= '"C:\Program Files\Aspell\bin\aspell.exe"';	// Ruta del Ejecutable para Windows
//$aspell_prog	= 'aspell';										// Ruta del Ejecutable para Linux

$lang			= 'en_US'; // String de lenguaje ejectuado
$aspell_opts	= "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt";		// Strign del encoding estos deben ser parametros q se le pasan al .exe que se ejecuta

$tempfiledir	= "./"; // ruta del archivo 

$spellercss		= '../spellerStyle.css';	//Ruta de la hoja de estilos
$word_win_src	= '../wordWindow.js';							// Ruta de los javascripts

$textinputs		= $_POST['textinputs']; # array    //esto es un Request POSt, quiere decir algo que se envio por POST desde un formulario o algo
$input_separator = "A";

# set the JavaScript variable to the submitted text.
# textinputs is an array, each element corresponding to the (url-encoded)
# value of the text control submitted for spell-checking
function print_textinputs_var() { // ESTO REEMPLAZA los %27 por espacios, es decir las variable global textinputs tiene %27 en vez de espacios y para imprimirlos 
	global $textinputs;           // los pasa a espacios .
	foreach( $textinputs as $key=>$val ) {
		# $val = str_replace( "'", "%27", $val );
		echo "textinputs[$key] = decodeURIComponent(\"" . $val . "\");\n";
	}
}

# make declarations for the text input index
function print_textindex_decl( $text_input_idx ) { /// esto tambien imprime los "echo" son de impresion
	echo "words[$text_input_idx] = [];\n";
	echo "suggs[$text_input_idx] = [];\n";
}

# set an element of the JavaScript 'words' array to a misspelled word
function print_words_elem( $word, $index, $text_input_idx ) { //ESTO TAMBIEN IMPRIME en pantalla tambien
	echo "words[$text_input_idx][$index] = '" . escape_quote( $word ) . "';\n";
}


# set an element of the JavaScript 'suggs' array to a list of suggestions
function print_suggs_elem( $suggs, $index, $text_input_idx ) {
	echo "suggs[$text_input_idx][$index] = [";  // ESTO REEMPLAZA Las barras /'/  por \\ segun la funcion escape_quote que esta abajo definida, es un foreach,
	foreach( $suggs as $key=>$val ) {           // Fijate los parametros como usa esta funcion print_suggs_elem
		if( $val ) {
			echo "'" . escape_quote( $val ) . "'";
			if ( $key+1 < count( $suggs )) {
				echo ", ";
			}
		}
	}
	echo "];\n";
}

# escape single quote
function escape_quote( $str ) { // funcion que reemplaza un string es como un REPLACE
	return preg_replace ( "/'/", "\\'", $str );
}


# handle a server-side error.
function error_handler( $err ) {  // REEMPLAZA TAMBIEN
	echo "error = '" . preg_replace( "/['\\\\]/", "\\\\$0", $err ) . "';\n";
}

## get the list of misspelled words. Put the results in the javascript words array
## for each misspelled word, get suggestions and put in the javascript suggs array
function print_checker_results() {

	global $aspell_prog;
	global $aspell_opts;
	global $tempfiledir;
	global $textinputs;  // VARIABLE GLOBALES
	global $input_separator;
	$aspell_err = "";
	# create temp file
	$tempfile = tempnam( $tempfiledir, 'aspell_data_' );
	// CARGA EL ARCHIVO TEMPORAL
	# open temp file, add the submitted text.

	// ABRE EL ARCHIVO TEMPORAL PARA ESCRITURA
	if( $fh = fopen( $tempfile, 'w' )) {
		//RECORRE EL ARCHIVO
		for( $i = 0; $i < count( $textinputs ); $i++ ) {
			$text = urldecode( $textinputs[$i] );
			// REEMPLAZA TEXTO
			// Strip all tags for the text. (by FredCK - #339 / #681)
			$text = preg_replace( "/<[^>]+>/", " ", $text ) ;

			$lines = explode( "\n", $text );
			fwrite ( $fh, "%\n" ); # exit terse mode
			// CUANDO PONE UN $ es el valor de la variable por ejemplo aca no imprime $input_separator sino su contenido y el ^ es como un enter| 
			fwrite ( $fh, "^$input_separator\n" );
			fwrite ( $fh, "!\n" ); # enter terse mode
			//ESCRIBE EN EL ARCHIVO
			foreach( $lines as $key=>$value ) {
				# use carat on each line to escape possible aspell commands
				fwrite( $fh, "^$value\n" );
			}
		}
		fclose( $fh );

		//aca pone los comandos en la variable cmd que luego sera ejecutado

		# exec aspell command - redirect STDERR to STDOUT
		$cmd = "$aspell_prog $aspell_opts < $tempfile 2>&1";
		if( $aspellret = shell_exec( $cmd )) {

			// EJECUTA el EXE con los parametros

			$linesout = explodwe( "\n", $aspellret );
			$index = 0;
			$text_input_index = -1;


			// BUEN ACA TE FIJAS LINEA A LINEA LO QUE TE TIRA LA EJECUCION	
			// y segun lo que sea  
			// imprime print_words_elem
			// print_suggs_elem
			// y  print_textindex_decl

			# parse each line of aspell return
			foreach( $linesout as $key=>$val ) {
				$chardesc = substr( $val, 0, 1 );
				# if '&', then not in dictionary but has suggestions
				# if '#', then not in dictionary and no suggestions
				# if '*', then it is a delimiter between text inputs
				# if '@' then version info
				if( $chardesc == '&' || $chardesc == '#' ) {
					$line = explode( " ", $val, 5 );
					print_words_elem( $line[1], $index, $text_input_index );
					if( isset( $line[4] )) {
						$suggs = explode( ", ", $line[4] );
					} else {
						$suggs = array();
					}
					print_suggs_elem( $suggs, $index, $text_input_index );
					$index++;
				} elseif( $chardesc == '*' ) {
					$text_input_index++;
					print_textindex_decl( $text_input_index );
					$index = 0;
				} elseif( $chardesc != '@' && $chardesc != "" ) {
					# assume this is error output
					$aspell_err .= $val;
				}
			}
			if( $aspell_err ) {

				/// SI DEVUELVE ERROR MOSTAR ERROR EN LA variable $aspell_err
				$aspell_err = "Error executing `$cmd`\\n$aspell_err";
				error_handler( $aspell_err );
			}
		} else {
			error_handler( "System error: Aspell program execution failed (`$cmd`)" );

			// otar impresion
		}
	} else {
		error_handler( "System error: Could not open file '$tempfile' for writing" );
		//otra impresion
	}

	# close temp file, delete file
	unlink( $tempfile );
	//elimina y cierra el archivo abierto
}


?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<!-- ACA SE IMPRIMEN LAS RUTAS de los js y css-->
<link rel="stylesheet" type="text/css" href="<?php echo $spellercss ?>" />
<script language="javascript" src="<?php echo $word_win_src ?>"></script>
<script language="javascript">
var suggs = new Array();
var words = new Array();
var textinputs = new Array();
var error;
<?php
// EJECUTA LAS DOS FUNCIONES
print_textinputs_var();
			
print_checker_results();

?>


/// ESTO ES JAVASCRIPTS ESTO LO SABES jeje

var wordWindowObj = new wordWindow();
wordWindowObj.originalSpellings = words;
wordWindowObj.suggestions = suggs;
wordWindowObj.textInputs = textinputs;

function init_spell() {
	// check if any error occured during server-side processing
	if( error ) {
		alert( error );
	} else {
		// call the init_spell() function in the parent frameset
		if (parent.frames.length) {
			parent.init_spell( wordWindowObj );
		} else {
			alert('This page was loaded outside of a frameset. It might not display properly');
		}
	}
}



</script>

</head>
<!-- <body onLoad="init_spell();">		by FredCK 

ACA SE EJECUTA ni biej cargas la pagina la funcion javascript
init_spell();

-->
<body onLoad="init_spell();" bgcolor="#ffffff"> 

<script type="text/javascript">
wordWindowObj.writeBody();
</script>

</body>
Desde ya muchas gracias!
  #2 (permalink)  
Antiguo 14/08/2008, 09:04
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Ayuda con traducir SpellChecker PHP

Hola Matt-CodeGlide,

Podrías explicar más lo que deseas hacer, tus dudas no son claras.

Saludos.
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 20:59.