2013-04-29 04:22:45 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: superblock
|
|
|
|
* Description: block people
|
|
|
|
* Version: 1.0
|
|
|
|
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
|
2017-04-21 06:47:33 +00:00
|
|
|
*
|
2013-04-29 04:22:45 +00:00
|
|
|
*/
|
2021-11-20 09:56:55 +00:00
|
|
|
|
|
|
|
use Friendica\App;
|
2018-12-26 07:28:16 +00:00
|
|
|
use Friendica\Core\Hook;
|
2021-11-20 09:56:55 +00:00
|
|
|
use Friendica\Core\Renderer;
|
2019-12-30 02:55:10 +00:00
|
|
|
use Friendica\DI;
|
2018-11-08 16:45:19 +00:00
|
|
|
use Friendica\Util\Strings;
|
2017-11-06 23:55:24 +00:00
|
|
|
|
2018-08-08 06:24:47 +00:00
|
|
|
function superblock_install()
|
|
|
|
{
|
2018-12-26 07:28:16 +00:00
|
|
|
Hook::register('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
|
|
|
|
Hook::register('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
|
|
|
|
Hook::register('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
|
|
|
|
Hook::register('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
|
|
|
|
Hook::register('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
|
2013-04-29 04:22:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 09:56:55 +00:00
|
|
|
function superblock_addon_settings(App &$a, array &$data)
|
2018-08-08 06:24:47 +00:00
|
|
|
{
|
2022-10-20 21:51:49 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2013-04-29 04:22:45 +00:00
|
|
|
return;
|
2017-04-21 06:47:33 +00:00
|
|
|
}
|
2013-04-29 04:22:45 +00:00
|
|
|
|
2022-10-20 21:51:49 +00:00
|
|
|
$blocked = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked', '');
|
2013-04-29 04:22:45 +00:00
|
|
|
|
2021-11-20 09:56:55 +00:00
|
|
|
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/superblock/');
|
|
|
|
$html = Renderer::replaceMacros($t, [
|
|
|
|
'$urls' => ['superblock-words', DI::l10n()->t('Comma separated profile URLs to block'), $blocked],
|
|
|
|
]);
|
2013-04-29 04:22:45 +00:00
|
|
|
|
2021-11-20 09:56:55 +00:00
|
|
|
$data = [
|
|
|
|
'addon' => 'superblock',
|
|
|
|
'title' => DI::l10n()->t('Superblock'),
|
|
|
|
'html' => $html,
|
|
|
|
];
|
2013-04-29 04:22:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 05:16:22 +00:00
|
|
|
function superblock_addon_settings_post(App $a, array &$b)
|
2018-08-08 06:24:47 +00:00
|
|
|
{
|
2022-10-20 21:51:49 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2013-04-29 04:22:45 +00:00
|
|
|
return;
|
2018-08-08 06:24:47 +00:00
|
|
|
}
|
2013-04-29 04:22:45 +00:00
|
|
|
|
2018-08-08 06:24:47 +00:00
|
|
|
if (!empty($_POST['superblock-submit'])) {
|
2022-10-20 21:51:49 +00:00
|
|
|
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'blocked',trim($_POST['superblock-words']));
|
2013-04-29 04:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 05:16:22 +00:00
|
|
|
function superblock_enotify_store(App $a, array &$b)
|
|
|
|
{
|
2020-09-19 02:51:05 +00:00
|
|
|
if (empty($b['uid'])) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-09 08:18:03 +00:00
|
|
|
|
2020-01-18 15:50:56 +00:00
|
|
|
$words = DI::pConfig()->get($b['uid'], 'system', 'blocked');
|
2018-08-08 06:24:47 +00:00
|
|
|
if ($words) {
|
|
|
|
$arr = explode(',', $words);
|
|
|
|
} else {
|
2013-05-09 08:18:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$found = false;
|
2018-08-08 06:24:47 +00:00
|
|
|
if (count($arr)) {
|
|
|
|
foreach ($arr as $word) {
|
|
|
|
if (!strlen(trim($word))) {
|
2013-05-09 08:18:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-11-08 16:45:19 +00:00
|
|
|
if (Strings::compareLink($b['url'], $word)) {
|
2013-05-09 08:18:03 +00:00
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-23 05:16:22 +00:00
|
|
|
|
2018-08-08 06:24:47 +00:00
|
|
|
if ($found) {
|
2020-01-28 00:12:41 +00:00
|
|
|
// Empty out the fields
|
|
|
|
$b = [];
|
2013-05-09 08:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-23 05:16:22 +00:00
|
|
|
function superblock_conversation_start(App $a, array &$b)
|
2018-08-08 06:24:47 +00:00
|
|
|
{
|
2022-10-20 21:51:49 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2013-04-29 04:22:45 +00:00
|
|
|
return;
|
2018-08-08 06:24:47 +00:00
|
|
|
}
|
2013-04-29 04:22:45 +00:00
|
|
|
|
2022-10-20 21:51:49 +00:00
|
|
|
$words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked');
|
2018-08-08 06:24:47 +00:00
|
|
|
if ($words) {
|
|
|
|
$a->data['superblock'] = explode(',', $words);
|
2013-04-29 04:22:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 05:16:22 +00:00
|
|
|
DI::page()['htmlhead'] .= <<< EOT
|
2013-04-29 04:22:45 +00:00
|
|
|
<script>
|
|
|
|
function superblockBlock(author) {
|
|
|
|
$.get('superblock?block=' +author, function(data) {
|
|
|
|
location.reload(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
EOT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-23 05:16:22 +00:00
|
|
|
function superblock_item_photo_menu(App $a, array &$b)
|
2018-08-08 06:24:47 +00:00
|
|
|
{
|
2022-10-20 21:51:49 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId() || $b['item']['self']) {
|
2013-04-29 04:22:45 +00:00
|
|
|
return;
|
2018-08-08 06:24:47 +00:00
|
|
|
}
|
2013-04-29 04:22:45 +00:00
|
|
|
|
|
|
|
$blocked = false;
|
|
|
|
$author = $b['item']['author-link'];
|
2018-08-08 06:24:47 +00:00
|
|
|
if (!empty($a->data['superblock'])) {
|
|
|
|
foreach ($a->data['superblock'] as $bloke) {
|
2018-11-08 16:45:19 +00:00
|
|
|
if (Strings::compareLink($bloke, $author)) {
|
2013-04-29 04:22:45 +00:00
|
|
|
$blocked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 19:52:33 +00:00
|
|
|
$b['menu'][DI::l10n()->t('Block Completely')] = 'javascript:superblockBlock(\'' . $author . '\'); return false;';
|
2013-04-29 04:22:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 21:27:58 +00: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.
|
|
|
|
*/
|
2013-04-29 04:22:45 +00:00
|
|
|
function superblock_module() {}
|
|
|
|
|
2022-06-23 05:16:22 +00:00
|
|
|
function superblock_init(App $a)
|
2018-08-08 06:24:47 +00:00
|
|
|
{
|
2022-10-20 21:51:49 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2013-04-29 04:22:45 +00:00
|
|
|
return;
|
2018-08-08 06:24:47 +00:00
|
|
|
}
|
2013-04-29 04:22:45 +00:00
|
|
|
|
2022-10-20 21:51:49 +00:00
|
|
|
$words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked');
|
2013-04-29 04:22:45 +00:00
|
|
|
|
2018-08-08 06:24:47 +00:00
|
|
|
if (array_key_exists('block', $_GET) && $_GET['block']) {
|
|
|
|
if (strlen($words))
|
2013-04-29 04:22:45 +00:00
|
|
|
$words .= ',';
|
|
|
|
$words .= trim($_GET['block']);
|
|
|
|
}
|
|
|
|
|
2022-10-20 21:51:49 +00:00
|
|
|
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'blocked', $words);
|
2018-12-26 05:39:53 +00:00
|
|
|
exit();
|
2013-04-29 04:22:45 +00:00
|
|
|
}
|