Official Addons for the Friendica Communications Platform. (please note that this is a clone of the repository at github, issues are handled there)
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.

160 lines
4.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. <?php
  2. /**
  3. * Name: superblock
  4. * Description: block people
  5. * Version: 1.0
  6. * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
  7. *
  8. */
  9. use Friendica\Core\Hook;
  10. use Friendica\DI;
  11. use Friendica\Util\Strings;
  12. function superblock_install()
  13. {
  14. Hook::register('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
  15. Hook::register('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
  16. Hook::register('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
  17. Hook::register('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
  18. Hook::register('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
  19. }
  20. function superblock_addon_settings(&$a, &$s)
  21. {
  22. if (!local_user()) {
  23. return;
  24. }
  25. /* Add our stylesheet to the page so we can make our settings look nice */
  26. DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/superblock/superblock.css' . '" media="all" />' . "\r\n";
  27. $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
  28. if (!$words) {
  29. $words = '';
  30. }
  31. $s .= '<span id="settings_superblock_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
  32. $s .= '<h3>' . DI::l10n()->t('Superblock') . '</h3>';
  33. $s .= '</span>';
  34. $s .= '<div id="settings_superblock_expanded" class="settings-block" style="display: none;">';
  35. $s .= '<span class="fakelink" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
  36. $s .= '<h3>' . DI::l10n()->t('Superblock') . '</h3>';
  37. $s .= '</span>';
  38. $s .= '<div id="superblock-wrapper">';
  39. $s .= '<label id="superblock-label" for="superblock-words">' . DI::l10n()->t('Comma separated profile URLS to block') . ' </label>';
  40. $s .= '<textarea id="superblock-words" type="text" name="superblock-words" >' . htmlspecialchars($words) . '</textarea>';
  41. $s .= '</div><div class="clear"></div>';
  42. $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="superblock-submit" name="superblock-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
  43. return;
  44. }
  45. function superblock_addon_settings_post(&$a, &$b)
  46. {
  47. if (!local_user()) {
  48. return;
  49. }
  50. if (!empty($_POST['superblock-submit'])) {
  51. DI::pConfig()->set(local_user(), 'system', 'blocked',trim($_POST['superblock-words']));
  52. }
  53. }
  54. function superblock_enotify_store(&$a,&$b) {
  55. if (empty($b['uid'])) {
  56. return;
  57. }
  58. $words = DI::pConfig()->get($b['uid'], 'system', 'blocked');
  59. if ($words) {
  60. $arr = explode(',', $words);
  61. } else {
  62. return;
  63. }
  64. $found = false;
  65. if (count($arr)) {
  66. foreach ($arr as $word) {
  67. if (!strlen(trim($word))) {
  68. continue;
  69. }
  70. if (Strings::compareLink($b['url'], $word)) {
  71. $found = true;
  72. break;
  73. }
  74. }
  75. }
  76. if ($found) {
  77. // Empty out the fields
  78. $b = [];
  79. }
  80. }
  81. function superblock_conversation_start(&$a, &$b)
  82. {
  83. if (!local_user()) {
  84. return;
  85. }
  86. $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
  87. if ($words) {
  88. $a->data['superblock'] = explode(',', $words);
  89. }
  90. DI::page()['htmlhead'] .= <<< EOT
  91. <script>
  92. function superblockBlock(author) {
  93. $.get('superblock?block=' +author, function(data) {
  94. location.reload(true);
  95. });
  96. }
  97. </script>
  98. EOT;
  99. }
  100. function superblock_item_photo_menu(&$a, &$b)
  101. {
  102. if (!local_user() || $b['item']['self']) {
  103. return;
  104. }
  105. $blocked = false;
  106. $author = $b['item']['author-link'];
  107. if (!empty($a->data['superblock'])) {
  108. foreach ($a->data['superblock'] as $bloke) {
  109. if (Strings::compareLink($bloke, $author)) {
  110. $blocked = true;
  111. break;
  112. }
  113. }
  114. }
  115. $b['menu'][DI::l10n()->t('Block Completely')] = 'javascript:superblockBlock(\'' . $author . '\'); return false;';
  116. }
  117. function superblock_module() {}
  118. function superblock_init(&$a)
  119. {
  120. if (!local_user()) {
  121. return;
  122. }
  123. $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
  124. if (array_key_exists('block', $_GET) && $_GET['block']) {
  125. if (strlen($words))
  126. $words .= ',';
  127. $words .= trim($_GET['block']);
  128. }
  129. DI::pConfig()->set(local_user(), 'system', 'blocked', $words);
  130. exit();
  131. }