2019-05-02 06:01:43 +02:00
< ? php
2020-02-09 15:45:36 +01:00
/**
2021-03-29 08:40:20 +02:00
* @ copyright Copyright ( C ) 2010 - 2021 , the Friendica project
2020-02-09 15:45:36 +01:00
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
*/
2019-05-02 06:01:43 +02:00
namespace Friendica\Module\Admin\Blocklist ;
use Friendica\Content\Pager ;
use Friendica\Core\Renderer ;
2021-10-13 02:15:20 +02:00
use Friendica\Core\Worker ;
2019-05-02 06:01:43 +02:00
use Friendica\Database\DBA ;
2019-12-15 22:34:11 +01:00
use Friendica\DI ;
2019-05-02 06:01:43 +02:00
use Friendica\Model ;
2021-10-13 02:15:20 +02:00
use Friendica\Module\BaseAdmin ;
use Friendica\Util\Network ;
2019-05-02 06:01:43 +02:00
2020-01-23 05:14:14 +01:00
class Contact extends BaseAdmin
2019-05-02 06:01:43 +02:00
{
2019-11-05 22:48:54 +01:00
public static function post ( array $parameters = [])
2019-05-02 06:01:43 +02:00
{
2020-09-08 16:44:27 +02:00
self :: checkAdminAccess ();
2019-05-02 06:01:43 +02:00
2020-09-08 16:42:25 +02:00
self :: checkFormSecurityTokenRedirectOnError ( '/admin/blocklist/contact' , 'admin_contactblock' );
2019-05-02 06:01:43 +02:00
2019-10-15 15:20:32 +02:00
$contact_url = $_POST [ 'contact_url' ] ? ? '' ;
$block_reason = $_POST [ 'contact_block_reason' ] ? ? '' ;
2021-10-13 02:15:20 +02:00
$block_purge = $_POST [ 'contact_block_purge' ] ? ? false ;
2019-10-15 15:20:32 +02:00
$contacts = $_POST [ 'contacts' ] ? ? [];
2019-05-02 06:01:43 +02:00
if ( ! empty ( $_POST [ 'page_contactblock_block' ])) {
2021-10-13 02:15:20 +02:00
$contact = Model\Contact :: getByURL ( $contact_url , null , [ 'id' , 'nurl' ]);
if ( empty ( $contact )) {
2020-01-18 20:52:34 +01:00
notice ( DI :: l10n () -> t ( 'Could not find any contact entry for this URL (%s)' , $contact_url ));
2021-10-13 02:15:20 +02:00
DI :: baseUrl () -> redirect ( 'admin/blocklist/contact' );
}
if ( Network :: isLocalLink ( $contact [ 'nurl' ])) {
notice ( DI :: l10n () -> t ( 'You can\'t block a local contact, please block the user instead' ));
DI :: baseUrl () -> redirect ( 'admin/blocklist/contact' );
2019-05-02 06:01:43 +02:00
}
2021-10-13 02:15:20 +02:00
Model\Contact :: block ( $contact [ 'id' ], $block_reason );
if ( $block_purge ) {
foreach ( Model\Contact :: selectToArray ([ 'id' ], [ 'nurl' => $contact [ 'nurl' ]]) as $contact ) {
Worker :: add ( PRIORITY_LOW , 'Contact\RemoveContent' , $contact [ 'id' ]);
}
}
info ( DI :: l10n () -> t ( 'The contact has been blocked from the node' ));
2019-05-02 06:01:43 +02:00
}
if ( ! empty ( $_POST [ 'page_contactblock_unblock' ])) {
foreach ( $contacts as $uid ) {
Model\Contact :: unblock ( $uid );
}
2020-09-07 12:17:42 +02:00
info ( DI :: l10n () -> tt ( '%s contact unblocked' , '%s contacts unblocked' , count ( $contacts )));
2019-05-02 06:01:43 +02:00
}
2019-12-16 00:28:31 +01:00
DI :: baseUrl () -> redirect ( 'admin/blocklist/contact' );
2019-05-02 06:01:43 +02:00
}
2019-11-05 22:48:54 +01:00
public static function content ( array $parameters = [])
2019-05-02 06:01:43 +02:00
{
2019-11-05 21:22:54 +01:00
parent :: content ( $parameters );
2019-05-02 06:01:43 +02:00
$condition = [ 'uid' => 0 , 'blocked' => true ];
$total = DBA :: count ( 'contact' , $condition );
2020-02-16 17:53:52 +01:00
$pager = new Pager ( DI :: l10n (), DI :: args () -> getQueryString (), 30 );
2019-05-02 06:01:43 +02:00
2019-07-27 17:57:23 +02:00
$contacts = Model\Contact :: selectToArray ([], $condition , [ 'limit' => [ $pager -> getStart (), $pager -> getItemsPerPage ()]]);
2019-05-02 06:01:43 +02:00
$t = Renderer :: getMarkupTemplate ( 'admin/blocklist/contact.tpl' );
$o = Renderer :: replaceMacros ( $t , [
// strings //
2020-01-18 20:52:34 +01: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 06:01:43 +02:00
2020-09-08 16:42:25 +02:00
'$form_security_token' => self :: getFormSecurityToken ( 'admin_contactblock' ),
2019-05-02 06:01:43 +02:00
// values //
2019-12-16 01:05:15 +01:00
'$baseurl' => DI :: baseUrl () -> get ( true ),
2019-05-02 06:01:43 +02:00
'$contacts' => $contacts ,
2020-01-18 20:53:01 +01:00
'$total_contacts' => DI :: l10n () -> tt ( '%s total blocked contact' , '%s total blocked contacts' , $total ),
2019-05-02 06:01:43 +02:00
'$paginate' => $pager -> renderFull ( $total ),
2020-01-18 20:52:34 +01:00
'$contacturl' => [ 'contact_url' , DI :: l10n () -> t ( 'Profile URL' ), '' , DI :: l10n () -> t ( 'URL of the remote contact to block.' )],
2021-10-13 02:15:20 +02:00
'$contact_block_purge' => [ 'contact_block_purge' , DI :: l10n () -> t ( 'Also purge contact' ), false , DI :: l10n () -> t ( 'Removes all content related to this contact from the node. Keeps the contact record. This action canoot be undone.' )],
2020-01-18 20:52:34 +01:00
'$contact_block_reason' => [ 'contact_block_reason' , DI :: l10n () -> t ( 'Block Reason' )],
2019-05-02 06:01:43 +02:00
]);
return $o ;
}
}