2013-04-29 00:22:45 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: superblock
|
|
|
|
* Description: block people
|
|
|
|
* Version: 1.0
|
|
|
|
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
|
2017-04-21 02:47:33 -04:00
|
|
|
*
|
2013-04-29 00:22:45 -04:00
|
|
|
*/
|
2018-01-16 19:51:12 -05:00
|
|
|
use Friendica\Core\Addon;
|
2018-01-22 14:03:11 -05:00
|
|
|
use Friendica\Core\L10n;
|
2017-11-06 18:55:24 -05:00
|
|
|
use Friendica\Core\PConfig;
|
2018-11-08 11:45:19 -05:00
|
|
|
use Friendica\Util\Strings;
|
2017-11-06 18:55:24 -05:00
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function superblock_install()
|
|
|
|
{
|
2018-01-20 08:57:41 -05:00
|
|
|
Addon::registerHook('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
|
|
|
|
Addon::registerHook('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
|
2018-01-16 19:51:12 -05:00
|
|
|
Addon::registerHook('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
|
|
|
|
Addon::registerHook('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
|
|
|
|
Addon::registerHook('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
|
2013-04-29 00:22:45 -04:00
|
|
|
}
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function superblock_uninstall()
|
|
|
|
{
|
2018-01-20 08:57:41 -05:00
|
|
|
Addon::unregisterHook('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
|
|
|
|
Addon::unregisterHook('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
|
2018-01-16 19:51:12 -05:00
|
|
|
Addon::unregisterHook('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
|
|
|
|
Addon::unregisterHook('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
|
|
|
|
Addon::unregisterHook('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
|
2013-04-29 00:22:45 -04:00
|
|
|
}
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function superblock_addon_settings(&$a, &$s)
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
2013-04-29 00:22:45 -04:00
|
|
|
return;
|
2017-04-21 02:47:33 -04:00
|
|
|
}
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2017-04-21 02:47:33 -04:00
|
|
|
/* Add our stylesheet to the page so we can make our settings look nice */
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2018-10-09 14:13:22 -04:00
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseURL() . '/addon/superblock/superblock.css' . '" media="all" />' . "\r\n";
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
$words = PConfig::get(local_user(), 'system', 'blocked');
|
|
|
|
if (!$words) {
|
2013-04-29 00:22:45 -04:00
|
|
|
$words = '';
|
2017-04-21 02:47:33 -04:00
|
|
|
}
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2017-04-21 02:47:33 -04:00
|
|
|
$s .= '<span id="settings_superblock_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
|
2018-08-16 13:49:41 -04:00
|
|
|
$s .= '<h3>' . L10n::t('Superblock') . '</h3>';
|
2017-04-21 02:47:33 -04:00
|
|
|
$s .= '</span>';
|
|
|
|
$s .= '<div id="settings_superblock_expanded" class="settings-block" style="display: none;">';
|
|
|
|
$s .= '<span class="fakelink" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
|
2018-08-16 13:49:41 -04:00
|
|
|
$s .= '<h3>' . L10n::t('Superblock') . '</h3>';
|
2017-04-21 02:47:33 -04:00
|
|
|
$s .= '</span>';
|
|
|
|
$s .= '<div id="superblock-wrapper">';
|
2018-01-22 14:03:11 -05:00
|
|
|
$s .= '<label id="superblock-label" for="superblock-words">' . L10n::t('Comma separated profile URLS to block') . ' </label>';
|
2017-04-21 02:47:33 -04:00
|
|
|
$s .= '<textarea id="superblock-words" type="text" name="superblock-words" >' . htmlspecialchars($words) . '</textarea>';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2018-01-22 14:03:11 -05:00
|
|
|
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="superblock-submit" name="superblock-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
|
2013-04-29 00:22:45 -04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function superblock_addon_settings_post(&$a, &$b)
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
2013-04-29 00:22:45 -04:00
|
|
|
return;
|
2018-08-08 02:24:47 -04:00
|
|
|
}
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
if (!empty($_POST['superblock-submit'])) {
|
|
|
|
PConfig::set(local_user(), 'system', 'blocked',trim($_POST['superblock-words']));
|
2018-01-22 14:03:11 -05:00
|
|
|
info(L10n::t('SUPERBLOCK Settings saved.') . EOL);
|
2013-04-29 00:22:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 04:18:03 -04:00
|
|
|
function superblock_enotify_store(&$a,&$b) {
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
$words = PConfig::get($b['uid'], 'system', 'blocked');
|
|
|
|
if ($words) {
|
|
|
|
$arr = explode(',', $words);
|
|
|
|
} else {
|
2013-05-09 04:18:03 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$found = false;
|
2018-08-08 02:24:47 -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-08-08 02:24:47 -04:00
|
|
|
if ($found) {
|
2013-05-09 04:18:03 -04:00
|
|
|
$b['abort'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function superblock_conversation_start(&$a, &$b)
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
2013-04-29 00:22:45 -04:00
|
|
|
return;
|
2018-08-08 02:24:47 -04:00
|
|
|
}
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
$words = PConfig::get(local_user(), 'system', 'blocked');
|
|
|
|
if ($words) {
|
|
|
|
$a->data['superblock'] = explode(',', $words);
|
2013-04-29 00:22:45 -04:00
|
|
|
}
|
|
|
|
$a->page['htmlhead'] .= <<< EOT
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function superblockBlock(author) {
|
|
|
|
$.get('superblock?block=' +author, function(data) {
|
|
|
|
location.reload(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
EOT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function superblock_item_photo_menu(&$a, &$b)
|
|
|
|
{
|
|
|
|
if (!local_user() || $b['item']['self']) {
|
2013-04-29 00:22:45 -04:00
|
|
|
return;
|
2018-08-08 02:24:47 -04:00
|
|
|
}
|
2013-04-29 00:22:45 -04:00
|
|
|
|
|
|
|
$blocked = false;
|
|
|
|
$author = $b['item']['author-link'];
|
2018-08-08 02:24:47 -04:00
|
|
|
if (!empty($a->data['superblock'])) {
|
|
|
|
foreach ($a->data['superblock'] as $bloke) {
|
2018-11-08 11:45:19 -05:00
|
|
|
if (Strings::compareLink($bloke, $author)) {
|
2013-04-29 00:22:45 -04:00
|
|
|
$blocked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-22 14:03:11 -05:00
|
|
|
$b['menu'][L10n::t('Block Completely')] = 'javascript:superblockBlock(\'' . $author . '\'); return false;';
|
2013-04-29 00:22:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function superblock_module() {}
|
|
|
|
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
function superblock_init(&$a)
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
2013-04-29 00:22:45 -04:00
|
|
|
return;
|
2018-08-08 02:24:47 -04:00
|
|
|
}
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
$words = PConfig::get(local_user(), 'system', 'blocked');
|
2013-04-29 00:22:45 -04:00
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
if (array_key_exists('block', $_GET) && $_GET['block']) {
|
|
|
|
if (strlen($words))
|
2013-04-29 00:22:45 -04:00
|
|
|
$words .= ',';
|
|
|
|
$words .= trim($_GET['block']);
|
|
|
|
}
|
|
|
|
|
2018-08-08 02:24:47 -04:00
|
|
|
PConfig::set(local_user(), 'system', 'blocked', $words);
|
2018-01-22 14:03:11 -05:00
|
|
|
info(L10n::t('superblock settings updated') . EOL );
|
2013-04-29 00:22:45 -04:00
|
|
|
killme();
|
|
|
|
}
|