<?php

$requested_action = '';
if (isset($_REQUEST['action'])) {
	$requested_action = (string)$_REQUEST['action'];
} elseif (isset($action)) {
	$requested_action = (string)$action;
}

if (!defined('DATALIFEENGINE') || !defined('LOGGED_IN')) {
	header("HTTP/1.1 403 Forbidden");
	header('Location: ../../');
	die('Hacking attempt!');
}

if (!$user_group[$member_id['user_group']]['admin_addnews']) {
	msg("error", $lang['index_denied'], $lang['index_denied']);
}

function dle_addradio_ensure_xfields() {
	$defaults = [
		'description' => '',
		'hint' => '',
		'category' => '',
		'allow_add_usergroups' => '',
		'allow_view_usergroups' => '',
		'storage' => -1,
		'type' => 'text',
		'default' => '',
		'not_required' => 1,
		'use_as_links' => 0,
		'use_editor' => 0,
		'safe_mode' => 0,
		'min' => '',
		'max' => '',
		'allow_multi' => 0,
		'select_separator' => '',
		'links_separator' => '',
		'image_sizes' => '',
		'image_size' => '',
		'image_max_size' => '',
		'make_watermark' => 0,
		'make_thumb' => 0,
		'thumb_size' => '',
		'max_images' => '',
		'use_opengraph' => '',
		'image_side' => '',
		'thumb_side' => '',
		'max_files' => '',
		'max_size' => '',
		'files_ext' => '',
		'file_max_size' => '',
		'is_public' => '',
		'condition' => '',
		'date_format' => '',
		'date_view_format' => '',
		'date_local' => '',
		'date_declension' => '',
		'group' => '',
		'allow_in_news' => 0,
		'lazy_load' => '',
	];

	DLEXFields::Init();

	$ensure = function (string $name, array $data) use ($defaults) {
		$current = DLEXFields::GETField($name);
		if (is_array($current) && count($current)) {
			return;
		}
		$data = array_merge($defaults, $data);
		$data['name'] = $name;
		DLEXFields::SaveField($name, $data);
	};

	// Reuse track display fields used by the theme
	$ensure('songname', [
		'description' => 'Title',
		'type' => 'text',
		'not_required' => 0,
		'safe_mode' => 1,
	]);

	$ensure('artistsong', [
		'description' => 'Subtitle',
		'type' => 'text',
		'not_required' => 1,
		'safe_mode' => 1,
		'default' => 'Radio',
	]);

	// Radio-specific fields
	$ensure('is_radio', [
		'description' => 'Is radio stream',
		'type' => 'yesorno',
		'not_required' => 1,
		'default' => '1',
	]);

	$ensure('radiostream', [
		'description' => 'Stream URL',
		'type' => 'text',
		'not_required' => 0,
		'safe_mode' => 1,
	]);

	$ensure('radiocover', [
		'description' => 'Cover URL',
		'type' => 'text',
		'not_required' => 1,
		'safe_mode' => 1,
	]);
}

dle_addradio_ensure_xfields();

