<?php
if(!defined('AUTHACCESS')){echo "Not Allowed";exit();}
//awempire_update
$xmlmodels = array();
$xml=simplexml_load_string($xmlfile);
$p_end = count($xml->data->models->model);
$t_ndx = 0;
$mnndx = 0;
$npt = $p_end;
$npt--;
$ordinator = get_ordinator($npt);

for($x=0;$x<$p_end;$x++) {
	$rsindx = (int)$ordinator[$x];

			$model_gen = strtolower($xml->data->models->model[$rsindx]->persons->person->sex);
			if (in_array(strtolower($model_gen), $allowed_genders) ) {
			//if ( (in_array($model_gen, array_map("strtolower", $modelgender))) ){

				$model_info['sponsor'] = "awempire";
				$sponsor = $model_info['sponsor'];
				$model_info['gender'] = clean_basic($xml->data->models->model[$rsindx]->persons->person->sex);
				$model_info['topic'] = "";


				$model_info['username'] = clean_basic($xml->data->models->model[$rsindx]->performerId);
				$model_info['display_name'] = $model_info['username'];
				$model_info['username'] = strtolower($model_info['username']);
				$model_name = $model_info['username'];
	
				$model_info['display_age'] = clean_basic($xml->data->models->model[$rsindx]->persons->person->age);

				$model_info['ethnicity'] = preg_replace("/\//", " ", $xml->data->models->model[$rsindx]->ethnicity);
				$model_info['ethnicity'] = clean_basic($model_info['ethnicity']);

				$model_info['hair_color'] = clean_basic($xml->data->models->model[$rsindx]->persons->person->body->hairColor);
				$model_info['eye_color'] = clean_basic($xml->data->models->model[$rsindx]->persons->person->body->eyeColor);

				$model_info['bust_penis_size'] = clean_basic($xml->data->models->model[$rsindx]->bust_penis_size);

				$model_info['primary_language'] = clean_basic($xml->data->models->model[$rsindx]->details->languages->language[0]);

				$model_info['turns_on'] = clean_basic($xml->data->models->model[$rsindx]->details->about->turnsOn);
				$model_info['turns_off'] = clean_basic($xml->data->models->model[$rsindx]->details->about->turnsOff);

				$model_info['biography'] =  clean_basic($xml->data->models->model[$rsindx]->details->about->biography);


				$model_info['thumbnail_image_big_live'] = (string)$xml->data->models->model[$rsindx]->profilePictureUrl->size320x240;
				$model_info['thumb'] = $model_info['thumbnail_image_big_live'];
				$model_info['thumb'] = cleanthumb($model_info['thumb']);
				//$thm = $model_info['thumb'];
				//$model_info['thumb'] = base64_encode($thm);
				$model_info['status'] = clean_basic($xml->data->models->model[$rsindx]->status);
				//$model_info['chat_status'] = clean_basic($xml->data->models->model[$rsindx]->chat_status);

				$model_info['chat_url'] = (string)$xml->data->models->model[$rsindx]->chatRoomUrl[0];
				$model_info['iframe_src'] = $model_info['chat_url'];
				$thm = $model_info['iframe_src'];
				//$model_info['iframe_src'] = base64_encode($thm);
				$model_info['embed_chat_url'] = $model_info['chat_url'];
				$model_info['topic'] = $model_info['gender'] . " " . $model_info['turns_on'] . " " . $model_info['turns_off'];


				$tags = $xml->data->models->model[$rsindx]->details->willingnesses->willingness;
				$numtags = sizeof($tags);
				if ($numtags > 10) {$numtags = 10;}

				$tagsarray = array();
				for ($ctr=0;$ctr<$numtags;$ctr++) {
					$tag = $tags[$ctr];
					$tagsarray[] = clean_tags($tag);
						
				}
				$model_info['tags'] = $tagsarray;
				$tags = $tagsarray;

				if(in_array($model_info['username'], $used_modelnames)) {
					$model_info['username'] = $model_info['username'] . "_sc";
				}
				$used_modelnames[] = $model_info['username'];
				$xmlmodels[] = $model_info;
				$allmodel_array[] = $model_info;
				$xmlmodels_allcams[] = $model_info;
			}
			$t_ndx++;
			if($t_ndx>9000){echo "overflow! 9000 ";exit();}


			 
	}	//awempire



$total_item_count += count($xmlmodels);
$out_file = __DIR__ . "/../feeds/feed_awempire.txt";
$filedata = serialize($xmlmodels);
writetxtfile($out_file, $filedata);
$out_file = __DIR__ . "/../feeds/modelndx_awempire.txt";
$filedata = serialize($xmlmodels_names);
writetxtfile($out_file, $filedata);	

?>
