/wp-admin/plugins.php';
	return;
}
if (!class_exists('acf') )
{
	echo 'ACF not activated. Make sure you activate the plugin in /wp-admin/plugins.php';
	return;
}
$context = Timber::get_context();
if (is_post_type_archive('project'))
{
	$page = get_page_by_path('projecten');
	$page = get_page(icl_object_id($page->ID, 'page', true, ICL_LANGUAGE_CODE));
	$context['page']   = new TimberPost($page->ID);
	$context['themes'] = Timber::get_terms('theme');
	$context['news']   = Timber::get_posts(array('numberposts' => 2, 'post_type' => 'news'));
	
	$template = array('project-index.twig');
}
else if (is_tax('subject') || is_tax('theme'))
{
	$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
	$term = new TimberTerm($term);
	$context['posts'] = $term->get_posts(array('numberposts' => -1));
	$context['term'] = $term;
	$template = array('project-taxonomy.twig');
}
else if (is_singular('project'))
{
	$context['post'] = new TimberPost();
	$template = array('project-single.twig');
}
else if (is_post_type_archive('story'))
{
	$page = get_page_by_path('verhalen');
	$page = get_page(icl_object_id($page->ID, 'page', true, ICL_LANGUAGE_CODE));
	$context['page']   = new TimberPost($page->ID);
	$context['stories'] = Timber::get_posts(array('numberposts' => -1, 'post_type' => 'story'));
	
	$template = array('story-index.twig');
}
else if (is_singular('story'))
{
	$context['post'] = new TimberPost();
	$context['stories'] = Timber::get_posts(array('numberposts' => 2, 'post_type' => 'story', 'orderby' => 'rand', 'post__not_in' => array($context['post']->ID)));
	$template = array('story-single.twig');
}
else if (is_post_type_archive('news'))
{
	$page = get_page_by_path('nieuws');
	$page = get_page(icl_object_id($page->ID, 'page', true, ICL_LANGUAGE_CODE));
	$context['page']   = new TimberPost($page->ID);
	$context['news'] = Timber::get_posts(array('numberposts' => -1, 'post_type' => 'news'));
	
	$template = array('news-index.twig');
}
else if (is_singular('news'))
{
	
	$context['post'] = new TimberPost();
	$context['news'] = Timber::get_posts(array('numberposts' => 2, 'post_type' => 'news', 'post__not_in' => array($context['post']->ID)));
	
	$template = array('news-single.twig');
}
else if (is_post_type_archive('job'))
{
	wp_safe_redirect( home_url() );
	exit;
}
else if (is_singular('job'))
{
	
	$context['post'] = new TimberPost();
	$context['jobs'] = Timber::get_posts(array('numberposts' => -1, 'post_type' => 'job', 'post__not_in' => array($context['post']->ID)));
	$template = array('job-single.twig');
}
else if (is_page())
{
	$context['post'] = new TimberPost();
	if ($context['post']->ID !== $context['donate']->ID)
	{
		$context['themes'] = Timber::get_terms('theme');
		$context['news'] = Timber::get_posts(array('numberposts' => 2, 'post_type' => 'news'));
		$context['jobs'] = Timber::get_posts(array('numberposts' => -1, 'post_type' => 'job'));
		$template = is_front_page() ? array('front-page.twig') : array('page-' . $context['post']->post_name . '.twig', 'page.twig');
	}
	else
	{
		if (!empty($_POST))
		{
			if ($_POST['type'] === 'once')
			{
				$amount = (isset($_POST['predefined-amount']) ? $_POST['predefined-amount'] : $_POST['custom-amount']);
				$amount = number_format($amount, 2, '.', '');
				
				$data = [
					'description' => 'Donatie aan Stichting Niketan',
					'locale' => $context['languages'][$context['language']]['default_locale'],
					'amount' => ['currency' => 'EUR', 'value' => $amount],
					'method' => isset($_POST['payment']) && in_array($_POST['payment'], ['ideal', 'creditcard', 'paypal']) ? $_POST['payment'] : 'ideal',
					'redirectUrl' => ($context['language'] === 'nl') ? 'https://www.niketan.nl/bedankt/' : 'https://www.niketan.nl/en/thanks/',
					'webhookUrl' => ($context['language'] === 'nl') ? 'https://www.niketan.nl/bedankt/' : 'https://www.niketan.nl/en/thanks/',
				];
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL, 'https://api.mollie.com/v2/payments');
				curl_setopt($ch, CURLOPT_POST, true);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				curl_setopt($ch, CURLOPT_HTTPHEADER, array
				(
					// live_792UtKUhMC6NCB6vFSB8cztyAsacR6
					// test_baNytSk8s9JgxPg9NCcsxABPRNc4FV
					'Authorization: Bearer live_792UtKUhMC6NCB6vFSB8cztyAsacR6',
					'Content-Type: application/json'
				));
				curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
				
				$response = curl_exec($ch);
				$response = json_decode($response);
				
				curl_close($ch);
				if (!isset($response->error))
				{
					wp_redirect($response->_links->checkout->href);
					exit;
				}
				else
				{
					wp_safe_redirect($context['post']->link . '?error=1');
					exit;
				}
			}
			else if (!empty($_POST['type']) && !empty($_POST['iban']) && !empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['gender']) && !empty($_POST['mail']) && !empty($_POST['street_name']) && !empty($_POST['street_no']) && !empty($_POST['zip']) && !empty($_POST['location']) && wp_verify_nonce($_POST['_wpnonce'], 'donation') && empty($_POST['url']))
			{
				$message  = 'Bedankt voor uw donatie! Wij hebben de volgende gegevens van u ontvangen:' . "\n\n";
				$message .= 'Ik doneer ' . ($_POST['type'] === 'once' ? 'eenmalig' : ($_POST['type'] === 'monthly' ? 'maandelijks' : 'jaarlijks')) . ' een bedrag van E ' . (!empty($_POST['custom-amount']) ? $_POST['custom-amount'] : $_POST['predefined-amount']) . "\n";
				$message .= 'Rekeningnummer: ' . ($_POST['iban']) . "\n\n";
				$message .= 'Geslacht: ' . ($_POST['gender'] === 'm' ? 'man' : 'vrouw') . "\n";
				$message .= 'Naam: ' . ($_POST['firstname'] . ' ' . $_POST['lastname']) . "\n";
				$message .= 'Adres: ' . ($_POST['street_name'] . ' ' . $_POST['street_no']) . "\n";
				$message .= 'Postcode: ' . ($_POST['zip']) . "\n";
				$message .= 'Plaats: ' . ($_POST['location']) . "\n";
				$message .= 'E-mail: ' . ($_POST['mail']) . "\n";
				if (!empty($_POST['phone']))
				{
					$message .= 'Telefoon: ' . ($_POST['phone']) . "\n";
				}
				wp_mail($_POST['mail'], 'Donatie via de website', $message, array('From: Stichting Niketan ', 'Bcc: info@niketan.nl'));
				wp_safe_redirect($context['post']->link . '?success=1');
				exit;
			}
			wp_safe_redirect($context['post']->link . '?error=1');
			exit;
		}
		$template = array('donate.twig');
				
	}
}
else if (is_404())
{
	$template = array('errors/404.twig');
}
Timber::render($template, $context);
?>