toggle_special_state.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * (un)Mark a group a as special
  4. */
  5. $group_guid = (int) get_input("group_guid");
  6. $state = get_input("state");
  7. if (!empty($group_guid)) {
  8. $group = get_entity($group_guid);
  9. if (!empty($group) && ($group instanceof ElggGroup)) {
  10. $result = false;
  11. switch ($state) {
  12. case "auto_join":
  13. $auto_join_groups = array();
  14. $auto_join_setting = elgg_get_plugin_setting("auto_join", "group_tools");
  15. if (!empty($auto_join_setting)) {
  16. $auto_join_groups = string_to_tag_array($auto_join_setting);
  17. }
  18. if (($key = array_search($group_guid, $auto_join_groups)) !== false) {
  19. unset($auto_join_groups[$key]);
  20. } else {
  21. $auto_join_groups[] = $group_guid;
  22. }
  23. if (!empty($auto_join_groups)) {
  24. $result = elgg_set_plugin_setting("auto_join", implode(",", $auto_join_groups), "group_tools");
  25. } else {
  26. $result = elgg_unset_plugin_setting("auto_join", "group_tools");
  27. }
  28. $success_message = elgg_echo("group_tools:action:toggle_special_state:auto_join");
  29. $error_message = elgg_echo("group_tools:action:toggle_special_state:error:auto_join");
  30. break;
  31. case "suggested":
  32. $suggested_groups = array();
  33. $suggested_setting = elgg_get_plugin_setting("suggested_groups", "group_tools");
  34. if (!empty($suggested_setting)) {
  35. $suggested_groups = string_to_tag_array($suggested_setting);
  36. }
  37. if (($key = array_search($group_guid, $suggested_groups)) !== false) {
  38. unset($suggested_groups[$key]);
  39. } else {
  40. $suggested_groups[] = $group_guid;
  41. }
  42. if (!empty($suggested_groups)) {
  43. $result = elgg_set_plugin_setting("suggested_groups", implode(",", $suggested_groups), "group_tools");
  44. } else {
  45. $result = elgg_unset_plugin_setting("suggested_groups", "group_tools");
  46. }
  47. $success_message = elgg_echo("group_tools:action:toggle_special_state:suggested");
  48. $error_message = elgg_echo("group_tools:action:toggle_special_state:error:suggested");
  49. break;
  50. default:
  51. $error_message = elgg_echo("group_tools:action:toggle_special_state:error:state");
  52. break;
  53. }
  54. if ($result) {
  55. system_message($success_message);
  56. } else {
  57. register_error($error_message);
  58. }
  59. } else {
  60. register_error(elgg_echo("group_tools:action:error:entity"));
  61. }
  62. } else {
  63. register_error(elgg_echo("group_tools:action:error:input"));
  64. }
  65. forward(REFERER);