/tine20/Addressbook/Convert/Contact/VCard/Sogo.php

https://gitlab.com/rsilveira1987/Expresso · PHP · 152 lines · 75 code · 27 blank · 50 comment · 4 complexity · b99fbb73d5a3c4cde43cfe2960c4b827 MD5 · raw file

  1. <?php
  2. /**
  3. * Tine 2.0
  4. *
  5. * @package Addressbook
  6. * @subpackage Convert
  7. * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
  8. * @author Lars Kneschke <l.kneschke@metaways.de>
  9. * @copyright Copyright (c) 2011-2013 Metaways Infosystems GmbH (http://www.metaways.de)
  10. *
  11. */
  12. /**
  13. * class to convert a SOGO vcard to contact model and back again
  14. *
  15. * @package Addressbook
  16. * @subpackage Convert
  17. */
  18. class Addressbook_Convert_Contact_VCard_Sogo extends Addressbook_Convert_Contact_VCard_Abstract
  19. {
  20. // Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.21) Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13
  21. // Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130529 Icedove/17.0.5
  22. const HEADER_MATCH = '/ (Thunderbird|Icedove)\/(?P<version>.*)/';
  23. protected $_emptyArray = array(
  24. 'adr_one_countryname' => null,
  25. 'adr_one_locality' => null,
  26. 'adr_one_postalcode' => null,
  27. 'adr_one_region' => null,
  28. 'adr_one_street' => null,
  29. 'adr_one_street2' => null,
  30. 'adr_two_countryname' => null,
  31. 'adr_two_locality' => null,
  32. 'adr_two_postalcode' => null,
  33. 'adr_two_region' => null,
  34. 'adr_two_street' => null,
  35. 'adr_two_street2' => null,
  36. #'assistent' => null,
  37. 'bday' => null,
  38. #'calendar_uri' => null,
  39. 'email' => null,
  40. 'email_home' => null,
  41. 'jpegphoto' => null,
  42. #'freebusy_uri' => null,
  43. 'note' => null,
  44. #'role' => null,
  45. #'salutation' => null,
  46. 'title' => null,
  47. 'url' => null,
  48. 'url_home' => null,
  49. 'n_family' => null,
  50. 'n_fileas' => null,
  51. #'n_fn' => null,
  52. 'n_given' => null,
  53. #'n_middle' => null,
  54. #'n_prefix' => null,
  55. #'n_suffix' => null,
  56. 'org_name' => null,
  57. 'org_unit' => null,
  58. #'pubkey' => null,
  59. #'room' => null,
  60. #'tel_assistent' => null,
  61. #'tel_car' => null,
  62. 'tel_cell' => null,
  63. #'tel_cell_private' => null,
  64. 'tel_fax' => null,
  65. #'tel_fax_home' => null,
  66. 'tel_home' => null,
  67. 'tel_pager' => null,
  68. 'tel_work' => null,
  69. #'tel_other' => null,
  70. #'tel_prefer' => null,
  71. #'tz' => null,
  72. #'geo' => null,
  73. #'lon' => null,
  74. #'lat' => null,
  75. 'tags' => null,
  76. 'notes' => null,
  77. );
  78. /**
  79. * (non-PHPdoc)
  80. * @see Addressbook_Convert_Contact_VCard_Abstract::toTine20Model()
  81. */
  82. public function toTine20Model($_blob, Tinebase_Record_Abstract $_record = null, $options = array())
  83. {
  84. $contact = parent::toTine20Model($_blob, $_record, $options);
  85. if (!empty($contact->url)) {
  86. $contact->url = strtr($contact->url, array('http\:' => 'http:'));
  87. }
  88. if (!empty($contact->url_home)) {
  89. $contact->url_home = strtr($contact->url_home, array('http\:' => 'http:'));
  90. }
  91. return $contact;
  92. }
  93. /**
  94. * converts Addressbook_Model_Contact to vcard
  95. *
  96. * @param Addressbook_Model_Contact $_record
  97. * @return string
  98. */
  99. public function fromTine20Model(Tinebase_Record_Abstract $_record)
  100. {
  101. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG))
  102. Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' contact ' . print_r($_record->toArray(), true));
  103. // initialize vcard object
  104. $card = $this->_fromTine20ModelRequiredFields($_record);
  105. $card->add('TEL', $_record->tel_work, array('TYPE' => 'WORK'));
  106. $card->add('TEL', $_record->tel_home, array('TYPE' => 'HOME'));
  107. $card->add('TEL', $_record->tel_cell, array('TYPE' => 'CELL'));
  108. $card->add('TEL', $_record->tel_fax, array('TYPE' => 'FAX'));
  109. $card->add('TEL', $_record->tel_pager, array('TYPE' => 'PAGER'));
  110. $card->add('ADR', array(null, $_record->adr_one_street2, $_record->adr_one_street, $_record->adr_one_locality, $_record->adr_one_region, $_record->adr_one_postalcode, $_record->adr_one_countryname), array('TYPE' => 'WORK'));
  111. $card->add('ADR', array(null, $_record->adr_two_street2, $_record->adr_two_street, $_record->adr_two_locality, $_record->adr_two_region, $_record->adr_two_postalcode, $_record->adr_two_countryname), array('TYPE' => 'HOME'));
  112. $card->add('EMAIL', $_record->email, array('TYPE' => 'WORK'));
  113. $card->add('EMAIL', $_record->email_home, array('TYPE' => 'HOME'));
  114. $card->add('URL', $_record->url, array('TYPE' => 'WORK'));
  115. $card->add('URL', $_record->url_home, array('TYPE' => 'HOME'));
  116. $card->add('NOTE', $_record->note);
  117. $this->_fromTine20ModelAddBirthday($_record, $card);
  118. $this->_fromTine20ModelAddPhoto($_record, $card);
  119. $this->_fromTine20ModelAddGeoData($_record, $card);
  120. $this->_fromTine20ModelAddCategories($_record, $card);
  121. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG))
  122. Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' card ' . $card->serialize());
  123. return $card;
  124. }
  125. }