2012-01-10 04:16:09 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: blockem
|
2018-02-09 05:14:20 -05:00
|
|
|
* Description: Allows users to hide content by collapsing posts and replies.
|
2012-01-10 04:16:09 -05:00
|
|
|
* Version: 1.0
|
|
|
|
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
|
2018-07-20 21:51:15 -04:00
|
|
|
* Author: Roland Haeder <https://f.haeder.net/roland>
|
2023-01-08 14:11:35 -05:00
|
|
|
* Status: unsupported
|
2012-01-10 04:16:09 -05:00
|
|
|
*/
|
2018-07-20 21:51:15 -04:00
|
|
|
|
|
|
|
use Friendica\App;
|
2018-12-26 02:28:16 -05:00
|
|
|
use Friendica\Core\Hook;
|
2021-11-20 04:56:55 -05:00
|
|
|
use Friendica\Core\Renderer;
|
2019-12-15 19:05:14 -05:00
|
|
|
use Friendica\DI;
|
2018-11-08 11:45:19 -05:00
|
|
|
use Friendica\Util\Strings;
|
2017-11-06 18:55:24 -05:00
|
|
|
|
2021-07-25 13:28:07 -04:00
|
|
|
global $blockem_words;
|
|
|
|
|
2018-01-22 14:03:11 -05:00
|
|
|
function blockem_install()
|
|
|
|
{
|
2018-12-26 02:28:16 -05:00
|
|
|
Hook::register('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
|
|
|
|
Hook::register('display_item' , 'addon/blockem/blockem.php', 'blockem_display_item');
|
|
|
|
Hook::register('addon_settings' , 'addon/blockem/blockem.php', 'blockem_addon_settings');
|
|
|
|
Hook::register('addon_settings_post' , 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
|
|
|
|
Hook::register('conversation_start' , 'addon/blockem/blockem.php', 'blockem_conversation_start');
|
|
|
|
Hook::register('item_photo_menu' , 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
|
|
|
|
Hook::register('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
|
2012-01-10 04:16:09 -05:00
|
|
|
}
|
|
|
|
|
2023-01-13 21:16:09 -05:00
|
|
|
function blockem_addon_settings(array &$data)
|
2018-01-20 08:57:41 -05:00
|
|
|
{
|
2022-10-20 17:51:49 -04:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2012-01-10 04:16:09 -05:00
|
|
|
return;
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
2012-01-10 04:16:09 -05:00
|
|
|
|
2022-10-20 17:51:49 -04:00
|
|
|
$words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'blockem', 'words', '');
|
2012-01-10 04:16:09 -05:00
|
|
|
|
2021-11-20 04:56:55 -05:00
|
|
|
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/blockem/');
|
|
|
|
$html = Renderer::replaceMacros($t, [
|
|
|
|
'$info' => DI::l10n()->t("Hides user's content by collapsing posts. Also replaces their avatar with generic image."),
|
|
|
|
'$words' => ['blockem-words', DI::l10n()->t('Comma separated profile URLS:'), $words],
|
|
|
|
]);
|
2012-01-10 04:16:09 -05:00
|
|
|
|
2021-11-20 04:56:55 -05:00
|
|
|
$data = [
|
|
|
|
'addon' => 'blockem',
|
|
|
|
'title' => DI::l10n()->t('Blockem'),
|
|
|
|
'html' => $html,
|
|
|
|
];
|
2012-01-10 04:16:09 -05:00
|
|
|
}
|
|
|
|
|
2023-01-13 21:16:09 -05:00
|
|
|
function blockem_addon_settings_post(array &$b)
|
2018-07-20 21:51:15 -04:00
|
|
|
{
|
2022-10-20 17:51:49 -04:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2012-01-10 04:16:09 -05:00
|
|
|
return;
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
2012-01-10 04:16:09 -05:00
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
if (!empty($_POST['blockem-submit'])) {
|
2022-10-20 17:51:49 -04:00
|
|
|
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'blockem', 'words', trim($_POST['blockem-words']));
|
2012-01-10 04:16:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 21:16:09 -05:00
|
|
|
function blockem_enotify_store(array &$b)
|
2018-07-20 21:51:15 -04:00
|
|
|
{
|
2020-01-18 10:50:56 -05:00
|
|
|
$words = DI::pConfig()->get($b['uid'], 'blockem', 'words');
|
2013-05-09 04:18:03 -04:00
|
|
|
|
2018-07-20 21:51:15 -04:00
|
|
|
if ($words) {
|
|
|
|
$arr = explode(',', $words);
|
|
|
|
} else {
|
2013-05-09 04:18:03 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$found = false;
|
2018-07-20 21:51:15 -04:00
|
|
|
|
|
|
|
if (count($arr)) {
|
|
|
|
foreach ($arr as $word) {
|
|
|
|
if (!strlen(trim($word))) {
|
2013-05-09 04:18:03 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-11-08 11:45:19 -05:00
|
|
|
if (Strings::compareLink($b['url'], $word)) {
|
2013-05-09 04:18:03 -04:00
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-20 21:51:15 -04:00
|
|
|
|
|
|
|
if ($found) {
|
2020-01-27 19:12:41 -05:00
|
|
|
// empty out the fields
|
|
|
|
$b = [];
|
2013-05-09 04:18:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 21:16:09 -05:00
|
|
|
function blockem_prepare_body_content_filter(array &$hook_data)
|
2018-04-01 02:31:15 -04:00
|
|
|
{
|
2022-10-20 17:51:49 -04:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2012-01-10 04:16:09 -05:00
|
|
|
return;
|
|
|
|
}
|
2018-04-01 02:31:15 -04:00
|
|
|
|
|
|
|
$profiles_string = null;
|
2018-07-20 21:51:15 -04:00
|
|
|
|
2022-10-20 17:51:49 -04:00
|
|
|
if (DI::userSession()->getLocalUserId()) {
|
|
|
|
$profiles_string = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'blockem', 'words');
|
2012-01-10 04:16:09 -05:00
|
|
|
}
|
2018-04-01 02:31:15 -04:00
|
|
|
|
|
|
|
if ($profiles_string) {
|
|
|
|
$profiles_array = explode(',', $profiles_string);
|
|
|
|
} else {
|
2012-01-10 04:16:09 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$found = false;
|
2018-07-20 21:51:15 -04:00
|
|
|
|
2018-04-01 02:31:15 -04:00
|
|
|
foreach ($profiles_array as $word) {
|
2018-11-08 11:45:19 -05:00
|
|
|
if (Strings::compareLink($hook_data['item']['author-link'], trim($word))) {
|
2018-04-01 02:31:15 -04:00
|
|
|
$found = true;
|
|
|
|
break;
|
2012-01-10 04:16:09 -05:00
|
|
|
}
|
|
|
|
}
|
2018-04-01 02:31:15 -04:00
|
|
|
|
|
|
|
if ($found) {
|
2020-01-18 14:52:33 -05:00
|
|
|
$hook_data['filter_reasons'][] = DI::l10n()->t('Filtered user: %s', $hook_data['item']['author-name']);
|
2012-01-10 04:16:09 -05:00
|
|
|
}
|
|
|
|
}
|
2012-01-10 19:54:47 -05:00
|
|
|
|
2023-01-13 21:16:09 -05:00
|
|
|
function blockem_display_item(array &$b = null)
|
2018-07-20 21:51:15 -04:00
|
|
|
{
|
|
|
|
if (!empty($b['output']['body']) && strstr($b['output']['body'], 'id="blockem-wrap-')) {
|
2019-12-15 19:05:14 -05:00
|
|
|
$b['output']['thumb'] = DI::baseUrl()->get() . "/images/person-80.jpg";
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
2012-01-10 19:54:47 -05:00
|
|
|
}
|
|
|
|
|
2023-01-13 21:16:09 -05:00
|
|
|
function blockem_conversation_start(array &$b)
|
2018-07-20 21:51:15 -04:00
|
|
|
{
|
2021-07-25 13:28:07 -04:00
|
|
|
global $blockem_words;
|
|
|
|
|
2022-10-20 17:51:49 -04:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2012-01-11 20:36:20 -05:00
|
|
|
return;
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
2012-01-11 20:36:20 -05:00
|
|
|
|
2022-10-20 17:51:49 -04:00
|
|
|
$words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'blockem', 'words');
|
2018-07-20 21:51:15 -04:00
|
|
|
|
|
|
|
if ($words) {
|
2021-07-25 13:28:07 -04:00
|
|
|
$blockem_words = explode(',', $words);
|
2012-01-11 20:36:20 -05:00
|
|
|
}
|
2018-07-20 21:51:15 -04:00
|
|
|
|
2019-12-30 14:02:08 -05:00
|
|
|
DI::page()['htmlhead'] .= <<< EOT
|
2012-01-11 20:36:20 -05:00
|
|
|
|
|
|
|
<script>
|
|
|
|
function blockemBlock(author) {
|
|
|
|
$.get('blockem?block=' +author, function(data) {
|
|
|
|
location.reload(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function blockemUnblock(author) {
|
|
|
|
$.get('blockem?unblock=' +author, function(data) {
|
|
|
|
location.reload(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
EOT;
|
|
|
|
}
|
|
|
|
|
2023-01-13 21:16:09 -05:00
|
|
|
function blockem_item_photo_menu(array &$b)
|
2018-07-20 21:51:15 -04:00
|
|
|
{
|
2021-07-25 13:28:07 -04:00
|
|
|
global $blockem_words;
|
|
|
|
|
2022-10-20 17:51:49 -04:00
|
|
|
if (!DI::userSession()->getLocalUserId() || $b['item']['self']) {
|
2012-01-11 20:52:53 -05:00
|
|
|
return;
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
2012-01-11 20:52:53 -05:00
|
|
|
|
2012-01-11 20:36:20 -05:00
|
|
|
$blocked = false;
|
|
|
|
$author = $b['item']['author-link'];
|
2018-07-20 21:51:15 -04:00
|
|
|
|
2021-07-25 13:28:07 -04:00
|
|
|
if (!empty($blockem_words)) {
|
|
|
|
foreach($blockem_words as $bloke) {
|
2018-11-08 11:45:19 -05:00
|
|
|
if (Strings::compareLink($bloke,$author)) {
|
2012-01-11 20:36:20 -05:00
|
|
|
$blocked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-20 21:51:15 -04:00
|
|
|
if ($blocked) {
|
2020-01-18 14:52:33 -05:00
|
|
|
$b['menu'][DI::l10n()->t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
|
2018-07-20 21:51:15 -04:00
|
|
|
} else {
|
2020-01-18 14:52:33 -05:00
|
|
|
$b['menu'][DI::l10n()->t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
2012-01-11 20:36:20 -05:00
|
|
|
}
|
|
|
|
|
2022-06-24 17:27:58 -04:00
|
|
|
/**
|
|
|
|
* This is a statement rather than an actual function definition. The simple
|
|
|
|
* existence of this method is checked to figure out if the addon offers a
|
|
|
|
* module.
|
|
|
|
*/
|
|
|
|
function blockem_module() {}
|
2012-01-11 20:36:20 -05:00
|
|
|
|
2023-01-13 21:16:09 -05:00
|
|
|
function blockem_init()
|
2018-07-20 21:51:15 -04:00
|
|
|
{
|
2022-10-20 17:51:49 -04:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2012-01-11 20:36:20 -05:00
|
|
|
return;
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
2012-01-11 20:36:20 -05:00
|
|
|
|
2022-10-20 17:51:49 -04:00
|
|
|
$words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'blockem', 'words');
|
2012-01-11 20:36:20 -05:00
|
|
|
|
2018-07-20 21:51:15 -04:00
|
|
|
if (array_key_exists('block', $_GET) && $_GET['block']) {
|
|
|
|
if (strlen($words)) {
|
2012-01-11 20:36:20 -05:00
|
|
|
$words .= ',';
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
|
|
|
|
2012-01-11 20:36:20 -05:00
|
|
|
$words .= trim($_GET['block']);
|
|
|
|
}
|
2018-07-20 21:51:15 -04:00
|
|
|
|
|
|
|
if (array_key_exists('unblock', $_GET) && $_GET['unblock']) {
|
2012-01-11 20:36:20 -05:00
|
|
|
$arr = explode(',',$words);
|
2018-01-15 08:15:33 -05:00
|
|
|
$newarr = [];
|
2012-01-11 20:36:20 -05:00
|
|
|
|
2018-07-20 21:51:15 -04:00
|
|
|
if (count($arr)) {
|
|
|
|
foreach ($arr as $x) {
|
2018-11-08 11:45:19 -05:00
|
|
|
if (!Strings::compareLink(trim($x), trim($_GET['unblock']))) {
|
2012-01-11 20:36:20 -05:00
|
|
|
$newarr[] = $x;
|
2018-07-20 21:51:15 -04:00
|
|
|
}
|
2012-01-11 20:36:20 -05:00
|
|
|
}
|
|
|
|
}
|
2018-07-20 21:51:15 -04:00
|
|
|
|
|
|
|
$words = implode(',', $newarr);
|
2012-01-11 20:36:20 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 17:51:49 -04:00
|
|
|
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'blockem', 'words', $words);
|
2018-12-26 00:39:53 -05:00
|
|
|
exit();
|
2012-03-02 05:33:07 -05:00
|
|
|
}
|