<?php
if(!isset($CRON_GUVENLIK)){
    echo "cron dosyasını manuel çalıştıramazsınız";
    exit;
}


require_once "mp-content/init.php";

$query = $db->from('proxy')->orderby('proxy_id', 'ASC')->all();

foreach ($query as $proxy) {

	if($proxy['proxy_user'] && $proxy['proxy_pass']){

		$ip = $proxy['proxy_ip'] . ':' . $proxy['proxy_port'];
		$user = $proxy['proxy_user'] . ':' . $proxy['proxy_pass'];

		$instagramUserId = instagram_usernameConvert('instagram');
		$link = "https://www.instagram.com/graphql/query/?query_id=17888483320059182&id=".$instagramUserId."&first=20&after=";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $link);
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_PROXY, $ip);
		curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 33);
		$result = curl_exec($ch);
		curl_close($ch);
		$object		= json_decode($result , true);

	}else{ 

		$ip = $proxy['proxy_ip'] . ':' . $proxy['proxy_port'];

		$instagramUserId = instagram_usernameConvert('instagram');
		$link = "https://www.instagram.com/graphql/query/?query_id=17888483320059182&id=".$instagramUserId."&first=20&after=";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $link);
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_PROXY, $ip);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 33);
		$result = curl_exec($ch);
		curl_close($ch);
		$object		= json_decode($result , true);

	}



	if($object){

		$photoCount		=  $object['data']['user']["edge_owner_to_timeline_media"]["count"];
		$photos    		=  $object['data']['user']["edge_owner_to_timeline_media"]["edges"];

		if($photos){

			if($proxy['proxy_status'] == 0){

				$update = $db->update('proxy')->where('proxy_id', $proxy['proxy_id'])
				->set(array(
					'proxy_status' => 1
				));

				echo "g端ncel";

			}

		}						

	}else{

		$update = $db->update('proxy')->where('proxy_id', $proxy['proxy_id'])
		->set(array(
			'proxy_status' => 0
		));

	}


}
?>