You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Contacts.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin McCorkell <robin@mccorkell.me.uk>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. /**
  26. * Public interface of ownCloud for apps to use.
  27. * Contacts Class
  28. *
  29. */
  30. // use OCP namespace for all classes that are considered public.
  31. // This means that they should be used by apps instead of the internal ownCloud classes
  32. namespace OCP {
  33. /**
  34. * This class provides access to the contacts app. Use this class exclusively if you want to access contacts.
  35. *
  36. * Contacts in general will be expressed as an array of key-value-pairs.
  37. * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1
  38. *
  39. * Proposed workflow for working with contacts:
  40. * - search for the contacts
  41. * - manipulate the results array
  42. * - createOrUpdate will save the given contacts overwriting the existing data
  43. *
  44. * For updating it is mandatory to keep the id.
  45. * Without an id a new contact will be created.
  46. *
  47. * @deprecated 8.1.0 use methods of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  48. * @since 5.0.0
  49. */
  50. class Contacts {
  51. /**
  52. * This function is used to search and find contacts within the users address books.
  53. * In case $pattern is empty all contacts will be returned.
  54. *
  55. * Example:
  56. * Following function shows how to search for contacts for the name and the email address.
  57. *
  58. * public static function getMatchingRecipient($term) {
  59. * // The API is not active -> nothing to do
  60. * if (!\OCP\Contacts::isEnabled()) {
  61. * return array();
  62. * }
  63. *
  64. * $result = \OCP\Contacts::search($term, array('FN', 'EMAIL'));
  65. * $receivers = array();
  66. * foreach ($result as $r) {
  67. * $id = $r['id'];
  68. * $fn = $r['FN'];
  69. * $email = $r['EMAIL'];
  70. * if (!is_array($email)) {
  71. * $email = array($email);
  72. * }
  73. *
  74. * // loop through all email addresses of this contact
  75. * foreach ($email as $e) {
  76. * $displayName = $fn . " <$e>";
  77. * $receivers[] = array(
  78. * 'id' => $id,
  79. * 'label' => $displayName,
  80. * 'value' => $displayName);
  81. * }
  82. * }
  83. *
  84. * return $receivers;
  85. * }
  86. *
  87. *
  88. * @param string $pattern which should match within the $searchProperties
  89. * @param array $searchProperties defines the properties within the query pattern should match
  90. * @param array $options - for future use. One should always have options!
  91. * @return array an array of contacts which are arrays of key-value-pairs
  92. * @deprecated 8.1.0 use search() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  93. * @since 5.0.0
  94. */
  95. public static function search($pattern, $searchProperties = array(), $options = array()) {
  96. $cm = \OC::$server->getContactsManager();
  97. return $cm->search($pattern, $searchProperties, $options);
  98. }
  99. /**
  100. * This function can be used to delete the contact identified by the given id
  101. *
  102. * @param object $id the unique identifier to a contact
  103. * @param string $address_book_key
  104. * @return bool successful or not
  105. * @deprecated 8.1.0 use delete() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  106. * @since 5.0.0
  107. */
  108. public static function delete($id, $address_book_key) {
  109. $cm = \OC::$server->getContactsManager();
  110. return $cm->delete($id, $address_book_key);
  111. }
  112. /**
  113. * This function is used to create a new contact if 'id' is not given or not present.
  114. * Otherwise the contact will be updated by replacing the entire data set.
  115. *
  116. * @param array $properties this array if key-value-pairs defines a contact
  117. * @param string $address_book_key identifier of the address book in which the contact shall be created or updated
  118. * @return array an array representing the contact just created or updated
  119. * @deprecated 8.1.0 use createOrUpdate() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  120. * @since 5.0.0
  121. */
  122. public static function createOrUpdate($properties, $address_book_key) {
  123. $cm = \OC::$server->getContactsManager();
  124. return $cm->createOrUpdate($properties, $address_book_key);
  125. }
  126. /**
  127. * Check if contacts are available (e.g. contacts app enabled)
  128. *
  129. * @return bool true if enabled, false if not
  130. * @deprecated 8.1.0 use isEnabled() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  131. * @since 5.0.0
  132. */
  133. public static function isEnabled() {
  134. $cm = \OC::$server->getContactsManager();
  135. return $cm->isEnabled();
  136. }
  137. /**
  138. * @param \OCP\IAddressBook $address_book
  139. * @deprecated 8.1.0 use registerAddressBook() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  140. * @since 5.0.0
  141. */
  142. public static function registerAddressBook(\OCP\IAddressBook $address_book) {
  143. $cm = \OC::$server->getContactsManager();
  144. $cm->registerAddressBook($address_book);
  145. }
  146. /**
  147. * @param \OCP\IAddressBook $address_book
  148. * @deprecated 8.1.0 use unregisterAddressBook() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  149. * @since 5.0.0
  150. */
  151. public static function unregisterAddressBook(\OCP\IAddressBook $address_book) {
  152. $cm = \OC::$server->getContactsManager();
  153. $cm->unregisterAddressBook($address_book);
  154. }
  155. /**
  156. * @return array
  157. * @deprecated 8.1.0 use getAddressBooks() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  158. * @since 5.0.0
  159. */
  160. public static function getAddressBooks() {
  161. $cm = \OC::$server->getContactsManager();
  162. return $cm->getAddressBooks();
  163. }
  164. /**
  165. * removes all registered address book instances
  166. * @deprecated 8.1.0 use clear() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  167. * @since 5.0.0
  168. */
  169. public static function clear() {
  170. $cm = \OC::$server->getContactsManager();
  171. $cm->clear();
  172. }
  173. }
  174. }