1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OCA\OwnNote\ShareBackend; |
4
|
|
|
|
5
|
|
|
use \OCP\Share_Backend; |
6
|
|
|
|
7
|
|
|
class OwnnoteShareBackend implements Share_Backend { |
8
|
|
|
|
9
|
|
|
private $db; |
10
|
|
|
|
11
|
|
|
public function __construct() { |
12
|
|
|
$this->db = \OC::$server->getDatabaseConnection(); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Check if this $itemSource exist for the user |
17
|
|
|
* @param string $itemSource |
18
|
|
|
* @param string $uidOwner Owner of the item |
19
|
|
|
* @return boolean|null Source |
20
|
|
|
* |
21
|
|
|
* Return false if the item does not exist for the user |
22
|
|
|
* @since 5.0.0 |
23
|
|
|
*/ |
24
|
|
|
public function isValidSource($itemSource, $uidOwner) { |
25
|
|
|
// todo: real test |
26
|
|
|
// id => 1, has admin |
27
|
|
|
// has owner this note? |
28
|
|
|
|
29
|
|
|
return true; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get a unique name of the item for the specified user |
34
|
|
|
* @param string $itemSource |
35
|
|
|
* @param string|false $shareWith User the item is being shared with |
36
|
|
|
* @param array|null $exclude List of similar item names already existing as shared items @deprecated since version OC7 |
37
|
|
|
* @return string Target name |
38
|
|
|
* |
39
|
|
|
* This function needs to verify that the user does not already have an item with this name. |
40
|
|
|
* If it does generate a new name e.g. name_# |
41
|
|
|
* @since 5.0.0 |
42
|
|
|
*/ |
43
|
|
|
public function generateTarget($itemSource, $shareWith, $exclude = null) { |
44
|
|
|
// note id (should be unique) |
45
|
|
|
return $itemSource; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Converts the shared item sources back into the item in the specified format |
50
|
|
|
* @param array $items Shared items |
51
|
|
|
* @param int $format |
52
|
|
|
* @return array |
53
|
|
|
* |
54
|
|
|
* The items array is a 3-dimensional array with the item_source as the |
55
|
|
|
* first key and the share id as the second key to an array with the share |
56
|
|
|
* info. |
57
|
|
|
* |
58
|
|
|
* The key/value pairs included in the share info depend on the function originally called: |
59
|
|
|
* If called by getItem(s)Shared: id, item_type, item, item_source, |
60
|
|
|
* share_type, share_with, permissions, stime, file_source |
61
|
|
|
* |
62
|
|
|
* If called by getItem(s)SharedWith: id, item_type, item, item_source, |
63
|
|
|
* item_target, share_type, share_with, permissions, stime, file_source, |
64
|
|
|
* file_target |
65
|
|
|
* |
66
|
|
|
* This function allows the backend to control the output of shared items with custom formats. |
67
|
|
|
* It is only called through calls to the public getItem(s)Shared(With) functions. |
68
|
|
|
* @since 5.0.0 |
69
|
|
|
*/ |
70
|
|
|
public function formatItems($items, $format, $parameters = null) { |
71
|
|
|
if ($format === 'shares') { |
|
|
|
|
72
|
|
|
return $items; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// get the ownnote ids |
76
|
|
|
$ids = Array(); |
77
|
|
|
foreach($items as $item) { |
78
|
|
|
$ids[] = $item['item_source']; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// get notes from database |
82
|
|
|
$select_clause = "SELECT id, uid, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE id in ("; |
83
|
|
|
$select_clause .= implode(',', $ids); |
84
|
|
|
$select_clause .= ") ORDER BY id"; |
85
|
|
|
$q = $this->db->executeQuery($select_clause, array()); |
86
|
|
|
//$query = \OCP\DB::prepare($select_clause); |
87
|
|
|
$results = $q->fetchAll(); |
88
|
|
|
|
89
|
|
|
// add permissions to items |
90
|
|
|
if ($format === 'populated_shares') { |
|
|
|
|
91
|
|
|
$full_items = Array(); |
92
|
|
|
foreach($results as $index => $result) { |
93
|
|
|
$full_items[] = array_merge($items[$index], $result); |
94
|
|
|
} |
95
|
|
|
$results = $full_items; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $results; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Check if a given share type is allowd by the back-end |
103
|
|
|
* |
104
|
|
|
* @param int $shareType share type |
105
|
|
|
* @return boolean |
106
|
|
|
* |
107
|
|
|
* The back-end can enable/disable specific share types. Just return true if |
108
|
|
|
* the back-end doesn't provide any specific settings for it and want to allow |
109
|
|
|
* all share types defined by the share API |
110
|
|
|
* @since 8.0.0 |
111
|
|
|
*/ |
112
|
|
|
public function isShareTypeAllowed($shareType) { |
113
|
|
|
return true; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
} |