<?php
	function replace($output, $extra = null) {
		global $siteLinks;
		foreach($GLOBALS as $key => $val) {
			$$key = $val;
		}
		$translations = $db->query("SELECT * FROM `translations` INNER JOIN `translation_codes` ON translation_codes.code_id = translations.code_id")->fetchAll(PDO::FETCH_ASSOC);
		$replace = array(
			"{PAGE_TITLE}" => (isset($title) ? $title : null),
			"{SITE_LOGO}" => LOGO,
			"{SITE_DARKLOGO}" => DARKLOGO,
			"{ADMİN_İLETİSİM}" => ADMİNS,
			"{SITE_FAVO}" => FAVO,
			"{AVA_LOGO}" => AVLOGO,
			"{SITE_TITLE}" => TITLE,
			"{SITE_DESC}" => DESC,
			"{SITE_KEYW}" => KEYW,
			"{CURRENCY_SYMBOL}" => CURRENCY_SYMBOL,
			"{CURRENCY_CODE}" => CURRENCY_CODE,
			"{JQUERY_JS}" => theme("scripts/jquery.min.js"),
			"{JQUERY_UI_JS}" => theme("scripts/jquery-ui.js"),
			"{BOOTSTRAP_JS}" => theme("scripts/bootstrap.min.js"),
			"{ALERTIFY_JS}" => theme("scripts/alertify.js"),
			"{DATEPICKER_JS}" => theme("scripts/bootstrap-datepicker.min.js"),
			"{CHART_JS}" => theme("scripts/Chart.min.js"),
			"{SUMMERNOTE_JS}" => theme("scripts/summernote-bs4.min.js"),
			"{DATATABLEBS4_JS}" => theme("scripts/dataTables.bootstrap4.js"),
			"{DATATABLE_JS}" => theme("scripts/jquery.dataTables.js"),
			"{ADMIN_JS}" => theme("scripts/admin.js"),
			"{MAIN_JS}" => theme("scripts/main.js"),
			"{ALERTIFY_CSS}" => theme("styles/alertify.css"),
			"{SUMMERNOTE_CSS}" => theme("styles/summernote-bs4.css"),
			"{DATATABLE_CSS}" => theme("styles/dataTables.bootstrap4.css"),
			"{DATEPICKER_CSS}" => theme("styles/bootstrap-datepicker.min.css"),
			"{MAIN_CSS}" => theme("styles/main.css"),
			"{LINK_HOMEPAGE}" => site(),
			"{LINK_FORGOT_PASSWORD}" => site($siteLinks['forgot']['url']),
			"{LINK_FAQ}" => site($siteLinks['faq']['url']),
			"{LINK_TERMS}" => site($siteLinks['terms']['url']),
			"{LINK_ADD}" => site($siteLinks['add-funds']['url']),
			"{LINK_TICKETS}" => site($siteLinks['tickets']['url']),
			"{LINK_SERVICES}" => site($siteLinks['services']['url']),
			"{LINK_ORDERS}" => site($siteLinks['orders']['url']),
			"{LINK_DRIPS}" => site($siteLinks['drips']['url']),
			"{LINK_LOGIN}" => site(),
			"{LINK_REGISTER}" => site($siteLinks['register']['url']),
			"{LINK_LOGOUT}" => site("logout"),
			"{LINK_CONTACT}" => site($siteLinks['contact']['url']),
			"{LINK_ACCOUNT}" => site($siteLinks['account']['url']),
			"{LINK_AUTO}" => site($siteLinks['auto']['url']),
			"{LINK_AUTOS}" => site($siteLinks['autos']['url']),
			"{LINK_API}" => site("api"),
			"{LINK_BLOG}" => site($siteLinks['blog']['url']),
			"{API_URL}" => site("api/v2"),
			"{PANEL_URL}" => site("panel"),
			"{LINK_POST}" => site("request/"),
			"{LINK_REFF}" => site($siteLinks['reff']['url']),
			"{USER_AVATAR}" => public_url("avatar.jpg"),
			"{LINK_CONT}" => site($siteLinks['contact']['url'])

		);
		if(login_control()) {
			global $user;
			@$user_replace = array(
				"{USER_USERNAME}" => $user["user_username"],
				"{USER_BALANCE}" => $user["user_balance"],
				"{USER_SPENT}" => $user["user_spent"],
				"{USER_EMAIL}" => $user["user_email"],
				"{USER_FIRST_NAME}" => $user["user_first_name"],
				"{USER_LAST_NAME}" => $user["user_last_name"],
				"{USER_SKYPE}" => $user["user_skype"],
				"{USER_API_KEY}" => $user["user_key"]
			);
			foreach($user_replace as $key => $val) {
				$replace[$key] = $val;
			}
		}
		foreach($translations as $translation) {
			if($translation["lang_id"] == $lang) {
				$replace["{".$translation["code_text"]."}"] = $translation["translation_text"];
			} else {
				if(!array_key_exists("{".$translation["code_text"]."}", $replace)) {
					if($translation["lang_id"] == 1) {
						$replace["{".$translation["code_text"]."}"] = $translation["translation_text"];
					}
				}
			}
		}
		$output = str_replace(array_keys($replace), $replace, $output);
		if($extra != null) {
			$output = str_replace(array_keys($extra), $extra, $output);
		}
		$output = announcements($output);
		return $output;
	}