if ($action == 'addradio') {

	DLEXFields::Init();
	$xfields = DLEXFields::FieldsList();

	$duplicateprotection = UniqIDReal(32);

	echoheader("<i class=\"fa fa-broadcast-tower position-left\"></i><span class=\"text-semibold\">Add Radio Stream</span>", "Add Radio Stream");

	$categories_list = CategoryNewsSelection(0, 0);
	if ($config['allow_multi_category']) {
		$category_multiple = "class=\"categoryselect\" multiple";
		$category_size = " size=\"10\"";
	} else {
		$category_multiple = "class=\"uniform\" data-live-search=\"true\" data-none-results-text=\"{$lang['addnews_cat_fault']}\" data-width=\"350\"";
		$category_size = "";
	}

	$fix_input = ($user_group[$member_id['user_group']]['allow_fixed'] && $config['allow_fixed'])
		? "<div class=\"checkbox\"><label><input class=\"icheck\" type=\"checkbox\" id=\"news_fixed\" name=\"news_fixed\" value=\"1\">{$lang['addnews_fix']}</label></div>"
		: "";

	$main_input = $user_group[$member_id['user_group']]['allow_main']
		? "<div class=\"checkbox\" id=\"opt_holder_main\"><label><input class=\"icheck\" type=\"checkbox\" id=\"allow_main\" name=\"allow_main\" value=\"1\" checked>{$lang['addnews_main']}</label></div>"
		: "";

	if ($member_id['user_group'] < 3) {
		$disable_index = "<div class=\"checkbox\"><label><input class=\"icheck\" type=\"checkbox\" id=\"disable_index\" name=\"disable_index\" value=\"1\">{$lang['add_disable_index']}</label></div>";
		$disable_search = "<div class=\"checkbox\"><label><input class=\"icheck\" type=\"checkbox\" id=\"disable_search\" name=\"disable_search\" value=\"1\">{$lang['cat_d_search']}</label></div>";

		if ($config['allow_yandex_dzen']) {
			$yandex_dzen = "<div class=\"checkbox\"><label><input class=\"icheck\" type=\"checkbox\" name=\"allow_rss_dzen\" id=\"allow_rss_dzen\" value=\"1\" checked>{$lang['allow_rss_dzen']}</label></div>";
		} else {
			$yandex_dzen = "";
		}

		if ($config['allow_rss']) {
			$rss_option = <<<HTML
				<div class="row mt-15" id="opt_cat_rss">
					<div class="col-sm-6" style="max-width:21.67em;">
						<div class="checkbox"><label><input class="icheck" type="checkbox" name="allow_rss" value="1" checked>{$lang['allow_rss_news']}</label></div>
					</div>
					<div class="col-sm-6">
						{$yandex_dzen}
					</div>
				</div>
HTML;
		} else {
			$rss_option = "";
		}
	} else {
		$disable_index = "";
		$disable_search = "";
		$rss_option = "";
	}

	echo <<<HTML
<div class="panel panel-default">
	<div class="panel-heading">
		<h6 class="panel-title">Add Radio Stream</h6>
	</div>
	<form method="post" enctype="multipart/form-data" name="addradio" id="addradio" onsubmit="if(typeof checkxf === 'function' && checkxf()=='fail') return false;" class="form-horizontal">
		<div class="panel-body">
			<div class="form-group">
				<label class="control-label col-sm-2">Title</label>
				<div class="col-sm-10">
					<input type="text" dir="auto" class="form-control width-550" name="title" id="title" maxlength="250" placeholder="Radio station name">
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">Stream URL</label>
				<div class="col-sm-10">
					<input type="text" dir="auto" class="form-control width-550" name="xfield[radiostream]" id="radiostream" maxlength="500" placeholder="https://...">
					<div class="help-block">Use a direct stream URL (MP3/AAC recommended). HTTPS is preferred for best browser compatibility.</div>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">Cover upload</label>
				<div class="col-sm-10">
					<input type="file" class="file-styled" name="radiocover_file" id="radiocover_file" accept="image/png,image/jpeg,image/webp,image/gif">
					<div class="help-block">Optional. Upload an image to use as the station cover.</div>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">{$lang['addnews_cat']}</label>
				<div class="col-sm-10">
					<select data-placeholder="{$lang['addnews_cat_sel']}" title="{$lang['addnews_cat_sel']}" name="category[]" id="category" {$category_multiple}{$category_size} style="width:100%;max-width:24.3em;">{$categories_list}</select>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">Description</label>
				<div class="col-sm-10">
					<textarea dir="auto" class="classic" style="width:100%;height: 12.5rem;" name="full_story" id="full_story"></textarea>
				</div>
			</div>

			<input type="hidden" name="xfield[is_radio]" value="1">
			<input type="hidden" name="xfield[songname]" id="songname" value="">
			<input type="hidden" name="xfield[artistsong]" value="Radio">

			<div class="form-group">
				<label class="control-label col-sm-2">{$lang['addnews_option']}</label>
				<div class="col-sm-10">
					<div class="row">
						<div class="col-sm-6" style="max-width:21.67em;">
							<div class="checkbox"><label><input class="icheck" type="checkbox" id="approve" name="approve" value="1" checked>{$lang['addnews_mod']}</label></div>
							{$main_input}
							<div class="checkbox" id="opt_holder_rating"><label><input class="icheck" type="checkbox" id="allow_rating" name="allow_rating" value="1" checked>{$lang['addnews_allow_rate']}</label></div>
						</div>
						<div class="col-sm-6">
							<div class="checkbox" id="opt_holder_comments"><label><input class="icheck" type="checkbox" id="allow_comm" name="allow_comm" value="1" checked>{$lang['addnews_comm']}</label></div>
							{$fix_input}
							{$disable_index}
							{$disable_search}
						</div>
					</div>
					{$rss_option}
				</div>
			</div>

		</div>
		<div class="panel-footer">
			<input type="hidden" name="mod" value="addradio">
			<input type="hidden" name="action" value="doaddradio">
			<input type="hidden" name="user_hash" value="{$dle_login_hash}">
			<input type="hidden" name="duplicateprotection" value="{$duplicateprotection}">
			<button type="submit" class="btn bg-teal btn-sm btn-raised legitRipple"><i class="fa fa-plus-square"></i> Post Radio</button>
		</div>
	</form>
</div>
<script>
{$xfields['js_functions']}
{$xfields['js_scripts']}

if (typeof $ === 'function') {
	$(function(){
		if ( typeof $.fn.chosen === 'function' ) {
			$(".categoryselect").chosen({ allow_single_deselect:true, no_results_text: "{$lang['addnews_cat_fault']}", width: "100%" });
		}
	});
}
</script>
<script>
(function(){
	var title = document.getElementById('title');
	var songname = document.getElementById('songname');
	if(title && songname){
		title.addEventListener('input', function(){ songname.value = title.value; });
		// initialize
		songname.value = title.value;
	}
})();
</script>
HTML;

	echofooter();
	die();
}

