start.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace AU\SuggestedFriends;
  3. const PLUGIN_ID = 'suggested_friends';
  4. require_once __DIR__ . '/lib/functions.php';
  5. require_once __DIR__ . '/lib/events.php';
  6. elgg_register_event_handler('init', 'system', __NAMESPACE__ . '\\init');
  7. /**
  8. * plugin init
  9. */
  10. function init() {
  11. elgg_extend_view('css/elgg', 'css/suggested_friends');
  12. elgg_register_page_handler('suggested_friends', __NAMESPACE__ . '\\suggested_friends_page_handler');
  13. elgg_register_widget_type('suggested_friends', elgg_echo('suggested_friends:people:you:may:know'), elgg_echo('suggested_friends:widget:description'), array('dashboard', 'profile'));
  14. elgg_register_event_handler('pagesetup', 'system', __NAMESPACE__ . '\\pagesetup');
  15. elgg_load_js('lightbox');
  16. elgg_load_css('lightbox');
  17. elgg_register_ajax_view('suggested_friends/mutual');
  18. elgg_register_ajax_view('suggested_friends/groups');
  19. }
  20. /**
  21. * server our pages through resource views
  22. *
  23. * @param type $page
  24. * @return boolean
  25. */
  26. function suggested_friends_page_handler($page) {
  27. elgg_gatekeeper();
  28. $friends = $groups = 0;
  29. switch ($page[0]) {
  30. case 'friends':
  31. $friends = 10;
  32. break;
  33. case 'groups':
  34. $groups = 10;
  35. break;
  36. default:
  37. $friends = $groups = 10;
  38. break;
  39. }
  40. $page_owner = elgg_get_logged_in_user_entity();
  41. elgg_set_page_owner_guid($page_owner->guid);
  42. $content = elgg_view('resources/suggested_friends/list', array(
  43. 'owner' => $page_owner,
  44. 'friends' => $friends,
  45. 'groups' => $groups
  46. ));
  47. if ($content) {
  48. echo $content;
  49. return true;
  50. }
  51. return false;
  52. }