mark.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * mark an announcement as read
  4. */
  5. $guid = (int) get_input("guid");
  6. if (!empty($guid)) {
  7. $entity = get_entity($guid);
  8. if (!empty($entity)) {
  9. if (elgg_instanceof($entity, "object", SITE_ANNOUNCEMENT_SUBTYPE)) {
  10. if (elgg_is_logged_in()) {
  11. // logged in user are different from logged out users
  12. add_entity_relationship(elgg_get_logged_in_user_guid(), SITE_ANNOUNCEMENT_RELATIONSHIP, $entity->getGUID());
  13. } else {
  14. $guids = array();
  15. if (isset($_COOKIE["site_announcements"])) {
  16. $guids = string_to_tag_array($_COOKIE["site_announcements"]);
  17. }
  18. $guids[] = $entity->getGUID();
  19. $expire = time() + (30 * 24 * 60 * 60); // in 30 days
  20. setcookie(site_announcements, implode(",", $guids), $expire, "/");
  21. }
  22. } else {
  23. register_error(elgg_echo("ClassException:ClassnameNotClass", array($guid, elgg_echo("item:object:site_announcement"))));
  24. }
  25. } else {
  26. register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
  27. }
  28. } else {
  29. register_error(elgg_echo("InvalidParameterException:MissingParameter"));
  30. }
  31. forward(REFERER);