start.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. /**
  3. * Start file for this plugin
  4. */
  5. // define for default group access
  6. define("GROUP_TOOLS_GROUP_ACCESS_DEFAULT", -10);
  7. require_once(dirname(__FILE__) . "/lib/functions.php");
  8. require_once(dirname(__FILE__) . "/lib/events.php");
  9. require_once(dirname(__FILE__) . "/lib/hooks.php");
  10. require_once(dirname(__FILE__) . "/lib/page_handlers.php");
  11. // default elgg event handlers
  12. elgg_register_event_handler("init", "system", "group_tools_init");
  13. elgg_register_event_handler("ready", "system", "group_tools_ready");
  14. elgg_register_event_handler("pagesetup", "system", "group_tools_pagesetup", 550);
  15. /**
  16. * called when the Elgg system get initialized
  17. *
  18. * @return void
  19. */
  20. function group_tools_init() {
  21. // extend css & js
  22. elgg_extend_view("css/elgg", "css/group_tools/site");
  23. elgg_extend_view("css/admin", "css/group_tools/admin");
  24. elgg_extend_view("js/elgg", "js/group_tools/site");
  25. elgg_extend_view("js/admin", "js/group_tools/admin");
  26. // extend page handlers
  27. elgg_register_plugin_hook_handler("route", "groups", "group_tools_route_groups_handler");
  28. elgg_register_plugin_hook_handler("route", "livesearch", "group_tools_route_livesearch_handler");
  29. elgg_register_page_handler("groupicon", "group_tools_groupicon_page_handler");
  30. elgg_register_plugin_hook_handler("entity:icon:url", "group", "groups_tools_group_icon_url_handler");
  31. // hook on title menu
  32. elgg_register_plugin_hook_handler("register", "menu:title", "group_tools_menu_title_handler");
  33. elgg_register_plugin_hook_handler("register", "menu:user_hover", "group_tools_menu_user_hover_handler");
  34. elgg_register_plugin_hook_handler("register", "menu:entity", "group_tools_menu_entity_handler");
  35. elgg_register_plugin_hook_handler("register", "menu:filter", "group_tools_menu_filter_handler");
  36. if (group_tools_multiple_admin_enabled()) {
  37. // add group tool option
  38. add_group_tool_option("group_multiple_admin_allow", elgg_echo("group_tools:multiple_admin:group_tool_option"), false);
  39. // register permissions check hook
  40. elgg_register_plugin_hook_handler("permissions_check", "group", "group_tools_multiple_admin_can_edit_hook");
  41. // register on group leave
  42. elgg_register_event_handler("leave", "group", "group_tools_multiple_admin_group_leave");
  43. //notify admin on membership request
  44. elgg_register_event_handler("create", "membership_request", "group_tools_membership_request");
  45. }
  46. // register group activity widget
  47. // 2012-05-03: restored limited functionality of group activity widget, will be fully restored if Elgg fixes widget settings
  48. elgg_register_widget_type("group_river_widget", elgg_echo("widgets:group_river_widget:title"), elgg_echo("widgets:group_river_widget:description"), array("dashboard", "profile", "index", "groups"), true);
  49. // register group members widget
  50. elgg_register_widget_type("group_members", elgg_echo("widgets:group_members:title"), elgg_echo("widgets:group_members:description"), array("groups"), false);
  51. // register groups invitations widget
  52. elgg_register_widget_type("group_invitations", elgg_echo("widgets:group_invitations:title"), elgg_echo("widgets:group_invitations:description"), array("index", "dashboard"), false);
  53. // register featured groups widget
  54. elgg_register_widget_type("featured_groups", elgg_echo("groups:featured"), elgg_echo("widgets:featured_groups:description"), array("index"));
  55. // register index groups widget
  56. elgg_register_widget_type("index_groups", elgg_echo("groups"), elgg_echo("widgets:index_groups:description"), array("index"), true);
  57. // quick start discussion
  58. elgg_register_widget_type("start_discussion", elgg_echo("group_tools:widgets:start_discussion:title"), elgg_echo("group_tools:widgets:start_discussion:description"), array("index", "dashboard", "groups"));
  59. // group invitation
  60. elgg_register_action("groups/invite", dirname(__FILE__) . "/actions/groups/invite.php");
  61. // manage auto join for groups
  62. elgg_extend_view("groups/edit", "group_tools/forms/special_states", 350);
  63. elgg_register_event_handler("create", "member_of_site", "group_tools_join_site_handler");
  64. // show group edit as tabbed
  65. elgg_extend_view("groups/edit", "group_tools/group_edit_tabbed", 1);
  66. elgg_extend_view("groups/edit", "group_tools/group_edit_tabbed_js", 999999999);
  67. // show group profile widgets - edit form
  68. elgg_extend_view("groups/edit", "group_tools/forms/profile_widgets", 400);
  69. // cleanup group side menu
  70. elgg_extend_view("groups/edit", "group_tools/forms/cleanup", 450);
  71. // group notifications
  72. elgg_extend_view("groups/edit", "group_tools/forms/notifications", 375);
  73. // allow group members to invite new members
  74. elgg_extend_view("groups/edit", "group_tools/forms/invite_members", 475);
  75. // configure a group welcome message
  76. elgg_extend_view("groups/edit", "group_tools/forms/welcome_message");
  77. // configure domain based group join
  78. elgg_extend_view("groups/edit", "group_tools/forms/domain_based");
  79. // show group status in owner block
  80. elgg_extend_view("page/elements/owner_block/extend", "group_tools/owner_block");
  81. // show group status in stats (on group profile)
  82. elgg_extend_view("groups/profile/summary", "group_tools/group_stats");
  83. if (elgg_is_active_plugin("blog")) {
  84. elgg_register_widget_type("group_news", elgg_echo("widgets:group_news:title"), elgg_echo("widgets:group_news:description"), array("profile", "index", "dashboard"), true);
  85. elgg_extend_view("css/elgg", "widgets/group_news/css");
  86. }
  87. // related groups
  88. add_group_tool_option("related_groups", elgg_echo("groups_tools:related_groups:tool_option"), false);
  89. elgg_extend_view("groups/tool_latest", "group_tools/modules/related_groups");
  90. elgg_register_widget_type("group_related", elgg_echo("groups_tools:related_groups:widget:title"), elgg_echo("groups_tools:related_groups:widget:description"), array("groups"));
  91. // registration
  92. elgg_extend_view("register/extend", "group_tools/register_extend");
  93. // theme sandbox
  94. elgg_extend_view("theme_sandbox/forms", "group_tools/theme_sandbox/grouppicker");
  95. // register index widget to show latest discussions
  96. elgg_register_widget_type("discussion", elgg_echo("discussion:latest"), elgg_echo("widgets:discussion:description"), array("index", "dashboard"), true);
  97. elgg_register_widget_type("group_forum_topics", elgg_echo("discussion:group"), elgg_echo("widgets:group_forum_topics:description"), array("groups"));
  98. // register events
  99. elgg_register_event_handler("join", "group", "group_tools_join_group_event");
  100. elgg_register_event_handler("delete", "relationship", array('ColdTrick\GroupTools\Membership', 'deleteRequest'));
  101. // register plugin hooks
  102. elgg_register_plugin_hook_handler("entity:url", "object", "group_tools_widget_url_handler");
  103. elgg_register_plugin_hook_handler("default", "access", "group_tools_access_default_handler");
  104. elgg_register_plugin_hook_handler("access:collections:write", "user", "group_tools_access_write_handler");
  105. elgg_register_plugin_hook_handler("action", "groups/join", "group_tools_join_group_action_handler");
  106. elgg_register_plugin_hook_handler("register", "menu:owner_block", "group_tools_register_owner_block_menu_handler");
  107. elgg_register_plugin_hook_handler("route", "register", "group_tools_route_register_handler");
  108. elgg_register_plugin_hook_handler("action", "register", "group_tools_action_register_handler");
  109. elgg_register_plugin_hook_handler("group_tool_widgets", "widget_manager", "group_tools_tool_widgets_handler");
  110. // actions
  111. elgg_register_action("group_tools/toggle_admin", dirname(__FILE__) . "/actions/toggle_admin.php");
  112. elgg_register_action("group_tools/mail", dirname(__FILE__) . "/actions/mail.php");
  113. elgg_register_action("group_tools/profile_widgets", dirname(__FILE__) . "/actions/profile_widgets.php");
  114. elgg_register_action("group_tools/cleanup", dirname(__FILE__) . "/actions/cleanup.php");
  115. elgg_register_action("group_tools/invite_members", dirname(__FILE__) . "/actions/invite_members.php");
  116. elgg_register_action("group_tools/welcome_message", dirname(__FILE__) . "/actions/welcome_message.php");
  117. elgg_register_action("group_tools/domain_based", dirname(__FILE__) . "/actions/domain_based.php");
  118. elgg_register_action("group_tools/related_groups", dirname(__FILE__) . "/actions/related_groups.php");
  119. elgg_register_action("group_tools/remove_related_groups", dirname(__FILE__) . "/actions/remove_related_groups.php");
  120. elgg_register_action("group_tools/member_export", dirname(__FILE__) . "/actions/member_export.php");
  121. elgg_register_action("group_tools/toggle_special_state", dirname(__FILE__) . "/actions/admin/toggle_special_state.php", "admin");
  122. elgg_register_action("group_tools/fix_auto_join", dirname(__FILE__) . "/actions/admin/fix_auto_join.php", "admin");
  123. elgg_register_action("group_tools/notifications", dirname(__FILE__) . "/actions/admin/notifications.php", "admin");
  124. elgg_register_action("group_tools/fix_acl", dirname(__FILE__) . "/actions/admin/fix_acl.php", "admin");
  125. elgg_register_action("group_tools/group_tool_presets", dirname(__FILE__) . "/actions/admin/group_tool_presets.php", "admin");
  126. elgg_register_action("group_tools/admin/bulk_delete", dirname(__FILE__) . "/actions/admin/bulk_delete.php", "admin");
  127. elgg_register_action("groups/email_invitation", dirname(__FILE__) . "/actions/groups/email_invitation.php");
  128. elgg_register_action("groups/decline_email_invitation", dirname(__FILE__) . "/actions/groups/decline_email_invitation.php");
  129. elgg_register_action("group_tools/revoke_email_invitation", dirname(__FILE__) . "/actions/groups/revoke_email_invitation.php");
  130. elgg_register_action("groups/edit", dirname(__FILE__) . "/actions/groups/edit.php");
  131. elgg_register_action("group_tools/order_groups", dirname(__FILE__) . "/actions/order_groups.php", "admin");
  132. elgg_register_action("discussion/toggle_status", dirname(__FILE__) . "/actions/discussion/toggle_status.php");
  133. }
  134. /**
  135. * called when the system is ready
  136. *
  137. * @return void
  138. */
  139. function group_tools_ready() {
  140. // unregister dashboard widget group_activity
  141. elgg_unregister_widget_type("group_activity");
  142. }
  143. /**
  144. * called just before a page starts with output
  145. *
  146. * @return void
  147. */
  148. function group_tools_pagesetup() {
  149. $user = elgg_get_logged_in_user_entity();
  150. $page_owner = elgg_get_page_owner_entity();
  151. // admin menu item
  152. elgg_register_admin_menu_item("configure", "group_tool_presets", "appearance");
  153. elgg_register_admin_menu_item("administer", "group_bulk_delete", "administer_utilities");
  154. if (elgg_in_context("groups") && ($page_owner instanceof ElggGroup)) {
  155. if ($page_owner->forum_enable == "no") {
  156. // unset if not enabled for this plugin
  157. elgg_unregister_widget_type("group_forum_topics");
  158. }
  159. if (!empty($user)) {
  160. // check multiple admin
  161. if (elgg_get_plugin_setting("multiple_admin", "group_tools") == "yes") {
  162. // extend group members sidebar list
  163. elgg_extend_view("groups/sidebar/members", "group_tools/group_admins", 400);
  164. // remove group tool options for group admins
  165. if (($page_owner->getOwnerGUID() != $user->getGUID()) && !$user->isAdmin()) {
  166. remove_group_tool_option("group_multiple_admin_allow");
  167. }
  168. }
  169. // invitation management
  170. if ($page_owner->canEdit()) {
  171. $request_options = array(
  172. "type" => "user",
  173. "relationship" => "membership_request",
  174. "relationship_guid" => $page_owner->getGUID(),
  175. "inverse_relationship" => true,
  176. "count" => true
  177. );
  178. $requests = elgg_get_entities_from_relationship($request_options);
  179. $postfix = "";
  180. if (!empty($requests)) {
  181. $postfix = " [" . $requests . "]";
  182. }
  183. if (!$page_owner->isPublicMembership()) {
  184. elgg_register_menu_item("page", array(
  185. "name" => "membership_requests",
  186. "text" => elgg_echo("groups:membershiprequests") . $postfix,
  187. "href" => "groups/requests/" . $page_owner->getGUID(),
  188. ));
  189. } else {
  190. elgg_register_menu_item("page", array(
  191. "name" => "membership_requests",
  192. "text" => elgg_echo("group_tools:menu:invitations") . $postfix,
  193. "href" => "groups/requests/" . $page_owner->getGUID(),
  194. ));
  195. }
  196. }
  197. // group mail options
  198. if ($page_owner->canEdit() && (elgg_get_plugin_setting("mail", "group_tools") == "yes")) {
  199. elgg_register_menu_item("page", array(
  200. "name" => "mail",
  201. "text" => elgg_echo("group_tools:menu:mail"),
  202. "href" => "groups/mail/" . $page_owner->getGUID(),
  203. ));
  204. }
  205. }
  206. }
  207. if ($page_owner instanceof ElggGroup) {
  208. if (!$page_owner->isPublicMembership()) {
  209. if (elgg_get_plugin_setting("search_index", "group_tools") != "yes") {
  210. // closed groups should be indexed by search engines
  211. elgg_extend_view("page/elements/head", "metatags/noindex");
  212. }
  213. }
  214. // cleanup sidebar
  215. elgg_extend_view("page/elements/sidebar", "group_tools/sidebar/cleanup");
  216. }
  217. }