<commit_before><?php
/**
 * Copyright (c) 2013 <NAME> <EMAIL>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
namespace OC\Preview;

class TXT extends Provider {

	public function getMimeType() {
		return '/text\/.*/';
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		$content = $fileview->fopen($path, 'r');
		$content = stream_get_contents($content);

		//don't create previews of empty text files
		if(trim($content) === '') {
			return false;
		}

		$lines = preg_split("/\r\n|\n|\r/", $content);

		$fontSize = 5; //5px
		$lineSize = ceil($fontSize * 1.25);

		$image = imagecreate($maxX, $maxY);
		imagecolorallocate($image, 255, 255, 255);
		$textColor = imagecolorallocate($image, 0, 0, 0);

		foreach($lines as $index => $line) {
			$index = $index + 1;
<commit_msg>add blacklist to txt preview backend<commit_after><?php
/**
 * Copyright (c) 2013 <NAME> <EMAIL>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
namespace OC\Preview;

class TXT extends Provider {

	private static $blacklist = array(
		'text/calendar',
		'text/vcard',
	);

	public function getMimeType() {
		return '/text\/.*/';
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		$mimetype = $fileview->getMimeType($path);
		if(in_array($mimetype, self::$blacklist)) {
			return false;
		}

		$content = $fileview->fopen($path, 'r');
		$content = stream_get_contents($content);

		//don't create previews of empty text files
		if(trim($content) === '') {
			return false;
		}

		$lines = preg_split("/\r\n|\n|\r/", $content);

		$fontSize = 5; //5px
		$lineSize = ceil($fontSize * 1.25);

		$image = imagecreate($maxX, $maxY);
		imagecolorallocate($image, 255, 255, 255);
		$textColor = imagecolorallocate($image, 0, 0, 0);

		foreach($lines as $index => $line) {
			$index = $index + 1;

{'fraction_non_alphanumeric': 0.1707070707070707, 'fraction_numerical': 0.023232323232323233, 'mean_word_length': 3.8673218673218672, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '7087568', 'n_tokens_mistral': 796, 'n_tokens_neox': 685, 'n_words': 187}