<commit_before><?php

/*   ---------------------------------------------

Author : <NAME>

License: MIT (see http://opensource.org/licenses/MIT and LICENSE.txt which should be in the root folder with this file)
			
Date of creation : 2013-12-22
Last modified : 2013-12-29

Plugin providing functions which could be used in multiple LCA tools and/or multiple instances of the same tool.
Stored here mostly to keep main files cleaner.
			
---------------------------------------------   */

$config = parse_ini_file('lcaToolsConfig.ini');

function setupdataurl($inputfile) {
	/* in case a real file is passed instead of _FILES (should not happen in current setup) 
	or in case something went wrong and file is not stored in system anymore. */
	if (!array_key_exists('tmp_name', $inputfile)) {
		if (array_key_exists('name', $inputfile)) {
			$inputfile['tmp_name'] = $inputfile['name'];
		} else {
			return 'No file appears to be present, please try again';
		}
	}

	$tempfile = array();
	$tempfile['file_name'] = $inputfile['name'];
	$datatemp = file_get_contents($inputfile['tmp_name']);
	$datatemp = base64_encode($datatemp);
	$uri = 'data: '. $inputfile['type'].';base64,'.$datatemp;
	$tempfile['file'] = $uri;
	
	return $tempfile;
}

function curlAPIpost ($url,$data,$headers='',$debug=0) {
	if ($debug=1) {
		$f = fopen('request.txt', 'w');
	}
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_VERBOSE, true);
	if ($debug=1) {
	curl_setopt($ch, CURLOPT_STDERR, $f);
}

$result = curl_exec($ch);
if ($debug=1) {
fclose($f);
}
curl_close($ch);
return $result;
}

function lcalog($user,$type,$title) {
	$mysql = new mysqli($config['database_address'],$config['database_user'],$config['database_password'],$config['database']);

	$template = 'INSERT INTO centrallog (user,timestamp,type,title) VALUES (?,?,?,?)';

	$submittime = gmdate("Y-m-d H:i:s", time());

	$log = $mysql->prepare($template);
	if ($log === false) {
		echo 'Error while preparing: ' . $template . ' Error text: ' . $mysql->error, E_USER_ERROR;
	}

	$log->bind_param('ssss',$user,$submittime,$type,$title);

	$log->execute();

	return $log->insert_id;
	$mysql->close();
}<commit_msg>adjust logging function to use variables correction<commit_after><?php

/*   ---------------------------------------------

Author : <NAME>

License: MIT (see http://opensource.org/licenses/MIT and LICENSE.txt which should be in the root folder with this file)
			
Date of creation : 2013-12-22
Last modified : 2013-12-29

Plugin providing functions which could be used in multiple LCA tools and/or multiple instances of the same tool.
Stored here mostly to keep main files cleaner.
			
---------------------------------------------   */

$config = parse_ini_file('lcaToolsConfig.ini');
$dbaddress = $config['database_address'];
$dbuser = $config['database_user'];
$dbpw = $config['database_password'];
$db = $config['database'];

function setupdataurl($inputfile) {
	/* in case a real file is passed instead of _FILES (should not happen in current setup) 
	or in case something went wrong and file is not stored in system anymore. */
	if (!array_key_exists('tmp_name', $inputfile)) {
		if (array_key_exists('name', $inputfile)) {
			$inputfile['tmp_name'] = $inputfile['name'];
		} else {
			return 'No file appears to be present, please try again';
		}
	}

	$tempfile = array();
	$tempfile['file_name'] = $inputfile['name'];
	$datatemp = file_get_contents($inputfile['tmp_name']);
	$datatemp = base64_encode($datatemp);
	$uri = 'data: '. $inputfile['type'].';base64,'.$datatemp;
	$tempfile['file'] = $uri;
	
	return $tempfile;
}

function curlAPIpost ($url,$data,$headers='',$debug=0) {
	if ($debug=1) {
		$f = fopen('request.txt', 'w');
	}
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_VERBOSE, true);
	if ($debug=1) {
	curl_setopt($ch, CURLOPT_STDERR, $f);
}

$result = curl_exec($ch);
if ($debug=1) {
fclose($f);
}
curl_close($ch);
return $result;
}


function lcalog($user,$type,$title) {

	global $dbaddress, $dbuser, $dbpw, $db;

	$mysql = new mysqli($dbaddress,$dbuser,$dbpw,$db);

	$template = 'INSERT INTO centrallog (user,timestamp,type,title) VALUES (?,?,?,?)';

	$submittime = gmdate("Y-m-d H:i:s", time());

	$log = $mysql->prepare($template);
	if ($log === false) {
		echo 'Error while preparing: ' . $template . ' Error text: ' . $mysql->error, E_USER_ERROR;
	}

	$log->bind_param('ssss',$user,$submittime,$type,$title);

	$log->execute();

	return $log->insert_id;
	$mysql->close();
}
{'fraction_non_alphanumeric': 0.20324543610547668, 'fraction_numerical': 0.00973630831643002, 'mean_word_length': 4.313577586206897, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '315037', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1672, 'n_words': 409}