4 * Description: block people
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
9 use Friendica\Core\Hook;
11 use Friendica\Util\Strings;
13 function superblock_install()
15 Hook::register('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
16 Hook::register('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
17 Hook::register('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
18 Hook::register('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
19 Hook::register('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
22 function superblock_addon_settings(&$a, &$s)
28 /* Add our stylesheet to the page so we can make our settings look nice */
30 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/superblock/superblock.css' . '" media="all" />' . "\r\n";
32 $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
37 $s .= '<span id="settings_superblock_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
38 $s .= '<h3>' . DI::l10n()->t('Superblock') . '</h3>';
40 $s .= '<div id="settings_superblock_expanded" class="settings-block" style="display: none;">';
41 $s .= '<span class="fakelink" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
42 $s .= '<h3>' . DI::l10n()->t('Superblock') . '</h3>';
44 $s .= '<div id="superblock-wrapper">';
45 $s .= '<label id="superblock-label" for="superblock-words">' . DI::l10n()->t('Comma separated profile URLS to block') . ' </label>';
46 $s .= '<textarea id="superblock-words" type="text" name="superblock-words" >' . htmlspecialchars($words) . '</textarea>';
47 $s .= '</div><div class="clear"></div>';
49 $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>';
54 function superblock_addon_settings_post(&$a, &$b)
60 if (!empty($_POST['superblock-submit'])) {
61 DI::pConfig()->set(local_user(), 'system', 'blocked',trim($_POST['superblock-words']));
65 function superblock_enotify_store(&$a,&$b) {
66 if (empty($b['uid'])) {
70 $words = DI::pConfig()->get($b['uid'], 'system', 'blocked');
72 $arr = explode(',', $words);
79 foreach ($arr as $word) {
80 if (!strlen(trim($word))) {
84 if (Strings::compareLink($b['url'], $word)) {
91 // Empty out the fields
97 function superblock_conversation_start(&$a, &$b)
103 $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
105 $a->data['superblock'] = explode(',', $words);
107 DI::page()['htmlhead'] .= <<< EOT
110 function superblockBlock(author) {
111 $.get('superblock?block=' +author, function(data) {
112 location.reload(true);
121 function superblock_item_photo_menu(&$a, &$b)
123 if (!local_user() || $b['item']['self']) {
128 $author = $b['item']['author-link'];
129 if (!empty($a->data['superblock'])) {
130 foreach ($a->data['superblock'] as $bloke) {
131 if (Strings::compareLink($bloke, $author)) {
138 $b['menu'][DI::l10n()->t('Block Completely')] = 'javascript:superblockBlock(\'' . $author . '\'); return false;';
141 function superblock_module() {}
144 function superblock_init(&$a)
150 $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
152 if (array_key_exists('block', $_GET) && $_GET['block']) {
155 $words .= trim($_GET['block']);
158 DI::pConfig()->set(local_user(), 'system', 'blocked', $words);