<commit_before><?php defined('ROOT') or die('No direct script access.');
/**
 * X3 CMS - A smart Content Management System
 *
 * @author		<NAME>
 * @copyright	(c) CBlu.net di <NAME>
 * @license		http://www.gnu.org/licenses/agpl.htm
 * @package		X4WEBAPP
 */

/**
 * Helper for files handling
 * 
 * @package X4WEBAPP
 */
class X4Files_helper 
{
	/**
	 * Arrays of handled mimetypes
	 */
	private static $mimg = array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png');
	private static $mmedia = array('video/quicktime', 'application/vnd.rn-realmedia', 'audio/x-pn-realaudio', 'application/vnd.adobe.flash.movie', 'application/x-shockwave-flash', 'video/x-ms-wmv', 'video/avi', 'video/msvideo', 'video/x-msvideo','video/mpeg', 'video/mp4', 'video/3gpp', 'video/x-flv', 'video/ogg', 'application/ogg');
	private static $mtemplate = array('text/html');
// TODO: this must be defined in the administration
	private static $mfiles = array('text/plain', 'application/vnd.ms-excel', 'application/pdf', 'application/zip', 'application/x-zip', 'application/x-zip-compressed', 'binary/octet-stream', 'audio/mpeg', 'audio/wav', 'audio/x-wav', 'application/x-compress', 'application/x-compressed', 'multipart/x-zip');
	private static $file = array();
	
	private static function phpv()
	{
		$v = explode('.', phpversion());
		return floatval($v[0].'.'.$v[1]);
	}
	
	// path to the folder managed by filemanager
	private static $file_path = 'files/filemanager/'; 
	
	/**
	 * Get a code related to the file type
	 *
	 * @param	string	file with path
	 * @param	boolean	switch between folder name and X3 CMS file type
	 * @return	mixed	code type or folder name
	 */
	public static function get_type($file, $folder = false) 
	{
		// this require PHP 5.3+
		if (self::phpv() >= 5.3)
		{
			$finfo = @new finfo(FILEINFO_MIME);
			$info = @$finfo->file($file);
			
			$mime = explode(';', $info);
			$type = explode('/', $mime[0]);
			
			switch ($type[0])
			{
				case 'img':
				case 'image':
					return ($folder)
						? 'img'
						: 0;
					break;
				case 'video':
					return ($folder)
						? 'media'
						: 2;
					break;
				case 'text':
					switch($type[1])
					{
					case 'htm':
					case 'html':
						return ($folder)
							? 'template'
							: 3;
						break;
					default:
						return ($folder)
							? 'files'
							: 1;
						break;
					}
					break;
				case 'xls':
				default:
					return ($folder)
						? 'files'
						: 1;
					break;
			}
		}
		else
		{
			// get by name
			self::get_type_by_name($file, $folder);
		}
	}
	
