<commit_before><?php

/**
 * @name		Upload Module
 * @author		<NAME>
 * @author		<NAME>
 * @copyright	2014 by <NAME>, <NAME>
 */

if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');

function upload($files, $albumID, $description = '', $tags = '') {

	global $database, $settings;

	switch($albumID) {
		// s for public (share)
		case 's':
			$public		= 1;
			$star		= 0;
			$albumID	= 0;
			break;
		// f for starred (fav)
		case 'f':
			$star		= 1;
			$public		= 0;
			$albumID	= 0;
			break;
		default:
			$star		= 0;
			$public		= 0;
	}

	foreach ($files as $file) {

		if ($file['type']!=='image/jpeg'&&
			$file['type']!=='image/png'&&
			$file['type']!=='image/gif')
				return false;

		$id = str_replace('.', '', microtime(true));
		while(strlen($id)<14) $id .= 0;

		$tmp_name	= $file['tmp_name'];
		$extension	= array_reverse(explode('.', $file['name']));
		$extension	= $extension[0];
		$photo_name	= md5($id) . ".$extension";

		// Import if not uploaded via web
		if (!is_uploaded_file($tmp_name)) {
			if (copy($tmp_name, __DIR__ . '/../../uploads/big/' . $photo_name)) {
				@unlink($tmp_name);
				$import_name = $tmp_name;
			}
		} else {
			move_uploaded_file($tmp_name, __DIR__ . '/../../uploads/big/' . $photo_name);
			$import_name = '';
		}

		// Read infos
		$info = getInfo($photo_name);

		// Use title of file if IPTC title missing
		if ($info['title']==='') $info['title'] = mysqli_real_escape_string($database, substr(basename($file['name'], ".$extension"), 0, 30));

		// Use description parameter if set
		if ($description==='') $description = $info['description'];

		// Set orientation based on EXIF data
		if ($file['type'] === 'image/jpeg' && isset($info['orientation']) && isset($info['width']) && isset($info['height'])) {

			if(extension_loaded('imagick')) {

				$rotateImage = 0;

				switch ($info['orientation']) {

					case 3:
						$rotateImage = 180;
						$imageOrientation = 1;
						break;

					case 6:
						$rotateImage = 90;
						$imageOrientation = 1;
						break;

					case 8:
						$rotateImage = 270;
						$imageOrientation = 1;
						break;

				}

				if ($rotateImage) {
					$image = new Imagick();
					$image->readImage(__DIR__ . '/../../uploads/big/' . $photo_name);
					$image->rotateImage(new ImagickPixel(), $rotateImage);<commit_msg>Code adjustment<commit_after><?php

/**
 * @name		Upload Module
 * @author		<NAME>
 * @author		<NAME>
 * @copyright	2014 by <NAME>, <NAME>
 */

if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');

function upload($files, $albumID, $description = '', $tags = '') {

	global $database, $settings;

	switch($albumID) {
		// s for public (share)
		case 's':
			$public		= 1;
			$star		= 0;
			$albumID	= 0;
			break;
		// f for starred (fav)
		case 'f':
			$star		= 1;
			$public		= 0;
			$albumID	= 0;
			break;
		default:
			$star		= 0;
			$public		= 0;
	}

	foreach ($files as $file) {

		if ($file['type']!=='image/jpeg'&&
			$file['type']!=='image/png'&&
			$file['type']!=='image/gif')
				return false;

		$id = str_replace('.', '', microtime(true));
		while(strlen($id)<14) $id .= 0;

		$tmp_name	= $file['tmp_name'];
		$extension	= array_reverse(explode('.', $file['name']));
		$extension	= $extension[0];
		$photo_name	= md5($id) . ".$extension";

		// Import if not uploaded via web
		if (!is_uploaded_file($tmp_name)) {
			if (copy($tmp_name, __DIR__ . '/../../uploads/big/' . $photo_name)) {
				@unlink($tmp_name);
				$import_name = $tmp_name;
			}
		} else {
			move_uploaded_file($tmp_name, __DIR__ . '/../../uploads/big/' . $photo_name);
			$import_name = '';
		}

		// Read infos
		$info = getInfo($photo_name);

		// Use title of file if IPTC title missing
		if ($info['title']==='') $info['title'] = mysqli_real_escape_string($database, substr(basename($file['name'], ".$extension"), 0, 30));

		// Use description parameter if set
		if ($description==='') $description = $info['description'];

		// Set orientation based on EXIF data
		if ($file['type']==='image/jpeg'&&isset($info['orientation'])&&isset($info['width'])&&isset($info['height'])) {

			if(extension_loaded('imagick')) {

				$rotateImage = 0;

				switch ($info['orientation']) {

					case 3:
						$rotateImage = 180;
						$imageOrientation = 1;
						break;

					case 6:
						$rotateImage = 90;
						$imageOrientation = 1;
						break;

					case 8:
						$rotateImage = 270;
						$imageOrientation = 1;
						break;

				}

				if ($rotateImage) {
					$image = new Imagick();
					$image->readImage(__DIR__ . '/../../uploads/big/' . $photo_name);
					$image->rotateImage(new ImagickPixel(), $rotateImage);
{'fraction_non_alphanumeric': 0.2050840155105558, 'fraction_numerical': 0.015079707022834985, 'mean_word_length': 3.0943562610229276, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3357267', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1636, 'n_words': 370}