~vcs-imports/eyeos/1.6

« back to all changes in this revision

Viewing changes to eyeos/apps/files/mobile/files.php

  • Committer: eyeos
  • Date: 2011-03-31 11:07:17 UTC
  • Revision ID: svn-v4:8c553ec3-4020-0410-92ea-9a3d4a83ea35:eyeOS/trunk:7176
Changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
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}
44
44
         * 
45
 
         Array $params = (
46
 
         *              path => string                          Path of input image
47
 
         * )
48
 
         * @return Array (
49
 
         *              hash => string,         See schema above
50
 
         *              images => Array ()                      
51
 
         * )
 
45
         * @param
 
46
         *  Array (
 
47
         *              path => string                          Absolute path of input image
 
48
         *  )
 
49
         * 
 
50
         * @return
 
51
         *      Array (
 
52
         *              images => Array ()                      paths of the images
 
53
         *              previews => Array()                     paths with the preview of the images
 
54
         *              hash => string                          See schema above
 
55
         *      )
52
56
         */
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;
64
68
 
 
69
                $pathinfo = pathinfo($filepath);
 
70
                $extension = strtoupper($pathinfo['extension']);
 
71
                
 
72
                if($extension == 'EDOC') {
 
73
                        return self::openEdocument($filepath);
 
74
                } else {
 
75
                        return self::openOOdocument($filepath);
 
76
                }
 
77
 
 
78
        }
 
79
 
 
80
        /**
 
81
         * Open eyeOS document (.edoc)
 
82
         * @return
 
83
         *      Array (
 
84
         *              images => Array ()                      paths of the images
 
85
         *              previews => Array()                     paths with the preview of the images
 
86
         *              hash => string                          See schema above
 
87
         *      )
 
88
         */
 
89
        public static function openEdocument($filepath) {
 
90
                throw new EyeInvalidArgumentException('TODO: Not implemented yet...');
 
91
                return;exit;
 
92
                
 
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');
 
98
                }
 
99
 
 
100
                $file = FSI::getFile($path);
 
101
                $memory = MemoryManager::getInstance();
 
102
 
 
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();
 
110
 
 
111
                if(!file_exists(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/')) {
 
112
                        mkdir(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/');
 
113
                } else {
 
114
                        $cmd = 'rm -fr ' . AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/documents/';
 
115
                        shell_exec($cmd);
 
116
                }
 
117
 
 
118
                mkdir(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/documents/');
 
119
 
 
120
                if(file_exists($fileNameDestination)) {
 
121
                        AdvancedPathLib::rmdirs($fileNameDestination);
 
122
                }
 
123
 
 
124
                mkdir($fileNameDestination);
 
125
                $myRealFile = $file->getRealFile();
 
126
                $originalFile = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
 
127
                $cmd = 'unzip  -d ' . escapeshellarg($fileNameDestination) . ' ' . escapeshellarg($originalFile);
 
128
                shell_exec($cmd);
 
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;
 
134
                /*END OF COPY*/
 
135
 
 
136
                /*TODO: return like the next pattern:*/
 
137
                return Array(
 
138
                'hash' => basename($PDFDir),
 
139
                'images' => array_values($imageList),
 
140
                'previews' => array_values($smallImageList),
 
141
                );
 
142
        }
 
143
 
 
144
        public static function openOOdocument($filepath) {
 
145
                $myConverter = new Converter();
65
146
                $pdfFilter = self::getPDFFilterString($filepath);
66
 
 
67
 
                if ($pdfFilter == 'NONE') {
68
 
                        $myConverter = new Converter();
 
147
                if ($pdfFilter == 'PDF') {
 
148
                        //None Convert anything
69
149
                        $PDFPath = $myConverter->Convert($filepath);
70
150
                } else {
71
151
                        //Convert to PDF
72
 
                        $myConverter = new Converter();
73
152
                        $PDFPath = $myConverter->Convert($filepath, $pdfFilter);
74
153
                }
75
154
 
85
164
                shell_exec('LANG=en_US.utf-8;' . $cmd);
86
165
 
87
166
                $cmd = 'convert -verbose -quality 30 -density 150 '. $PDFPath . ' ' . $PDFDir . '/' . $smallImageRadixName . '.jpg';
88
 
        shell_exec('LANG=en_US.utf-8;'.$cmd);
 
167
                shell_exec('LANG=en_US.utf-8;'.$cmd);
89
168
 
90
169
                $iterator = new DirectoryIterator($PDFDir);
91
170
                $imagesList = Array();
107
186
                );
108
187
        }
109
188
 
 
189
        
110
190
        /**
111
191
         * Return the correct openoffice filter string depending of file
112
 
         * 
 
192
         *
113
193
         * @param <String> $filePath
114
194
         * @return String
115
195
         */
116
196
        private static function getPDFFilterString ($filePath) {
117
197
                $pathinfo = pathinfo($filePath);
118
198
                $extension = strtoupper($pathinfo['extension']);
119
 
                
 
199
 
120
200
                switch ($extension) {
121
201
                        case 'DOC':
122
202
                        case 'DOCX':
151
231
                                return 'impress_pdf_Export';
152
232
                                break;
153
233
                        case 'PDF':
154
 
                                return 'NONE';
 
234
                                return 'PDF';
155
235
                                break;
156
236
                        default:
157
237
                                return 'writer_pdf_Export';
159
239
                }
160
240
        }
161
241
 
 
242
 
162
243
        /**
163
244
         * Return the scaled version of image giving the hash and the filename
164
245
         *
322
403
                }
323
404
 
324
405
                $response->getHeaders()->append('Content-Type:' . $mime);
 
406
                //TODO-> __lib_exceptions_error_handler(2, "strlen() expects parameter 1 to be strin"[..], "/var/www/trunknew/eyeos/apps/files/mobil"[..], 326, array(20))
325
407
                $response->getHeaders()->append('Content-Length: ' . strlen($imageData));
326
408
                $response->getHeaders()->append('Accept-Ranges: bytes');
327
409
                $response->getHeaders()->append('X-Pad: avoid browser bug');