	/**
	 * Get a code related to the file type by file name
	 *
	 * @param	string	file with path
	 * @param	boolean	switch between folder name and X3 CMS file type
	 * @return	mixed	code type or folder name
	 */
	public static function get_type_by_name($file, $folder = false) 
	{
		// get extension from file name
		$ext = pathinfo($file, PATHINFO_EXTENSION);
		switch($ext) 
		{
			case 'jpg':
			case 'jpeg':
			case 'gif':
			case 'png':
				return ($folder)
					? 'img'
					: 0;
				break;
			case 'swf':
			case 'flv':
			case 'rm':
			case 'wmv':
			case 'mov':
			case 'mp4':
			case 'ogv':
			case 'webm':
			case 'avi':
			case 'mpeg':
			case '3gp':
				return ($folder)
					? 'media'
					: 2;
				break;
			case 'htm':
			case 'html':
				return ($folder)
					? 'template'
					: 3;
				break;
			case 'xls':
			default:<commit_msg>added new MIME types in the file helper<commit_after><?php defined('ROOT') or die('No direct script access.');
/**
 * X3 CMS - A smart Content Management System
 *
 * @author		<NAME>
 * @copyright	(c) CBlu.net di <NAME>
 * @license		http://www.gnu.org/licenses/agpl.htm
 * @package		X4WEBAPP
 */

/**
 * Helper for files handling
 * 
 * @package X4WEBAPP
 */
class X4Files_helper 
{
	/**
	 * Arrays of handled mimetypes
	 */
	private static $mimg = array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png');
	private static $mmedia = array('video/quicktime', 'application/vnd.rn-realmedia', 'audio/x-pn-realaudio', 'application/vnd.adobe.flash.movie', 'application/x-shockwave-flash', 'video/x-ms-wmv', 'video/avi', 'video/msvideo', 'video/x-msvideo','video/mpeg', 'video/mp4', 'video/3gpp', 'video/x-flv', 'video/ogg', 'application/ogg');
	private static $mtemplate = array('text/html');
// TODO: this must be defined in the administration
	private static $mfiles = array('text/plain', 'application/pdf', 
	    'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 
	    'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
	    'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
	    'application/zip', 'application/x-zip', 'application/x-zip-compressed', 
	    'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.presentation', 'application/vnd.oasis.opendocument.spreadsheet',
	    'binary/octet-stream', 'audio/mpeg', 'audio/wav', 'audio/x-wav', 'application/x-compress', 'application/x-compressed', 'multipart/x-zip');
	private static $file = array();
	
	private static function phpv()
	{
		$v = explode('.', phpversion());
		return floatval($v[0].'.'.$v[1]);
	}
	
	// path to the folder managed by filemanager
	private static $file_path = 'files/filemanager/'; 
	
	/**
	 * Get a code related to the file type
	 *
	 * @param	string	file with path
	 * @param	boolean	switch between folder name and X3 CMS file type
	 * @return	mixed	code type or folder name
	 */
	public static function get_type($file, $folder = false) 
	{
		// this require PHP 5.3+
		if (self::phpv() >= 5.3)
		{
			$finfo = @new finfo(FILEINFO_MIME);
			$info = @$finfo->file($file);
			
			$mime = explode(';', $info);
			$type = explode('/', $mime[0]);
			
			switch ($type[0])
			{
				case 'img':
				case 'image':
					return ($folder)
						? 'img'
						: 0;
					break;
				case 'video':
					return ($folder)
						? 'media'
						: 2;
					break;
				case 'text':
					switch($type[1])
					{
					case 'htm':
					case 'html':
						return ($folder)
							? 'template'
							: 3;
						break;
					default:
						return ($folder)
							? 'files'
							: 1;
						break;
					}
					break;
				case 'xls':
				case 'xlsx':
				case 'doc':
				case 'docx':
				case 'ppt':
				case 'pptx':
				case 'odt':
				case 'odp':
				case 'ods':
				default:
					return ($folder)
						? 'files'
						: 1;
					break;
			}
		}
		else
		{
			// get by name
			self::get_type_by_name($file, $folder);
		}
	}
	
	/**
	 * Get a code related to the file type by file name
	 *
	 * @param	string	file with path
	 * @param	boolean	switch between folder name and X3 CMS file type
	 * @return	mixed	code type or folder name
	 */
	public static function get_type_by_name($file, $folder = false) 
	{
		// get extension from file name
		$ext = pathinfo($file, PATHINFO_EXTENSION);
		switch($ext) 
		{
			case 'jpg':
			case 'jpeg':
			case 'gif':
			case 'png':
				return ($folder)
					? 'img'
					: 0;
				break;
			case 'swf':
			case 'flv':
			case 'rm':
			case 'wmv':
			case 'mov':
			case 'mp4':
			case 'ogv':
			case 'webm':
			case 'avi':
			case 'mpeg':
			case '3gp':
				return ($folder)
					? 'media'
					: 2;
				break;
			case 'htm':
			case 'html':
				return ($folder)
					? 'template'
					: 3;
				break;
			case 'xls':
            case 'xlsx':
            case 'doc':
            case 'docx':
            case 'ppt':
            case 'pptx':
            case 'odt':
            case 'odp':
            case 'ods':
			default:
{'fraction_non_alphanumeric': 0.16266246553761324, 'fraction_numerical': 0.0070894052776683735, 'mean_word_length': 2.6484674329501914, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 3}, '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': '2627550', 'n_tokens_mistral': 3320, 'n_tokens_neox': 2638, 'n_words': 688}