start.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. elgg_register_event_handler('init', 'system', 'personal_actitivy_init');
  3. /**
  4. * Initalize the plugin
  5. */
  6. function personal_actitivy_init() {
  7. elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'personal_activity_user_hover_menu_setup');
  8. elgg_register_plugin_hook_handler('route', 'activity', 'personal_activity_page_handler');
  9. }
  10. /**
  11. * Add personal activity link to user_hover menu
  12. *
  13. * @param string $hook Hook name
  14. * @param string $type Hook type
  15. * @param ElggMenuItem[] $return Array of ElggMenuItem objects
  16. * @param array $params
  17. * @return ElggMenuItem[] $return Array of ElggMenuItem objects
  18. */
  19. function personal_activity_user_hover_menu_setup($hook, $type, $return, $params) {
  20. if (!elgg_is_logged_in()) {
  21. return $return;
  22. }
  23. $user = $params['entity'];
  24. $return[] = ElggMenuItem::factory(array(
  25. 'name' => 'personal_activity',
  26. 'text' => elgg_echo('personal_activity'),
  27. 'href' => "activity/owner/{$user->username}",
  28. ));
  29. return $return;
  30. }
  31. /**
  32. * Handle requests to activity/owner/<username>
  33. *
  34. * @param string $hook Hook name
  35. * @param string $type Hook type
  36. * @param array $return Array of url segments
  37. * @param array $params
  38. * @return boolean False if the request was handled
  39. */
  40. function personal_activity_page_handler($hook, $type, $return, $params) {
  41. $segments = $return['segments'];
  42. if (isset($segments[0]) && $segments[0] == 'owner') {
  43. $user = get_user_by_username($segments[1]);
  44. // Use default page handler if no user or user is looking at own activity
  45. if (!$user || $user->guid == elgg_get_logged_in_user_guid()) {
  46. return $return;
  47. }
  48. $params['title'] = elgg_echo('personal_activity:owner', array($user->name));
  49. $params['filter_context'] = '';
  50. $params['content'] = elgg_list_river(array(
  51. 'subject_guids' => $user->guid,
  52. ));
  53. if (!$params['content']) {
  54. $params['content'] = elgg_echo('river:none');
  55. }
  56. $body = elgg_view_layout('content', $params);
  57. echo elgg_view_page($params['title'], $body);
  58. return false;
  59. }
  60. return $return;
  61. }