Game server and admin dashboard for TerranQuest.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Notifications.lib.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. class Notifications {
  8. /**
  9. * Add a new notification.
  10. * @global $database
  11. * @param User $user
  12. * @param string $title
  13. * @param string $content
  14. * @param string $timestamp If left empty, the current date and time will be used.
  15. * @param string $url
  16. * @param bool $sensitive If true, the notification is marked as containing sensitive content, and the $content might be hidden on lockscreens and other non-secure places.
  17. * @return int The newly-created notification ID.
  18. * @throws Exception
  19. */
  20. public static function add(User $user, string $title, string $content, string $timestamp = "", string $url = "", bool $sensitive = false): int {
  21. global $Strings;
  22. if ($user->exists()) {
  23. if (empty($title) || empty($content)) {
  24. throw new Exception($Strings->get("invalid parameters", false));
  25. }
  26. $timestamp = date("Y-m-d H:i:s");
  27. if (!empty($timestamp)) {
  28. $timestamp = date("Y-m-d H:i:s", strtotime($timestamp));
  29. }
  30. $resp = AccountHubApi::get("addnotification", [
  31. 'uid' => $user->getUID(),
  32. 'title' => $title,
  33. 'content' => $content,
  34. 'timestamp' => $timestamp,
  35. 'url' => $url,
  36. 'sensitive' => $sensitive
  37. ]
  38. );
  39. if ($resp['status'] == "OK") {
  40. return $resp['id'] * 1;
  41. } else {
  42. return false;
  43. }
  44. }
  45. throw new Exception($Strings->get("user does not exist", false));
  46. }
  47. }