<?php
if(!defined('AUTHACCESS')){echo "Not Allowed";exit();}
//camsoda_update
$xmlmodels = array();
$xml=json_decode($xmlfile);
$p_end = count($xml->results);
$t_ndx = 0;
$mnndx = 0;
$npt = count($xml->results);
$npt--;
$ordinator = get_ordinator($npt);
for($x=0;$x<$p_end;$x++) {
	$rsindx = (int)$ordinator[$x];
	if (in_array($xml->results[$rsindx]->gender, $allowed_genders) ) { 
		//$xmlmodels[] = $xml->results[$rsindx];
		$nmx = clean_username($xml->results[$rsindx]->username);
		$nmx = strtolower($nmx);
		$xmlmodels_names[$nmx] = $mnndx;
		$xmlmodels_names_allcams[$nmx] = $mnndx_all;
		$mnndx++;
		$t_ndx++;
		$model_info = array();
		$model_info['sponsor'] = "camsoda";
		$thm = (string)$xml->results[$rsindx]->link_iframe;
		$model_info['iframe_src'] = $thm;
		$model_info['display_name'] = cleandisplayname($xml->results[$rsindx]->name);
		if (ctype_space($model_info['display_name'])) {unset($model_info['display_name']);}
		$tags = array();
		$tagsarray = array();
		if(is_array($xml->results[$rsindx]->tags)){
			$tags = $xml->results[$rsindx]->tags;
			$numtags = sizeof($tags);
			if ($numtags > 10) {$numtags = 10;}
			unset($tagsarray);
			$tagsarray = array();
			for ($ctr=0;$ctr<$numtags;$ctr++) {
				$tag = $tags[$ctr];
				$tagsarray[] = clean_tags($tag);
			}
			$model_info['tags'] = $tagsarray;
			$tags = $tagsarray;
		}
		$model_info['gender'] = clean_username($xml->results[$rsindx]->gender);
		$model_info['username'] = clean_username($xml->results[$rsindx]->username);
		$model_info['username'] = strtolower($model_info['username']);
		$model_info['thumb'] = (string)$xml->results[$rsindx]->thumb;
		$model_info['thumb'] = cleanthumb($model_info['thumb']);
		$model_info['topic'] = cleansub($xml->results[$rsindx]->subject);
		
		if(in_array($model_info['username'], $used_modelnames)) {
			$model_info['username'] = $model_info['username'] . "_cs";
		}
		$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_camsoda.txt";
$filedata = serialize($xmlmodels);
writetxtfile($out_file, $filedata);
$out_file = __DIR__ . "/../feeds/modelndx_camsoda.txt";
$filedata = serialize($xmlmodels_names);
writetxtfile($out_file, $filedata);
?>
