4 * Description: Allows users to hide content by collapsing posts and replies.
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7 * Author: Roland Haeder <https://f.haeder.net/roland>
11 use Friendica\Core\Hook;
13 use Friendica\Util\Strings;
15 global $blockem_words;
17 function blockem_install()
19 Hook::register('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
20 Hook::register('display_item' , 'addon/blockem/blockem.php', 'blockem_display_item');
21 Hook::register('addon_settings' , 'addon/blockem/blockem.php', 'blockem_addon_settings');
22 Hook::register('addon_settings_post' , 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
23 Hook::register('conversation_start' , 'addon/blockem/blockem.php', 'blockem_conversation_start');
24 Hook::register('item_photo_menu' , 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
25 Hook::register('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
28 function blockem_addon_settings (App $a, &$s)
34 /* Add our stylesheet to the page so we can make our settings look nice */
35 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/blockem/blockem.css' . '" media="all" />' . "\r\n";
37 $words = DI::pConfig()->get(local_user(), 'blockem', 'words');
43 $s .= '<span id="settings_blockem_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
44 $s .= '<h3>' . DI::l10n()->t('Blockem') . '</h3>';
46 $s .= '<div id="settings_blockem_expanded" class="settings-block" style="display: none;">';
47 $s .= '<span class="fakelink" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
48 $s .= '<h3>' . DI::l10n()->t('Blockem') . '</h3>';
51 $s .= '<div id="blockem-wrapper">';
52 $s .= '<div id="blockem-desc">'. DI::l10n()->t("Hides user's content by collapsing posts. Also replaces their avatar with generic image.") . ' </div>';
53 $s .= '<label id="blockem-label" for="blockem-words">' . DI::l10n()->t('Comma separated profile URLS:') . ' </label>';
54 $s .= '<textarea id="blockem-words" type="text" name="blockem-words" >' . htmlspecialchars($words) . '</textarea>';
55 $s .= '</div><div class="clear"></div>';
57 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blockem-submit" name="blockem-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
63 function blockem_addon_settings_post(App $a, array &$b)
69 if (!empty($_POST['blockem-submit'])) {
70 DI::pConfig()->set(local_user(), 'blockem', 'words', trim($_POST['blockem-words']));
74 function blockem_enotify_store(App $a, array &$b)
76 $words = DI::pConfig()->get($b['uid'], 'blockem', 'words');
79 $arr = explode(',', $words);
87 foreach ($arr as $word) {
88 if (!strlen(trim($word))) {
92 if (Strings::compareLink($b['url'], $word)) {
100 // empty out the fields
105 function blockem_prepare_body_content_filter(App $a, array &$hook_data)
111 $profiles_string = null;
114 $profiles_string = DI::pConfig()->get(local_user(), 'blockem', 'words');
117 if ($profiles_string) {
118 $profiles_array = explode(',', $profiles_string);
125 foreach ($profiles_array as $word) {
126 if (Strings::compareLink($hook_data['item']['author-link'], trim($word))) {
133 $hook_data['filter_reasons'][] = DI::l10n()->t('Filtered user: %s', $hook_data['item']['author-name']);
137 function blockem_display_item(App $a, array &$b = null)
139 if (!empty($b['output']['body']) && strstr($b['output']['body'], 'id="blockem-wrap-')) {
140 $b['output']['thumb'] = DI::baseUrl()->get() . "/images/person-80.jpg";
144 function blockem_conversation_start(App $a, array &$b)
146 global $blockem_words;
152 $words = DI::pConfig()->get(local_user(), 'blockem', 'words');
155 $blockem_words = explode(',', $words);
158 DI::page()['htmlhead'] .= <<< EOT
161 function blockemBlock(author) {
162 $.get('blockem?block=' +author, function(data) {
163 location.reload(true);
166 function blockemUnblock(author) {
167 $.get('blockem?unblock=' +author, function(data) {
168 location.reload(true);
176 function blockem_item_photo_menu(App $a, array &$b)
178 global $blockem_words;
180 if (!local_user() || $b['item']['self']) {
185 $author = $b['item']['author-link'];
187 if (!empty($blockem_words)) {
188 foreach($blockem_words as $bloke) {
189 if (Strings::compareLink($bloke,$author)) {
196 $b['menu'][DI::l10n()->t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
198 $b['menu'][DI::l10n()->t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
202 function blockem_module()
206 function blockem_init(App $a)
212 $words = DI::pConfig()->get(local_user(), 'blockem', 'words');
214 if (array_key_exists('block', $_GET) && $_GET['block']) {
215 if (strlen($words)) {
219 $words .= trim($_GET['block']);
222 if (array_key_exists('unblock', $_GET) && $_GET['unblock']) {
223 $arr = explode(',',$words);
227 foreach ($arr as $x) {
228 if (!Strings::compareLink(trim($x), trim($_GET['unblock']))) {
234 $words = implode(',', $newarr);
237 DI::pConfig()->set(local_user(), 'blockem', 'words', $words);