<?php
if(!defined('AUTHACCESS')){echo "Not Allowed";exit();}
//bongacams_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($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'] = "bongacams";
		$thm = (string)$xml->models[$rsindx]->chat_url;
		$model_info['iframe_src'] = $thm;
		$model_info['display_name'] = cleandisplayname($xml->models[$rsindx]->display_name);
		if (ctype_space($model_info['display_name'])) {unset($model_info['display_name']);}
		$tags = array();
		if( is_array($xml->models[$rsindx]->tags) || is_object($xml->models[$rsindx]->tags) ){
			foreach($xml->models[$rsindx]->tags as $xt){
				$tags[] = $xt;
			}
			shuffle($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['chat_url'] = $xml->models[$rsindx]->chat_url;
		$model_info['turns_on'] = clean_basic($xml->models[$rsindx]->turns_on);
		$model_info['turns_off'] = clean_basic($xml->models[$rsindx]->turns_off);
		$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']);
		$profile_images = $xml->models[$rsindx]->profile_images;
		$model_info['thumbnail_image_big'] = (string)$profile_images->thumbnail_image_big;
		$model_info['thumbnail_image_medium'] = (string)$profile_images->thumbnail_image_medium;
		$live_images = $xml->models[$rsindx]->live_images;
		$model_info['thumb'] = cleanthumb($live_images->thumbnail_image_medium);
		$model_info['topic'] = $model_info['gender'] . " " . $model_info['turns_on'] . " " . $model_info['turns_off'];

		$model_info['topic'] = cleansub($model_info['topic']);

		if(in_array($model_info['username'], $used_modelnames)) {
			$model_info['username'] = $model_info['username'] . "_bc";
		}
		$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_bongacams.txt";
$filedata = serialize($xmlmodels);
writetxtfile($out_file, $filedata);
$out_file = __DIR__ . "/../feeds/modelndx_bongacams.txt";
$filedata = serialize($xmlmodels_names);
writetxtfile($out_file, $filedata);
?>
