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;
12 use Friendica\Core\Renderer;
14 use Friendica\Util\Strings;
16 global $blockem_words;
18 function blockem_install()
20 Hook::register('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
21 Hook::register('display_item' , 'addon/blockem/blockem.php', 'blockem_display_item');
22 Hook::register('addon_settings' , 'addon/blockem/blockem.php', 'blockem_addon_settings');
23 Hook::register('addon_settings_post' , 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
24 Hook::register('conversation_start' , 'addon/blockem/blockem.php', 'blockem_conversation_start');
25 Hook::register('item_photo_menu' , 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
26 Hook::register('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
29 function blockem_addon_settings(App $a, array &$data)
35 $words = DI::pConfig()->get(local_user(), 'blockem', 'words', '');
37 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/blockem/');
38 $html = Renderer::replaceMacros($t, [
39 '$info' => DI::l10n()->t("Hides user's content by collapsing posts. Also replaces their avatar with generic image."),
40 '$words' => ['blockem-words', DI::l10n()->t('Comma separated profile URLS:'), $words],
45 'title' => DI::l10n()->t('Blockem'),
50 function blockem_addon_settings_post(App $a, array &$b)
56 if (!empty($_POST['blockem-submit'])) {
57 DI::pConfig()->set(local_user(), 'blockem', 'words', trim($_POST['blockem-words']));
61 function blockem_enotify_store(App $a, array &$b)
63 $words = DI::pConfig()->get($b['uid'], 'blockem', 'words');
66 $arr = explode(',', $words);
74 foreach ($arr as $word) {
75 if (!strlen(trim($word))) {
79 if (Strings::compareLink($b['url'], $word)) {
87 // empty out the fields
92 function blockem_prepare_body_content_filter(App $a, array &$hook_data)
98 $profiles_string = null;
101 $profiles_string = DI::pConfig()->get(local_user(), 'blockem', 'words');
104 if ($profiles_string) {
105 $profiles_array = explode(',', $profiles_string);
112 foreach ($profiles_array as $word) {
113 if (Strings::compareLink($hook_data['item']['author-link'], trim($word))) {
120 $hook_data['filter_reasons'][] = DI::l10n()->t('Filtered user: %s', $hook_data['item']['author-name']);
124 function blockem_display_item(App $a, array &$b = null)
126 if (!empty($b['output']['body']) && strstr($b['output']['body'], 'id="blockem-wrap-')) {
127 $b['output']['thumb'] = DI::baseUrl()->get() . "/images/person-80.jpg";
131 function blockem_conversation_start(App $a, array &$b)
133 global $blockem_words;
139 $words = DI::pConfig()->get(local_user(), 'blockem', 'words');
142 $blockem_words = explode(',', $words);
145 DI::page()['htmlhead'] .= <<< EOT
148 function blockemBlock(author) {
149 $.get('blockem?block=' +author, function(data) {
150 location.reload(true);
153 function blockemUnblock(author) {
154 $.get('blockem?unblock=' +author, function(data) {
155 location.reload(true);
163 function blockem_item_photo_menu(App $a, array &$b)
165 global $blockem_words;
167 if (!local_user() || $b['item']['self']) {
172 $author = $b['item']['author-link'];
174 if (!empty($blockem_words)) {
175 foreach($blockem_words as $bloke) {
176 if (Strings::compareLink($bloke,$author)) {
183 $b['menu'][DI::l10n()->t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
185 $b['menu'][DI::l10n()->t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
189 function blockem_module()
193 function blockem_init(App $a)
199 $words = DI::pConfig()->get(local_user(), 'blockem', 'words');
201 if (array_key_exists('block', $_GET) && $_GET['block']) {
202 if (strlen($words)) {
206 $words .= trim($_GET['block']);
209 if (array_key_exists('unblock', $_GET) && $_GET['unblock']) {
210 $arr = explode(',',$words);
214 foreach ($arr as $x) {
215 if (!Strings::compareLink(trim($x), trim($_GET['unblock']))) {
221 $words = implode(',', $newarr);
224 DI::pConfig()->set(local_user(), 'blockem', 'words', $words);