summaryrefslogtreecommitdiffstats
path: root/lib/preview/msoffice.php
blob: c99ca313c7296a75e1ef660aec832464bdda92e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
 * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
namespace OC\Preview;

class MSOffice2003 extends Provider {

	public function getMimeType(){
		return null;
	}

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


class MSOffice2007 extends Provider {

	public function getMimeType(){
		return null;
	}

	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);

		//new image object
		$image = new \OC_Image($pdf);
		//check if image object is valid
		if (!$image->valid()) return false;

		return $image;
	}
}

class DOC extends MSOffice2003 {

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

}

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

class DOCX extends MSOffice2007 {

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

}

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

class XLS extends MSOffice2003 {

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

}

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

class XLSX extends MSOffice2007 {

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

}

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

class PPT extends MSOffice2003 {

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

}

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

class PPTX extends MSOffice2007 {

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

}

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