<?php
if(!defined('AUTHACCESS')){echo "Not Allowed";exit();}
//stripchat_update

$xmlmodels = array();
$xml=json_decode($xmlfile);	
$p_end = count($xml->models);
$t_ndx = 0;
$mnndx = 0;
$npt = count($xml->models);
$npt--;
$ordinator = get_ordinator($npt);
for($x=0;$x<$p_end;$x++) {
	$rsindx = (int)$ordinator[$x];
	if (in_array(strtolower($xml->models[$rsindx]->gender), $allowed_genders) ) {
		$nmx = clean_username($xml->models[$rsindx]->username);
		$nmx = strtolower($nmx);
		$xmlmodels_names[$nmx] = $mnndx;
		$xmlmodels_names_allcams[$nmx] = $mnndx_all;
		$mnndx++;
		$mnndx_all++;
		$model_info = array();
		$model_info['sponsor'] = "stripchat";
		$tags = array();
		$tagsarray = array();
		if(is_array($xml->models[$rsindx]->tags)){
			$tags = $xml->models[$rsindx]->tags;
			shuffle($tags);
			$numtags = sizeof($tags);
			if ($numtags > 10) {$numtags = 10;}
			for ($ctr=0;$ctr<$numtags;$ctr++) {
				$tag = $tags[$ctr];
				$tag = str_replace("girls","",$tag);
				$tag = str_replace("boys","",$tag);
				$tag = str_replace("/","",$tag);
				//$tag = str_replace("-","",$tag);
				if(!empty($tag)){
					$tagsarray[] = clean_tags($tag);
				}
			}
			$model_info['tags'] = $tagsarray;
		}
		$model_info['stream_width'] = clean_username($xml->models[$rsindx]->stream->width);
		$model_info['stream_height'] = clean_username($xml->models[$rsindx]->stream->height);
		$model_info['gender'] = clean_username($xml->models[$rsindx]->gender);
		$model_info['username'] = clean_username($xml->models[$rsindx]->username);
		$model_info['username'] = strtolower($model_info['username']);
		$model_info['thumb'] = cleanthumb($xml->models[$rsindx]->previewUrlThumbBig);
		$model_info['topic'] = "Strip Chat" . " " . $model_info['gender'] . " ";
		if(!empty($xml->models[$rsindx]->profileEthnicity)) {
			$model_info['topic'] .= cleansub($xml->models[$rsindx]->profileEthnicity);
		}
		if(!empty($xml->models[$rsindx]->subcultureGlamour)){
			$model_info['topic'] .= "  About me - " . cleansub($xml->models[$rsindx]->subcultureGlamour);
		}
		if(!empty($xml->models[$rsindx]->profileInterestedIn)){
			$model_info['topic'] .= "  Expertise - " . cleansub($xml->models[$rsindx]->profileInterestedIn);		
		}
		
		
		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! 900 ";exit();}
}
$total_item_count += count($xmlmodels);
$out_file = __DIR__ . "/../feeds/feed_stripchat.txt";
$filedata = serialize($xmlmodels);
writetxtfile($out_file, $filedata);
$out_file = __DIR__ . "/../feeds/modelndx_stripchat.txt";
$filedata = serialize($xmlmodels_names);
writetxtfile($out_file, $filedata);	
?>
