hooks.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * ownCloud - Addressbook
  4. *
  5. * @author Jakob Sack
  6. * @copyright 2011 Jakob Sack mail@jakobsack.de
  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. /**
  23. * This class contains all hooks.
  24. */
  25. class OC_Contacts_Hooks{
  26. /**
  27. * @brief Add default Addressbook for a certain user
  28. * @param paramters parameters from postCreateUser-Hook
  29. * @return array
  30. */
  31. static public function createUser($parameters) {
  32. OC_Contacts_Addressbook::add($parameters['uid'],'default','Default Address Book');
  33. return true;
  34. }
  35. /**
  36. * @brief Deletes all Addressbooks of a certain user
  37. * @param paramters parameters from postDeleteUser-Hook
  38. * @return array
  39. */
  40. static public function deleteUser($parameters) {
  41. $addressbooks = OC_Contacts_Addressbook::all($parameters['uid']);
  42. foreach($addressbooks as $addressbook) {
  43. OC_Contacts_Addressbook::delete($addressbook['id']);
  44. }
  45. return true;
  46. }
  47. static public function getCalenderSources($parameters) {
  48. $base_url = OCP\Util::linkTo('calendar', 'ajax/events.php').'?calendar_id=';
  49. foreach(OC_Contacts_Addressbook::all(OCP\USER::getUser()) as $addressbook) {
  50. $parameters['sources'][] =
  51. array(
  52. 'url' => $base_url.'birthday_'. $addressbook['id'],
  53. 'backgroundColor' => '#cccccc',
  54. 'borderColor' => '#888',
  55. 'textColor' => 'black',
  56. 'cache' => true,
  57. 'editable' => false,
  58. );
  59. }
  60. }
  61. static public function getBirthdayEvents($parameters) {
  62. $name = $parameters['calendar_id'];
  63. if (strpos('birthday_', $name) != 0) {
  64. return;
  65. }
  66. $info = explode('_', $name);
  67. $aid = $info[1];
  68. OC_Contacts_App::getAddressbook($aid);
  69. foreach(OC_Contacts_VCard::all($aid) as $card){
  70. $vcard = OC_VObject::parse($card['carddata']);
  71. if (!$vcard) {
  72. continue;
  73. }
  74. $birthday = $vcard->BDAY;
  75. if ($birthday) {
  76. $date = new DateTime($birthday);
  77. $vevent = new OC_VObject('VEVENT');
  78. $vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
  79. $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
  80. $vevent->setString('DURATION', 'P1D');
  81. // DESCRIPTION?
  82. $vevent->setString('RRULE', 'FREQ=YEARLY');
  83. $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
  84. $parameters['events'][] = array(
  85. 'id' => 0,//$card['id'],
  86. 'vevent' => $vevent,
  87. 'repeating' => true,
  88. 'summary' => $title,
  89. );
  90. }
  91. }
  92. }
  93. }