<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 DOC extends Provider {

	public function getMimeType() {
		return '/application\/msword/';
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		
	}

}

\OC\Preview::registerProvider('OC\Preview\DOC');

class DOCX extends Provider {

	public function getMimeType() {
		return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/';
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		require_once('phpdocx/classes/TransformDoc.inc');

		$tmpdoc = $fileview->toTmpFile($path);

		$transformdoc = new \TransformDoc();
		$transformdoc->setStrFile($tmpdoc);
		$transformdoc->generatePDF($tmpdoc);

		$pdf = new \imagick($tmpdoc . '[0]');
		$pdf->setImageFormat('jpg');

		unlink($tmpdoc);

		$image = new \OC_Image($pdf);
		
		return $image->valid() ? $image : false;
	}

}

\OC\Preview::registerProvider('OC\Preview\DOCX');

class MSOfficeExcel extends Provider {

	public function getMimeType() {
		return null;
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		require_once('PHPExcel/Classes/PHPExcel.php');
		require_once('PHPExcel/Classes/PHPExcel/IOFactory.php');
		//require_once('mpdf/mpdf.php');

		$abspath = $fileview->toTmpFile($path);
		$tmppath = \OC_Helper::tmpFile();

		$rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF;
		$rendererLibraryPath = \OC::$THIRDPARTYROOT . '/dompdf';

		\PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath);

		$phpexcel = new \PHPExcel($abspath);
		$excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF');
		$excel->save($tmppath);

		$pdf = new \imagick($tmppath . '[0]');
		$pdf->setImageFormat('jpg');

		unlink($abspath);
		unlink($tmppath);

		return $image->valid() ? $image : false;
	}

}

class XLS extends MSOfficeExcel {

	public function getMimeType() {
		return '/application\/vnd.ms-excel/';
	}

}

\OC\Preview::registerProvider('OC\Preview\XLS');

class XLSX extends MSOfficeExcel {

	public function getMimeType() {
		return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/';
	}

}

\OC\Preview::registerProvider('OC\Preview\XLSX');<commit_msg>finish implementation of Excel preview fallback<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 DOC extends Provider {

	public function getMimeType() {
		return '/application\/msword/';
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		
	}

}

\OC\Preview::registerProvider('OC\Preview\DOC');

class DOCX extends Provider {

	public function getMimeType() {
		return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/';
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		require_once('phpdocx/classes/TransformDoc.inc');

		$tmpdoc = $fileview->toTmpFile($path);

		$transformdoc = new \TransformDoc();
		$transformdoc->setStrFile($tmpdoc);
		$transformdoc->generatePDF($tmpdoc);

		$pdf = new \imagick($tmpdoc . '[0]');
		$pdf->setImageFormat('jpg');

		unlink($tmpdoc);

		$image = new \OC_Image($pdf);

		return $image->valid() ? $image : false;
	}

}

\OC\Preview::registerProvider('OC\Preview\DOCX');

class MSOfficeExcel extends Provider {

	public function getMimeType() {
		return null;
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		require_once('PHPExcel/Classes/PHPExcel.php');
		require_once('PHPExcel/Classes/PHPExcel/IOFactory.php');
		//require_once('mpdf/mpdf.php');

		$abspath = $fileview->toTmpFile($path);
		$tmppath = \OC_Helper::tmpFile();

		$rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF;
		$rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf';

		\PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath);

		$phpexcel = new \PHPExcel($abspath);
		$excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF');
		$excel->save($tmppath);

		$pdf = new \imagick($tmppath . '[0]');
		$pdf->setImageFormat('jpg');

		unlink($abspath);
		unlink($tmppath);

		$image = new \OC_Image($pdf);

		return $image->valid() ? $image : false;
	}

}

class XLS extends MSOfficeExcel {

	public function getMimeType() {
		return '/application\/vnd.ms-excel/';
	}

}

\OC\Preview::registerProvider('OC\Preview\XLS');

class XLSX extends MSOfficeExcel {

	public function getMimeType() {
		return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/';
	}

}

\OC\Preview::registerProvider('OC\Preview\XLSX');
{'fraction_non_alphanumeric': 0.16135705419942076, 'fraction_numerical': 0.003103020273065784, 'mean_word_length': 4.86060606060606, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3185911', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1675, 'n_words': 305}