subscribe.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Toggle the subscription for a user
  4. */
  5. $user_guid = (int) get_input("user_guid", elgg_get_logged_in_user_guid());
  6. $entity_guid = (int) get_input("entity_guid");
  7. if (empty($user_guid) || empty($entity_guid)) {
  8. register_error(elgg_echo("InvalidParameterException:MissingParameter"));
  9. forward(REFERER);
  10. }
  11. $user = get_user($user_guid);
  12. $entity = get_entity($entity_guid);
  13. if (empty($user) || empty($entity)) {
  14. register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
  15. forward(REFERER);
  16. }
  17. // user cant be the owner
  18. if ($entity->getOwnerGUID() == $user->getGUID()) {
  19. register_error(elgg_echo("content_subscriptions:action:subscribe:error:owner"));
  20. forward(REFERER);
  21. }
  22. // subscribe or unsubscribe
  23. if (content_subscriptions_check_subscription($entity->getGUID(), $user->getGUID())) {
  24. // unsubscribe
  25. if (content_subscriptions_unsubscribe($entity->getGUID(), $user->getGUID())) {
  26. system_message(elgg_echo("content_subscriptions:action:subscribe:success:unsubscribe"));
  27. } else {
  28. register_error(elgg_echo("content_subscriptions:action:subscribe:error:unsubscribe"));
  29. }
  30. } else {
  31. // subscribe
  32. if (content_subscriptions_subscribe($entity->getGUID(), $user->getGUID())) {
  33. system_message(elgg_echo("content_subscriptions:action:subscribe:success:subscribe"));
  34. } else {
  35. register_error(elgg_echo("content_subscriptions:action:subscribe:error:subscribe"));
  36. }
  37. }
  38. forward(REFERER);