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>
12 use Friendica\Core\Hook;
13 use Friendica\Core\Renderer;
15 use Friendica\Util\Strings;
17 global $blockem_words;
19 function blockem_install()
21 Hook::register('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
22 Hook::register('display_item' , 'addon/blockem/blockem.php', 'blockem_display_item');
23 Hook::register('addon_settings' , 'addon/blockem/blockem.php', 'blockem_addon_settings');
24 Hook::register('addon_settings_post' , 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
25 Hook::register('conversation_start' , 'addon/blockem/blockem.php', 'blockem_conversation_start');
26 Hook::register('item_photo_menu' , 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
27 Hook::register('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
30 function blockem_addon_settings(array &$data)
32 if (!DI::userSession()->getLocalUserId()) {
36 $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'blockem', 'words', '');
38 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/blockem/');
39 $html = Renderer::replaceMacros($t, [
40 '$info' => DI::l10n()->t("Hides user's content by collapsing posts. Also replaces their avatar with generic image."),
41 '$words' => ['blockem-words', DI::l10n()->t('Comma separated profile URLS:'), $words],
46 'title' => DI::l10n()->t('Blockem'),
51 function blockem_addon_settings_post(array &$b)
53 if (!DI::userSession()->getLocalUserId()) {
57 if (!empty($_POST['blockem-submit'])) {
58 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'blockem', 'words', trim($_POST['blockem-words']));
62 function blockem_enotify_store(array &$b)
64 $words = DI::pConfig()->get($b['uid'], 'blockem', 'words');
67 $arr = explode(',', $words);
75 foreach ($arr as $word) {
76 if (!strlen(trim($word))) {
80 if (Strings::compareLink($b['url'], $word)) {
88 // empty out the fields
93 function blockem_prepare_body_content_filter(array &$hook_data)
95 if (!DI::userSession()->getLocalUserId()) {
99 $profiles_string = null;
101 if (DI::userSession()->getLocalUserId()) {
102 $profiles_string = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'blockem', 'words');
105 if ($profiles_string) {
106 $profiles_array = explode(',', $profiles_string);
113 foreach ($profiles_array as $word) {
114 if (Strings::compareLink($hook_data['item']['author-link'], trim($word))) {
121 $hook_data['filter_reasons'][] = DI::l10n()->t('Filtered user: %s', $hook_data['item']['author-name']);
125 function blockem_display_item(array &$b = null)
127 if (!empty($b['output']['body']) && strstr($b['output']['body'], 'id="blockem-wrap-')) {
128 $b['output']['thumb'] = DI::baseUrl()->get() . "/images/person-80.jpg";
132 function blockem_conversation_start(array &$b)
134 global $blockem_words;
136 if (!DI::userSession()->getLocalUserId()) {
140 $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'blockem', 'words');
143 $blockem_words = explode(',', $words);
146 DI::page()['htmlhead'] .= <<< EOT
149 function blockemBlock(author) {
150 $.get('blockem?block=' +author, function(data) {
151 location.reload(true);
154 function blockemUnblock(author) {
155 $.get('blockem?unblock=' +author, function(data) {
156 location.reload(true);
164 function blockem_item_photo_menu(array &$b)
166 global $blockem_words;
168 if (!DI::userSession()->getLocalUserId() || $b['item']['self']) {
173 $author = $b['item']['author-link'];
175 if (!empty($blockem_words)) {
176 foreach($blockem_words as $bloke) {
177 if (Strings::compareLink($bloke,$author)) {
184 $b['menu'][DI::l10n()->t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
186 $b['menu'][DI::l10n()->t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
191 * This is a statement rather than an actual function definition. The simple
192 * existence of this method is checked to figure out if the addon offers a
195 function blockem_module() {}
197 function blockem_init()
199 if (!DI::userSession()->getLocalUserId()) {
203 $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'blockem', 'words');
205 if (array_key_exists('block', $_GET) && $_GET['block']) {
206 if (strlen($words)) {
210 $words .= trim($_GET['block']);
213 if (array_key_exists('unblock', $_GET) && $_GET['unblock']) {
214 $arr = explode(',',$words);
218 foreach ($arr as $x) {
219 if (!Strings::compareLink(trim($x), trim($_GET['unblock']))) {
225 $words = implode(',', $newarr);
228 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'blockem', 'words', $words);