<commit_before><?php

/*

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

-------------------------------------------------

License: AGPL
Authors: <NAME>, olivierm, regilero
Last revision: 12/06/12

*/

// The function to get the cached content
function readCache($hash) {
	return file_get_contents(JAPPIX_BASE.'/store/cache/'.$hash.'.cache');
}

// The function to generate a cached file
function genCache($string, $mode, $cache) {
	if(!$mode) {
		$cache_dir = JAPPIX_BASE.'/store/cache';
		$file_put = $cache_dir.'/'.$cache.'.cache';
		
		// Cache not yet wrote
		if(is_dir($cache_dir) && !file_exists($file_put))
			file_put_contents($file_put, $string, LOCK_EX);
	}
}

// The function to remove the BOM from a string
function rmBOM($string) { 
	if(substr($string, 0, 3) == pack('CCC', 0xef, 0xbb, 0xbf))
		$string = substr($string, 3);
	
	return $string; 
}

// The function to compress the CSS
function compressCSS($buffer) {
	// We remove the comments
	$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
	
	// We remove the useless spaces
	$buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '	 ', '	 '), '', $buffer);
	
	// We remove the last useless spaces
	$buffer = str_replace(array(' { ',' {','{ '), '{', $buffer);
	$buffer = str_replace(array(' } ',' }','} '), '}', $buffer);
	$buffer = str_replace(array(' : ',' :',': '), ':', $buffer);
 	
	return $buffer;
}

// The function to replace classical path to get.php paths
function setPath($string, $hash, $host, $type, $locale) {
	// Initialize the static server path
	$static = '.';
	
	// Replace the JS strings
	if($type == 'js') {
		// Static host defined
		if($host && ($host != '.'))
			$static = $host;
		
		// Links to JS (must have a lang parameter)
		$string = preg_replace('/((\")|(\'))(\.\/)(js)(\/)(\S+)(js)((\")|(\'))/', '$1'.$static.'/php/get.php?h='.$hash.'&l='.$locale.'&t=$5&f=$7$8$9', $string);
		
		// Other "normal" links (no lang parameter)
		$string = preg_replace('/((\")|(\'))(\.\/)(css|img|store|snd)(\/)(\S+)(css|png|jpg|jpeg|gif|bmp|ogg|oga)((\")|(\'))/', '$1'.$static.'/php/get.php?h='.$hash.'&t=$5&f=$7$8$9', $string);

		// Links to JS that are prefixed with JAPPIX_STATIC (must have a lang parameter)
		$string = preg_replace('/(\WJAPPIX_STATIC\s*\+\s*)((\")|(\'))(js)(\/)(\S+)(js)((\")|(\'))/', '$1$2'.'php/get.php?h='.$hash.'&l='.$locale.'&t=$5&f=$7$8$9', $string);

		// Other "normal" links prefixed with JAPPIX_STATIC (no lang parameter) (used by mini)
		$string = preg_replace('/(\WJAPPIX_STATIC\s*\+\s*)((\")|(\'))(css|img|store|snd)(\/)(\S+)(css|png|jpg|jpeg|gif|bmp|ogg|oga)((\")|(\'))/', '$1$2'.'php/get.php?h='.$hash.'&t=$5&f=$7$8$9', $string);
	}
	
	// Replace the CSS strings
	else if($type == 'css') {
		// Static host defined
		if($host && ($host != '.'))
			$static = $host.'/php';
		
		$string = preg_replace('/(\(\.\.\/)(css|js|img|store|snd)(\/)(\S+)(css|js|png|jpg|jpeg|gif|bmp|ogg|oga)(\))/', '('.$static.'/get.php?h='.$hash.'&t=$2&f=$4$5)', $string);
	}
	
	return $string;
}

// The function to set the good translation to a JS file
function setTranslation($string) {
	return preg_replace('/_e\("([^\"\"]+)"\)/e', "'_e(\"'.addslashes(T_gettext(stripslashes('$1'))).'\")'", $string);
}

