<commit_before><?php
	/**
	 * SD-Formatter (maybe renamed ... who knows)
	 *
	 * (c) Copyright 2014 Tyler Junior College
	 * See LICENSE file for License details
	 *
	 * Purpose: A simple mini web application to make sure HTML is formatted for the SoftDocs system.
	 * 			Uses Slim Framework and Idiorm.
	 * Requirements: PHP 5.3+ and SQLite for simple user/database stores.
	 **/

	function upload_error($error_code) {
		switch($error_code) {
			case UPLOAD_ERR_INI_SIZE:
				return 'The Uploaded File is bigger than ' . ini_get('upload_max_filesize');
				break;

			case UPLOAD_ERR_FORM_SIZE:
				return 'The Uploaded File is bigger than the form specified.';
				break;

			case UPLOAD_ERR_PARTIAL:
				return 'The file was partially uploaded. Please Try Again.';
				break;

			case UPLOAD_ERR_NO_FILE:
				return 'No File was Uploaded.';
				break;

			case UPLOAD_ERR_NO_TMP_DIR:
				return 'Configuration Error. No Temporary Folder was found.';
				break;

			case UPLOAD_ERR_CANT_WRITE:
				return "Can't write file to disk.";
				break;

			case UPLOAD_ERR_EXTENSION:
				return 'A PHP Extension blocked the upload.';
				break;
		}
	}

	function content_type($content_type) {
		return ORM::for_table('source_type')->select('id')->where('type', $content_type)->find_one();
	}

	function source_array($filename, $content, $user_id = 1, $type = 'text/html') {
		$source_type_id = content_type($type);
		return array(
			'uniqid'   	  => uniqid(),
			'md5'	   	  => md5($content),
			'user_id'  	  => $user_id,
			'filename' 	  => $filename,
			'content'  	  => $content,
			'source_type' => $source_type_id->id
		);
	}

	function source_exists($md5_str) {
		return (ORM::for_table('source')->where('md5', $md5_str)->count() > 0);
	}<commit_msg>Updated functions. Added an alert processor.<commit_after><?php
	/**
	 * SD-Formatter (maybe renamed ... who knows)
	 *
	 * (c) Copyright 2014 Tyler Junior College
	 * See LICENSE file for License details
	 *
	 * Purpose: A simple mini web application to make sure HTML is formatted for the SoftDocs system.
	 * 			Uses Slim Framework and Idiorm.
	 * Requirements: PHP 5.3+ and SQLite for simple user/database stores.
	 **/

	function upload_error($error_code) {
		switch($error_code) {
			case UPLOAD_ERR_INI_SIZE:
				return 'The Uploaded File is bigger than ' . ini_get('upload_max_filesize');
				break;

			case UPLOAD_ERR_FORM_SIZE:
				return 'The Uploaded File is bigger than the form specified.';
				break;

			case UPLOAD_ERR_PARTIAL:
				return 'The file was partially uploaded. Please Try Again.';
				break;

			case UPLOAD_ERR_NO_FILE:
				return 'No File was Uploaded.';
				break;

			case UPLOAD_ERR_NO_TMP_DIR:
				return 'Configuration Error. No Temporary Folder was found.';
				break;

			case UPLOAD_ERR_CANT_WRITE:
				return "Can't write file to disk.";
				break;

			case UPLOAD_ERR_EXTENSION:
				return 'A PHP Extension blocked the upload.';
				break;
		}
	}

	function content_type($content_type) {
		return ORM::for_table('source_type')->select('id')->where('type', $content_type)->find_one();
	}

	function source_array($filename, $content, $user_id = 1, $type = 'text/html') {
		$source_type_id = content_type($type);
		return array(
			'uniqid'   	  => uniqid(),
			'md5'	   	  => md5($content),
			'user_id'  	  => $user_id,
			'filename' 	  => $filename,
			'content'  	  => $content,
			'source_type' => $source_type_id->id
		);
	}

	function source_exists($md5_str, $filename = null) {
		$where = array(array('md5' => $md5_str));
		if(!is_null($filename)) {
			$where[] = array('filename' => $filename);
		}

		return (ORM::for_table('source')->where_any_is($where)->count() > 0);
	}

	function alert_view($flash) {
		$alert_html = '<div class="alert alert-%s alert-dismissible" role="alert">'
				    . '<button type="button" class="close" data-dismiss="alert">'
				    . '<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>'
				    . '</button>'
				    . '<strong>%s</strong> %s'
				    . '</div>';
		foreach($flash as $type => $alert) {
			switch($type) {
				case 'url-error':
				case 'file-error':
					printf($alert_html, 'danger', ($type == 'url-error' ? 'URL' : 'File Upload') . ' Error:', $alert);
					break;

				case 'delete-action':
					printf($alert_html, 'warning', 'File Deleted', $alert);
					break;
			}
		}
	}
{'fraction_non_alphanumeric': 0.14144434222631094, 'fraction_numerical': 0.005979760809567618, 'mean_word_length': 3.415228426395939, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 42, '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': '1418812', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1482, 'n_words': 377}