').appendTo($('body')[0]);
11 | }
12 |
13 | $('#SearchView').html(jsondata);
14 | window.location.hash = '#';
15 | });
16 | }
17 | });
--------------------------------------------------------------------------------
/js/settings.js:
--------------------------------------------------------------------------------
1 | OC.ContactsPlus = OC.ContactsPlus || {};
2 | OC.ContactsPlus.appname='contactsplus';
3 |
4 | OC.ContactsPlus.Settings = {
5 | init:function() {
6 | this.Addressbook.adrsettings = $('.addressbooks-settings').first();
7 | this.Addressbook.adractions = $('#contacts-settings').find('.actions');
8 |
9 | //console.log('actions: ' + this.Addressbook.adractions.length);
10 | //var ABooksList=$('.addressbook');
11 | $('#toggleIosSupport').on('change',function(){
12 | OC.ContactsPlus.addIosSupport(this);
13 | });
14 |
15 | OC.ContactsPlus.Settings.Addressbook.adrsettings.keydown(function(event) {
16 | if(event.which == 13 || event.which == 32) {
17 | OC.ContactsPlus.Settings.Addressbook.adrsettings.click();
18 | }
19 | });
20 |
21 | OC.ContactsPlus.Settings.Addressbook.adractions.find('button.hidden').hide();
22 | OC.ContactsPlus.Settings.Addressbook.adrsettings.on('click', function(event){
23 | $('.tipsy').remove();
24 | var tgt = $(event.target);
25 |
26 | if(tgt.is('i.ioc') || tgt.is(':checkbox')) {
27 | var id = tgt.parents('tr').first().data('id');
28 | if(!id) {
29 | return;
30 | }
31 |
32 | if(tgt.is('#active_aid_'+id+':checkbox')) {
33 |
34 | OC.ContactsPlus.Settings.Addressbook.doActivate(id, tgt);
35 |
36 | } else if(tgt.is('i.ioc')) {
37 |
38 | if(tgt.hasClass('edit')) {
39 | OC.ContactsPlus.Settings.Addressbook.doEdit(id);
40 | } else if(tgt.hasClass('delete')) {
41 | OC.ContactsPlus.Settings.Addressbook.doDelete(id);
42 | } else if(tgt.hasClass('globe')) {
43 | OC.ContactsPlus.Settings.Addressbook.showCardDAV(id);
44 | } else if(tgt.hasClass('cloud')) {
45 | OC.ContactsPlus.Settings.Addressbook.showVCF(id);
46 | }
47 | else if(tgt.hasClass('abo')) {
48 | OC.ContactsPlus.Settings.Addressbook.showAboBirthday(id);
49 | }
50 | else if(tgt.hasClass('export')) {
51 | OC.ContactsPlus.Settings.Addressbook.VCFExport(id);
52 | }
53 | }
54 | } else if(tgt.is('button')) {
55 | event.preventDefault();
56 | if(tgt.hasClass('save')) {
57 | OC.ContactsPlus.Settings.Addressbook.doSave();
58 | } else if(tgt.hasClass('cancel')) {
59 | OC.ContactsPlus.Settings.Addressbook.showActions(['new']);
60 | } else if(tgt.hasClass('new')) {
61 | OC.ContactsPlus.Settings.Addressbook.doEdit('new');
62 | }
63 | }
64 | });
65 |
66 |
67 | },
68 | Addressbook:{
69 | showActions:function(act) {
70 | this.adractions.children().hide();
71 | this.adractions.children('.'+act.join(',.')).show();
72 | },
73 | doActivate:function(id, tgt) {
74 | var active = tgt.is(':checked');
75 |
76 | //console.log('doActivate: ', id, active);
77 | $.post(OC.generateUrl('apps/'+OC.ContactsPlus.appname+'/activateaddrbook'), {id: id, active: Number(active)}, function(jsondata) {
78 | if (jsondata.status == 'success') {
79 | $(document).trigger('request.addressbook.activate', {
80 | id: id,
81 | activate: active,
82 | });
83 |
84 | if(active === true){
85 | OC.ContactsPlus.getAddressBooks(id);
86 | }else{
87 | $('#cAddressbooks .dropcontainerAddressBook[data-adrbid="'+id+'"]').remove();
88 | }
89 |
90 | } else {
91 | //console.log('Error:', jsondata.data.message);
92 | OC.ContactsPlus.notify(t(OC.ContactsPlus.appname, 'Error') + ': ' + jsondata.data.message);
93 | tgt.checked = !active;
94 | }
95 | });
96 | },
97 |
98 | doDelete:function(id) {
99 | //console.log('doDelete: ', id);
100 |
101 |
102 | var handleDelete=function(YesNo){
103 |
104 | if(YesNo){
105 | var row = $('.addressbooks-settings tr[data-id="'+id+'"]');
106 |
107 | $.post(OC.generateUrl('apps/'+OC.ContactsPlus.appname+'/deleteaddrbook'), { id: id}, function(jsondata) {
108 | if (jsondata.status == 'success'){
109 |
110 | row.remove();
111 | OC.ContactsPlus.Settings.Addressbook.showActions(['new',]);
112 | $('#cAddressbooks').find('.dropcontainerAddressBook[data-adrbid="'+id+'"]').remove();
113 | OC.ContactsPlus.getAddressBooks(0);
114 | } else {
115 | OC.dialogs.alert(jsondata.data.message, t(OC.ContactsPlus.appname, 'Error'));
116 | }
117 | });
118 | }
119 | };
120 |
121 | OC.dialogs.confirm(t(OC.ContactsPlus.appname,'Do you really want to delete this address book?'),t(OC.ContactsPlus.appname,'Delete Addressbook'),handleDelete);
122 |
123 | },
124 | doEdit:function(id) {
125 | //console.log('doEdit: ', id);
126 |
127 | var owner = this.adrsettings.find('[data-id="'+id+'"]').data('owner');
128 | var actions = ['description', 'save', 'cancel'];
129 | if(owner == OC.currentUser || id === 'new') {
130 | actions.push('active', 'name');
131 | }
132 | this.showActions(actions);
133 | var name = this.adrsettings.find('[data-id="'+id+'"]').find('.name').text();
134 | var description = this.adrsettings.find('[data-id="'+id+'"]').find('.description').text();
135 | var active = true;
136 | //console.log('name, desc', name, description);
137 | this.adractions.find('.active').prop('checked', active);
138 | this.adractions.find('.name').val(name);
139 | this.adractions.find('.description').val(description);
140 | this.adractions.data('id', id);
141 | },
142 | doSave:function() {
143 | var name = this.adractions.find('.name').val();
144 | var description = this.adractions.find('.description').val();
145 | var active = this.adractions.find('.active').is(':checked');
146 | var id = this.adractions.data('id');
147 | //console.log('doSave:', id, name, description, active);
148 |
149 | if(name.length == 0) {
150 | OC.dialogs.alert(t(OC.ContactsPlus.appname, 'Displayname cannot be empty.'), t(OC.ContactsPlus.appname, 'Error'));
151 | return false;
152 | }
153 | var url;
154 | if (id == 'new'){
155 | url = OC.generateUrl('apps/'+OC.ContactsPlus.appname+'/addaddrbook');
156 | }else{
157 | url = OC.generateUrl('apps/'+OC.ContactsPlus.appname+'/updateaddrbook');
158 | }
159 | self = this;
160 | $.post(url, { id: id, name: name, active: Number(active), description: description },
161 | function(jsondata){
162 | if(jsondata.status == 'success'){
163 | self.showActions(['new',]);
164 | self.adractions.removeData('id');
165 | active = Boolean(Number(jsondata.data.addressbook.active));
166 | if(id == 'new') {
167 |
168 |
169 |
170 | self.adrsettings.find('table')
171 | .append('
'
172 | + ' | '
173 | + ''+jsondata.data.addressbook.displayname+' | '
174 | + ' | '
175 | + ' | '
176 | + ' | '
177 | + ' | '
178 | + '
');
179 |
180 | OC.ContactsPlus.loadContacts(jsondata.data.addressbook.id,'',0,0);
181 | OC.ContactsPlus.getAddressBooks(jsondata.data.addressbook.id);
182 |
183 |
184 | } else {
185 | var row = self.adrsettings.find('tr[data-id="'+id+'"]');
186 | row.find('td.name').text(jsondata.data.addressbook.displayname);
187 | row.find('td.description').text(jsondata.data.addressbook.description);
188 | $('#cAddressbooks').find('.dropcontainerAddressBook[data-adrbid="'+id+'"] .groupname').text(jsondata.data.addressbook.displayname);
189 | }
190 |
191 | } else {
192 | OC.dialogs.alert(jsondata.data.message, t(OC.ContactsPlus.appname, 'Error'));
193 | }
194 | });
195 | },
196 | showLink:function(id, row, link) {
197 | //console.log('row:', row.length);
198 | row.next('tr.link').remove();
199 | var linkrow = $('
| '
200 | + ' |
').insertAfter(row);
201 | linkrow.find('input').focus().select();
202 | linkrow.find('.ioc').click(function() {
203 | $(this).parents('tr').first().remove();
204 | });
205 | },
206 | showCardDAV:function(id) {
207 | //console.log('showCardDAV: ', id);
208 | var row = this.adrsettings.find('tr[data-id="'+id+'"]');
209 | var owner = row.data('owner');
210 | var uri = (owner === oc_current_user ) ? row.data('uri') : row.data('uri') + '_shared_by_' + owner;
211 | this.showLink(id, row, $('#totalurl').val()+'addressbooks/'+encodeURIComponent(oc_current_user)+'/'+encodeURIComponent(uri));
212 | },
213 | showVCF:function(id) {
214 | //console.log('showVCF: ', id);
215 | var row = this.adrsettings.find('tr[data-id="'+id+'"]');
216 | var owner = row.data('owner');
217 | var uri = (owner === oc_current_user ) ? row.data('uri') : row.data('uri') + '_shared_by_' + owner;
218 | var link = $('#totalurl').val()+'addressbooks/'+encodeURIComponent(oc_current_user)+'/'+encodeURIComponent(uri)+'?export';
219 | //console.log(link);
220 | this.showLink(id, row, link);
221 | },
222 | VCFExport:function(id) {
223 | //console.log('showVCF: ', id);
224 | var row = this.adrsettings.find('tr[data-id="'+id+'"]');
225 | var owner = row.data('owner');
226 | var uri = (owner === oc_current_user ) ? row.data('uri') : row.data('uri') + '_shared_by_' + owner;
227 | var link = OC.generateUrl('apps/'+OC.ContactsPlus.appname+'/exportcontacts') + '?bookid=' +id;
228 | document.location.href =link;
229 |
230 | },
231 | showAboBirthday:function(id) {
232 | //console.log('showVCF: ', id);
233 | var row = this.adrsettings.find('tr[data-id="'+id+'"]');
234 | var owner = row.data('owner');
235 | var uri = (owner === oc_current_user ) ? row.data('uri') : row.data('uri') + '_shared_by_' + owner;
236 | var link = OC.generateUrl('apps/'+OC.ContactsPlus.appname+'/exportbirthdays')+'?aid=' +id;
237 | document.location.href =link;
238 |
239 | }
240 | }
241 | };
242 |
243 |
244 |
245 |
--------------------------------------------------------------------------------
/lib/addressbookprovider.php:
--------------------------------------------------------------------------------
1 | addressBook = $addressBook;
18 |
19 | }
20 |
21 | public function getAddressbook() {
22 | return $this->addressBook;
23 | }
24 |
25 | /**
26 | * @return string defining the technical unique key
27 | */
28 | public function getKey() {
29 | return $this->addressBook['id'];
30 | }
31 |
32 | /**
33 | * In comparison to getKey() this function returns a human readable (maybe translated) name
34 | * @return string
35 | */
36 | public function getDisplayName() {
37 | return $this->addressBook['displayname'];
38 | }
39 |
40 | /**
41 | * @return integer
42 | */
43 | public function getPermissions() {
44 | return $this->addressBook['permissions'];
45 | }
46 |
47 | /**
48 | * @param string $pattern
49 | * @param string[] $searchProperties
50 | * @param $options
51 | * @return array|false
52 | */
53 | public function search($pattern, $searchProperties, $options) {
54 | $propTable = '*PREFIX*conplus_cards_properties';
55 | $contTable = '*PREFIX*conplus_cards';
56 | $addrTable = '*PREFIX*conplus_addressbooks';
57 | $results = array();
58 |
59 | /**
60 | * This query will fetch all contacts which match the $searchProperties
61 | * It will look up the addressbookid of the contact and the user id of the owner of the contact app
62 | */
63 | $query = <<
getKey();
84 |
85 | foreach ($searchProperties as $property) {
86 | $params[] = $property;
87 | $params[] = '%' . $pattern . '%';
88 | $query .= '(`name` = ? AND `value` ILIKE ?) OR ';
89 | }
90 |
91 | $query = substr($query, 0, strlen($query) - 4);
92 | $query .= ')';
93 |
94 | $stmt = \OCP\DB::prepare($query);
95 | $result = $stmt->execute($params);
96 |
97 | if (\OCP\DB::isError($result)) {
98 | \OCP\Util::writeLog('contactsplus', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result),
99 | \OCP\Util::ERROR);
100 | return false;
101 | }
102 |
103 | $j = [];
104 |
105 | while ($row = $result->fetchRow()) {
106 | $id = $row['contactid'];
107 | //$addressbookKey = $row['addressbookid'];
108 | $vcard = App::getContactVCard($id);
109 |
110 | $contact = VCard::structureContact($vcard);
111 |
112 | $j['data'] = $contact;
113 | $j['data']['id'] = $id;
114 | $j['data']['metadata'] = $row;
115 | $j['data']['photo'] = false;
116 | if(isset($vcard->BDAY)){
117 | $j['data']['birthday'] = $vcard->BDAY;
118 | }
119 | if(isset($vcard->PHOTO) || isset($vcard->LOGO)) {
120 | $j['data']['photo'] = true;
121 | $url = \OC::$server->getURLGenerator()->linkToRoute('contactsplus.contacts.getContactPhoto',array('id' => $id));
122 | $url = \OC::$server->getURLGenerator()->getAbsoluteURL($url);
123 | $j['data']['PHOTO'] = "uri:$url";
124 | }
125 |
126 | $results[] = $this->convertToSearchResult($j);
127 |
128 | }
129 | return $results;
130 |
131 | }
132 |
133 | /**
134 | * @param $properties
135 | * @return Contact|null
136 | */
137 | public function createOrUpdate($properties) {
138 |
139 | }
140 |
141 | /**
142 | * @param $id
143 | * @return mixed
144 | */
145 | public function delete($id) {
146 |
147 | VCard::delete($id);
148 | }
149 |
150 |
151 |
152 | /**
153 | * @param $j
154 | * @return array
155 | */
156 | private function convertToSearchResult($j) {
157 | $data = $j['data'];
158 | $result = array();
159 | foreach( $data as $key => $d) {
160 | $d = $data[$key];
161 | if (in_array($key, App::$multi_properties)) {
162 | $result[$key] = array_map(function($v){
163 | return $v['value'];
164 | }, $d);
165 | } else {
166 | if (is_array($d)) {
167 | $result[$key] = $d[0]['value'];
168 | } else {
169 | $result[$key] = $d;
170 | }
171 | }
172 | }
173 |
174 | return $result;
175 | }
176 | }
--------------------------------------------------------------------------------
/lib/connector/sabre/carddav/addressbook.php:
--------------------------------------------------------------------------------
1 | .
20 | *
21 | */
22 |
23 | /**
24 | * This class overrides __construct to get access to $addressBookInfo and
25 | * $carddavBackend, Sabre_CardDAV_AddressBook::getACL() to return read/write
26 | * permissions based on user and shared state and it overrides
27 | * Sabre_CardDAV_AddressBook::getChild() and Sabre_CardDAV_AddressBook::getChildren()
28 | * to instantiate OC_Connector_Sabre_CardDAV_Cards.
29 | */
30 | namespace OCA\ContactsPlus\Connector\Sabre\Carddav;
31 |
32 | use \OCA\ContactsPlus\Addressbook as AddrBook;
33 | use \OCA\ContactsPlus\App as ContactsApp;
34 |
35 | class AddressBook extends \Sabre\CardDAV\AddressBook {
36 |
37 |
38 |
39 | /**
40 | * Returns a list of ACE's for this node.
41 | *
42 | * Each ACE has the following properties:
43 | * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
44 | * currently the only supported privileges
45 | * * 'principal', a url to the principal who owns the node
46 | * * 'protected' (optional), indicating that this ACE is not allowed to
47 | * be updated.
48 | *
49 | * @return array
50 | */
51 | public function getACL() {
52 |
53 | $readprincipal = $this->getOwner();
54 | $writeprincipal = $this->getOwner();
55 | $createprincipal = $this->getOwner();
56 | $deleteprincipal = $this->getOwner();
57 | $uid = AddrBook::extractUserID($this->getOwner());
58 |
59 | //\OCP\Config::setUserValue($uid, 'contactsplus', 'syncaddrbook', $this->addressBookInfo['uri']);
60 |
61 | $readWriteACL = array(
62 | array(
63 | 'privilege' => '{DAV:}read',
64 | 'principal' => 'principals/' . \OCP\User::getUser(),
65 | 'protected' => true,
66 | ),
67 | array(
68 | 'privilege' => '{DAV:}write',
69 | 'principal' => 'principals/' . \OCP\User::getUser(),
70 | 'protected' => true,
71 | ),
72 | );
73 |
74 | if($uid !== \OCP\USER::getUser()) {
75 | $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX.$this->addressBookInfo['id']);
76 | if($sharedAddressbook) {
77 | if(($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE)
78 | && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE)
79 | && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)
80 | ) {
81 | return $readWriteACL;
82 | }
83 | if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) {
84 | $createprincipal = 'principals/' . \OCP\USER::getUser();
85 | }
86 | if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
87 | $readprincipal = 'principals/' . \OCP\USER::getUser();
88 | }
89 | if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
90 | $writeprincipal = 'principals/' . \OCP\USER::getUser();
91 | }
92 | if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
93 | $deleteprincipal = 'principals/' . \OCP\USER::getUser();
94 | }
95 | }
96 | } else {
97 | return parent::getACL();
98 | }
99 |
100 | return array(
101 | array(
102 | 'privilege' => '{DAV:}read',
103 | 'principal' => $readprincipal,
104 | 'protected' => true,
105 | ),
106 | array(
107 | 'privilege' => '{DAV:}write-content',
108 | 'principal' => $writeprincipal,
109 | 'protected' => true,
110 | ),
111 | array(
112 | 'privilege' => '{DAV:}bind',
113 | 'principal' => $createprincipal,
114 | 'protected' => true,
115 | ),
116 | array(
117 | 'privilege' => '{DAV:}unbind',
118 | 'principal' => $deleteprincipal,
119 | 'protected' => true,
120 | ),
121 | );
122 |
123 | }
124 |
125 | function getSupportedPrivilegeSet() {
126 |
127 | return array(
128 | 'privilege' => '{DAV:}all',
129 | 'abstract' => true,
130 | 'aggregates' => array(
131 | array(
132 | 'privilege' => '{DAV:}read',
133 | 'aggregates' => array(
134 | array(
135 | 'privilege' => '{DAV:}read-acl',
136 | 'abstract' => true,
137 | ),
138 | array(
139 | 'privilege' => '{DAV:}read-current-user-privilege-set',
140 | 'abstract' => true,
141 | ),
142 | ),
143 | ), // {DAV:}read
144 | array(
145 | 'privilege' => '{DAV:}write',
146 | 'aggregates' => array(
147 | array(
148 | 'privilege' => '{DAV:}write-acl',
149 | 'abstract' => true,
150 | ),
151 | array(
152 | 'privilege' => '{DAV:}write-properties',
153 | 'abstract' => true,
154 | ),
155 | array(
156 | 'privilege' => '{DAV:}write-content',
157 | 'abstract' => false,
158 | ),
159 | array(
160 | 'privilege' => '{DAV:}bind',
161 | 'abstract' => false,
162 | ),
163 | array(
164 | 'privilege' => '{DAV:}unbind',
165 | 'abstract' => false,
166 | ),
167 | array(
168 | 'privilege' => '{DAV:}unlock',
169 | 'abstract' => true,
170 | ),
171 | ),
172 | ), // {DAV:}write
173 | ),
174 | ); // {DAV:}all
175 |
176 | }
177 |
178 | /**
179 | * Returns a card
180 | *
181 | * @param string $name
182 | * @return OC_Connector_Sabre_DAV_Card
183 | */
184 | public function getChild($name) {
185 |
186 | $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'],$name);
187 | if (!$obj) throw new \Sabre\DAV\Exception\NotFound('Card not found');
188 | return new Card($this->carddavBackend,$this->addressBookInfo,$obj);
189 |
190 | }
191 |
192 | /**
193 | * Returns the full list of cards
194 | *
195 | * @return array
196 | */
197 | public function getChildren() {
198 |
199 | $objs = $this->carddavBackend->getCards($this->addressBookInfo['id']);
200 | $children = array();
201 | foreach($objs as $obj) {
202 | $children[] = new Card($this->carddavBackend,$this->addressBookInfo,$obj);
203 | }
204 | return $children;
205 |
206 | }
207 |
208 | /**
209 | * This method receives a list of paths in it's first argument.
210 | * It must return an array with Node objects.
211 | *
212 | * If any children are not found, you do not have to return them.
213 | *
214 | * @return array
215 | */
216 | function getMultipleChildren(array $paths) {
217 | $objs = $this->carddavBackend->getMultipleCards($this->addressBookInfo['id'], $paths);
218 | $children = [];
219 | foreach($objs as $obj) {
220 |
221 | $children[] = new Card($this->carddavBackend,$this->addressBookInfo,$obj);
222 | }
223 | return $children;
224 | }
225 |
226 | }
227 |
--------------------------------------------------------------------------------
/lib/connector/sabre/carddav/addressbookroot.php:
--------------------------------------------------------------------------------
1 | .
20 | *
21 | */
22 |
23 | /**
24 | * This class overrides Sabre_CardDAV_AddressBookRoot::getChildForPrincipal()
25 | * to instantiate OC_Connector_CardDAV_UserAddressBooks.
26 | */
27 | namespace OCA\ContactsPlus\Connector\Sabre\Carddav;
28 |
29 | class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
30 |
31 | /**
32 | * This method returns a node for a principal.
33 | *
34 | * The passed array contains principal information, and is guaranteed to
35 | * at least contain a uri item. Other properties may or may not be
36 | * supplied by the authentication backend.
37 | *
38 | * @param array $principal
39 | * @return Sabre_DAV_INode
40 | */
41 | public function getChildForPrincipal(array $principal) {
42 |
43 | return new UserAddressBooks($this->carddavBackend, $principal['uri']);
44 |
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/lib/connector/sabre/carddav/backend.php:
--------------------------------------------------------------------------------
1 | .
20 | *
21 | */
22 |
23 | /**
24 | * This CardDAV backend uses PDO to store addressbooks
25 | */
26 | namespace OCA\ContactsPlus\Connector\Sabre\Carddav;
27 |
28 | use \OCA\ContactsPlus\Addressbook as AddrBook;
29 | use \OCA\ContactsPlus\VCard;
30 |
31 | class Backend extends \Sabre\CardDAV\Backend\AbstractBackend {
32 | /**
33 | * Returns the list of addressbooks for a specific user.
34 | *
35 | * @param string $principaluri
36 | * @return array
37 | */
38 | public function getAddressBooksForUser($principaluri) {
39 | $data = AddrBook::allWherePrincipalURIIs($principaluri);
40 | $addressbooks = array();
41 |
42 | foreach($data as $i) {
43 | if($i['userid'] !== \OCP\USER::getUser()) {
44 | $i['uri'] = $i['uri'] . '_shared_by_' . $i['userid'];
45 | }
46 | $addressbooks[] = array(
47 | 'id' => $i['id'],
48 | 'uri' => $i['uri'],
49 | 'principaluri' => 'principals/'.$i['userid'],
50 | '{DAV:}displayname' => $i['displayname'],
51 | '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => $i['description'],
52 | '{http://calendarserver.org/ns/}getctag' => $i['ctag'],
53 | '{http://sabredav.org/ns}sync-token' => $i['ctag']?$i['ctag']:'0',
54 | );
55 |
56 | //\OCP\Util::writeLog('kontakte','CARDDAV->:'.$i['displayname'], \OCP\Util::DEBUG);
57 | }
58 |
59 |
60 | return $addressbooks;
61 | }
62 |
63 |
64 | /**
65 | * Updates an addressbook's properties
66 | *
67 | * See Sabre_DAV_IProperties for a description of the mutations array, as
68 | * well as the return value.
69 | *
70 | * @param mixed $addressbookid
71 | * @param array $mutations
72 | * @see Sabre_DAV_IProperties::updateProperties
73 | * @return bool|array
74 | */
75 | public function updateAddressBook($addressbookid, \Sabre\DAV\PropPatch $mutations) {
76 |
77 | $supportedProperties = [
78 | '{DAV:}displayname',
79 | '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV . '}addressbook-description',
80 | ];
81 |
82 | $propPatch->handle($supportedProperties, function($mutations) use ($addressbookid) {
83 |
84 | $updates = [];
85 | foreach($mutations as $property=>$newValue) {
86 |
87 | switch($property) {
88 | case '{DAV:}displayname' :
89 | $updates['displayname'] = $newValue;
90 | break;
91 | case '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' :
92 | $updates['description'] = $newValue;
93 | break;
94 | }
95 | }
96 |
97 | AddrBook::edit($addressbookid, $updates['displayname'], $updates['description']);
98 | return true;
99 | });
100 |
101 | }
102 |
103 | /**
104 | * Creates a new address book
105 | *
106 | * @param string $principaluri
107 | * @param string $url Just the 'basename' of the url.
108 | * @param array $properties
109 | * @return void
110 | */
111 | public function createAddressBook($principaluri, $url, array $properties) {
112 |
113 | $displayname = null;
114 | $description = null;
115 |
116 | foreach($properties as $property => $newvalue) {
117 |
118 | switch($property) {
119 | case '{DAV:}displayname' :
120 | $name = $newvalue;
121 | break;
122 | case '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV
123 | . '}addressbook-description' :
124 | $description = $newvalue;
125 | break;
126 | default :
127 | throw new \Sabre\DAV\Exception\BadRequest('Unknown property: '
128 | . $property);
129 | }
130 |
131 | }
132 |
133 | AddrBook::addFromDAVData(
134 | $principaluri,
135 | $url,
136 | $name,
137 | $description
138 | );
139 | }
140 |
141 | /**
142 | * Deletes an entire addressbook and all its contents
143 | *
144 | * @param int $addressbookid
145 | * @return void
146 | */
147 | public function deleteAddressBook($addressbookid) {
148 | AddrBook::delete($addressbookid);
149 | }
150 |
151 | /**
152 | * Returns all cards for a specific addressbook id.
153 | *
154 | * @param mixed $addressbookid
155 | * @return array
156 | */
157 | public function getCards($addressbookid) {
158 | $data = VCard::all($addressbookid);
159 | $cards = array();
160 | foreach($data as $i) {
161 | //OCP\Util::writeLog('contacts', __METHOD__.', uri: ' . $i['uri'], OCP\Util::DEBUG);
162 | $cards[] = array(
163 | 'id' => $i['id'],
164 | //'carddata' => $i['carddata'],
165 | 'size' => strlen($i['carddata']),
166 | 'etag' => '"' . md5($i['carddata']) . '"',
167 | 'uri' => $i['uri'],
168 | 'lastmodified' => $i['lastmodified'] );
169 | }
170 |
171 | return $cards;
172 | }
173 |
174 | /**
175 | * Returns a specfic card
176 | *
177 | * @param mixed $addressbookid
178 | * @param string $carduri
179 | * @return array
180 | */
181 | public function getCard($addressbookid, $carduri) {
182 | return VCard::findWhereDAVDataIs($addressbookid, $carduri);
183 |
184 | }
185 | /**
186 | * Returns a list of cards.
187 | *
188 | * This method should work identical to getCard, but instead return all the
189 | * cards in the list as an array.
190 | *
191 | * If the backend supports this, it may allow for some speed-ups.
192 | *
193 | * @param mixed $addressBookId
194 | * @param array $uris
195 | * @return array
196 | */
197 | public function getMultipleCards($addressBookId, array $uris) {
198 |
199 | return array_map(function($uri) use ($addressBookId) {
200 | return $this->getCard($addressBookId, $uri);
201 | }, $uris);
202 |
203 | return VCard::getMultipleCardsDavData($addressBookId, $uris);
204 |
205 | }
206 |
207 |
208 | /**
209 | * Creates a new card
210 | *
211 | * @param mixed $addressbookid
212 | * @param string $carduri
213 | * @param string $carddata
214 | * @return bool
215 | */
216 | public function createCard($addressbookid, $carduri, $carddata) {
217 | VCard::addFromDAVData($addressbookid, $carduri, $carddata);
218 | }
219 |
220 | /**
221 | * Updates a card
222 | *
223 | * @param mixed $addressbookid
224 | * @param string $carduri
225 | * @param string $carddata
226 | * @return bool
227 | */
228 | public function updateCard($addressbookid, $carduri, $carddata) {
229 | return VCard::editFromDAVData($addressbookid, $carduri, $carddata);
230 | }
231 |
232 | /**
233 | * Deletes a card
234 | *
235 | * @param mixed $addressbookid
236 | * @param string $carduri
237 | * @return bool
238 | */
239 | public function deleteCard($addressbookid, $carduri) {
240 | return VCard::deleteFromDAVData($addressbookid, $carduri);
241 | }
242 |
243 |
244 | /**
245 | * @brief gets the userid from a principal path
246 | * @param string $principaluri
247 | * @return string
248 | */
249 | public function userIDByPrincipal($principaluri) {
250 | list(, $userid) = \Sabre\DAV\URLUtil::splitPath($principaluri);
251 | return $userid;
252 | }
253 |
254 |
255 |
256 | }
257 |
--------------------------------------------------------------------------------
/lib/connector/sabre/carddav/card.php:
--------------------------------------------------------------------------------
1 | .
20 | *
21 | */
22 |
23 | /**
24 | * This class overrides Sabre_CardDAV_Card::getACL()
25 | * to return read/write permissions based on user and shared state.
26 | */
27 | namespace OCA\ContactsPlus\Connector\Sabre\Carddav;
28 |
29 | use \OCA\ContactsPlus\Addressbook as AddrBook;
30 | use \OCA\ContactsPlus\App as ContactsApp;
31 |
32 | class Card extends \Sabre\CardDAV\Card {
33 |
34 |
35 |
36 |
37 | /**
38 | * Returns a list of ACE's for this node.
39 | *
40 | * Each ACE has the following properties:
41 | * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
42 | * currently the only supported privileges
43 | * * 'principal', a url to the principal who owns the node
44 | * * 'protected' (optional), indicating that this ACE is not allowed to
45 | * be updated.
46 | *
47 | * @return array
48 | */
49 | public function getACL() {
50 |
51 | $readprincipal = $this->getOwner();
52 | $writeprincipal = $this->getOwner();
53 | $uid = AddrBook::extractUserID($this->getOwner());
54 |
55 | if($uid !== \OCP\USER::getUser()) {
56 | $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK,ContactsApp::SHAREADDRESSBOOKPREFIX.$this->addressBookInfo['id']);
57 | if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ)) {
58 | $readprincipal = 'principals/' . \OCP\USER::getUser();
59 | }
60 | if ($sharedAddressbook && ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE)) {
61 | $writeprincipal = 'principals/' . \OCP\USER::getUser();
62 | }
63 | }
64 |
65 | return array(
66 | array(
67 | 'privilege' => '{DAV:}read',
68 | 'principal' => $readprincipal,
69 | 'protected' => true,
70 | ),
71 | array(
72 | 'privilege' => '{DAV:}write',
73 | 'principal' => $writeprincipal,
74 | 'protected' => true,
75 | ),
76 |
77 | );
78 |
79 | }
80 |
81 | }
--------------------------------------------------------------------------------
/lib/connector/sabre/carddav/useraddressbooks.php:
--------------------------------------------------------------------------------
1 | .
20 | *
21 | */
22 |
23 | /**
24 | * This class overrides Sabre_CardDAV_UserAddressBooks::getChildren()
25 | * to instantiate OC_Connector_Sabre_CardDAV_AddressBooks.
26 | */
27 |
28 | namespace OCA\ContactsPlus\Connector\Sabre\Carddav;
29 |
30 | class UserAddressBooks extends \Sabre\CardDAV\UserAddressBooks {
31 |
32 | /**
33 | * Returns a list of addressbooks
34 | *
35 | * @return array
36 | */
37 | public function getChildren() {
38 |
39 | $addressbooks = $this->carddavBackend->getAddressbooksForUser($this->principalUri);
40 | $objs = array();
41 | foreach($addressbooks as $addressbook) {
42 |
43 | $objs[] = new AddressBook($this->carddavBackend, $addressbook);
44 | }
45 | return $objs;
46 |
47 | }
48 |
49 | }
--------------------------------------------------------------------------------
/lib/hooks.php:
--------------------------------------------------------------------------------
1 |
4 | * This file is licensed under the Affero General Public License version 3 or
5 | * later.
6 | * See the COPYING-README file.
7 | */
8 |
9 | /**
10 | * This class contains all hooks.
11 | */
12 |
13 | namespace OCA\ContactsPlus;
14 | use Sabre\VObject;
15 |
16 | class Hooks{
17 |
18 | /**
19 | * @brief Deletes all addressbooks of a certain user
20 | * @param parameters parameters from postDeleteUser-Hook
21 | * @return array
22 | */
23 | public static function deleteUser($parameters) {
24 | \OCP\Util::writeLog('contactsplus', 'Hook DEL ID-> '.$parameters['uid'], \OCP\Util::DEBUG);
25 | $addressbooks = Addressbook::all($parameters['uid']);
26 |
27 | foreach($addressbooks as $addressbook) {
28 | if($parameters['uid'] === $addressbook['userid']) {
29 | Addressbook::delete($addressbook['id']);
30 | }
31 | }
32 | //delete preferences
33 |
34 | return true;
35 | }
36 |
37 |
38 | public static function getBirthdayCalender($params){
39 |
40 | $isAktiv= 1;
41 | if(\OCP\Config::getUserValue(\OCP\USER::getUser(), 'calendarplus', 'calendar_birthday_'. \OCP\USER::getUser()) !== ''){
42 | $isAktiv = (int)\OCP\Config::getUserValue(\OCP\USER::getUser(), 'calendarplus','calendar_birthday_'. \OCP\USER::getUser());
43 | }
44 | $base_url = \OC::$server->getURLGenerator()->linkToRoute('calendarplus.event.getEvents').'?calendar_id=';
45 |
46 | $Calendar=array(
47 | 'url' => $base_url.'birthday_'. \OCP\USER::getUser(),
48 | 'uri' => 'birthday_'. \OCP\USER::getUser(),
49 | 'externuri'=> '',
50 | 'displayname'=> App::$l10n->t('Birthdays'),
51 | 'permissions'=>\OCP\PERMISSION_READ,
52 | 'id'=>'birthday_'. \OCP\USER::getUser(),
53 | 'owner'=>\OCP\USER::getUser(),
54 | 'userid'=>\OCP\USER::getUser(),
55 | 'issubscribe' => 1,
56 | 'cache' => false,
57 | 'ctag'=>1,
58 | 'className' => 'birthday-calendar',
59 | 'editable' => false,
60 | 'startEditable' => false,
61 | 'active' => $isAktiv,
62 | );
63 |
64 | $params['calendar'][] =$Calendar;
65 |
66 | }
67 |
68 | public static function getCalenderSources($parameters) {
69 |
70 | $base_url = \OC::$server->getURLGenerator()->linkToRoute('calendarplus.event.getEvents').'?calendar_id=';
71 |
72 | $addSource= array(
73 | 'url' => $base_url.'birthday_'. \OCP\USER::getUser(),
74 | 'id'=>'birthday_'. \OCP\USER::getUser(),
75 | 'className' => 'birthday-calendar',
76 | 'permissions'=>\OCP\PERMISSION_READ,
77 | 'cache' => false,
78 | 'ctag'=>2,
79 | 'editable' => false,
80 | 'startEditable' => false,
81 | 'issubscribe' => 1,
82 | );
83 |
84 | $parameters['sources'] = $addSource;
85 |
86 |
87 |
88 | }
89 |
90 | public static function getBirthdayEvents($params) {
91 |
92 | if(\OCP\Config::getUserValue(\OCP\USER::getUser(), 'calendarplus','calendar_birthday_'. \OCP\USER::getUser())){
93 |
94 | $name = $params['calendar_id'];
95 |
96 | if (strpos($name, 'birthday_') != 0) {
97 | return;
98 | }
99 |
100 | $info = explode('_', $name);
101 | $aid = $info[1];
102 | $aDefNArray=array('0'=>'fname','1'=>'lname','3'=>'title','4'=>'');
103 |
104 | foreach(Addressbook::all($aid) as $addressbook) {
105 |
106 | foreach(VCard::all($addressbook['id']) as $contact) {
107 | try {
108 | $vcard = VObject\Reader::read($contact['carddata']);
109 | } catch (Exception $e) {
110 | continue;
111 | }
112 |
113 |
114 | $birthday = $vcard->BDAY;
115 |
116 | if ((string)$birthday) {
117 | $details = VCard::structureContact($vcard);
118 |
119 | $BirthdayTemp = new \DateTime($birthday);
120 | $checkForm=$BirthdayTemp->format('d-m-Y');
121 | $temp=explode('-',$checkForm);
122 | $getAge=self::getAge($temp[2],$temp[1],$temp[0]);
123 | //$getAge=$BirthdayTemp->format('d-m-Y');
124 | $title=isset($vcard->FN)?strtr($vcard->FN->getValue(), array('\,' => ',', '\;' => ';')):'';
125 |
126 | $sNameOutput='';
127 | if(isset($details['N'][0]['value']) && count($details['N'][0]['value'])>0){
128 | foreach($details['N'][0]['value'] as $key => $val){
129 | if($val!='') {
130 | $aNameOutput[$aDefNArray[$key]]=$val;
131 |
132 | }
133 | }
134 | //$sNameOutput=isset($aNameOutput['title'])?$aNameOutput['title'].' ':'';
135 | $sNameOutput.=isset($aNameOutput['lname'])?$aNameOutput['lname'].' ':'';
136 | $sNameOutput.=isset($aNameOutput['fname'])?$aNameOutput['fname'].' ':'';
137 |
138 | unset($aNameOutput);
139 | }
140 | if($sNameOutput=='') {$sNameOutput=$title;}
141 |
142 | $sTitle1 =(string)App::$l10n->t('%1$s (%2$s)',array($sNameOutput,$getAge));
143 |
144 |
145 | $aktYear=$BirthdayTemp->format('d-m');
146 | $aktYear=$aktYear.date('-Y');
147 | $start = new \DateTime($aktYear);
148 | $end = new \DateTime($aktYear.' +1 day');
149 |
150 | $vcalendar = new VObject\Component\VCalendar();
151 | $vevent = $vcalendar->createComponent('VEVENT');
152 | $vevent->add('DTSTART');
153 | $vevent->DTSTART->setDateTime(
154 | $start
155 | );
156 | $vevent->DTSTART['VALUE'] = 'date';
157 | $vevent->add('DTEND');
158 | $vevent->DTEND->setDateTime(
159 | $end
160 | );
161 | $vevent->DTEND['VALUE'] = 'date';
162 | $vevent->{'SUMMARY'} = (string)$sTitle1;
163 | $vevent->{'UID'} = substr(md5(rand().time()), 0, 10);
164 |
165 |
166 |
167 |
168 | // DESCRIPTION?
169 | $aktYear1=$BirthdayTemp->format('-m-d');
170 | $aktYear1=date('Y').$aktYear1;
171 | $params['events'][] = array(
172 | 'id' => 0,//$card['id'],
173 | 'vevent' => $vevent,
174 | 'repeating' => true,
175 | 'calendarid'=>$params['calendar_id'],
176 | 'privat'=>false,
177 | 'bday'=>true,
178 | 'shared'=>false,
179 | 'isalarm'=>false,
180 | 'summary' =>$sTitle1,
181 | 'start' => $aktYear1,
182 | 'allDay'=>true,
183 | 'startlist' =>$aktYear1,
184 | 'editable' => false,
185 | 'className' => 'birthdayevent',
186 | 'startEditable ' => false,
187 | 'durationEditable ' => false,
188 | );
189 | }
190 | }
191 | }
192 | }
193 | return true;
194 | }
195 |
196 | public static function getAge ($y, $m, $d) {
197 | return date('Y') - $y - (date('n') < (ltrim($m,'0') + (date('j') < ltrim($d,'0'))));
198 | }
199 | }
--------------------------------------------------------------------------------
/lib/search/provider.php:
--------------------------------------------------------------------------------
1 | .
17 | *
18 | */
19 |
20 | namespace OCA\ContactsPlus\Search;
21 |
22 | use \OCA\ContactsPlus\Addressbook;
23 | use \OCA\ContactsPlus\App as ContactsApp;
24 | use \OCA\ContactsPlus\VCard;
25 | /**
26 | * Provide search results from the 'calendar' app
27 | */
28 | class Provider extends \OCP\Search\Provider {
29 |
30 | /**
31 | *
32 | * @param string $query
33 | * @return \OCP\Search\Result
34 | */
35 | function search($query) {
36 | $unescape = function($value) {
37 | return strtr($value, array('\,' => ',', '\;' => ';'));
38 | };
39 |
40 | $searchresults = array( );
41 | $results = ContactsApp::searchProperties($query);
42 | $l = \OC::$server->getL10N(ContactsApp::$appname);
43 |
44 | foreach($results as $result) {
45 | $vcard = VCard::find($result['id']);
46 |
47 | $link = '#'.intval($vcard['id']);
48 |
49 | $props = '';
50 |
51 |
52 | foreach(array('EMAIL', 'NICKNAME', 'ORG','TEL') as $searchvar) {
53 | if(isset($result['name']) && $searchvar == $result['name']) {
54 | //\OCP\Util::writeLog(ContactsApp::$appname,'FOUND id: ' . $result['value'], \OCP\Util::DEBUG);
55 | $props .= $searchvar.':'.$result['value'].' ';
56 | }
57 | }
58 |
59 |
60 | $returnData['id']=$vcard['id'];
61 | $returnData['description']=$vcard['fullname'].' '.$props;
62 | $returnData['link']=$link;
63 |
64 | $results[]=new Result($returnData);
65 |
66 |
67 | }
68 | return $results;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/lib/search/result.php:
--------------------------------------------------------------------------------
1 | .
17 | *
18 | */
19 |
20 | namespace OCA\ContactsPlus\Search;
21 |
22 | /**
23 | * A found file
24 | */
25 | class Result extends \OCP\Search\Result {
26 |
27 | /**
28 | * Type name; translated in templates
29 | * @var string
30 | */
31 | public $type = 'contacts';
32 |
33 |
34 | /**
35 | * Create a new file search result
36 | * @param array $data file data given by provider
37 | */
38 | public function __construct(array $data = null) {
39 |
40 | $this->id = $data['id'];
41 | $this->name = $data['description'];
42 | $this->link = $data['link'];
43 | $this->icon = 'fa fa-book';
44 |
45 |
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/lib/share/backend/addressbook.php:
--------------------------------------------------------------------------------
1 |
4 | * This file is licensed under the Affero General Public License version 3 or
5 | * later.
6 | * See the COPYING-README file.
7 | */
8 |
9 | namespace OCA\ContactsPlus\Share\Backend;
10 |
11 | use \OCA\ContactsPlus\Addressbook as AddrBook;
12 | use \OCA\ContactsPlus\App as ContactsApp;
13 | use \OCA\ContactsPlus\VCard;
14 |
15 | class Addressbook implements \OCP\Share_Backend_Collection {
16 | const FORMAT_ADDRESSBOOKS = 1;
17 |
18 | /**
19 | * @brief Get the source of the item to be stored in the database
20 | * @param string Item
21 | * @param string Owner of the item
22 | * @return mixed|array|false Source
23 | *
24 | * Return an array if the item is file dependent, the array needs two keys: 'item' and 'file'
25 | * Return false if the item does not exist for the user
26 | *
27 | * The formatItems() function will translate the source returned back into the item
28 | */
29 | public function isValidSource($itemSource, $uidOwner) {
30 | $addressbook = AddrBook::find( $itemSource );
31 | if( $addressbook === false || $addressbook['userid'] !== $uidOwner) {
32 | return false;
33 | }
34 | return true;
35 | }
36 |
37 | public function isShareTypeAllowed($shareType) {
38 | return true;
39 | }
40 |
41 | /**
42 | * @brief Get a unique name of the item for the specified user
43 | * @param string Item
44 | * @param string|false User the item is being shared with
45 | * @param array|null List of similar item names already existing as shared items
46 | * @return string Target name
47 | *
48 | * This function needs to verify that the user does not already have an item with this name.
49 | * If it does generate a new name e.g. name_#
50 | */
51 | public function generateTarget($itemSource, $shareWith, $exclude = null) {
52 | $addressbook = AddrBook::find( $itemSource );
53 | $user_addressbooks = array();
54 | foreach(AddrBook::all($shareWith) as $user_addressbook) {
55 | $user_addressbooks[] = $user_addressbook['displayname'];
56 | }
57 | $name = $addressbook['displayname'];
58 | $suffix = '';
59 | while (in_array($name.$suffix, $user_addressbooks)) {
60 | $suffix++;
61 | }
62 |
63 | return $name.$suffix;
64 | }
65 |
66 | /**
67 | * @brief Converts the shared item sources back into the item in the specified format
68 | * @param array Shared items
69 | * @param int Format
70 | * @return ?
71 | *
72 | * The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info.
73 | * The key/value pairs included in the share info depend on the function originally called:
74 | * If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source
75 | * If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target
76 | * This function allows the backend to control the output of shared items with custom formats.
77 | * It is only called through calls to the public getItem(s)Shared(With) functions.
78 | */
79 | public function formatItems($items, $format, $parameters = null) {
80 | $addressbooks = array();
81 | if ($format == self::FORMAT_ADDRESSBOOKS) {
82 | foreach ($items as $item) {
83 | $addressbook = AddrBook::find($item['item_source']);
84 | if ($addressbook) {
85 | $addressbook['displayname'] = $item['item_target'];
86 | $addressbook['permissions'] = $item['permissions'];
87 | $addressbooks[] = $addressbook;
88 | }
89 | }
90 | }
91 | return $addressbooks;
92 | }
93 |
94 | public function getChildren($itemSource) {
95 | $query = \OCP\DB::prepare('SELECT `id`, `fullname` FROM `'.ContactsApp::ContactsTable.'` WHERE `addressbookid` = ?');
96 | $result = $query->execute(array($itemSource));
97 | $children = array();
98 | while ($contact = $result->fetchRow()) {
99 | $children[] = array('source' => $contact['id'], 'target' => $contact['fullname']);
100 | }
101 | return $children;
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/lib/share/backend/contact.php:
--------------------------------------------------------------------------------
1 | .
20 | */
21 |
22 | namespace OCA\ContactsPlus\Share\Backend;
23 |
24 | use \OCA\ContactsPlus\Addressbook as AddrBook;
25 | use \OCA\ContactsPlus\App as ContactsApp;
26 | use \OCA\ContactsPlus\VCard;
27 |
28 | class Contact implements \OCP\Share_Backend {
29 |
30 | const FORMAT_CONTACT = 0;
31 |
32 | private static $contact;
33 |
34 | public function isValidSource($itemSource, $uidOwner) {
35 | self::$contact = VCard::find($itemSource);
36 | if (self::$contact) {
37 | return true;
38 | }
39 | return false;
40 | }
41 |
42 | public function generateTarget($itemSource, $shareWith, $exclude = null) {
43 | // TODO Get default addressbook and check for conflicts
44 | return self::$contact['fullname'];
45 | }
46 |
47 | public function isShareTypeAllowed($shareType) {
48 | return true;
49 | }
50 |
51 | public function formatItems($items, $format, $parameters = null) {
52 | $contacts = array();
53 | if ($format == self::FORMAT_CONTACT) {
54 | foreach ($items as $item) {
55 | $contact = VCard::find($item['item_source']);
56 | $contact['fullname'] = $item['item_target'];
57 | $contacts[] = $contact;
58 | }
59 | }
60 | return $contacts;
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/lib/vobject/stringpropertycategories.php:
--------------------------------------------------------------------------------
1 | name;
18 | if ($this->group) {
19 | $str = $this->group . '.' . $this->name;
20 | }
21 |
22 |
23 | $src = array(
24 | ';',
25 | );
26 | $out = array(
27 | ',',
28 | );
29 |
30 | if(is_array($this->value)){
31 | $this->value = implode(',',$this->value);
32 | }
33 |
34 | $value = strtr($this->value, array('\,' => ',', '\;' => ';'));
35 | $str.=':' . str_replace($src, $out, $value);
36 |
37 | $out = '';
38 | while(strlen($str) > 0) {
39 | if (strlen($str) > 75) {
40 | $out .= mb_strcut($str, 0, 75, 'utf-8') . "\r\n";
41 | $str = ' ' . mb_strcut($str, 75, strlen($str), 'utf-8');
42 | } else {
43 | $out .= $str . "\r\n";
44 | $str = '';
45 | break;
46 | }
47 | }
48 |
49 | return $out;
50 |
51 |
52 | }
53 |
54 |
55 | }
--------------------------------------------------------------------------------
/templates/contact.show.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/templates/index.php:
--------------------------------------------------------------------------------
1 |
32 |
33 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
136 |
143 |
144 |
145 |
146 |
149 |
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/templates/part.cropphoto.php:
--------------------------------------------------------------------------------
1 | getCache()->hasKey($_['tmpkey'])) {
3 |
4 | $imgurl='';
5 | ?>
6 |
7 |
27 |
28 | t('The temporary image has been removed from cache.'));
31 | }
32 |
--------------------------------------------------------------------------------
/templates/part.import.php:
--------------------------------------------------------------------------------
1 | '404'));
6 | $file = $_['filename'];
7 | }else{
8 | $file = \OC\Files\Filesystem::file_get_contents($_['path'] . '/' . $_['filename']);
9 | }
10 |
11 | $import = new OCA\Kontakte\Import($file);
12 | $import->setUserID(OCP\User::getUser());
13 | //$newaddressbookname = OCP\Util::sanitizeHTML($import->createAddressbookName());
14 | //$guessedaddressbookname = OCP\Util::sanitizeHTML($import->guessAddressbookName());
15 | $newaddressbookname = '';
16 | $guessedaddressbookname = '';
17 | */
18 | //loading calendars for select box
19 | $newaddressbookname = '';
20 | $guessedaddressbookname = '';
21 | $contacts_options = OCA\ContactsPlus\Addressbook::all(OCP\USER::getUser());
22 |
23 | ?>
24 |
69 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 | .
10 |
11 |
12 |
13 |
14 | ../contactsplus
15 |
16 | ../contactsplus/l10n
17 | ../contactsplus/tests
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/tests/unit/importtest.php:
--------------------------------------------------------------------------------
1 | getCount();
10 | $this->assertEquals(0, $count);
11 | }
12 |
13 | /**
14 | * @expectedException Exception
15 | * @expectedExceptionMessage No user id set
16 | */
17 | public function testImportNoUserId() {
18 | $file = '';
19 | $import = new \OCA\ContactsPlus\Import($file);
20 | $import->import();
21 | }
22 |
23 | }
--------------------------------------------------------------------------------