<?php
if(!defined('AUTHACCESS')){echo "Not Allowed";exit();}
//imlive_update
$xmlmodels = array();
$xml=simplexml_load_string($xmlfile);
$p_end = count($xml->Host);
$t_ndx = 0;
$mnndx = 0;
$npt = count($xml->Host);
$npt--;
$ordinator = get_ordinator($npt);
for($x=0;$x<$p_end;$x++) {
	$rsindx = (int)$ordinator[$x];
	if (in_array(strtolower($xml->Host[$rsindx]->Gender), $allowed_genders) ) {
		$nmx = clean_username($xml->Host[$rsindx]->NickName);
		$nmx = strtolower($nmx);
		$xmlmodels_names[$nmx] = $mnndx;
		$xmlmodels_names_allcams[$nmx] = $mnndx_all;
		$mnndx++;
		$mnndx_all++;
		$model_info = array();
		$model_info['sponsor'] = "imlive";
		$model_info['display_name'] = cleandisplayname($xml->Host[$rsindx]->display_name);
		if (ctype_space($model_info['display_name'])) {unset($model_info['display_name']);}
		$tags = array();
		$tags_temp = array();		
		$tags = $xml->Host[$rsindx]->tags;
		unset($tags);
		$tags_temp = explode(",", $xml->Host[$rsindx]->Build);
		foreach($tags_temp as $tt){$tags[] = $tt;}
		$tags_temp = explode(",", $xml->Host[$rsindx]->SexualPreferences);
		foreach($tags_temp as $tt){$tags[] = $tt;}
		$tags_temp = explode(",", $xml->Host[$rsindx]->Kinkies);
		foreach($tags_temp as $tt){$tags[] = $tt;}
		$numtags = sizeof($tags);
		if ($numtags > 10) {$numtags = 10;}
		unset($tagsarray);
		for ($ctr=0;$ctr<$numtags;$ctr++) {
			$tag = $tags[$ctr];
			$tagsarray[] = clean_tags($tag);
		}
		$model_info['tags'] = $tagsarray;
		$model_info['iframe_src'] = (string)$xml->Host[$rsindx]->HostLink;
		$model_info['gender'] = clean_username($xml->Host[$rsindx]->Gender);
		$model_info['username'] = clean_username($xml->Host[$rsindx]->NickName);
		$model_info['username'] = strtolower($model_info['username']);
		$model_info['thumb'] = cleanthumb($xml->Host[$rsindx]->HostPicture);
		$model_info['topic'] = cleansub($xml->Host[$rsindx]->Description);
		$model_info['topic'] .= "  About me - " . cleansub($xml->Host[$rsindx]->AboutMe);
		$model_info['topic'] .= "  Expertise - " . cleansub($xml->Host[$rsindx]->Expertise);
		$model_info['turns_on'] = clean_basic($xml->Host[$rsindx]->TurnsOn);
		$model_info['turns_off'] = clean_basic($xml->Host[$rsindx]->TurnsOff);
		
		if(in_array($model_info['username'], $used_modelnames)) {
			$model_info['username'] = $model_info['username'] . "_iml";
		}
		$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();}
}
$total_item_count += count($xmlmodels);
$out_file = __DIR__ . "/../feeds/feed_imlive.txt";
$filedata = serialize($xmlmodels);
writetxtfile($out_file, $filedata);
$out_file = __DIR__ . "/../feeds/modelndx_imlive.txt";
$filedata = serialize($xmlmodels_names);
writetxtfile($out_file, $filedata);		
?>
