<commit_before><?php

/**
 * @name        functions.php
 * @author      <NAME>
 * @author      <NAME>
 * @copyright   2013 by <NAME>, <NAME>
 */

if (!defined('LYCHEE')) die('Direct access is not allowed!');

// Database Functions
function dbConnect() {
    global $db, $dbUser, $dbPassword, $dbHost;
    $database = new mysqli($dbHost, $dbUser, $dbPassword);
    if (mysqli_connect_errno() != 0) {
	    echo mysqli_connect_errno().': '.mysqli_connect_error();
        return false;
	}
	if (!$database->select_db($db)) {
		createDatabase($db, $database);
	}
    $query = "SELECT * FROM lychee_photos, lychee_albums;";
    if (!$database->query($query)) createTables($database);
    return $database;
}
function dbClose() {
	global $database;
    if (!$database->close()) {
        echo "Closing the connection failed!";
        return false;
    }
    return true;
}
function createDatabase($db, $database) {
	$result = $database->query("CREATE DATABASE IF NOT EXISTS $db;");
	$database->select_db($db);
	if (!$result) return false;
	return true;
}
function createTables($database) {
    $query = "CREATE TABLE IF NOT EXISTS `lychee_albums` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(50) NOT NULL,
  `sysdate` varchar(10) NOT NULL,
  `public` TINYINT(1) DEFAULT '0',
  `password` VARCHAR(100),
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
    $result = $database->query($query);
    if (!$result) return false;

    $query = "CREATE TABLE `lychee_photos` (
  `id` bigint(14) NOT NULL,
  `title` varchar(50) NOT NULL,
  `description` varchar(160) NOT NULL,
  `url` varchar(100) NOT NULL,
  `public` tinyint(1) NOT NULL,
  `type` varchar(10) NOT NULL,
  `width` int(11) NOT NULL,
  `height` int(11) NOT NULL,
  `size` varchar(10) NOT NULL,
  `sysdate` varchar(10) NOT NULL,
  `systime` varchar(8) NOT NULL,
  `iso` varchar(15) NOT NULL,
  `aperture` varchar(10) NOT NULL,
  `make` varchar(20) NOT NULL,
  `model` varchar(50) NOT NULL,
  `shutter` varchar(10) NOT NULL,
  `focal` varchar(10) NOT NULL,
  `takedate` varchar(10) NOT NULL,
  `taketime` varchar(8) NOT NULL,
  `star` tinyint(1) NOT NULL,
  `thumbUrl` varchar(50) NOT NULL,
  `album` varchar(30) NOT NULL DEFAULT '0',
  `import_name` varchar(100) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
    $result = $database->query($query);
    if (!$result) return false;
    return true;
}

// Upload Functions
function upload($files, $albumID) {

	global $database;

	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) {

	    $id = str_replace('.', '', microtime(true));
	    while(strlen($id)<14) $id .= 0;
	    $tmp_name = $file["tmp_name"];
	    $type = getimagesize($tmp_name);
	    if (($type[2]!=1)&&($type[2]!=2)&&($type[2]!=3)) return false;
	    $data = $file["name"];
	    $data = explode('.',$data);
	    $data = array_reverse ($data);
	    $data = $data[0];

	    // Import if not uploaded via web
	    if (!is_uploaded_file($file)) {
	    	if (copy($tmp_name, "../uploads/big/" . md5($id) . ".$data")) {
				unlink($tmp_name);
				$import_name = $tmp_name;
			}
	    } else {
		    move_uploaded_file($tmp_name, "../uploads/big/" . md5($id) . ".$data");<commit_msg>Fix PHP warning about is_uploaded_file()<commit_after><?php

/**
 * @name        functions.php
 * @author      <NAME>
 * @author      <NAME>
 * @copyright   2013 by <NAME>, <NAME>
 */

if (!defined('LYCHEE')) die('Direct access is not allowed!');

// Database Functions
function dbConnect() {
    global $db, $dbUser, $dbPassword, $dbHost;
    $database = new mysqli($dbHost, $dbUser, $dbPassword);
    if (mysqli_connect_errno() != 0) {
	    echo mysqli_connect_errno().': '.mysqli_connect_error();
        return false;
	}
	if (!$database->select_db($db)) {
		createDatabase($db, $database);
	}
    $query = "SELECT * FROM lychee_photos, lychee_albums;";
    if (!$database->query($query)) createTables($database);
    return $database;
}
function dbClose() {
	global $database;
    if (!$database->close()) {
        echo "Closing the connection failed!";
        return false;
    }
    return true;
}
function createDatabase($db, $database) {
	$result = $database->query("CREATE DATABASE IF NOT EXISTS $db;");
	$database->select_db($db);
	if (!$result) return false;
	return true;
}
function createTables($database) {
    $query = "CREATE TABLE IF NOT EXISTS `lychee_albums` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(50) NOT NULL,
  `sysdate` varchar(10) NOT NULL,
  `public` TINYINT(1) DEFAULT '0',
  `password` VARCHAR(100),
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
    $result = $database->query($query);
    if (!$result) return false;

    $query = "CREATE TABLE `lychee_photos` (
  `id` bigint(14) NOT NULL,
  `title` varchar(50) NOT NULL,
  `description` varchar(160) NOT NULL,
  `url` varchar(100) NOT NULL,
  `public` tinyint(1) NOT NULL,
  `type` varchar(10) NOT NULL,
  `width` int(11) NOT NULL,
  `height` int(11) NOT NULL,
  `size` varchar(10) NOT NULL,
  `sysdate` varchar(10) NOT NULL,
  `systime` varchar(8) NOT NULL,
  `iso` varchar(15) NOT NULL,
  `aperture` varchar(10) NOT NULL,
  `make` varchar(20) NOT NULL,
  `model` varchar(50) NOT NULL,
  `shutter` varchar(10) NOT NULL,
  `focal` varchar(10) NOT NULL,
  `takedate` varchar(10) NOT NULL,
  `taketime` varchar(8) NOT NULL,
  `star` tinyint(1) NOT NULL,
  `thumbUrl` varchar(50) NOT NULL,
  `album` varchar(30) NOT NULL DEFAULT '0',
  `import_name` varchar(100) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
    $result = $database->query($query);
    if (!$result) return false;
    return true;
}

// Upload Functions
function upload($files, $albumID) {

	global $database;

	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) {

	    $id = str_replace('.', '', microtime(true));
	    while(strlen($id)<14) $id .= 0;
	    $tmp_name = $file["tmp_name"];
	    $type = getimagesize($tmp_name);
	    if (($type[2]!=1)&&($type[2]!=2)&&($type[2]!=3)) return false;
	    $data = $file["name"];
	    $data = explode('.',$data);
	    $data = array_reverse ($data);
	    $data = $data[0];

	    // Import if not uploaded via web
	    if (!is_uploaded_file($tmp_name)) {
	    	if (copy($tmp_name, "../uploads/big/" . md5($id) . ".$data")) {
				unlink($tmp_name);
				$import_name = $tmp_name;
			}
	    } else {
		    move_uploaded_file($tmp_name, "../uploads/big/" . md5($id) . ".$data");
{'fraction_non_alphanumeric': 0.17353149327671621, 'fraction_numerical': 0.024062278839348902, 'mean_word_length': 3.2235505080693367, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, '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': '1500517', 'n_tokens_mistral': 2765, 'n_tokens_neox': 2516, 'n_words': 655}