<commit_before><?php declare(strict_types=1);

$location = Request::get('location');
$email = Request::get('email');

// get website (and validate it)
$website = Request::get('website');
if ($website != '') {
	// add http:// if missing
	if (!preg_match('=://=', $website)) {
		$website = 'http://' . $website;
	}

	// validate
	$status = floor(php_link_check($website) / 100);

	if ($status != 2 && $status != 3) {
		create_error('The website you entered is invalid!');
	}
}

$other = Request::get('other');

$day = Request::getInt('day');
$month = Request::getInt('month');
$year = Request::getInt('year');

// check if we have an image
$noPicture = true;
if ($_FILES['photo']['error'] == UPLOAD_ERR_OK) {
	$noPicture = false;
	// get dimensions
	$size = getimagesize($_FILES['photo']['tmp_name']);
	if (!isset($size)) {
		create_error('Uploaded file must be an image!');
	}

	$allowed_types = [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG];
	if (!in_array($size[2], $allowed_types)) {
		create_error('Only gif, jpg or png-image allowed!');
	}

	// check if width > 500
	if ($size[0] > 500) {
		create_error('Image is wider than 500 pixels!');
	}

	// check if height > 500
	if ($size[1] > 500) {
		create_error('Image is higher than 500 pixels!');
	}

	if (!move_uploaded_file($_FILES['photo']['tmp_name'], UPLOAD . $account->getAccountID())) {
		create_error('Failed to upload image!');
	}
}


