<commit_before><?php

/*

Jappix - An open social platform
These are the PHP functions for Jappix

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

License: AGPL
Authors: <NAME>, <NAME>, Mathieui, <NAME>.
Contact: http://project.jappix.com/contact
Last revision: 20/11/10

*/

// The function to check if Jappix is already installed
function isInstalled() {
	if(!file_exists(PHP_BASE.'/store/conf/installed.xml'))
		return false;
	
	return true;
}

// The function to get the users.xml file hashed name
function usersConfName() {
	$conf_dir = PHP_BASE.'/store/conf';
	
	// No conf folder?
	if(!is_dir($conf_dir))
		return '';
	
	// Read the conf folder
	$conf_scan = scandir($conf_dir.'/');
	$conf_name = '';
	
	// Loop the XML files
	foreach($conf_scan as $current) {
		if(preg_match('/(.+)(\.users\.xml)($)/', $current)) {
			$conf_name = $current;
			
			break;
		}
   	}
   	
   	// Return the users file name
   	return $conf_name;
}

// The function to write a XML file
function writeXML($type, $xmlns, $xml) {
	// Generate the file path
	$conf_path = PHP_BASE.'/store/'.$type.'/';
	$conf_name = $xmlns.'.xml';
	
	// Secured stored file?
	if(($type == 'conf') && ($xmlns == 'users')) {
		// Get the secured file name
		$conf_secured = usersConfName();
		
		// Does this file exist?
		if($conf_secured)
			$conf_name = $conf_secured;
		else
			$conf_name = hash('sha256', rand(1, 99999999).time()).'.users.xml';
	}
	
	// Generate the file complete path
	$conf_file = $conf_path.$conf_name;
	
	// Write the installed marker
	$gen_xml = '<?xml version="1.0" encoding="utf-8" ?>
<jappix xmlns="jappix:'.$type.':'.$xmlns.'">
	'.$xml.'
</jappix>';
	
	file_put_contents($conf_file, $gen_xml);<commit_msg>Added trim() for writeXML() function input XML.<commit_after><?php

/*

Jappix - An open social platform
These are the PHP functions for Jappix

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

License: AGPL
Authors: <NAME>, <NAME>, Mathieui, <NAME>.
Contact: http://project.jappix.com/contact
Last revision: 22/11/10

*/

// The function to check if Jappix is already installed
function isInstalled() {
	if(!file_exists(PHP_BASE.'/store/conf/installed.xml'))
		return false;
	
	return true;
}

// The function to get the users.xml file hashed name
function usersConfName() {
	$conf_dir = PHP_BASE.'/store/conf';
	
	// No conf folder?
	if(!is_dir($conf_dir))
		return '';
	
	// Read the conf folder
	$conf_scan = scandir($conf_dir.'/');
	$conf_name = '';
	
	// Loop the XML files
	foreach($conf_scan as $current) {
		if(preg_match('/(.+)(\.users\.xml)($)/', $current)) {
			$conf_name = $current;
			
			break;
		}
   	}
   	
   	// Return the users file name
   	return $conf_name;
}

// The function to write a XML file
function writeXML($type, $xmlns, $xml) {
	// Generate the file path
	$conf_path = PHP_BASE.'/store/'.$type.'/';
	$conf_name = $xmlns.'.xml';
	
	// Secured stored file?
	if(($type == 'conf') && ($xmlns == 'users')) {
		// Get the secured file name
		$conf_secured = usersConfName();
		
		// Does this file exist?
		if($conf_secured)
			$conf_name = $conf_secured;
		else
			$conf_name = hash('sha256', rand(1, 99999999).time()).'.users.xml';
	}
	
	// Generate the file complete path
	$conf_file = $conf_path.$conf_name;
	
	// Write the installed marker
	$gen_xml = '<?xml version="1.0" encoding="utf-8" ?>
<jappix xmlns="jappix:'.$type.':'.$xmlns.'">
	'.trim($xml).'
</jappix>';
	
	file_put_contents($conf_file, $gen_xml);
{'fraction_non_alphanumeric': 0.18405797101449275, 'fraction_numerical': 0.01217391304347826, 'mean_word_length': 3.31375, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 2, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 30}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3990648', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1255, 'n_words': 307}