start.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * Members plugin initialization
  4. *
  5. * To adding a list page, handle the hook (members:list, <page_name>) and return the HTML for the list.
  6. *
  7. * To alter the navigation tabs, use the hook (members:config, tabs) which receives the array used to build them.
  8. */
  9. elgg_register_event_handler('init', 'system', 'members_init');
  10. /**
  11. * Initialize page handler and site menu item
  12. */
  13. function members_init() {
  14. elgg_register_page_handler('members', 'members_page_handler');
  15. $item = new ElggMenuItem('members', elgg_echo('members'), 'members');
  16. elgg_register_menu_item('site', $item);
  17. /*$list_types = array('newest', 'popular', 'online');
  18. foreach ($list_types as $type) {
  19. elgg_register_plugin_hook_handler('members:list', $type, "members_list_$type");
  20. elgg_register_plugin_hook_handler('members:config', 'tabs', "members_nav_$type");
  21. }*/
  22. }
  23. /**
  24. * Returns content for the "popular" page
  25. *
  26. * @param string $hook "members:list"
  27. * @param string $type "popular"
  28. * @param string|null $returnvalue list content (null if not set)
  29. * @param array $params array with key "options"
  30. * @return string
  31. */
  32. function members_list_popular($hook, $type, $returnvalue, $params) {
  33. if ($returnvalue !== null) {
  34. return;
  35. }
  36. $options = $params['options'];
  37. $options['relationship'] = 'friend';
  38. $options['inverse_relationship'] = false;
  39. return elgg_list_entities_from_relationship_count($options);
  40. }
  41. /**
  42. * Returns content for the "newest" page
  43. *
  44. * @param string $hook "members:list"
  45. * @param string $type "newest"
  46. * @param string|null $returnvalue list content (null if not set)
  47. * @param array $params array with key "options"
  48. * @return string
  49. */
  50. function members_list_newest($hook, $type, $returnvalue, $params) {
  51. if ($returnvalue !== null) {
  52. return;
  53. }
  54. return elgg_list_entities($params['options']);
  55. }
  56. /**
  57. * Returns content for the "online" page
  58. *
  59. * @param string $hook "members:list"
  60. * @param string $type "online"
  61. * @param string|null $returnvalue list content (null if not set)
  62. * @param array $params array with key "options"
  63. * @return string
  64. */
  65. function members_list_online($hook, $type, $returnvalue, $params) {
  66. if ($returnvalue !== null) {
  67. return;
  68. }
  69. return get_online_users();
  70. }
  71. /**
  72. * Appends "popular" tab to the navigation
  73. *
  74. * @param string $hook "members:config"
  75. * @param string $type "tabs"
  76. * @param array $returnvalue array that build navigation tabs
  77. * @param array $params unused
  78. * @return array
  79. */
  80. function members_nav_popular($hook, $type, $returnvalue, $params) {
  81. $returnvalue['popular'] = array(
  82. 'title' => elgg_echo('sort:popular'),
  83. 'url' => "members/popular",
  84. );
  85. return $returnvalue;
  86. }
  87. /**
  88. * Appends "newest" tab to the navigation
  89. *
  90. * @param string $hook "members:config"
  91. * @param string $type "tabs"
  92. * @param array $returnvalue array that build navigation tabs
  93. * @param array $params unused
  94. * @return array
  95. */
  96. function members_nav_newest($hook, $type, $returnvalue, $params) {
  97. $returnvalue['newest'] = array(
  98. 'title' => elgg_echo('sort:newest'),
  99. 'url' => "members",
  100. );
  101. return $returnvalue;
  102. }
  103. /**
  104. * Appends "online" tab to the navigation
  105. *
  106. * @param string $hook "members:config"
  107. * @param string $type "tabs"
  108. * @param array $returnvalue array that build navigation tabs
  109. * @param array $params unused
  110. * @return array
  111. */
  112. function members_nav_online($hook, $type, $returnvalue, $params) {
  113. $returnvalue['online'] = array(
  114. 'title' => elgg_echo('members:label:online'),
  115. 'url' => "members/online",
  116. );
  117. return $returnvalue;
  118. }
  119. /**
  120. * Appends "suggested friends" tab to the navigation
  121. */
  122. function members_nav_suggested($hook, $type, $returnvalue, $params) {
  123. $returnvalue['suggested'] = array(
  124. 'title' => elgg_echo('members:label:suggested'),
  125. 'url' => "suggested_friends",
  126. );
  127. return $returnvalue;
  128. }
  129. /**
  130. * Members page handler
  131. *
  132. * @param array $page url segments
  133. * @return bool
  134. */
  135. function members_page_handler($page) {
  136. $base = elgg_get_plugins_path() . 'members/pages/members';
  137. if (empty($page[0])) {
  138. $page[0] = 'newest';
  139. }
  140. $vars = array();
  141. $vars['page'] = $page[0];
  142. if ($page[0] == 'search') {
  143. $vars['search_type'] = $page[1];
  144. require_once "$base/search.php";
  145. } else {
  146. require_once "$base/index.php";
  147. }
  148. return true;
  149. }