2012-01-10 10:16:09 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: blockem
|
2018-02-09 11:14:20 +01:00
|
|
|
* Description: Allows users to hide content by collapsing posts and replies.
|
2012-01-10 10:16:09 +01:00
|
|
|
* Version: 1.0
|
|
|
|
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
|
2018-07-21 03:51:15 +02:00
|
|
|
* Author: Roland Haeder <https://f.haeder.net/roland>
|
2012-01-10 10:16:09 +01:00
|
|
|
*/
|
2018-07-21 03:51:15 +02:00
|
|
|
|
|
|
|
use Friendica\App;
|
2018-12-26 08:28:16 +01:00
|
|
|
use Friendica\Core\Hook;
|
2018-01-22 20:03:11 +01:00
|
|
|
use Friendica\Core\L10n;
|
2019-12-16 01:05:14 +01:00
|
|
|
use Friendica\DI;
|
2018-11-08 17:45:19 +01:00
|
|
|
use Friendica\Util\Strings;
|
2017-11-07 00:55:24 +01:00
|
|
|
|
2018-01-22 20:03:11 +01:00
|
|
|
function blockem_install()
|
|
|
|
{
|
2018-12-26 08:28:16 +01: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 10:16:09 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:03:11 +01:00
|
|
|
function blockem_uninstall()
|
|
|
|
{
|
2018-12-26 08:28:16 +01:00
|
|
|
Hook::unregister('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
|
|
|
|
Hook::unregister('prepare_body' , 'addon/blockem/blockem.php', 'blockem_prepare_body');
|
|
|
|
Hook::unregister('display_item' , 'addon/blockem/blockem.php', 'blockem_display_item');
|
|
|
|
Hook::unregister('addon_settings' , 'addon/blockem/blockem.php', 'blockem_addon_settings');
|
|
|
|
Hook::unregister('addon_settings_post' , 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
|
|
|
|
Hook::unregister('conversation_start' , 'addon/blockem/blockem.php', 'blockem_conversation_start');
|
|
|
|
Hook::unregister('item_photo_menu' , 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
|
|
|
|
Hook::unregister('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
|
2012-01-10 10:16:09 +01:00
|
|
|
}
|
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_addon_settings (App $a, &$s)
|
2018-01-20 14:57:41 +01:00
|
|
|
{
|
2018-08-08 08:24:47 +02:00
|
|
|
if (!local_user()) {
|
2012-01-10 10:16:09 +01:00
|
|
|
return;
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-10 10:16:09 +01:00
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
/* Add our stylesheet to the page so we can make our settings look nice */
|
2019-12-30 20:02:08 +01:00
|
|
|
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/blockem/blockem.css' . '" media="all" />' . "\r\n";
|
2012-01-10 10:16:09 +01:00
|
|
|
|
2020-01-18 16:50:56 +01:00
|
|
|
$words = DI::pConfig()->get(local_user(), 'blockem', 'words');
|
2018-07-21 03:51:15 +02:00
|
|
|
|
2018-08-08 08:24:47 +02:00
|
|
|
if (!$words) {
|
2012-01-10 10:16:09 +01:00
|
|
|
$words = '';
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-10 10:16:09 +01:00
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
$s .= '<span id="settings_blockem_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
|
2020-01-18 20:52:33 +01:00
|
|
|
$s .= '<h3>' . DI::l10n()->t('Blockem') . '</h3>';
|
2018-07-21 03:51:15 +02:00
|
|
|
$s .= '</span>';
|
|
|
|
$s .= '<div id="settings_blockem_expanded" class="settings-block" style="display: none;">';
|
|
|
|
$s .= '<span class="fakelink" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
|
2020-01-18 20:52:33 +01:00
|
|
|
$s .= '<h3>' . DI::l10n()->t('Blockem') . '</h3>';
|
2018-07-21 03:51:15 +02:00
|
|
|
$s .= '</span>';
|
2013-11-30 21:18:37 +01:00
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
$s .= '<div id="blockem-wrapper">';
|
2020-01-18 20:52:33 +01:00
|
|
|
$s .= '<div id="blockem-desc">'. DI::l10n()->t("Hides user's content by collapsing posts. Also replaces their avatar with generic image.") . ' </div>';
|
|
|
|
$s .= '<label id="blockem-label" for="blockem-words">' . DI::l10n()->t('Comma separated profile URLS:') . ' </label>';
|
2018-07-21 03:51:15 +02:00
|
|
|
$s .= '<textarea id="blockem-words" type="text" name="blockem-words" >' . htmlspecialchars($words) . '</textarea>';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
2012-01-10 10:16:09 +01:00
|
|
|
|
2020-01-18 20:52:33 +01:00
|
|
|
$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>';
|
2012-01-10 10:16:09 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_addon_settings_post(App $a, array &$b)
|
|
|
|
{
|
2018-08-08 08:24:47 +02:00
|
|
|
if (!local_user()) {
|
2012-01-10 10:16:09 +01:00
|
|
|
return;
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-10 10:16:09 +01:00
|
|
|
|
2018-08-08 08:24:47 +02:00
|
|
|
if (!empty($_POST['blockem-submit'])) {
|
2020-01-18 16:54:49 +01:00
|
|
|
DI::pConfig()->set(local_user(), 'blockem', 'words', trim($_POST['blockem-words']));
|
2020-01-18 20:52:33 +01:00
|
|
|
info(DI::l10n()->t('BLOCKEM Settings saved.') . EOL);
|
2012-01-10 10:16:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_enotify_store(App $a, array &$b)
|
|
|
|
{
|
2020-01-18 16:50:56 +01:00
|
|
|
$words = DI::pConfig()->get($b['uid'], 'blockem', 'words');
|
2013-05-09 10:18:03 +02:00
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
if ($words) {
|
|
|
|
$arr = explode(',', $words);
|
|
|
|
} else {
|
2013-05-09 10:18:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$found = false;
|
2018-07-21 03:51:15 +02:00
|
|
|
|
|
|
|
if (count($arr)) {
|
|
|
|
foreach ($arr as $word) {
|
|
|
|
if (!strlen(trim($word))) {
|
2013-05-09 10:18:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-11-08 17:45:19 +01:00
|
|
|
if (Strings::compareLink($b['url'], $word)) {
|
2013-05-09 10:18:03 +02:00
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-21 03:51:15 +02:00
|
|
|
|
|
|
|
if ($found) {
|
2013-05-09 10:18:03 +02:00
|
|
|
$b['abort'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_prepare_body_content_filter(App $a, array &$hook_data)
|
2018-04-01 08:31:15 +02:00
|
|
|
{
|
|
|
|
if (!local_user()) {
|
2012-01-10 10:16:09 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-04-01 08:31:15 +02:00
|
|
|
|
|
|
|
$profiles_string = null;
|
2018-07-21 03:51:15 +02:00
|
|
|
|
2018-04-01 08:31:15 +02:00
|
|
|
if (local_user()) {
|
2020-01-18 16:50:56 +01:00
|
|
|
$profiles_string = DI::pConfig()->get(local_user(), 'blockem', 'words');
|
2012-01-10 10:16:09 +01:00
|
|
|
}
|
2018-04-01 08:31:15 +02:00
|
|
|
|
|
|
|
if ($profiles_string) {
|
|
|
|
$profiles_array = explode(',', $profiles_string);
|
|
|
|
} else {
|
2012-01-10 10:16:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$found = false;
|
2018-07-21 03:51:15 +02:00
|
|
|
|
2018-04-01 08:31:15 +02:00
|
|
|
foreach ($profiles_array as $word) {
|
2018-11-08 17:45:19 +01:00
|
|
|
if (Strings::compareLink($hook_data['item']['author-link'], trim($word))) {
|
2018-04-01 08:31:15 +02:00
|
|
|
$found = true;
|
|
|
|
break;
|
2012-01-10 10:16:09 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-01 08:31:15 +02:00
|
|
|
|
|
|
|
if ($found) {
|
2020-01-18 20:52:33 +01:00
|
|
|
$hook_data['filter_reasons'][] = DI::l10n()->t('Filtered user: %s', $hook_data['item']['author-name']);
|
2012-01-10 10:16:09 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-11 01:54:47 +01:00
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_display_item(App $a, array &$b = null)
|
|
|
|
{
|
|
|
|
if (!empty($b['output']['body']) && strstr($b['output']['body'], 'id="blockem-wrap-')) {
|
2019-12-16 01:05:14 +01:00
|
|
|
$b['output']['thumb'] = DI::baseUrl()->get() . "/images/person-80.jpg";
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-11 01:54:47 +01:00
|
|
|
}
|
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_conversation_start(App $a, array &$b)
|
|
|
|
{
|
2018-08-08 08:24:47 +02:00
|
|
|
if (!local_user()) {
|
2012-01-12 02:36:20 +01:00
|
|
|
return;
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-12 02:36:20 +01:00
|
|
|
|
2020-01-18 16:50:56 +01:00
|
|
|
$words = DI::pConfig()->get(local_user(), 'blockem', 'words');
|
2018-07-21 03:51:15 +02:00
|
|
|
|
|
|
|
if ($words) {
|
|
|
|
$a->data['blockem'] = explode(',', $words);
|
2012-01-12 02:36:20 +01:00
|
|
|
}
|
2018-07-21 03:51:15 +02:00
|
|
|
|
2019-12-30 20:02:08 +01:00
|
|
|
DI::page()['htmlhead'] .= <<< EOT
|
2012-01-12 02:36:20 +01: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;
|
|
|
|
}
|
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_item_photo_menu(App $a, array &$b)
|
|
|
|
{
|
2018-08-08 08:24:47 +02:00
|
|
|
if (!local_user() || $b['item']['self']) {
|
2012-01-12 02:52:53 +01:00
|
|
|
return;
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-12 02:52:53 +01:00
|
|
|
|
2012-01-12 02:36:20 +01:00
|
|
|
$blocked = false;
|
|
|
|
$author = $b['item']['author-link'];
|
2018-07-21 03:51:15 +02:00
|
|
|
|
|
|
|
if (!empty($a->data['blockem'])) {
|
2012-01-12 02:36:20 +01:00
|
|
|
foreach($a->data['blockem'] as $bloke) {
|
2018-11-08 17:45:19 +01:00
|
|
|
if (Strings::compareLink($bloke,$author)) {
|
2012-01-12 02:36:20 +01:00
|
|
|
$blocked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-21 03:51:15 +02:00
|
|
|
if ($blocked) {
|
2020-01-18 20:52:33 +01:00
|
|
|
$b['menu'][DI::l10n()->t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
|
2018-07-21 03:51:15 +02:00
|
|
|
} else {
|
2020-01-18 20:52:33 +01:00
|
|
|
$b['menu'][DI::l10n()->t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-12 02:36:20 +01:00
|
|
|
}
|
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_module()
|
|
|
|
{
|
|
|
|
}
|
2012-01-12 02:36:20 +01:00
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
function blockem_init(App $a)
|
|
|
|
{
|
2018-08-08 08:24:47 +02:00
|
|
|
if (!local_user()) {
|
2012-01-12 02:36:20 +01:00
|
|
|
return;
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-12 02:36:20 +01:00
|
|
|
|
2020-01-18 16:50:56 +01:00
|
|
|
$words = DI::pConfig()->get(local_user(), 'blockem', 'words');
|
2012-01-12 02:36:20 +01:00
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
if (array_key_exists('block', $_GET) && $_GET['block']) {
|
|
|
|
if (strlen($words)) {
|
2012-01-12 02:36:20 +01:00
|
|
|
$words .= ',';
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 02:36:20 +01:00
|
|
|
$words .= trim($_GET['block']);
|
|
|
|
}
|
2018-07-21 03:51:15 +02:00
|
|
|
|
|
|
|
if (array_key_exists('unblock', $_GET) && $_GET['unblock']) {
|
2012-01-12 02:36:20 +01:00
|
|
|
$arr = explode(',',$words);
|
2018-01-15 14:15:33 +01:00
|
|
|
$newarr = [];
|
2012-01-12 02:36:20 +01:00
|
|
|
|
2018-07-21 03:51:15 +02:00
|
|
|
if (count($arr)) {
|
|
|
|
foreach ($arr as $x) {
|
2018-11-08 17:45:19 +01:00
|
|
|
if (!Strings::compareLink(trim($x), trim($_GET['unblock']))) {
|
2012-01-12 02:36:20 +01:00
|
|
|
$newarr[] = $x;
|
2018-07-21 03:51:15 +02:00
|
|
|
}
|
2012-01-12 02:36:20 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-21 03:51:15 +02:00
|
|
|
|
|
|
|
$words = implode(',', $newarr);
|
2012-01-12 02:36:20 +01:00
|
|
|
}
|
|
|
|
|
2020-01-18 16:54:49 +01:00
|
|
|
DI::pConfig()->set(local_user(), 'blockem', 'words', $words);
|
2020-01-18 20:52:33 +01:00
|
|
|
info(DI::l10n()->t('blockem settings updated') . EOL);
|
2018-12-26 06:39:53 +01:00
|
|
|
exit();
|
2012-03-02 11:33:07 +01:00
|
|
|
}
|