API_VER,'MAPIV'=>MIN_VER,'CLAPIV'=>CL_API_VER,'ERROR'=>$e,'RSP'=>$s))); } die(json_encode(array('APIV'=>API_VER,'MAPIV'=>MIN_VER,'CLAPIV'=>CL_API_VER,'ERROR'=>0,'RSP'=>$s))); } class s { var $c = 0; function s(){ $this->c = @mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); if(!$this->c) d('IMHUMAN API DATABASE CONNECTION ERROR',107); @mysql_select_db(DB_NAME); } function q($q){ $x= @mysql_query($q); if($x) return $x; else d('DB ERROR',114);} function r($q){ return @mysql_fetch_array($q); } function n($q){ return @mysql_num_rows($q); } function f($q){ @mysql_free_result($q); } function c() { @mysql_close($this->c); } } # ------------------------ if( !$api = g('api') ) { d('NO API SUPPLIED',105); } define('CL_API_VER', $api); if( doubleval($api) < MIN_VER ) { d('PLEASE UPDATE YOUR API TO CURRENT VERSION',106); } if( !$user = g('user') ) { d('NO USER SUPPLIED',100); } if( !$ky = g('key') ) { d('NO KEY SUPPLIED',101); } if( !$row = intval(g('row')) ) { d('NO ROW SUPPLIED',102); } if( !$col = intval(g('col')) ) { d('NO COLUMN SUPPLIED',103); } if( $row * $col < 3){ d('MINIMUM 3 HUMANIZERS REQUIRED',108); } if( $row * $col > 25){ d('MAXIMUM GRID SIZE 25',112); } if( !$sel = intval(g('sel')) ) { d('NO SELECTION SUPPLIED',104); } if( $sel < 2){ d('MINIMUM 2 SELECTION REQUIRED',109); } if( $sel >= ($row * $col) ){ d('SELECTION CAN NOT BE BIGGER THAN (OR EQUAL TO) GRID',110); } $GRID = $row * $col; $LANG = g('lang'); $s = new s(); $r = $s->q("SELECT * FROM h_ws WHERE au='$user' AND ak='$ky' LIMIT 1"); if( $s->n($r) == 0 ){ d('INVALID API USER | KEY',111); } $s->f($r); $r = $s->q("SELECT * FROM h_tags WHERE a='1' AND c > $sel ORDER BY RAND() LIMIT 1"); if( $s->n($r) == 0 ){ d('SELECTION IS TOO BIG',113); } $v = $s->r($r); $s->f($r); $CTAGID = $v['id']; $CTAGNAME = (!$LANG || $LANG == 'en' ) ? $v['tag'] : $v[$LANG]; $s->q("UPDATE h_sv SET s=s+1 WHERE id=1"); $r = $s->q("SELECT * FROM h_hm WHERE a='1' AND t <> $CTAGID ORDER BY RAND() LIMIT $GRID"); while($v = $s->r($r)) $mix[] = array($v['s'], substr(md5(uniqid()),0,6), substr(md5(microtime()),0,12)); $s->f($r); $r = $s->q("SELECT * FROM h_hm WHERE a='1' AND t = $CTAGID ORDER BY RAND() LIMIT $sel"); while($v = $s->r($r)) $ans[] = array($v['s'], substr(md5(uniqid()),0,6), substr(md5(microtime()),0,12)); $s->f($r); $picks = range(0,$GRID-1); srand((float)microtime() * 1000000); shuffle($picks); $pos = array_slice($picks, 0, $sel); for($i=0;$i<$sel;$i++){ $mix[$pos[$i]]=$ans[$i]; $a[]=$ans[$i][2]; } sort($a); reset($a); $ANSWER = md5(implode('.',$a)); d(array('WORD'=>$CTAGNAME,'GRID'=>$mix,'ANSWER'=>$ANSWER)); $s->c(); ?>