_word = $word; } function getWord() { return $this->_word;} function setQueryWord($word) { $this->_queryWord = $word; } function getQueryWord() { return $this->_queryWord;} /** * Va chercher le contenu chez google * @return faux en cas d'erreur */ function getContent() { $return = false; if ( $this->_word != '' ) { $stringResult = ''; // réception du fichier $filename = 'http://google.com/complete/search?hl='.$this->_lang.'&js=true&qu='.urlencode($this->_word); $fileResult = file($filename); echo 'Téléchargement en cours... '. htmlspecialchars($filename).'
'; if (is_array($fileResult) ) { $stringResult = implode('', $fileResult); //$matchReturn = preg_match("/\"([^\"]*)\", new Array\(([^\)]*)\), new Array\(([^\)]*)\)/", $stringResult, $tokenResult); //$this->setQueryWord($tokenResult[TOKEN_QUERY]); //$this->_stringText = $tokenResult[TOKEN_TEXT]; //$this->_stringResult = $tokenResult[TOKEN_RESULT]; echo '

Le résultat de google a changé, l\'analyse ne fonctionne plus.

'; echo '

'.htmlspecialchars($stringResult).'

'; $this->parse(); $return = true; } // pas de résultat } // mot vide return $return; } // function getContentTest() { // $fileResult = array('sendRPCDone(frameElement, "mozilla fire", new Array("mozilla firefox", "mozilla firefox download", "mozilla fire fox", "mozilla firefox 1.0", "mozilla firebird", "mozilla firefox browser", "mozilla firefox themes", "mozilla fire", "mozilla firebox", "mozilla firefox extensions"), new Array("6,520,000 results", "3,400,000 results", "88,400 results", "2,330,000 results", "723,000 results", "2,810,000 results", "384,000 results", "801,000 results", "5,670 results", "295,000 results"), new Array(""));'); // } /** * Essait de parser les résultats trouvés (stringText et stringResult) * Pour les mettre dans les tableau tabText et tabResult */ function parse() { $antiHack = ')'; $antiHack2 = '`'; $antiHack3 = '$'; if ( strstr($this->_stringText, $antiHack)===false && strstr($this->_stringResult, $antiHack)===false && strstr($this->_stringText, $antiHack2)===false && strstr($this->_stringResult, $antiHack2)===false && strstr($this->_stringText, $antiHack3)===false && strstr($this->_stringResult, $antiHack3)===false ) { // TODO: trouver une meilleur facon de faire ca... eval('$tabText=array('.$this->_stringText.');'); eval('$tabResult=array('.$this->_stringResult.');'); if ( isset($tabText) ) { $this->_tabText = $tabText; } if ( isset($tabResult) ) { $this->_tabResult = $tabResult; } } } /** * Indique s'il existe des résultats * @return true s'il y a des résultats */ function hasResult() { $c = count($this->_tabText); return ( $c && $c == count($this->_tabResult) ); } } $googleWord = new GoogleWord(); if ( isset($_GET['q']) && $_GET['q'] != '' ) { $googleWord->setWord($_GET['q']); } $doc = new simpleXHTML(); // document XHTML $doc->setTitle('Google Word for: ' . htmlspecialchars($googleWord->getWord())); $doc->setStyle('td.compte{text-align:right;}'); $doc->echoStart(); ?>
getContent() ) { echo '

'.htmlspecialchars($googleWord->getQueryWord()).'

'; if ( $googleWord->hasResult() ) { echo ''; foreach ( $googleWord->_tabText as $key=>$value) { echo '\n"; } echo '
Mots-clésCompte
'.$value . '' . $googleWord->_tabResult[$key] . "
'; } } $doc->echoEnd(); ?>