Notetaking app with Markdown support https://netsyms.com/apps/notepost
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.

cron.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // Run this script via cron every 15 minutes to send reminder notifications.
  8. require __DIR__ . '/settings.php';
  9. require __DIR__ . '/vendor/autoload.php';
  10. $libs = glob(__DIR__ . "/lib/*.lib.php");
  11. foreach ($libs as $lib) {
  12. require_once $lib;
  13. }
  14. $Strings = new Strings($SETTINGS['language']);
  15. date_default_timezone_set($SETTINGS['timezone']);
  16. use Medoo\Medoo;
  17. $database;
  18. try {
  19. $database = new Medoo([
  20. 'database_type' => $SETTINGS['database']['type'],
  21. 'database_name' => $SETTINGS['database']['name'],
  22. 'server' => $SETTINGS['database']['server'],
  23. 'username' => $SETTINGS['database']['user'],
  24. 'password' => $SETTINGS['database']['password'],
  25. 'charset' => $SETTINGS['database']['charset']
  26. ]);
  27. } catch (Exception $ex) {
  28. echo "Database error: $ex\n";
  29. exit(1);
  30. }
  31. $reminders = $database->select('reminders', [
  32. 'reminderid (id)',
  33. 'noteid',
  34. 'when'
  35. ], [
  36. 'when[<]' => date("Y-m-d H:i:s", strtotime("now + 15 minutes"))
  37. ]);
  38. echo "Start sending " . count($reminders) . " reminder notifications...\n";
  39. $deleteids = [];
  40. $linelimit = 3;
  41. foreach ($reminders as $r) {
  42. $note = Note::loadNote($r['noteid']);
  43. $lines = explode("\n", $note->getText(), $linelimit);
  44. if (count($lines) == $linelimit) {
  45. array_pop($lines);
  46. $lines[] = $Strings->build("Open {app} to read more", ["app" => $SETTINGS['site_title']], false);
  47. }
  48. $content = implode("\n", $lines);
  49. Notifications::add($note->getOwner(), $Strings->get("Note Reminder", false), $content);
  50. $deleteids[] = $r['id'];
  51. }
  52. echo "Sent " . count($reminders) . " notifications.\n";
  53. $deleted = $database->delete('reminders', ['reminderid' => $deleteids]);
  54. echo "Outdated reminder cleanup complete: " . $deleted->rowCount() . " records removed.\n";