<?php
if(!defined('AUTHACCESS')){echo "Not Allowed";exit();}
//chaturbate_update
$xmlmodels = array();
$holda = array();
$holdb = array();
$holdc = array();
$xml=simplexml_load_string($xmlfile);
$p_end = count($xml->results->resource);
$t_ndx = 0;
$mnndx = 0;
$npt = count($xml->results->resource);
$npt--;
$ordinator = get_ordinator($npt);
for($x=0;$x<$p_end;$x++) {
	$rsindx = (int)$ordinator[$x];
	if (in_array($xml->results->resource[$rsindx]->gender, $allowed_genders) ) {
		$nmx = clean_username($xml->results->resource[$rsindx]->username);
		$nmx = strtolower($nmx);
		$xmlmodels_names[$nmx] = $mnndx;
		$xmlmodels_names_allcams[$nmx] = $mnndx_all;
		$mnndx++;
		$mnndx_all++;
		$model_info = array();
		$model_info['sponsor'] = "chaturbate";
		$model_info['iframe_chatroom'] = (string)$xml->results->resource[$rsindx]->iframe_embed_revshare;;
		$holda = preg_split("/src=/i", $model_info['iframe_chatroom']);
		$holdb = explode(">", $holda[1]);
		$holdc = explode(" ", $holdb[0]);
		$output = preg_replace("/'/", "", $holdc[0]);
		$output = preg_replace('/"/', '', $output);
		$model_info['iframe_src'] = $output;
		$model_info['chat_room_url_revshare'] = (string)$xml->results->resource[$rsindx]->chat_room_url_revshare;
		$model_info['chat_room_url'] = (string)$xml->results->resource[$rsindx]->chat_room_url;
		$model_info['display_name'] = cleandisplayname($xml->results->resource[$rsindx]->display_name);
		if (ctype_space($model_info['display_name'])) {unset($model_info['display_name']);}
		$xtags = $xml->results->resource[$rsindx]->tags->resource;
		if( is_array($xtags) || is_object($xtags) ){
				$tags = $xml->results->resource[$rsindx]->tags->resource;
				$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;
		}else {
			$tags = array();
			$tagsarray = array();
		}
		$model_info['gender'] = clean_username($xml->results->resource[$rsindx]->gender);
		$model_info['username'] = clean_username($xml->results->resource[$rsindx]->username);
		$model_info['username'] = strtolower($model_info['username']);
		$model_info['thumb'] = (string)$xml->results->resource[$rsindx]->image_url;
		$model_info['thumb'] = cleanthumb($model_info['thumb']);
		$thm = $model_info['thumb'];
		$model_info['thumb'] = $thm;
		$model_info['topic'] = cleansub($xml->results->resource[$rsindx]->room_subject);
		
		if(in_array($model_info['username'], $used_modelnames)) {
			$model_info['username'] = $model_info['username'] . "_cb";
		}
		$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_chaturbate.txt";
$filedata = serialize($xmlmodels);
writetxtfile($out_file, $filedata);
$out_file = __DIR__ . "/../feeds/modelndx_chaturbate.txt";
$filedata = serialize($xmlmodels_names);
writetxtfile($out_file, $filedata);		
?>
