<commit_before><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: admin/download_submissions.php
| Author: <NAME> (Hien)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
if (fusion_get_settings("tinymce_enabled")) {
	echo "<script language='javascript' type='text/javascript'>advanced();</script>\n";
}
if (isset($_GET['submit_id']) && isnum($_GET['submit_id'])) {
	if (isset($_POST['publish']) && (isset($_GET['submit_id']) && isnum($_GET['submit_id']))) {
		$result = dbquery("SELECT ts.*, tu.user_id, tu.user_name FROM ".DB_SUBMISSIONS." ts
			LEFT JOIN ".DB_USERS." tu ON ts.submit_user=tu.user_id
			WHERE submit_id='".$_GET['submit_id']."'");
		if (dbrows($result)) {
			$callback_data = dbarray($result);
			$callback_data = array(
				"download_id" => 0,
				"download_title" => form_sanitizer($_POST['download_title'], '', 'download_title'),
				"download_description" => form_sanitizer($_POST['download_description'], '', 'download_description'),
				"download_description_short" => form_sanitizer($_POST['download_description_short'], '', 'download_description_short'),
				"download_cat" => form_sanitizer($_POST['download_cat'], 0, 'download_cat'),
				"download_homepage" => form_sanitizer($_POST['download_homepage'], '', 'download_homepage'),
				"download_license" => form_sanitizer($_POST['download_license'], '', 'download_license'),
				"download_copyright" => form_sanitizer($_POST['download_copyright'], '', 'download_copyright'),
				"download_os" => form_sanitizer($_POST['download_os'], '', 'download_os'),
				"download_version" => form_sanitizer($_POST['download_version'], '', 'download_version'),
				"download_file" => form_sanitizer($_POST['download_file'], '', 'download_file'),
				"download_url" => form_sanitizer($_POST['download_url'], '', 'download_url'),
				"download_filesize" => form_sanitizer($_POST['download_filesize'], '', 'download_filesize'),
				"download_image" => form_sanitizer($_POST['download_image'], '', 'download_image'),
				"download_image_thumb" => form_sanitizer($_POST['download_image_thumb'], '', 'download_image_thumb'),
				"download_allow_comments" => isset($_POST['download_allow_comments']) ? TRUE : FALSE,
				"download_allow_ratings" => isset($_POST['download_allow_ratings']) ? TRUE : FALSE,
				"download_visibility" => form_sanitizer($_POST['download_visibility'], '', 'download_visibility'),
				"download_keywords" => form_sanitizer($_POST['download_keywords'], '', 'download_keywords'),
				"download_datestamp" => $callback_data['submit_datestamp'],
			);
			if (defender::safe()) {
				// move files
				if (!empty($callback_data['download_file']) && file_exists(DOWNLOADS."/submissions/".$callback_data['download_file'])) {
					$dest = DOWNLOADS."files/";
					$temp_file = $callback_data['download_file'];
					$callback_data['download_file'] = filename_exists($dest, $callback_data['download_file']);
					copy(DOWNLOADS."submissions/".$callback_data['download_file'], $dest.$callback_data['download_file']);
					chmod($dest.$callback_data['download_file'], 0644);
					unlink(DOWNLOADS."submissions/".$temp_file);
				}
				// move images
				if (!empty($callback_data['download_image']) && file_exists(DOWNLOADS."/submissions/images/".$callback_data['download_image'])) {
					$dest = DOWNLOADS."images/";
					$temp_file = $callback_data['download_image'];
					$callback_data['download_image'] = filename_exists($dest, $callback_data['download_image']);
					copy(DOWNLOADS."submissions/images/".$callback_data['download_image'], $dest.$callback_data['download_image']);
					chmod($dest.$callback_data['download_image'], 0644);
					unlink(DOWNLOADS."submissions/images/".$temp_file);
				}
				// move thumbnail
				if (!empty($callback_data['download_image_thumb']) && file_exists(DOWNLOADS."/submissions/images/".$callback_data['download_image_thumb'])) {
					$dest = DOWNLOADS."images/";
					$temp_file = $callback_data['download_image_thumb'];
					$callback_data['download_image_thumb'] = filename_exists($dest, $callback_data['download_image_thumb']);
					copy(DOWNLOADS."submissions/images/".$callback_data['download_image_thumb'], $dest.$callback_data['download_image_thumb']);
					chmod($dest.$callback_data['download_image_thumb'], 0644);
					unlink(DOWNLOADS."submissions/images/".$temp_file);
				}
				dbquery_insert(DB_DOWNLOADS, $callback_data, "save");
				dbquery("DELETE FROM ".DB_SUBMISSIONS." WHERE submit_id='".intval($_GET['submit_id'])."'");
				addNotice("success", $locale['download_0063']);
				redirect(clean_request("", array("submit_id"), FALSE));
			}
		} else {
			redirect(clean_request("", array("submit_id"), FALSE));
		}
	} else if (isset($_POST['delete']) && (isset($_GET['submit_id']) && isnum($_GET['submit_id']))) {
		$result = dbquery("
			SELECT ts.submit_id, ts.submit_datestamp, ts.submit_criteria
			FROM ".DB_SUBMISSIONS." ts
			WHERE submit_type='d' and submit_id='".intval($_GET['submit_id'])."'
		");
		if (dbrows($result) > 0) {
			$callback_data = dbarray($result);
			// delete all the relevant files
			$delCriteria = unserialize($callback_data['submit_criteria']);
			if (!empty($delCriteria['download_image']) && file_exists(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_image'])) {
				unlink(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_image']);
			}
			if (!empty($delCriteria['download_image_thumb']) && file_exists(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_image_thumb'])) {
				unlink(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_image_thumb']);
			}
			if (!empty($delCriteria['download_file']) && file_exists(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_file'])) {
				unlink(INFUSIONS."downloads/submisisons/".$delCriteria['download_file']);
			}
			$result = dbquery("DELETE FROM ".DB_SUBMISSIONS." WHERE submit_id='".intval($callback_data['submit_id'])."'");
			addNotice("success", $locale['download_0062']);
		}
		redirect(clean_request("", array("submit_id"), FALSE));
	} else {
		$result = dbquery("SELECT ts.submit_id,
			ts.submit_datestamp, ts.submit_criteria, tu.user_id, tu.user_name, tu.user_avatar, tu.user_status
			FROM ".DB_SUBMISSIONS." ts
			LEFT JOIN ".DB_USERS." tu ON ts.submit_user=tu.user_id
			WHERE submit_type='d' order by submit_datestamp desc");
		if (dbrows($result) > 0) {
			$data = dbarray($result);
			$submit_criteria = unserialize($data['submit_criteria']);
			$callback_data = array(
				"download_title" => $submit_criteria['download_title'],
				"download_keywords" => $submit_criteria['download_keywords'],
				"download_description" => $submit_criteria['download_description'],
				"download_description_short" => $submit_criteria['download_description_short'],
				"download_cat" => $submit_criteria['download_cat'],
				"download_homepage" => $submit_criteria['download_homepage'],
				"download_license" => $submit_criteria['download_license'],
				"download_copyright" => $submit_criteria['download_copyright'],
				"download_os" => $submit_criteria['download_os'],
				"download_version" => $submit_criteria['download_version'],
				"download_file" => $submit_criteria['download_file'],
				"download_url" => $submit_criteria['download_url'],
				"download_filesize" => $submit_criteria['download_filesize'],
				"download_image" => $submit_criteria['download_image'],
				"download_image_thumb" => $submit_criteria['download_image_thumb'],
				// default to none
				"download_id" => 0,
				"download_allow_comments" => TRUE,
				"download_allow_ratings" => TRUE,
				"download_visibility" => iMEMBER,
				"download_datestamp" => $data['submit_datestamp'],
			);
			add_to_title($locale['global_200'].$locale['503'].$locale['global_201'].$callback_data['download_title']."?");
			echo openform("publish_download", "post", FUSION_REQUEST);
			echo "<div class='well clearfix'>\n";
			echo "<div class='pull-left'>\n";
			echo display_avatar($callback_data, "30px", "", "", "");
			echo "</div>\n";
			echo "<div class='overflow-hide'>\n";
			echo $locale['download_0056'].profile_link($data['user_id'], $data['user_name'], $data['user_status'])."<br/>\n";
			echo $locale['download_0057'].timer($data['submit_datestamp'])." - ".showdate("shortdate", $data['submit_datestamp']);
			echo "</div>\n";
			echo "</div>\n";
			echo "<div class='row'>\n";
			echo "<div class='col-xs-12 col-sm-8'>\n";
			openside('');
			echo form_hidden('submit_id', '', $data['submit_id']);
			echo form_hidden('download_datestamp', '', $callback_data['download_datestamp']);
			echo form_text('download_title', $locale['download_0200'], $callback_data['download_title'], array(
				'required' => TRUE,
				"inline" => TRUE,
				'error_text' => $locale['download_0110']
			));
			echo form_select('download_keywords', $locale['download_0203'], $callback_data['download_keywords'], array(
				"placeholder" => $locale['download_0203a'],
				'max_length' => 320,
				"inline" => TRUE,
				'width' => '100%',
				'tags' => 1,
				'multiple' => 1
			));<commit_msg>Fix - #220<commit_after><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: admin/download_submissions.php
| Author: <NAME> (Hien)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
if (fusion_get_settings("tinymce_enabled")) {
	echo "<script language='javascript' type='text/javascript'>advanced();</script>\n";
}
if (isset($_GET['submit_id']) && isnum($_GET['submit_id'])) {
	if (isset($_POST['publish']) && (isset($_GET['submit_id']) && isnum($_GET['submit_id']))) {
		$result = dbquery("SELECT ts.*, tu.user_id, tu.user_name FROM ".DB_SUBMISSIONS." ts
			LEFT JOIN ".DB_USERS." tu ON ts.submit_user=tu.user_id
			WHERE submit_id='".$_GET['submit_id']."'");
		if (dbrows($result)) {
			$callback_data = dbarray($result);
			$callback_data = array(
				"download_id" => 0,
				"download_title" => form_sanitizer($_POST['download_title'], '', 'download_title'),
				"download_description" => form_sanitizer($_POST['download_description'], '', 'download_description'),
				"download_description_short" => form_sanitizer($_POST['download_description_short'], '', 'download_description_short'),
				"download_cat" => form_sanitizer($_POST['download_cat'], 0, 'download_cat'),
				"download_homepage" => form_sanitizer($_POST['download_homepage'], '', 'download_homepage'),
				"download_license" => form_sanitizer($_POST['download_license'], '', 'download_license'),
				"download_copyright" => form_sanitizer($_POST['download_copyright'], '', 'download_copyright'),
				"download_os" => form_sanitizer($_POST['download_os'], '', 'download_os'),
				"download_version" => form_sanitizer($_POST['download_version'], '', 'download_version'),
				"download_file" => form_sanitizer($_POST['download_file'], '', 'download_file'),
				"download_url" => form_sanitizer($_POST['download_url'], '', 'download_url'),
				"download_filesize" => form_sanitizer($_POST['download_filesize'], '', 'download_filesize'),
				"download_image" => form_sanitizer($_POST['download_image'], '', 'download_image'),
				"download_image_thumb" => form_sanitizer($_POST['download_image_thumb'], '', 'download_image_thumb'),
				"download_allow_comments" => isset($_POST['download_allow_comments']) ? TRUE : FALSE,
				"download_allow_ratings" => isset($_POST['download_allow_ratings']) ? TRUE : FALSE,
				"download_visibility" => form_sanitizer($_POST['download_visibility'], '', 'download_visibility'),
				"download_keywords" => form_sanitizer($_POST['download_keywords'], '', 'download_keywords'),
				"download_datestamp" => $callback_data['submit_datestamp'],
			);
			if (defender::safe()) {
				// move files
				if (!empty($callback_data['download_file']) && file_exists(DOWNLOADS."/submissions/".$callback_data['download_file'])) {
					$dest = DOWNLOADS."files/";
					$temp_file = $callback_data['download_file'];
					$callback_data['download_file'] = filename_exists($dest, $callback_data['download_file']);
					copy(DOWNLOADS."submissions/".$callback_data['download_file'], $dest.$callback_data['download_file']);
					chmod($dest.$callback_data['download_file'], 0644);
					unlink(DOWNLOADS."submissions/".$temp_file);
				}
				// move images
				if (!empty($callback_data['download_image']) && file_exists(DOWNLOADS."/submissions/images/".$callback_data['download_image'])) {
					$dest = DOWNLOADS."images/";
					$temp_file = $callback_data['download_image'];
					$callback_data['download_image'] = filename_exists($dest, $callback_data['download_image']);
					copy(DOWNLOADS."submissions/images/".$callback_data['download_image'], $dest.$callback_data['download_image']);
					chmod($dest.$callback_data['download_image'], 0644);
					unlink(DOWNLOADS."submissions/images/".$temp_file);
				}
				// move thumbnail
				if (!empty($callback_data['download_image_thumb']) && file_exists(DOWNLOADS."/submissions/images/".$callback_data['download_image_thumb'])) {
					$dest = DOWNLOADS."images/";
					$temp_file = $callback_data['download_image_thumb'];
					$callback_data['download_image_thumb'] = filename_exists($dest, $callback_data['download_image_thumb']);
					copy(DOWNLOADS."submissions/images/".$callback_data['download_image_thumb'], $dest.$callback_data['download_image_thumb']);
					chmod($dest.$callback_data['download_image_thumb'], 0644);
					unlink(DOWNLOADS."submissions/images/".$temp_file);
				}
				dbquery_insert(DB_DOWNLOADS, $callback_data, "save");
				dbquery("DELETE FROM ".DB_SUBMISSIONS." WHERE submit_id='".intval($_GET['submit_id'])."'");
				addNotice("success", $locale['download_0063']);
				redirect(clean_request("", array("submit_id"), FALSE));
			}
		} else {
			redirect(clean_request("", array("submit_id"), FALSE));
		}
	} else if (isset($_POST['delete']) && (isset($_GET['submit_id']) && isnum($_GET['submit_id']))) {
		$result = dbquery("
			SELECT ts.submit_id, ts.submit_datestamp, ts.submit_criteria
			FROM ".DB_SUBMISSIONS." ts
			WHERE submit_type='d' and submit_id='".intval($_GET['submit_id'])."'
		");
		if (dbrows($result) > 0) {
			$callback_data = dbarray($result);
			// delete all the relevant files
			$delCriteria = unserialize($callback_data['submit_criteria']);
			if (!empty($delCriteria['download_image']) && file_exists(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_image'])) {
				unlink(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_image']);
			}
			if (!empty($delCriteria['download_image_thumb']) && file_exists(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_image_thumb'])) {
				unlink(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_image_thumb']);
			}
			if (!empty($delCriteria['download_file']) && file_exists(INFUSIONS."downloads/submisisons/images/".$delCriteria['download_file'])) {
				unlink(INFUSIONS."downloads/submisisons/".$delCriteria['download_file']);
			}
			$result = dbquery("DELETE FROM ".DB_SUBMISSIONS." WHERE submit_id='".intval($callback_data['submit_id'])."'");
			addNotice("success", $locale['download_0062']);
		}
		redirect(clean_request("", array("submit_id"), FALSE));
	} else {
		$result = dbquery("SELECT ts.submit_id,
			ts.submit_datestamp, ts.submit_criteria, tu.user_id, tu.user_name, tu.user_avatar, tu.user_status
			FROM ".DB_SUBMISSIONS." ts
			LEFT JOIN ".DB_USERS." tu ON ts.submit_user=tu.user_id
			WHERE submit_type='d' order by submit_datestamp desc");
		if (dbrows($result) > 0) {
			$data = dbarray($result);
			$submit_criteria = unserialize($data['submit_criteria']);
			$callback_data = array(
				"download_title" => $submit_criteria['download_title'],
				"download_keywords" => $submit_criteria['download_keywords'],
				"download_description" => $submit_criteria['download_description'],
				"download_description_short" => $submit_criteria['download_description_short'],
				"download_cat" => $submit_criteria['download_cat'],
				"download_homepage" => $submit_criteria['download_homepage'],
				"download_license" => $submit_criteria['download_license'],
				"download_copyright" => $submit_criteria['download_copyright'],
				"download_os" => $submit_criteria['download_os'],
				"download_version" => $submit_criteria['download_version'],
				"download_file" => $submit_criteria['download_file'],
				"download_url" => $submit_criteria['download_url'],
				"download_filesize" => $submit_criteria['download_filesize'],
				"download_image" => $submit_criteria['download_image'],
				"download_image_thumb" => $submit_criteria['download_image_thumb'],
				// default to none
				"download_id" => 0,
				"download_allow_comments" => TRUE,
				"download_allow_ratings" => TRUE,
				"download_visibility" => iGUEST,
				"download_datestamp" => $data['submit_datestamp'],
			);
			add_to_title($locale['global_200'].$locale['503'].$locale['global_201'].$callback_data['download_title']."?");
			echo openform("publish_download", "post", FUSION_REQUEST);
			echo "<div class='well clearfix'>\n";
			echo "<div class='pull-left'>\n";
			echo display_avatar($callback_data, "30px", "", "", "");
			echo "</div>\n";
			echo "<div class='overflow-hide'>\n";
			echo $locale['download_0056'].profile_link($data['user_id'], $data['user_name'], $data['user_status'])."<br/>\n";
			echo $locale['download_0057'].timer($data['submit_datestamp'])." - ".showdate("shortdate", $data['submit_datestamp']);
			echo "</div>\n";
			echo "</div>\n";
			echo "<div class='row'>\n";
			echo "<div class='col-xs-12 col-sm-8'>\n";
			openside('');
			echo form_hidden('submit_id', '', $data['submit_id']);
			echo form_hidden('download_datestamp', '', $callback_data['download_datestamp']);
			echo form_text('download_title', $locale['download_0200'], $callback_data['download_title'], array(
				'required' => TRUE,
				"inline" => TRUE,
				'error_text' => $locale['download_0110']
			));
			echo form_select('download_keywords', $locale['download_0203'], $callback_data['download_keywords'], array(
				"placeholder" => $locale['download_0203a'],
				'max_length' => 320,
				"inline" => TRUE,
				'width' => '100%',
				'tags' => 1,
				'multiple' => 1
			));
{'fraction_non_alphanumeric': 0.20275162925416365, 'fraction_numerical': 0.007499741388227992, 'mean_word_length': 5.298045602605863, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 129, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 290, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6776', 'n_tokens_mistral': 6922, 'n_tokens_neox': 5954, 'n_words': 877}