42
42
* images and then we return a hash that is and the filename of the image
43
43
* Real path of the image ishome://~{username}/.office/{hash}/{fileName}
46
* path => string Path of input image
49
* hash => string, See schema above
47
* path => string Absolute path of input image
52
* images => Array () paths of the images
53
* previews => Array() paths with the preview of the images
54
* hash => string See schema above
53
57
public static function convertDocumentToImagesHash ($params) {
54
58
if ($params === null || !is_array($params)) {
62
66
$filepath = $params['path'];
63
67
$maxWidth = isset($params['maxWidth']) ? $params['maxWidth'] : null;
69
$pathinfo = pathinfo($filepath);
70
$extension = strtoupper($pathinfo['extension']);
72
if($extension == 'EDOC') {
73
return self::openEdocument($filepath);
75
return self::openOOdocument($filepath);
81
* Open eyeOS document (.edoc)
84
* images => Array () paths of the images
85
* previews => Array() paths with the preview of the images
86
* hash => string See schema above
89
public static function openEdocument($filepath) {
90
throw new EyeInvalidArgumentException('TODO: Not implemented yet...');
93
/* TODO : copied from documents.php, it's necessary to make changes for make it work */
94
$pathinfo = pathinfo($filePath);
95
$extension = strtoupper($pathinfo['extension']);
96
if ($filepath === null || $extension != 'EDOC') {
97
throw new EyeInvalidArgumentException('Missing or invalid $filepath');
100
$file = FSI::getFile($path);
101
$memory = MemoryManager::getInstance();
103
$file->checkReadPermission();
104
//we have to extract etc etc
105
$filepath = 'home:///';
106
$myFile = FSI::getFile($filepath);
107
$myRealFile = $myFile->getRealFile();
108
$fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
109
$fileNameDestination .= '/.office/documents/' . ProcManager::getInstance()->getCurrentProcess()->getPid();
111
if(!file_exists(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/')) {
112
mkdir(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/');
114
$cmd = 'rm -fr ' . AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/documents/';
118
mkdir(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/documents/');
120
if(file_exists($fileNameDestination)) {
121
AdvancedPathLib::rmdirs($fileNameDestination);
124
mkdir($fileNameDestination);
125
$myRealFile = $file->getRealFile();
126
$originalFile = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
127
$cmd = 'unzip -d ' . escapeshellarg($fileNameDestination) . ' ' . escapeshellarg($originalFile);
129
$documentUniqueId = file_get_contents($fileNameDestination . '/duid');
130
$content = file_get_contents($fileNameDestination . '/document.html');
131
$return[] = $content;
132
$return[] = $file->getName();
133
$return[] = $documentUniqueId;
136
/*TODO: return like the next pattern:*/
138
'hash' => basename($PDFDir),
139
'images' => array_values($imageList),
140
'previews' => array_values($smallImageList),
144
public static function openOOdocument($filepath) {
145
$myConverter = new Converter();
65
146
$pdfFilter = self::getPDFFilterString($filepath);
67
if ($pdfFilter == 'NONE') {
68
$myConverter = new Converter();
147
if ($pdfFilter == 'PDF') {
148
//None Convert anything
69
149
$PDFPath = $myConverter->Convert($filepath);
72
$myConverter = new Converter();
73
152
$PDFPath = $myConverter->Convert($filepath, $pdfFilter);