|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ownCloud - Documents App |
|
5
|
|
|
* |
|
6
|
|
|
* @author Frank Karlitschek |
|
7
|
|
|
* @copyright 2013-2014 Frank Karlitschek [email protected] |
|
8
|
|
|
* |
|
9
|
|
|
* This library is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
11
|
|
|
* License as published by the Free Software Foundation; either |
|
12
|
|
|
* version 3 of the License, or any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This library is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public |
|
20
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
namespace OCA\Documents; |
|
26
|
|
|
|
|
27
|
|
|
class Storage { |
|
28
|
|
|
const MIMETYPE_LIBREOFFICE_WORDPROCESSOR = 'application/vnd.oasis.opendocument.text'; |
|
29
|
|
|
private static $SUPPORTED_MIMES_READ = array( |
|
30
|
|
|
'application/vnd.oasis.opendocument.spreadsheet', |
|
31
|
|
|
'application/vnd.oasis.opendocument.presentation', |
|
32
|
|
|
'application/vnd.oasis.opendocument.graphics', |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
public static function getDocuments() { |
|
36
|
|
|
$list = array_filter( |
|
37
|
|
|
self::searchDocuments(), |
|
38
|
|
|
function($item){ |
|
39
|
|
|
//filter Deleted |
|
40
|
|
|
if (strpos($item['path'], '_trashbin')===0){ |
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
return true; |
|
44
|
|
|
} |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
return $list; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public static function resolvePath($fileId){ |
|
51
|
|
|
$list = array_filter( |
|
52
|
|
|
self::searchDocuments(), |
|
53
|
|
|
function($item) use ($fileId){ |
|
54
|
|
|
return intval($item['fileid'])==$fileId; |
|
55
|
|
|
} |
|
56
|
|
|
); |
|
57
|
|
|
if (count($list)>0){ |
|
58
|
|
|
$item = current($list); |
|
59
|
|
|
return $item['path']; |
|
60
|
|
|
} |
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @brief Cleanup session data on removing the document |
|
66
|
|
|
* @param array |
|
67
|
|
|
* |
|
68
|
|
|
* This function is connected to the delete signal of OC_Filesystem |
|
69
|
|
|
* to delete the related info from database |
|
70
|
|
|
*/ |
|
71
|
|
|
public static function onDelete($params) { |
|
72
|
|
|
$info = \OC\Files\Filesystem::getFileInfo($params['path']); |
|
73
|
|
|
|
|
74
|
|
|
$fileId = @$info['fileid']; |
|
75
|
|
|
if (!$fileId){ |
|
76
|
|
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$session = new Db\Session(); |
|
80
|
|
|
$session->loadBy('file_id', $fileId); |
|
81
|
|
|
|
|
82
|
|
|
if (!$session->getEsId()){ |
|
83
|
|
|
return; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$member = new Db\Member(); |
|
87
|
|
|
$sessionMembers = $member->getCollectionBy('es_id', $session->getEsId()); |
|
88
|
|
|
foreach ($sessionMembers as $memberData){ |
|
89
|
|
|
if (intval($memberData['status'])===Db\Member::MEMBER_STATUS_ACTIVE){ |
|
90
|
|
|
return; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
Db\Session::cleanUp($session->getEsId()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
protected static function searchDocuments(){ |
|
98
|
|
|
$documents = array(); |
|
99
|
|
|
foreach (self::getSupportedMimetypes() as $mime){ |
|
100
|
|
|
if (!in_array($mime, self::$SUPPORTED_MIMES_READ)) { |
|
101
|
|
|
$documents = array_merge($documents, \OCP\Files::searchByMime($mime)); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
return $documents; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public static function getSupportedMimetypes(){ |
|
108
|
|
|
return array_merge( |
|
109
|
|
|
array(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR), |
|
110
|
|
|
self::$SUPPORTED_MIMES_READ, |
|
111
|
|
|
Filter::getAll() |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|