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