contactdetails.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * ownCloud - Addressbook
  4. *
  5. * @author Thomas Tanghus
  6. * @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. // Init owncloud
  23. function bailOut($msg) {
  24. OCP\JSON::error(array('data' => array('message' => $msg)));
  25. OCP\Util::writeLog('contacts','ajax/contactdetails.php: '.$msg, OCP\Util::DEBUG);
  26. exit();
  27. }
  28. // Check if we are a user
  29. OCP\JSON::checkLoggedIn();
  30. OCP\JSON::checkAppEnabled('contacts');
  31. $id = isset($_GET['id'])?$_GET['id']:null;
  32. if(is_null($id)) {
  33. bailOut(OC_Contacts_App::$l10n->t('Missing ID'));
  34. }
  35. $vcard = OC_Contacts_App::getContactVCard( $id );
  36. if(is_null($vcard)) {
  37. bailOut(OC_Contacts_App::$l10n->t('Error parsing VCard for ID: "'.$id.'"'));
  38. }
  39. $details = OC_Contacts_VCard::structureContact($vcard);
  40. // Some Google exported files have no FN field.
  41. /*if(!isset($details['FN'])) {
  42. $fn = '';
  43. if(isset($details['N'])) {
  44. $details['FN'] = array(implode(' ', $details['N'][0]['value']));
  45. } elseif(isset($details['EMAIL'])) {
  46. $details['FN'] = array('value' => $details['EMAIL'][0]['value']);
  47. } else {
  48. $details['FN'] = array('value' => OC_Contacts_App::$l10n->t('Unknown'));
  49. }
  50. }*/
  51. // Make up for not supporting the 'N' field in earlier version.
  52. if(!isset($details['N'])) {
  53. $details['N'] = array();
  54. $details['N'][0] = array($details['FN'][0]['value'],'','','','');
  55. }
  56. // Don't wanna transfer the photo in a json string.
  57. if(isset($details['PHOTO'])) {
  58. $details['PHOTO'] = true;
  59. //unset($details['PHOTO']);
  60. } else {
  61. $details['PHOTO'] = false;
  62. }
  63. $details['id'] = $id;
  64. OC_Contacts_App::setLastModifiedHeader($vcard);
  65. OCP\JSON::success(array('data' => $details));