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.

69 lines
2.0KB

  1. <?php
  2. if (!defined('GNUSOCIAL')) {
  3. exit(1);
  4. }
  5. class BrowserNotificationsPlugin extends Plugin
  6. {
  7. const VERSION = '0.0.1';
  8. function onEndAccountSettingsNav($action) {
  9. $action->elementStart('li');
  10. $action->element('a', array('href' => common_local_url('browsernotificationssettings')), 'Browser Notifications');
  11. $action->elementEnd('li');
  12. return true;
  13. }
  14. function onRouterInitialized($m) {
  15. $m->connect(
  16. 'settings/browsernotifications', array(
  17. 'action' => 'browsernotificationssettings'
  18. )
  19. );
  20. return true;
  21. }
  22. function onEndShowScripts($action) {
  23. $user_settings = BrowserNotificationSettings::getDefaults();
  24. if (common_logged_in()) {
  25. $user = common_current_user();
  26. $bns = BrowserNotificationSettings::getByUserId($user->id);
  27. if (!empty($bns)) {
  28. $user_settings = $bns;
  29. }
  30. }
  31. // Only include the JS if the setting is enabled
  32. if ($user_settings->enabled === true) {
  33. $action->inlineScript('BrowserNotifications = ' . $user_settings->toJSON());
  34. $action->script($this->path('js/browser-notifications.js'));
  35. }
  36. return true;
  37. }
  38. function onCheckSchema() {
  39. $schema = Schema::get();
  40. $schema->ensureTable('browser_notifications', BrowserNotificationSettings::schemaDef());
  41. return true;
  42. }
  43. function onPluginVersion(&$versions)
  44. {
  45. $versions[] = array('name' => 'BrowserNotifications',
  46. 'version' => self::VERSION,
  47. 'author' => 'chimo',
  48. 'homepage' => 'https://github.com/chimo/gs-browserNotifications',
  49. 'description' =>
  50. // TRANS: Plugin description.
  51. _m('Receive browser notifications when a new notice and/or mention comes in.'));
  52. return true;
  53. }
  54. }