// check if we had a album entry so far
$db->query('SELECT * FROM album WHERE account_id = ' . $db->escapeNumber($account->getAccountID()));
if ($db->nextRecord()) {
	if (!$noPicture) {
		$comment = '<span class="green">*** Picture changed</span>';
	}

	// change album entry
	$db->query('UPDATE album
				SET location = ' . $db->escapeString($location) . ',
					email = ' . $db->escapeString($email) . ',
					website= ' . $db->escapeString($website) . ',
					day = ' . $db->escapeNumber($day) . ',
					month = ' . $db->escapeNumber($month) . ',
					year = ' . $db->escapeNumber($year) . ',
					other = ' . $db->escapeString($other) . ',
					last_changed = ' . $db->escapeNumber(SmrSession::getTime()) . ',
					approved = \'TBC\',
					disabled = \'FALSE\'
				WHERE account_id = ' . $db->escapeNumber($account->getAccountID()) . ' LIMIT 1');
} else {
	// if he didn't upload a picture before
	// we kick him out here
	if ($noPicture) {
		create_error('What is it worth if you don\'t upload an image?');
	}

	$comment = '<span class="green">*** Picture added</span>';

	// add album entry
	$db->query('INSERT INTO album (account_id, location, email, website, day, month, year, other, created, last_changed, approved)
				VALUES(' . $db->escapeNumber($account->getAccountID()) . ', ' . $db->escapeString($location) . ', ' . $db->escapeString($email) . ', ' . $db->escapeString($website) . ', ' . $db->escapeNumber($day) . ', ' . $db->escapeNumber($month) . ', ' . $db->escapeNumber($year) . ', ' . $db->escapeString($other) . ', ' . $db->escapeNumber(SmrSession::getTime()) . ', ' . $db->escapeNumber(SmrSession::getTime()) . ', \'TBC\')');
}

if (!empty($comment)) {
	// check if we have comments for this album already
	$db->lockTable('album_has_comments');

	$db->query('SELECT MAX(comment_id) FROM album_has_comments WHERE album_id = ' . $db->escapeNumber($account->getAccountID()));
	if ($db->nextRecord()) {
		$comment_id = $db->getInt('MAX(comment_id)') + 1;
	} else {
		$comment_id = 1;
	}

	$db->query('INSERT INTO album_has_comments
				(album_id, comment_id, time, post_id, msg)
				VALUES (' . $db->escapeNumber($account->getAccountID()) . ', ' . $db->escapeNumber($comment_id) . ', ' . $db->escapeNumber(SmrSession::getTime()) . ', 0, ' . $db->escapeString($comment) . ')');
	$db->unlock();
}

$container = create_container('skeleton.php', 'album_edit.php');
$container['SuccessMsg'] = 'SUCCESS: Your information has been updated!';
forward($container);

function php_link_check($url) {
	/*	Purpose: Check HTTP Links
	*	Usage:	$var = phpLinkCheck(absoluteURI)
	*					$var['Status-Code'] will return the HTTP status code
	*					(e.g. 200 or 404). In case of a 3xx code (redirection)
	*					$var['Location-Status-Code'] will contain the status
	*					code of the new loaction.
	*					See echo_r($var) for the complete result
	*
	*	Author:	<NAME> <<EMAIL>>
	*	Date:		2001-04-14
	*	Version: 0.1 (currently requires PHP4)
	*/
	$url = trim($url);
	if (!preg_match('=://=', $url)) {
		$url = 'http://' . $url;
	}
	$url = parse_url($url);
	if (!in_array(strtolower($url['scheme']), ['http', 'https'])) {
		return false;
	}

	if (!isset($url['port'])) {
		$url['port'] = 80;
	}
	if (!isset($url['path'])) {
		$url['path'] = '/';
	}

	if (!checkdnsrr($url['host'], 'A')) {
		return false;
	}

	$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);

	if ($fp === false) {
		return false;
	} else {
		$head = '';
		$httpRequest = 'HEAD ' . $url['path'] . ' HTTP/1.1' . EOL
								.'Host: ' . $url['host'] . EOL
								.'Connection: close' . EOL . EOL;
		fputs($fp, $httpRequest);
		while (!feof($fp)) {
			$head .= fgets($fp, 1024);
		}
		fclose($fp);

		preg_match('=^(HTTP/\d+\.\d+) (\d{3}) ([^\r\n]*)=', $head, $matches);
		$http['Status-Line'] = $matches[0];
		$http['HTTP-Version'] = $matches[1];
		$http['Status-Code'] = $matches[2];
		$http['Reason-Phrase'] = $matches[3];

		return $http['Status-Code'];
	}
}<commit_msg>album_edit_processing.php: fix array initialization<commit_after><?php declare(strict_types=1);

$location = Request::get('location');
$email = Request::get('email');

// get website (and validate it)
$website = Request::get('website');
if ($website != '') {
	// add http:// if missing
	if (!preg_match('=://=', $website)) {
		$website = 'http://' . $website;
	}

	// validate
	$status = floor(php_link_check($website) / 100);

	if ($status != 2 && $status != 3) {
		create_error('The website you entered is invalid!');
	}
}

$other = Request::get('other');

$day = Request::getInt('day');
$month = Request::getInt('month');
$year = Request::getInt('year');

// check if we have an image
$noPicture = true;
if ($_FILES['photo']['error'] == UPLOAD_ERR_OK) {
	$noPicture = false;
	// get dimensions
	$size = getimagesize($_FILES['photo']['tmp_name']);
	if (!isset($size)) {
		create_error('Uploaded file must be an image!');
	}

	$allowed_types = [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG];
	if (!in_array($size[2], $allowed_types)) {
		create_error('Only gif, jpg or png-image allowed!');
	}

	// check if width > 500
	if ($size[0] > 500) {
		create_error('Image is wider than 500 pixels!');
	}

	// check if height > 500
	if ($size[1] > 500) {
		create_error('Image is higher than 500 pixels!');
	}

	if (!move_uploaded_file($_FILES['photo']['tmp_name'], UPLOAD . $account->getAccountID())) {
		create_error('Failed to upload image!');
	}
}


// check if we had a album entry so far
$db->query('SELECT * FROM album WHERE account_id = ' . $db->escapeNumber($account->getAccountID()));
if ($db->nextRecord()) {
	if (!$noPicture) {
		$comment = '<span class="green">*** Picture changed</span>';
	}

	// change album entry
	$db->query('UPDATE album
				SET location = ' . $db->escapeString($location) . ',
					email = ' . $db->escapeString($email) . ',
					website= ' . $db->escapeString($website) . ',
					day = ' . $db->escapeNumber($day) . ',
					month = ' . $db->escapeNumber($month) . ',
					year = ' . $db->escapeNumber($year) . ',
					other = ' . $db->escapeString($other) . ',
					last_changed = ' . $db->escapeNumber(SmrSession::getTime()) . ',
					approved = \'TBC\',
					disabled = \'FALSE\'
				WHERE account_id = ' . $db->escapeNumber($account->getAccountID()) . ' LIMIT 1');
} else {
	// if he didn't upload a picture before
	// we kick him out here
	if ($noPicture) {
		create_error('What is it worth if you don\'t upload an image?');
	}

	$comment = '<span class="green">*** Picture added</span>';

	// add album entry
	$db->query('INSERT INTO album (account_id, location, email, website, day, month, year, other, created, last_changed, approved)
				VALUES(' . $db->escapeNumber($account->getAccountID()) . ', ' . $db->escapeString($location) . ', ' . $db->escapeString($email) . ', ' . $db->escapeString($website) . ', ' . $db->escapeNumber($day) . ', ' . $db->escapeNumber($month) . ', ' . $db->escapeNumber($year) . ', ' . $db->escapeString($other) . ', ' . $db->escapeNumber(SmrSession::getTime()) . ', ' . $db->escapeNumber(SmrSession::getTime()) . ', \'TBC\')');
}

if (!empty($comment)) {
	// check if we have comments for this album already
	$db->lockTable('album_has_comments');

	$db->query('SELECT MAX(comment_id) FROM album_has_comments WHERE album_id = ' . $db->escapeNumber($account->getAccountID()));
	if ($db->nextRecord()) {
		$comment_id = $db->getInt('MAX(comment_id)') + 1;
	} else {
		$comment_id = 1;
	}

	$db->query('INSERT INTO album_has_comments
				(album_id, comment_id, time, post_id, msg)
				VALUES (' . $db->escapeNumber($account->getAccountID()) . ', ' . $db->escapeNumber($comment_id) . ', ' . $db->escapeNumber(SmrSession::getTime()) . ', 0, ' . $db->escapeString($comment) . ')');
	$db->unlock();
}

$container = create_container('skeleton.php', 'album_edit.php');
$container['SuccessMsg'] = 'SUCCESS: Your information has been updated!';
forward($container);

function php_link_check($url) {
	/*	Purpose: Check HTTP Links
	*	Usage:	$var = phpLinkCheck(absoluteURI)
	*					$var['Status-Code'] will return the HTTP status code
	*					(e.g. 200 or 404). In case of a 3xx code (redirection)
	*					$var['Location-Status-Code'] will contain the status
	*					code of the new loaction.
	*					See echo_r($var) for the complete result
	*
	*	Author:	<NAME> <<EMAIL>>
	*	Date:		2001-04-14
	*	Version: 0.1 (currently requires PHP4)
	*/
	$url = trim($url);
	if (!preg_match('=://=', $url)) {
		$url = 'http://' . $url;
	}
	$url = parse_url($url);
	if (!in_array(strtolower($url['scheme']), ['http', 'https'])) {
		return false;
	}

	if (!isset($url['port'])) {
		$url['port'] = 80;
	}
	if (!isset($url['path'])) {
		$url['path'] = '/';
	}

	if (!checkdnsrr($url['host'], 'A')) {
		return false;
	}

	$fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);

	if ($fp === false) {
		return false;
	} else {
		$head = '';
		$httpRequest = 'HEAD ' . $url['path'] . ' HTTP/1.1' . EOL
								.'Host: ' . $url['host'] . EOL
								.'Connection: close' . EOL . EOL;
		fputs($fp, $httpRequest);
		while (!feof($fp)) {
			$head .= fgets($fp, 1024);
		}
		fclose($fp);

		preg_match('=^(HTTP/\d+\.\d+) (\d{3}) ([^\r\n]*)=', $head, $matches);
		$http = [
			'Status-Line' => $matches[0],
			'HTTP-Version' => $matches[1],
			'Status-Code' => $matches[2],
			'Reason-Phrase' => $matches[3],
		];

		return $http['Status-Code'];
	}
}
{'fraction_non_alphanumeric': 0.22192189393233294, 'fraction_numerical': 0.011930282412153975, 'mean_word_length': 3.848621780388613, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3007938', 'n_tokens_mistral': 4224, 'n_tokens_neox': 3812, 'n_words': 836}