EmailSummaryPlugin.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. /**
  47. * Database schema setup
  48. *
  49. * @return boolean hook value
  50. */
  51. function onCheckSchema()
  52. {
  53. $schema = Schema::get();
  54. // For storing user-submitted flags on profiles
  55. $schema->ensureTable('email_summary_status', Email_summary_status::schemaDef());
  56. return true;
  57. }
  58. /**
  59. * Version info for this plugin
  60. *
  61. * @param array &$versions array of version data
  62. *
  63. * @return boolean hook value; true means continue processing, false means stop.
  64. */
  65. function onPluginVersion(array &$versions)
  66. {
  67. $versions[] = array('name' => 'EmailSummary',
  68. 'version' => GNUSOCIAL_VERSION,
  69. 'author' => 'Evan Prodromou',
  70. 'homepage' => 'http://status.net/wiki/Plugin:EmailSummary',
  71. 'rawdescription' =>
  72. // TRANS: Plugin description.
  73. _m('Send an email summary of the inbox to users.'));
  74. return true;
  75. }
  76. /**
  77. * Register our queue handlers
  78. *
  79. * @param QueueManager $qm Current queue manager
  80. *
  81. * @return boolean hook value
  82. */
  83. function onEndInitializeQueueManager($qm)
  84. {
  85. $qm->connect('sitesum', 'SiteEmailSummaryHandler');
  86. $qm->connect('usersum', 'UserEmailSummaryHandler');
  87. return true;
  88. }
  89. /**
  90. * Add a checkbox to turn off email summaries
  91. *
  92. * @param Action $action Action being executed (emailsettings)
  93. * @param Profile $scoped Profile for whom settings are configured (current user)
  94. *
  95. * @return boolean hook value
  96. */
  97. public function onEndEmailFormData(Action $action, Profile $scoped)
  98. {
  99. $action->elementStart('li');
  100. $action->checkbox('emailsummary',
  101. // TRANS: Checkbox label in e-mail preferences form.
  102. _m('Send me a periodic summary of updates from my network'),
  103. Email_summary_status::getSendSummary($scoped->id));
  104. $action->elementEnd('li');
  105. return true;
  106. }
  107. /**
  108. * Add a checkbox to turn off email summaries
  109. *
  110. * @param Action $action Action being executed (emailsettings)
  111. * @param Profile $scoped Profile for whom settings are configured (current user)
  112. *
  113. * @return boolean hook value
  114. */
  115. public function onEndEmailSaveForm(Action $action, Profile $scoped)
  116. {
  117. $sendSummary = $action->boolean('emailsummary');
  118. $ess = Email_summary_status::getKV('user_id', $scoped->id);
  119. if (empty($ess)) {
  120. $ess = new Email_summary_status();
  121. $ess->user_id = $scoped->id;
  122. $ess->send_summary = $sendSummary;
  123. $ess->created = common_sql_now();
  124. $ess->modified = common_sql_now();
  125. $ess->insert();
  126. } else {
  127. $orig = clone($ess);
  128. $ess->send_summary = $sendSummary;
  129. $ess->modified = common_sql_now();
  130. $ess->update($orig);
  131. }
  132. return true;
  133. }
  134. }