<?php
include ("../includes/db_functions.inc.php");

$keywords = array( array('puzzle','level','piece','block','ball','item','object','card','picture','tile','word','number','difference','skill','letter','color','pair','group','brick','contain','animal'),
				   array('action','level','track','race','point','course','wheel','enemies','enemy','game','ball','bonus','weapon','block','obstacle','increase','defend','stunt','truck','car','skill','star','upgrade','graphic','player','bomb','ship','wave','item','alien','steroid','bubble','score','feature','type','zombie','friend','high','object'),
				   array('adventure','level','item','game','point','enemies','object','treasure','skill','obstacle','star','weapon','graphic','clue','creature','player','series','defend','need','feature','zombie','alien','character','stone','dangerous'),
				   array('sports','sport','level','point','ball','again','obstacle','player','skill','bonus','finish','track','high','friend','opponent','score','team','time','race','goal','tennis','arrow','court','graphic','achievement','trick','shot','mode','character','stunt','jump','challenge','hole','card','level','piece','tile','pair','ball','block','letter','rule','mode','square','pile','opponent','board'),
				   array('shoot','shooting','shooter','shot','gun','weapon','aim','enemy','enemies','skill','bullet','point','alien','target','space','bomb','tank','invader','balloon','invade','dangerous','rocket','laser'),
				   array('casino','card','pile','number','slot','slots','bonus','graphic','rule','foundation','hand','texas','level','high','score','skill','sequence','ball','friend','spin','time','crap','combination','opponent','mode','feature','credit','chip','colour','column','color'),
				   array('dress','dress-up','clothing','clothes','styling','style','styles','accessories','girl','outfit','item','various','hair','look','shoe','color','love','delicious','nail','nails','gorgeous','pretty','necklace','fantasy','artist','flower','fabulous','glamorous','famous','costume'),
				   array('arcade','retro','pac-man','pacman','level','points','jump','atari','skill','block','brick','metroid','worm','mega','extra'),
				   array('strategy','level','point','defense','enemies','enemy','block','again','tower','item','puzzle','ball','skill','friend','player','bonus','object','wave','weapon','zombie','highest','piece','graphic','card','your','upgrade','ship','type','finish','bomb','achievement','number','tile'),
			    );
$count = array();
$count[6] = 0;
function wordsArray($string){
    $stopWords = array( 'the','of','and','a','to','in','is','you','that','it','he','was','for','on','are','as','with','his','they','I','at','be','this','have','from','or','one','had','by','word','but','not','what','all','were','we','when','your','can','said','there','use','an','each','which','she','do','how','their','if','will','up','other','about','out','many','then','them','these','so','some','her','would','make','like','him','into','has','two','more','write','go','see','number','no','way','could','people','my','than','first','water','been','call','who','oil','its','now','find','long','down','day','did','get','come','made','may','part','click');
	$punct = array('.',';','?','!',':');
	$string = str_replace($punct, ' ', $string);
	$string = preg_replace('/ss+/i', '', $string);
    $string = trim($string); // trim the string
    $string = preg_replace('/[^a-zA-Z0-9 -]/', '', $string); // only take alphanumerical characters, but keep the spaces and dashes too…
    $string = strtolower($string); // make it lowercase
 
    preg_match_all('/([a-z]*?)(?=s)/i', $string, $matchWords);
    $matchWords = $matchWords[0];
    foreach ( $matchWords as $key=>$item ) {
        if ( $item == '' || in_array(strtolower($item), $stopWords) || strlen($item) <= 3 ) {
            unset($matchWords[$key]);
        }
    }
    $wordCountArr = array();
    if ( is_array($matchWords) ) {
        foreach ( $matchWords as $key => $val ) {
            $val = strtolower($val);
            if ( isset($wordCountArr[$val]) ) {
                $wordCountArr[$val]++;
            } else {
                $wordCountArr[$val] = 1;
            }
        }
    }
    arsort($wordCountArr);
   return $wordCountArr;		
}
$query = yasDB_select("SELECT `title`, `description` FROM `fogfeed` WHERE `id` = 1");
$data = '';
while ($text = $query->fetch_array(MYSQLI_ASSOC)) {
	$data = $data . ' ' . $text['title'] . ' ' . $text['description'];
}
$words = wordsArray($data);
foreach ($words as $word) {
	if($word == $keywords[1][0]) {$category = 2; break;} //action
	if($word == $keywords[2][0]) {$category = 3; break;} //adventure
	if($word == $keywords[0][0]) {$category = 1; break;} //puzzle
	if($word == $keywords[3][0]) {$category = 4; break;} //sports
	if($word == $keywords[4][0]) {$category = 5; break;} //shooter
	if($word == $keywords[5][0]) {$category = 6; break;} //casino
	if($word == $keywords[7][0]) {$category = 8; break;} //dressup
	if($word == $keywords[8][0]) {$category = 9; break;} //arcade
	if($word == $keywords[9][0]) {$category = 10; break;} //strategy
	
	for($i=0; $i<=9;$i++) {
		
	}
}
?>