fbss_activity.module

Tracking 6.x-3.x branch
  1. drupal
    1. 6 contributions/facebook_status/submodules/fbss_activity/fbss_activity.module

Integrates Activity 2 with Facebook-style Statuses.

Functions & methods

NameDescription
facebook_status_activity_access_grantsImplementation of hook_activity_access_grants().
facebook_status_activity_grantsImplementation of hook_activity_grants().
facebook_status_activity_infoImplementation of hook_activity_info().
facebook_status_form_activity_form_alterImplementation of hook_form_FORM_ID_alter(). Activity 2.
facebook_status_list_activity_actionsImplementation of hook_list_activity_actions().
facebook_status_load_activity_contextImplementation of hook_load_activity_context().
fbss_activity_facebook_status_deleteImplementation of hook_facebook_status_delete().

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Integrates Activity 2 with Facebook-style Statuses.
  5. */
  6. /**
  7. * Implementation of hook_facebook_status_delete().
  8. */
  9. function fbss_activity_facebook_status_delete($status) {
  10. $result = db_query("SELECT aid FROM {activity} WHERE type = 'facebook_status' AND op NOT LIKE 'fbss_deleted%' AND eid = %d", $status->sid);
  11. $records = array();
  12. while ($record = db_fetch_object($result)) {
  13. $records[] = $record->aid;
  14. }
  15. if (!empty($records)) {
  16. activity_delete($records);
  17. }
  18. }
  19. //=====================================================================================
  20. // Hooks below this line are implemented on behalf of the main facebook_status module.
  21. //=====================================================================================
  22. /**
  23. * Implementation of hook_activity_info().
  24. */
  25. function facebook_status_activity_info() {
  26. $info = new stdClass();
  27. $info->api = 2;
  28. $info->name = 'facebook_status';
  29. $info->object_type = 'facebook_status';
  30. $info->eid_field = 'sid';
  31. $info->objects = array('Recipient' => 'facebook_status', 'Sender' => 'sender');
  32. $hooks = array(
  33. 'fbss_deleted',
  34. 'fbss_deleted_user_self',
  35. 'fbss_deleted_user_other',
  36. 'fbss_edited',
  37. 'fbss_edited_user_self',
  38. 'fbss_edited_user_other',
  39. 'fbss_submitted',
  40. 'fbss_submitted_user_self',
  41. 'fbss_submitted_user_other'
  42. );
  43. foreach (facebook_status_all_contexts() as $type => $details) {
  44. if ($type != 'user') {
  45. $hooks[] = 'fbss_deleted_'. $type;
  46. $hooks[] = 'fbss_edited_'. $type;
  47. $hooks[] = 'fbss_submitted_'. $type;
  48. }
  49. }
  50. sort($hooks);
  51. $info->hooks = array('facebook_status' => $hooks);
  52. $info->realms = array('facebook_status_sender' => 'Facebook-style Statuses Sender', 'facebook_status_recipient' => 'Facebook-style Statuses Recipient');
  53. return $info;
  54. }
  55. /**
  56. * Implementation of hook_activity_grants().
  57. */
  58. function facebook_status_activity_grants($activity) {
  59. $realms = array();
  60. if ($activity->type == 'facebook_status') {
  61. $realms['facebook_status_sender'] = array($activity->uid);
  62. $result = db_fetch_object(db_query("SELECT recipient FROM {facebook_status} WHERE sid = %d", $activity->eid));
  63. $realms['facebook_status_recipient'] = array($result->recipient);
  64. }
  65. return $realms;
  66. }
  67. /**
  68. * Implementation of hook_activity_access_grants().
  69. */
  70. function facebook_status_activity_access_grants($account) {
  71. return array(
  72. 'facebook_status_sender' => array($account->uid),
  73. 'facebook_status_recipient' => array($account->uid),
  74. );
  75. }
  76. /**
  77. * Implementation of hook_list_activity_actions().
  78. */
  79. function facebook_status_list_activity_actions($hook, $op, $max_age) {
  80. $actions = array();
  81. if (!empty($max_age)) {
  82. $min_time = time() - $max_age;
  83. }
  84. else {
  85. $min_time = 0;
  86. }
  87. if ($op == 'fbss_submitted_user_self') {
  88. $result = db_query(
  89. "SELECT sid as id, created, sender as actor FROM {facebook_status} WHERE created > %d AND type = 'user' AND sender = recipient",
  90. $min_time
  91. );
  92. }
  93. elseif ($op == 'fbss_submitted_user_other') {
  94. $result = db_query(
  95. "SELECT sid as id, created, sender as actor FROM {facebook_status} WHERE created > %d AND type = 'user' AND sender <> recipient",
  96. $min_time
  97. );
  98. }
  99. elseif (strpos($op, 'fbss_submitted_') === 0) {
  100. foreach (facebook_status_all_contexts() as $type => $details) {
  101. if ($op == 'fbss_submitted_'. $type) {
  102. $result = db_query(
  103. "SELECT sid as id, created, sender as actor FROM {facebook_status} WHERE created > %d AND type = '%s'",
  104. $min_time,
  105. $type
  106. );
  107. break;
  108. }
  109. }
  110. }
  111. if (isset($result)) {
  112. while ($row = db_fetch_array($result)) {
  113. $actions[] = $row;
  114. }
  115. }
  116. return $actions;
  117. }
  118. /**
  119. * Implementation of hook_load_activity_context().
  120. */
  121. function facebook_status_load_activity_context($hook, $op, $id) {
  122. $status = facebook_status_load($id);
  123. $activity_context = array();
  124. if (!empty($status)) {
  125. $context = facebook_status_determine_context($status->type);
  126. $recipient = $context['handler']->load_recipient($status->recipient);
  127. $sender = _facebook_status_user_load($status->sender);
  128. // Reduce the amount of recalculation we will need to do later.
  129. $sender->facebook_status = $status;
  130. $sender->context = $context;
  131. $activity_context = array(
  132. 'hook' => 'facebook_status',
  133. 'op' => $op,
  134. 'sender' => $sender,
  135. 'recipient' => $recipient,
  136. 'type' => $status->type,
  137. 'facebook_status' => $status,
  138. 'context' => $context,
  139. );
  140. }
  141. return $activity_context;
  142. }
  143. /**
  144. * Implementation of hook_form_FORM_ID_alter().
  145. * Activity 2.
  146. */
  147. function facebook_status_form_activity_form_alter(&$form, &$form_state) {
  148. if ($form_state['storage']['values']['triggers']['hook'] == 'facebook_status') {
  149. $op = $form_state['storage']['values']['operations']['operation'];
  150. // Remove the "Recipient" field unless this is for a user posting a message to another user.
  151. if ($op != 'fbss_submitted_user_other' && $op != 'fbss_edited_user_other' && $op != 'fbss_deleted_user_other') {
  152. foreach (activity_enabled_languages() as $id => $language) {
  153. unset($form[$id .'_fieldset']['facebook_status-pattern-'. $id]);
  154. }
  155. }
  156. }
  157. }