EmailSummaryPlugin.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * Sends an email summary of the inbox to users in the network
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Sample
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2010 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. exit(1);
  32. }
  33. /**
  34. * Plugin for sending email summaries to users
  35. *
  36. * @category Email
  37. * @package StatusNet
  38. * @author Brion Vibber <brionv@status.net>
  39. * @author Evan Prodromou <evan@status.net>
  40. * @copyright 2010 StatusNet, Inc.
  41. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  42. * @link http://status.net/
  43. */
  44. class EmailSummaryPlugin extends Plugin
  45. {
  46. const PLUGIN_VERSION = '2.0.0';
  47. /**
  48. * Database schema setup
  49. *
  50. * @return boolean hook value
  51. */
  52. function onCheckSchema()
  53. {
  54. $schema = Schema::get();
  55. // For storing user-submitted flags on profiles
  56. $schema->ensureTable('email_summary_status', Email_summary_status::schemaDef());
  57. return true;
  58. }
  59. /**
  60. * Version info for this plugin
  61. *
  62. * @param array &$versions array of version data
  63. *
  64. * @return boolean hook value; true means continue processing, false means stop.
  65. */
  66. public function onPluginVersion(array &$versions): bool
  67. {
  68. $versions[] = array('name' => 'EmailSummary',
  69. 'version' => self::PLUGIN_VERSION,
  70. 'author' => 'Evan Prodromou',
  71. 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/EmailSummary',
  72. 'rawdescription' =>
  73. // TRANS: Plugin description.
  74. _m('Send an email summary of the inbox to users.'));
  75. return true;
  76. }
  77. /**
  78. * Register our queue handlers
  79. *
  80. * @param QueueManager $qm Current queue manager
  81. *
  82. * @return boolean hook value
  83. */
  84. function onEndInitializeQueueManager($qm)
  85. {
  86. $qm->connect('sitesum', 'SiteEmailSummaryHandler');
  87. $qm->connect('usersum', 'UserEmailSummaryHandler');
  88. return true;
  89. }
  90. /**
  91. * Add a checkbox to turn off email summaries
  92. *
  93. * @param Action $action Action being executed (emailsettings)
  94. * @param Profile $scoped Profile for whom settings are configured (current user)
  95. *
  96. * @return boolean hook value
  97. */
  98. public function onEndEmailFormData(Action $action, Profile $scoped)
  99. {
  100. $action->elementStart('li');
  101. $action->checkbox('emailsummary',
  102. // TRANS: Checkbox label in e-mail preferences form.
  103. _m('Send me a periodic summary of updates from my network'),
  104. Email_summary_status::getSendSummary($scoped->id));
  105. $action->elementEnd('li');
  106. return true;
  107. }
  108. /**
  109. * Add a checkbox to turn off email summaries
  110. *
  111. * @param Action $action Action being executed (emailsettings)
  112. * @param Profile $scoped Profile for whom settings are configured (current user)
  113. *
  114. * @return boolean hook value
  115. */
  116. public function onEndEmailSaveForm(Action $action, Profile $scoped)
  117. {
  118. $sendSummary = $action->boolean('emailsummary');
  119. $ess = Email_summary_status::getKV('user_id', $scoped->id);
  120. if (empty($ess)) {
  121. $ess = new Email_summary_status();
  122. $ess->user_id = $scoped->id;
  123. $ess->send_summary = $sendSummary;
  124. $ess->created = common_sql_now();
  125. $ess->modified = common_sql_now();
  126. $ess->insert();
  127. } else {
  128. $orig = clone($ess);
  129. $ess->send_summary = $sendSummary;
  130. $ess->modified = common_sql_now();
  131. $ess->update($orig);
  132. }
  133. return true;
  134. }
  135. }