elseif ($action == 'doaddradio') {

	// Handle optional cover upload (sets xfield[radiocover] to a local uploaded file URL)
	if (isset($_FILES['radiocover_file']) && is_array($_FILES['radiocover_file']) && isset($_FILES['radiocover_file']['error']) && $_FILES['radiocover_file']['error'] !== UPLOAD_ERR_NO_FILE) {
		if ($_FILES['radiocover_file']['error'] !== UPLOAD_ERR_OK) {
			msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Cover upload failed', "javascript:history.go(-1)");
		}

		if (!isset($_FILES['radiocover_file']['tmp_name']) || !is_uploaded_file($_FILES['radiocover_file']['tmp_name'])) {
			msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Cover upload failed', "javascript:history.go(-1)");
		}

		$max_size = 5 * 1024 * 1024;
		if (isset($_FILES['radiocover_file']['size']) && intval($_FILES['radiocover_file']['size']) > $max_size) {
			msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Cover image is too large (max 5MB)', "javascript:history.go(-1)");
		}

		$img_info = @getimagesize($_FILES['radiocover_file']['tmp_name']);
		if (!$img_info || !isset($img_info['mime'])) {
			msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Cover file must be an image', "javascript:history.go(-1)");
		}

		$allowed = array(
			'image/jpeg' => 'jpg',
			'image/png'  => 'png',
			'image/webp' => 'webp',
			'image/gif'  => 'gif'
		);

		$mime = strtolower($img_info['mime']);
		if (!isset($allowed[$mime])) {
			msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Unsupported cover image type', "javascript:history.go(-1)");
		}

		$ext = $allowed[$mime];
		$cover_dir_rel = 'uploads/posts/radio';
		$cover_dir_abs = ROOT_DIR . '/' . $cover_dir_rel;
		if (!is_dir($cover_dir_abs)) {
			@mkdir($cover_dir_abs, 0777, true);
			@chmod($cover_dir_abs, 0777);
		}

		if (!is_dir($cover_dir_abs) || !is_writable($cover_dir_abs)) {
			msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Cover upload directory is not writable', "javascript:history.go(-1)");
		}

		$rand = '';
		try {
			$rand = bin2hex(random_bytes(6));
		} catch (Throwable $e) {
			$rand = md5(uniqid('', true));
		}

		$filename = 'radio_' . time() . '_' . $rand . '.' . $ext;
		$dest_abs = $cover_dir_abs . '/' . $filename;

		if (!@move_uploaded_file($_FILES['radiocover_file']['tmp_name'], $dest_abs)) {
			msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Failed to save cover image', "javascript:history.go(-1)");
		}
		@chmod($dest_abs, 0666);

		if (!isset($_POST['xfield']) || !is_array($_POST['xfield'])) {
			$_POST['xfield'] = array();
		}

		$_POST['xfield']['radiocover'] = $config['http_home_url'] . $cover_dir_rel . '/' . $filename;
	}

	if (!$_REQUEST['user_hash'] || $_REQUEST['user_hash'] != $dle_login_hash) {
		msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), $lang['sess_error'], "javascript:history.go(-1)");
	}

	if (!isset($_POST['duplicateprotection']) || (isset($_SESSION['dp']['dp_' . md5($_POST['duplicateprotection'])]) && $_SESSION['dp']['dp_' . md5($_POST['duplicateprotection'])] === true)) {
		msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), $lang['duplicate_protect'], "javascript:history.go(-1)");
	}

	@header('X-XSS-Protection: 0;');

	// Normalize xfields for theme compatibility
	if (!isset($_POST['xfield']) || !is_array($_POST['xfield'])) {
		$_POST['xfield'] = array();
	}

	$_POST['xfield']['is_radio'] = '1';

	$stream_url = isset($_POST['xfield']['radiostream']) ? trim((string)$_POST['xfield']['radiostream']) : '';
	if (!$stream_url) {
		msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Stream URL is required', "javascript:history.go(-1)");
	}

	// Best-effort URL validation (allow http/https)
	if (!preg_match('#^https?://#i', $stream_url)) {
		msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), 'Stream URL must start with http:// or https://', "javascript:history.go(-1)");
	}

	// Also populate mp3 xfield so existing player integrations keep working
	if (!isset($_POST['xfield']['mp3']) || trim((string)$_POST['xfield']['mp3']) === '') {
		$_POST['xfield']['mp3'] = $stream_url;
	}

	// Ensure display fields are set
	$title_raw = isset($_POST['title']) ? trim((string)$_POST['title']) : '';
	if (!isset($_POST['xfield']['songname']) || trim((string)$_POST['xfield']['songname']) === '') {
		$_POST['xfield']['songname'] = $title_raw;
	}
	if (!isset($_POST['xfield']['artistsong']) || trim((string)$_POST['xfield']['artistsong']) === '') {
		$_POST['xfield']['artistsong'] = 'Radio';
	}

	$parsed_fields = DLEXFields::Parse();
	if (DLEXFields::$error) {
		msg("error", "error", DLEXFields::$error, "javascript:history.go(-1)");
	}

	$filecontents = $parsed_fields['filecontents'];
	$xf_search_words = $parsed_fields['search_words'];
	$all_xf_content = $parsed_fields['all_xf_content'];
	unset($parsed_fields);

	$parse = new ParseFilter();

	$allow_comm = isset($_POST['allow_comm']) ? intval($_POST['allow_comm']) : 0;
	$approve = isset($_POST['approve']) ? intval($_POST['approve']) : 0;
	$allow_rating = isset($_POST['allow_rating']) ? intval($_POST['allow_rating']) : 0;
	$news_fixed = isset($_POST['news_fixed']) ? intval($_POST['news_fixed']) : 0;
	$disable_index = isset($_POST['disable_index']) ? intval($_POST['disable_index']) : 0;
	$disable_search = isset($_POST['disable_search']) ? intval($_POST['disable_search']) : 0;
	$need_pass = 0;
	$allow_rss = isset($_POST['allow_rss']) ? intval($_POST['allow_rss']) : 0;
	$allow_rss_dzen = isset($_POST['allow_rss_dzen']) ? intval($_POST['allow_rss_dzen']) : 0;
	$allowed_country = '';
	$not_allowed_country = '';
	$related_ids = '';
	$group_regel = '';

	$category = isset($_POST['category']) ? $_POST['category'] : array();
	if (!is_array($category)) $category = array();
	if (!count($category)) $category[] = '0';

	$category_list = array();
	foreach ($category as $value) {
		$category_list[] = intval($value);
	}

	$allow_main = 0;
	if ($user_group[$member_id['user_group']]['allow_main']) {
		$allow_main = isset($_POST['allow_main']) ? intval($_POST['allow_main']) : 0;
	}

	if (!$config['allow_fixed'] || !$user_group[$member_id['user_group']]['allow_fixed']) {
		$news_fixed = 0;
	}

	$disable_rss_dzen = 0;

	if ($member_id['user_group'] > 2) {
		$disable_index = 0;
		$disable_search = 0;
		$need_pass = 0;
		$allow_rss = 1;
		$allow_rss_dzen = 1;
		$allowed_country = '';
		$not_allowed_country = '';
	}

	if (!$config['allow_rss']) {
		$allow_rss = 1;
	}
	if (!$config['allow_yandex_dzen']) {
		$allow_rss_dzen = 0;
	}
	if (!$allow_rss) {
		$allow_rss_dzen = 0;
	}

	if ($member_id['cat_add']) $allow_list = explode(',', $member_id['cat_add']);
	else $allow_list = explode(',', $user_group[$member_id['user_group']]['cat_add']);

	$mail_send = false;

	if ($member_id['cat_allow_addnews']) $allow_list_add = explode(',', $member_id['cat_allow_addnews']);
	else $allow_list_add = explode(',', $user_group[$member_id['user_group']]['cat_allow_addnews']);

	foreach ($category_list as $selected) {
		if ($allow_list_add[0] != 'all' && !in_array($selected, $allow_list_add)) {
			msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), $lang['news_err_41'], "javascript:history.go(-1)");
		}
		if (isset($cat_info[$selected]['disable_main']) && $cat_info[$selected]['disable_main']) {
			$allow_main = 0;
		}
		if (isset($cat_info[$selected]['disable_comments']) && $cat_info[$selected]['disable_comments']) {
			$allow_comm = 1;
		}
		if (isset($cat_info[$selected]['disable_rating']) && $cat_info[$selected]['disable_rating']) {
			$allow_rating = 0;
		}

		if ($member_id['user_group'] > 2) {
			if (isset($cat_info[$selected]['enable_dzen']) && !$cat_info[$selected]['enable_dzen']) {
				$disable_rss_dzen++;
			}
		}
		if ($allow_list[0] != 'all' && !in_array($selected, $allow_list)) {
			$approve = 0;
			$mail_send = true;
		}
	}

	if ($member_id['user_group'] > 2) {
		if ($disable_rss_dzen > 0 && $disable_rss_dzen == count($category_list)) {
			$allow_rss_dzen = 0;
		}
	}

	$category_list = $db->safesql(implode(',', $category_list));

	if (!$user_group[$member_id['user_group']]['moderation']) {
		$approve = 0;
		$mail_send = true;
	}

	$title = $parse->process(trim(strip_tags($title_raw)));

	$_POST['full_story'] = isset($_POST['full_story']) ? (string)$_POST['full_story'] : '';
	$parse->allow_code = false;
	$full_story = $parse->process($_POST['full_story']);
	$full_story = $db->safesql($parse->BB_Parse($full_story));
	$short_story = '';

	if ($parse->not_allowed_text) {
		msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), $lang['news_err_39'], "javascript:history.go(-1)");
	}

	if (!$title) {
		msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), $lang['addnews_alert'], "javascript:history.go(-1)");
	}

	if (dle_strlen($title) > 255) {
		msg("error", array('javascript:history.go(-1)' => 'Add Radio', '' => $lang['addnews_error']), $lang['addnews_ermax'], "javascript:history.go(-1)");
	}

	$alt_name = totranslit(stripslashes($title), true, false, $config['translit_url']);

	$title_db = $db->safesql($title);
	$alt_name = $db->safesql($alt_name);

	$catalog_url = $db->safesql(dle_substr(htmlspecialchars(strip_tags(stripslashes(trim($_POST['catalog_url'] ?? ''))), ENT_QUOTES, 'UTF-8'), 0, 3));
	if ($config['create_catalog'] && !$catalog_url) $catalog_url = $db->safesql(dle_substr(htmlspecialchars(strip_tags(stripslashes($title)), ENT_QUOTES, 'UTF-8'), 0, 1));

	$added_time = time();
	$thistime = date("Y-m-d H:i:s", $added_time);

	$author = $member_id['name'];
	$userid = $member_id['user_id'];

	if (dle_strlen($full_story) > 12) $all_xf_content = stripslashes($full_story) . ' ' . $all_xf_content;

	$metatags = create_metatags($all_xf_content);

	$db->query("INSERT INTO " . PREFIX . "_post (date, autor, short_story, full_story, xfields, title, descr, keywords, category, alt_name, allow_comm, approve, allow_main, fixed, allow_br, symbol, tags, metatitle) values ('{$thistime}', '{$author}', '{$short_story}', '{$full_story}', '{$filecontents}', '{$title_db}', '{$metatags['description']}', '{$metatags['keywords']}', '{$category_list}', '{$alt_name}', '{$allow_comm}', '{$approve}', '{$allow_main}', '{$news_fixed}', '0', '{$catalog_url}', '', '{$metatags['title']}')");

	$id = $db->insert_id();

	$db->query("INSERT INTO " . PREFIX . "_post_extras (news_id, allow_rate, votes, disable_index, related_ids, access, user_id, disable_search, need_pass, allow_rss, allow_rss_dzen, allowed_country, not_allowed_country) VALUES('{$id}', '{$allow_rating}', '0', '{$disable_index}', '{$related_ids}', '{$group_regel}', '{$userid}', '{$disable_search}', '{$need_pass}', '{$allow_rss}', '{$allow_rss_dzen}', '{$allowed_country}', '{$not_allowed_country}')");

	if ($category_list && $approve) {
		$cat_ids = array();
		$cat_ids_arr = explode(",", $category_list);
		foreach ($cat_ids_arr as $value) {
			$cat_ids[] = "('" . $id . "', '" . trim($value) . "')";
		}
		$cat_ids = implode(", ", $cat_ids);
		$db->query("INSERT INTO " . PREFIX . "_post_extras_cats (news_id, cat_id) VALUES " . $cat_ids);
	}

	if (count($xf_search_words) && $approve) {
		$temp_array = array();
		foreach ($xf_search_words as $value) {
			$temp_array[] = "('" . $id . "', '" . $value[0] . "', '" . $value[1] . "')";
		}
		$xf_search_words_sql = implode(", ", $temp_array);
		$db->query("INSERT INTO " . PREFIX . "_xfsearch (news_id, tagname, tagvalue) VALUES " . $xf_search_words_sql);
	}

	$db->query("UPDATE " . PREFIX . "_images SET news_id='{$id}', author = '{$author}' WHERE author = '" . $db->safesql($member_id['name']) . "' AND news_id = '0'");
	$db->query("UPDATE " . PREFIX . "_files SET news_id='{$id}', author = '{$author}' WHERE author = '" . $db->safesql($member_id['name']) . "' AND news_id = '0'");
	$db->query("UPDATE " . USERPREFIX . "_users SET news_num=news_num+1 WHERE user_id='{$userid}'");

	$db->query("INSERT INTO " . USERPREFIX . "_admin_logs (name, date, ip, action, extras) values ('" . $db->safesql($member_id['name']) . "', '{$_TIME}', '{$_IP}', '1', '{$title_db}')");

	clear_cache(array('news_', 'tagscloud_', 'archives_', 'calendar_', 'topnews_', 'rss', 'stats'));

	$_SESSION['dp']['dp_' . md5($_POST['duplicateprotection'])] = true;

	$row = $db->super_query("SELECT id, date, category, alt_name FROM " . PREFIX . "_post WHERE id='{$id}' LIMIT 1");
	$row['date'] = strtotime($row['date']);
	$full_link = DLEUrl::BuildUrl('showfull', ['category' => get_url($row['category']), 'year' => date('Y', $row['date']), 'month' => date('m', $row['date']), 'day' => date('d', $row['date']), 'news_name' => $row['alt_name'], 'newsid' => $row['id']]);

	msg("success", $lang['addnews_ok'], $lang['addnews_ok_1'] . " \"" . stripslashes(stripslashes($title_db)) . "\" " . $lang['addnews_ok_2'], array('?mod=addradio&action=addradio' => 'Add Radio Stream', '?mod=editnews&action=editnews&id=' . $id => $lang['add_s_2'], '?mod=editnews&action=list' => $lang['add_s_3'], $full_link => $lang['add_s_5']));
}

else {
	msg("error", $lang['index_denied'], $lang['index_denied']);
}