// The function to set the good locales
function setLocales($string, $locale) {
	// Generate the two JS array list
	$available_list = availableLocales($locale);
	$available_id = '';
	$available_names = '';
	
	// Add the values to the arrays
	foreach($available_list as $current_id => $current_name) {
		$available_id .= '\''.$current_id.'\', ';
		$available_names .= '\''.addslashes($current_name).'\', ';<commit_msg>Get API fix with MP3 files<commit_after><?php

/*

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

-------------------------------------------------

License: AGPL
Authors: Vanaryon, Mathieui, olivierm, regilero
Last revision: 25/08/12

*/

// The function to get the cached content
function readCache($hash) {
	return file_get_contents(JAPPIX_BASE.'/store/cache/'.$hash.'.cache');
}

// The function to generate a cached file
function genCache($string, $mode, $cache) {
	if(!$mode) {
		$cache_dir = JAPPIX_BASE.'/store/cache';
		$file_put = $cache_dir.'/'.$cache.'.cache';
		
		// Cache not yet wrote
		if(is_dir($cache_dir) && !file_exists($file_put))
			file_put_contents($file_put, $string, LOCK_EX);
	}
}

// The function to remove the BOM from a string
function rmBOM($string) { 
	if(substr($string, 0, 3) == pack('CCC', 0xef, 0xbb, 0xbf))
		$string = substr($string, 3);
	
	return $string; 
}

// The function to compress the CSS
function compressCSS($buffer) {
	// We remove the comments
	$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
	
	// We remove the useless spaces
	$buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '	 ', '	 '), '', $buffer);
	
	// We remove the last useless spaces
	$buffer = str_replace(array(' { ',' {','{ '), '{', $buffer);
	$buffer = str_replace(array(' } ',' }','} '), '}', $buffer);
	$buffer = str_replace(array(' : ',' :',': '), ':', $buffer);
 	
	return $buffer;
}

// The function to replace classical path to get.php paths
function setPath($string, $hash, $host, $type, $locale) {
	// Initialize the static server path
	$static = '.';
	
	// Replace the JS strings
	if($type == 'js') {
		// Static host defined
		if($host && ($host != '.'))
			$static = $host;
		
		// Links to JS (must have a lang parameter)
		$string = preg_replace('/((\")|(\'))(\.\/)(js)(\/)(\S+)(js)((\")|(\'))/', '$1'.$static.'/php/get.php?h='.$hash.'&l='.$locale.'&t=$5&f=$7$8$9', $string);
		
		// Other "normal" links (no lang parameter)
		$string = preg_replace('/((\")|(\'))(\.\/)(css|img|store|snd)(\/)(\S+)(css|png|jpg|jpeg|gif|bmp|ogg|oga|mp3)((\")|(\'))/', '$1'.$static.'/php/get.php?h='.$hash.'&t=$5&f=$7$8$9', $string);

		// Links to JS that are prefixed with JAPPIX_STATIC (must have a lang parameter)
		$string = preg_replace('/(\WJAPPIX_STATIC\s*\+\s*)((\")|(\'))(js)(\/)(\S+)(js)((\")|(\'))/', '$1$2'.'php/get.php?h='.$hash.'&l='.$locale.'&t=$5&f=$7$8$9', $string);

		// Other "normal" links prefixed with JAPPIX_STATIC (no lang parameter) (used by mini)
		$string = preg_replace('/(\WJAPPIX_STATIC\s*\+\s*)((\")|(\'))(css|img|store|snd)(\/)(\S+)(css|png|jpg|jpeg|gif|bmp|ogg|oga|mp3)((\")|(\'))/', '$1$2'.'php/get.php?h='.$hash.'&t=$5&f=$7$8$9', $string);
	}
	
	// Replace the CSS strings
	else if($type == 'css') {
		// Static host defined
		if($host && ($host != '.'))
			$static = $host.'/php';
		
		$string = preg_replace('/(\(\.\.\/)(css|js|img|store|snd)(\/)(\S+)(css|js|png|jpg|jpeg|gif|bmp|ogg|oga|mp3)(\))/', '('.$static.'/get.php?h='.$hash.'&t=$2&f=$4$5)', $string);
	}
	
	return $string;
}

// The function to set the good translation to a JS file
function setTranslation($string) {
	return preg_replace('/_e\("([^\"\"]+)"\)/e', "'_e(\"'.addslashes(T_gettext(stripslashes('$1'))).'\")'", $string);
}

// The function to set the good locales
function setLocales($string, $locale) {
	// Generate the two JS array list
	$available_list = availableLocales($locale);
	$available_id = '';
	$available_names = '';
	
	// Add the values to the arrays
	foreach($available_list as $current_id => $current_name) {
		$available_id .= '\''.$current_id.'\', ';
		$available_names .= '\''.addslashes($current_name).'\', ';
{'fraction_non_alphanumeric': 0.2726903827945354, 'fraction_numerical': 0.010821046936291085, 'mean_word_length': 3.7981829980532122, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2933071', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2769, 'n_words': 578}