4 * Description: block people
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
14 use Friendica\Util\Strings;
16 function superblock_install()
18 Hook::register('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
19 Hook::register('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
20 Hook::register('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
21 Hook::register('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
22 Hook::register('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
25 function superblock_addon_settings(App &$a, array &$data)
27 if (!DI::userSession()->getLocalUserId()) {
31 $blocked = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked', '');
33 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/superblock/');
34 $html = Renderer::replaceMacros($t, [
35 '$urls' => ['superblock-words', DI::l10n()->t('Comma separated profile URLs to block'), $blocked],
39 'addon' => 'superblock',
40 'title' => DI::l10n()->t('Superblock'),
45 function superblock_addon_settings_post(App $a, array &$b)
47 if (!DI::userSession()->getLocalUserId()) {
51 if (!empty($_POST['superblock-submit'])) {
52 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'blocked',trim($_POST['superblock-words']));
56 function superblock_enotify_store(App $a, array &$b)
58 if (empty($b['uid'])) {
62 $words = DI::pConfig()->get($b['uid'], 'system', 'blocked');
64 $arr = explode(',', $words);
71 foreach ($arr as $word) {
72 if (!strlen(trim($word))) {
76 if (Strings::compareLink($b['url'], $word)) {
84 // Empty out the fields
90 function superblock_conversation_start(App $a, array &$b)
92 if (!DI::userSession()->getLocalUserId()) {
96 $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked');
98 $a->data['superblock'] = explode(',', $words);
101 DI::page()['htmlhead'] .= <<< EOT
103 function superblockBlock(author) {
104 $.get('superblock?block=' +author, function(data) {
105 location.reload(true);
113 function superblock_item_photo_menu(App $a, array &$b)
115 if (!DI::userSession()->getLocalUserId() || $b['item']['self']) {
120 $author = $b['item']['author-link'];
121 if (!empty($a->data['superblock'])) {
122 foreach ($a->data['superblock'] as $bloke) {
123 if (Strings::compareLink($bloke, $author)) {
130 $b['menu'][DI::l10n()->t('Block Completely')] = 'javascript:superblockBlock(\'' . $author . '\'); return false;';
134 * This is a statement rather than an actual function definition. The simple
135 * existence of this method is checked to figure out if the addon offers a
138 function superblock_module() {}
140 function superblock_init(App $a)
142 if (!DI::userSession()->getLocalUserId()) {
146 $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked');
148 if (array_key_exists('block', $_GET) && $_GET['block']) {
151 $words .= trim($_GET['block']);
154 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'blocked', $words);