No Description
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.

BrowserNotificationsPlugin.php 2.0KB

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