Single-sign-on and self-serve account management. https://netsyms.biz/apps/accounthub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

feed.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. require __DIR__ . "/required.php";
  8. date_default_timezone_set('UTC');
  9. use \FeedWriter\RSS1;
  10. use \FeedWriter\RSS2;
  11. use \FeedWriter\ATOM;
  12. if (empty($_GET['key']) || empty($_GET['type'])) {
  13. http_response_code(400);
  14. die("400 Bad Request: please send a user key and a feed type");
  15. }
  16. if (!$database->has('userkeys', ['key' => $_GET['key']])) {
  17. http_response_code(403);
  18. die("403 Forbidden: provide valid key");
  19. }
  20. $uid = $database->get('userkeys', 'uid', ['key' => $_GET['key']]);
  21. $user = new User($uid);
  22. switch ($user->getStatus()->get()) {
  23. case AccountStatus::NORMAL:
  24. case AccountStatus::CHANGE_PASSWORD:
  25. case AccountStatus::ALERT_ON_ACCESS:
  26. break;
  27. default:
  28. http_response_code(403);
  29. die("403 Forbidden: user account not active");
  30. }
  31. $notifications = Notifications::get($user);
  32. switch ($_GET['type']) {
  33. case "rss1":
  34. $feed = new RSS1();
  35. break;
  36. case "rss":
  37. case "rss2":
  38. $feed = new RSS2();
  39. break;
  40. case "atom":
  41. $feed = new ATOM();
  42. break;
  43. default:
  44. http_response_code(400);
  45. die("400 Bad Request: feed parameter must have a value of \"rss\", \"rss1\", \"rss2\" or \"atom\".");
  46. }
  47. $feed->setTitle($Strings->build("Notifications from server for user", ['server' => $SETTINGS['site_title'], 'user' => $user->getName()], false));
  48. if (strpos($SETTINGS['url'], "http") === 0) {
  49. $url = $SETTINGS['url'];
  50. } else {
  51. $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . $SETTINGS['url'];
  52. }
  53. $feed->setLink($url);
  54. foreach ($notifications as $n) {
  55. $item = $feed->createNewItem();
  56. $item->setTitle($n['title']);
  57. if (empty($n['url'])) {
  58. $item->setLink($url);
  59. } else {
  60. $item->setLink($n['url']);
  61. }
  62. $item->setDate(strtotime($n['timestamp']));
  63. if ($n['sensitive']) {
  64. $content = $Strings->get("Sensitive content hidden", false);
  65. } else {
  66. $content = $n['content'];
  67. }
  68. if ($_GET['type'] == "atom") {
  69. $item->setContent($content);
  70. } else {
  71. $item->setDescription($content);
  72. }
  73. $feed->addItem($item);
  74. }
  75. $feed->printFeed();