<?

if ($set['cron_trash'] == 1 AND $set['cron_trash_time'] != 0) {
	$hfile = H.'files/cache/cron/newsTrash.json';
	if (@filectime($hfile) < $system['time'] - 86400 * $set['cron_trash_time']) {
		@unlink($hfile);
	}
	if (!file_exists($hfile)) {
		$query = $sql->fetchAll("SELECT * FROM `news` where `act` = '2' ORDER BY `id` DESC LIMIT 9999");
		foreach ($query AS $p) {
			unlink(H.'files/news-images/big/'. $p['img'] .'.jpg');
			unlink(H.'files/news-images/mid/'. $p['img'] .'.jpg');
			unlink(H.'files/news-images/large/'. $p['img'] .'.jpg');
			unlink(H.'files/news-images/min/'. $p['img'] .'.jpg');
			CacheDelete::news($p['link']);
			$sql->query("DELETE FROM `news` WHERE `id` = ". $p['id']);
		}
		file_put_contents($hfile, json_encode(['time' => $system['time']], true));
	}
}

if ($set['cron_public'] == 1 AND $set['cron_system_limit'] != 0) {
	$hfile = H.'files/cache/cron/newsPublic.json';
	if (@filectime($hfile) < $system['time'] - 1) {
		@unlink($hfile);
	}
	if (!file_exists($hfile)) {
		$query = $sql->fetchAll("SELECT * FROM `news` where `act` = '0' ORDER BY `sort` DESC LIMIT {$set['cron_system_limit']}");
		foreach ($query AS $p) {
			$sql->query("UPDATE `news` SET `act` = '1' , `date_public` = '{$system['time']}' WHERE `id` = ". $p['id']);
			CacheDelete::news($p['link']);
		}
		file_put_contents($hfile, json_encode(['time' => $system['time']], true));
	}
}

$hfile = H.'files/cache/cron/users_recovery.json';
if (@filectime($hfile) < time() - 86400) {
	@unlink($hfile);
}
if (!file_exists($hfile)) {
	$sql->query("DELETE FROM `users_recovery` WHERE `date_create` < '".(time() - 86400)."'");
	file_put_contents($hfile, json_encode(['time' => time()], true));
}