AutoSandboxPlugin.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Plugin to automatically sandbox newly registered users in an effort to beat
  6. * spammers. If the user proves to be legitimate, moderators can un-sandbox them.
  7. *
  8. * PHP version 5
  9. *
  10. * LICENCE: 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 Plugin
  24. * @package StatusNet
  25. * @author Sean Carmody<seancarmody@gmail.com>
  26. * @copyright 2010
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. define('AUTOSANDBOX', '0.1');
  34. //require_once(INSTALLDIR.'/plugins/AutoSandbox/autosandbox.php');
  35. class AutoSandboxPlugin extends Plugin
  36. {
  37. const PLUGIN_VERSION = '2.0.0';
  38. var $contact;
  39. var $debug;
  40. function onInitializePlugin()
  41. {
  42. if(!isset($this->debug))
  43. {
  44. $this->debug = 0;
  45. }
  46. if(!isset($this->contact)) {
  47. $default = common_config('newuser', 'default');
  48. if (!empty($default)) {
  49. $this->contact = $default;
  50. }
  51. }
  52. }
  53. public function onPluginVersion(array &$versions): bool
  54. {
  55. $versions[] = array('name' => 'AutoSandbox',
  56. 'version' => self::PLUGIN_VERSION,
  57. 'author' => 'Sean Carmody',
  58. 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/AutoSandbox',
  59. 'rawdescription' =>
  60. // TRANS: Plugin description.
  61. _m('Automatically sandboxes newly registered members.'));
  62. return true;
  63. }
  64. function onStartRegistrationFormData($action)
  65. {
  66. // TRANS: User instructions after registration.
  67. $instr = _m('Note you will initially be "sandboxed" so your posts will not appear in the public timeline.');
  68. if (isset($this->contact)) {
  69. $contactuser = User::getKV('nickname', $this->contact);
  70. if ($contactuser instanceof User) {
  71. $contactlink = sprintf('@<a href="%s">%s</a>',
  72. htmlspecialchars($contactuser->getProfile()->getUrl()),
  73. htmlspecialchars($contactuser->getProfile()->getNickname()));
  74. // TRANS: User instructions after registration.
  75. // TRANS: %s is a clickable OStatus profile URL.
  76. $instr = sprintf(_m('Note you will initially be "sandboxed" so your posts will not appear in the public timeline. '.
  77. 'Send a message to %s to speed up the unsandboxing process.'),$contactlink);
  78. }
  79. }
  80. $output = common_markup_to_html($instr);
  81. $action->elementStart('div', 'instructions');
  82. $action->raw($output);
  83. $action->elementEnd('div');
  84. }
  85. public function onEndUserRegister(Profile $profile)
  86. {
  87. $profile->sandbox();
  88. if ($this->debug) {
  89. common_log(LOG_WARNING, "AutoSandbox: sandboxed of $profile->nickname");
  90. }
  91. }
  92. }