<?
/**
* PHPPolygen - wrapper for polygen online generator service
*
* @package PHPPolygen
* @author InuYaksa
* @version 1.1
* @copyright 2008-2009 InuYaksa
* @link http://www.areaaperta.com
*/
class PHPPolygen {
var $gram = FALSE;
var $text = '';
var $err = '';
/**
* costruttore di classe - (opzionale) permette di impostare la grammatica di partenza
* class constructor - (optional) you can select default grammar
*/
function phppolygen($gram = FALSE) {
if ($gram) {
$this->gram = $gram;
}
}
/**
* funzione interna (non richiamare)
* internal function (do NOT recall)
*/
function _getPolygen($gram) {
$out = '';
$raw = @file_get_contents("http://www.polygen.org/polygen/remote/$gram?phppolygen");
if ($raw) {
$raw = str_replace(array("\n","\r"),'',$raw);
$beg = stripos($raw,'class=polygenOutput>");document.write("');
if ($beg) {
$end = stripos($raw,'");',$beg+39);
if ($end) {
$out = substr($raw,$beg + 39, $end - $beg - 39);
}
$out = stripslashes($out);
} else {
$this->err = $raw;
}
} else {
$this->err = 'grammar not loaded';
}
return $out;
}
/**
* genera una nuova frase polygen - (opzionale) puoi selezionare la grammatica, oppure usa quella di partenza
* restituire TRUE se completato, oppure FALSE in caso di errore
* generate new polygen text - (optional) you can select grammar class, otherwise it use default grammar
* return TRUE if successful or FALSE on error
*/
function generate($gram = FALSE) {
$this->text = '';
$this->err = '';
if ($gram) {
$this->gram = gram;
}
if ($this->gram == '') {
$this->err = 'no grammar selected';
return FALSE;
}
$out = $this->_getPolygen($this->gram);
if ($out) {
$this->text = $out;
return TRUE;
}
return FALSE;
}
/**
* Ottieni la frase in formato testuale
* Return only text
*/
function getText() {
$txt = str_ireplace('<br>',"\n",$this->text);
$txt = str_ireplace('<br/>',"\n",$txt);
return html_entity_decode(strip_tags($txt));
}
/**
* Ottieni la frase in formato HTML
* Return text as HTML format
*/
function getHTML() {
return $this->text;
}
/**
* Ottieni l'ultimo messaggio di errore
* Return last error message
*/
function getError() {
return $this->err;
}
/**
* Ottieni il codice HTML per il link a Polygen (mettilo sempre sul tuo sito!)
* Return link code for Polygen site as HTML (link'em on your site always!)
*/
function getPolygenLink() {
return '<a href="http://www.polygen.org/" target="_blank">'.
'<img border="0" src="http://www.polygen.org/media/generatedby.gif?phppolygen"/>'.
'</a>';
}
}
?>