2019-05-02 04:01:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module\Admin\Blocklist;
|
|
|
|
|
|
|
|
use Friendica\Content\Pager;
|
|
|
|
use Friendica\Core\L10n;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Database\DBA;
|
2019-12-15 21:34:11 +00:00
|
|
|
use Friendica\DI;
|
2019-05-02 04:01:43 +00:00
|
|
|
use Friendica\Module\BaseAdminModule;
|
|
|
|
use Friendica\Model;
|
|
|
|
|
|
|
|
class Contact extends BaseAdminModule
|
|
|
|
{
|
2019-11-05 21:48:54 +00:00
|
|
|
public static function post(array $parameters = [])
|
2019-05-02 04:01:43 +00:00
|
|
|
{
|
2019-11-05 20:22:54 +00:00
|
|
|
parent::post($parameters);
|
2019-05-02 04:01:43 +00:00
|
|
|
|
2019-10-15 13:20:32 +00:00
|
|
|
$contact_url = $_POST['contact_url'] ?? '';
|
|
|
|
$block_reason = $_POST['contact_block_reason'] ?? '';
|
|
|
|
$contacts = $_POST['contacts'] ?? [];
|
2019-05-02 04:01:43 +00:00
|
|
|
|
|
|
|
parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
|
|
|
|
|
|
|
|
if (!empty($_POST['page_contactblock_block'])) {
|
|
|
|
$contact_id = Model\Contact::getIdForURL($contact_url);
|
|
|
|
if ($contact_id) {
|
2019-05-15 23:30:13 +00:00
|
|
|
Model\Contact::block($contact_id, $block_reason);
|
2020-01-18 19:52:34 +00:00
|
|
|
notice(DI::l10n()->t('The contact has been blocked from the node'));
|
2019-05-02 04:01:43 +00:00
|
|
|
} else {
|
2020-01-18 19:52:34 +00:00
|
|
|
notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
|
2019-05-02 04:01:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($_POST['page_contactblock_unblock'])) {
|
|
|
|
foreach ($contacts as $uid) {
|
|
|
|
Model\Contact::unblock($uid);
|
|
|
|
}
|
2019-05-15 23:30:13 +00:00
|
|
|
notice(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
|
2019-05-02 04:01:43 +00:00
|
|
|
}
|
|
|
|
|
2019-12-15 23:28:31 +00:00
|
|
|
DI::baseUrl()->redirect('admin/blocklist/contact');
|
2019-05-02 04:01:43 +00:00
|
|
|
}
|
|
|
|
|
2019-11-05 21:48:54 +00:00
|
|
|
public static function content(array $parameters = [])
|
2019-05-02 04:01:43 +00:00
|
|
|
{
|
2019-11-05 20:22:54 +00:00
|
|
|
parent::content($parameters);
|
2019-05-02 04:01:43 +00:00
|
|
|
|
|
|
|
$condition = ['uid' => 0, 'blocked' => true];
|
|
|
|
|
|
|
|
$total = DBA::count('contact', $condition);
|
|
|
|
|
2019-12-16 00:30:34 +00:00
|
|
|
$pager = new Pager(DI::args()->getQueryString(), 30);
|
2019-05-02 04:01:43 +00:00
|
|
|
|
2019-07-27 15:57:23 +00:00
|
|
|
$contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
|
2019-05-02 04:01:43 +00:00
|
|
|
|
|
|
|
$t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
|
|
|
|
$o = Renderer::replaceMacros($t, [
|
|
|
|
// strings //
|
2020-01-18 19:52:34 +00:00
|
|
|
'$title' => DI::l10n()->t('Administration'),
|
|
|
|
'$page' => DI::l10n()->t('Remote Contact Blocklist'),
|
|
|
|
'$description' => DI::l10n()->t('This page allows you to prevent any message from a remote contact to reach your node.'),
|
|
|
|
'$submit' => DI::l10n()->t('Block Remote Contact'),
|
|
|
|
'$select_all' => DI::l10n()->t('select all'),
|
|
|
|
'$select_none' => DI::l10n()->t('select none'),
|
|
|
|
'$block' => DI::l10n()->t('Block'),
|
|
|
|
'$unblock' => DI::l10n()->t('Unblock'),
|
|
|
|
'$no_data' => DI::l10n()->t('No remote contact is blocked from this node.'),
|
|
|
|
|
|
|
|
'$h_contacts' => DI::l10n()->t('Blocked Remote Contacts'),
|
|
|
|
'$h_newblock' => DI::l10n()->t('Block New Remote Contact'),
|
|
|
|
'$th_contacts' => [DI::l10n()->t('Photo'), DI::l10n()->t('Name'), DI::l10n()->t('Reason')],
|
2019-05-02 04:01:43 +00:00
|
|
|
|
2019-05-15 23:30:13 +00:00
|
|
|
'$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
|
2019-05-02 04:01:43 +00:00
|
|
|
|
|
|
|
// values //
|
2019-12-16 00:05:15 +00:00
|
|
|
'$baseurl' => DI::baseUrl()->get(true),
|
2019-05-02 04:01:43 +00:00
|
|
|
|
|
|
|
'$contacts' => $contacts,
|
|
|
|
'$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total),
|
|
|
|
'$paginate' => $pager->renderFull($total),
|
2020-01-18 19:52:34 +00:00
|
|
|
'$contacturl' => ['contact_url', DI::l10n()->t('Profile URL'), '', DI::l10n()->t('URL of the remote contact to block.')],
|
|
|
|
'$contact_block_reason' => ['contact_block_reason', DI::l10n()->t('Block Reason')],
|
2019-05-02 04:01:43 +00:00
|
|
|
]);
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|