2021-04-02 17:20:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2021 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace ActivityPub\Controllers;
|
|
|
|
|
|
|
|
use CodeIgniter\Controller;
|
|
|
|
|
|
|
|
class BlockController extends Controller
|
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2021-04-02 17:20:02 +00:00
|
|
|
protected $helpers = ['activitypub'];
|
|
|
|
|
|
|
|
public function attemptBlockActor()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'handle' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$handle = $this->request->getPost('handle');
|
|
|
|
|
|
|
|
if ($parts = split_handle($handle)) {
|
2021-05-12 14:00:25 +00:00
|
|
|
if (
|
|
|
|
($actor = get_or_create_actor(
|
|
|
|
$parts['username'],
|
|
|
|
$parts['domain'],
|
|
|
|
)) === null
|
|
|
|
) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', 'Actor not found.');
|
|
|
|
}
|
|
|
|
|
|
|
|
model('ActorModel')->blockActor($actor->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
function attemptBlockDomain()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'domain' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
model('BlockedDomainModel')->blockDomain(
|
|
|
|
$this->request->getPost('domain'),
|
|
|
|
);
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
function attemptUnblockActor()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'actor_id' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
model('ActorModel')->unblockActor($this->request->getPost('actor_id'));
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
function attemptUnblockDomain()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'domain' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
model('BlockedDomainModel')->unblockDomain(
|
|
|
|
$this->request->getPost('domain'),
|
|
|
|
);
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
}
|