notification.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * ElggNotification view.
  4. *
  5. * @package Notifier
  6. */
  7. $notification = $vars['entity'];
  8. // Ignore access to make e.g. a hidden group visible in membership invitation
  9. // TODO Find an alternate approach that doesn't risk security
  10. $ia = elgg_set_ignore_access(true);
  11. $target = $notification->getTarget();
  12. elgg_set_ignore_access($ia);
  13. $subjects = $notification->getSubjects();
  14. $subject = $notification->getSubject();
  15. if (empty($target) || empty($subjects)) {
  16. $title = $notification->title;
  17. $event = $notification->event;
  18. $subject = $subject->username;
  19. $user = $notification->getOwnerEntity()->username;
  20. error_log("NOTICE: Failed to view notification $title ($event) from user $subject to user $user");
  21. // The notification is useless with missing information, so it can be deleted
  22. $notification->delete();
  23. return false;
  24. }
  25. $vars['target'] = $target;
  26. $vars['subject'] = $subject;
  27. $vars['subjects'] = $subjects;
  28. $vars['notification'] = $notification;
  29. $event_view = str_replace(':', '/', $notification->event);
  30. $view = "notifier/messages/$event_view";
  31. if (elgg_view_exists($view)) {
  32. // Use special view for this notification type
  33. $subtitle = elgg_view($view, $vars);
  34. } else {
  35. $subtitle = elgg_view('notifier/messages/create/default', $vars);
  36. }
  37. $time = elgg_view_friendly_time($notification->time_created);
  38. if (elgg_in_context('widgets')) {
  39. // Do not show the delete link in widget view
  40. $metadata = '';
  41. } else {
  42. // Use link instead of entity menu since we don't want any links besides delete
  43. $metadata = elgg_view('output/url', array(
  44. 'name' => 'delete',
  45. 'href' => "action/notifier/delete?guid={$notification->getGUID()}",
  46. 'text' => elgg_view_icon('delete'),
  47. 'data-confirm' => elgg_echo('question:areyousure'),
  48. 'is_action' => true,
  49. 'class' => 'float-alt',
  50. ));
  51. }
  52. $icon = elgg_view_entity_icon($subject, 'tiny');
  53. if ($notification->status === 'unread') {
  54. $vars['class'] = 'elgg-notifier-unread';
  55. }
  56. $params = array(
  57. 'entity' => $notification,
  58. 'title' => false,
  59. 'metadata' => $metadata,
  60. 'subtitle' => "$subtitle $time",
  61. );
  62. $params = $params + $vars;
  63. $body = elgg_view('object/elements/summary', $params);
  64. echo elgg_view_image_block($icon, $body, $vars);