sensitivecontentsettings.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Adds a setting to allow a user to hide #NSFW-hashtagged notices behind a
  18. * blocker image until clicked.
  19. *
  20. * @package GNUsocial
  21. * @author MoonMan
  22. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Class SensitiveContentSettingsAction
  28. * Handles the settings action for this plugin
  29. *
  30. * @package GNUsocial
  31. * @author MoonMan
  32. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  33. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  34. */
  35. class SensitiveContentSettingsAction extends SettingsAction
  36. {
  37. public function title()
  38. {
  39. return _m('Sensitive content settings');
  40. }
  41. public function getInstructions()
  42. {
  43. return _m('Set preferences for display of "sensitive" content');
  44. }
  45. public function showContent()
  46. {
  47. $user = $this->scoped->getUser();
  48. $this->elementStart(
  49. 'form',
  50. [
  51. 'method' => 'post',
  52. 'id' => 'sensitivecontent',
  53. 'class' => 'form_settings',
  54. 'action' => common_local_url('sensitivecontentsettings'),
  55. ]
  56. );
  57. $this->elementStart('fieldset');
  58. $this->hidden('token', common_session_token());
  59. $this->elementStart('ul', 'form_data');
  60. $this->elementStart('li');
  61. $this->checkbox(
  62. 'hidesensitive',
  63. _('Hide attachments in posts hashtagged #NSFW'),
  64. ($this->arg('hidesensitive') ?
  65. $this->boolean('hidesensitive') : $this->scoped->getPref('MoonMan', 'hide_sensitive', 0))
  66. );
  67. $this->elementEnd('li');
  68. $this->elementEnd('ul');
  69. $this->submit('save', _m('BUTTON', 'Save'));
  70. $this->elementEnd('fieldset');
  71. $this->elementEnd('form');
  72. }
  73. public function doPost()
  74. {
  75. $hidesensitive = $this->boolean('hidesensitive') ? '1' : '0';
  76. $this->scoped->setPref('MoonMan', 'hide_sensitive', $hidesensitive);
  77. return _m('Settings saved.');
  78. }
  79. }