2021-04-02 17:20:02 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2021 Ad Aures
|
2021-04-02 17:20:02 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-08-23 11:05:16 +00:00
|
|
|
namespace Modules\Fediverse\Controllers;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
use CodeIgniter\Controller;
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2022-03-04 14:33:48 +00:00
|
|
|
use Exception;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
class BlockController extends Controller
|
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
2024-04-28 16:39:01 +00:00
|
|
|
* @var list<string>
|
2021-05-06 14:00:48 +00:00
|
|
|
*/
|
2021-08-27 10:58:22 +00:00
|
|
|
protected $helpers = ['fediverse'];
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2024-12-18 16:05:25 +00:00
|
|
|
public function blockActorAction(): RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
2022-03-04 14:33:48 +00:00
|
|
|
'handle' => 'required|regex_match[/^@?([\w\.\-]+)@([\w\.\-]+)(:[\d]+)?$/]',
|
2021-04-02 17:20:02 +00:00
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2023-08-29 15:42:52 +00:00
|
|
|
$validData = $this->validator->getValidated();
|
|
|
|
|
|
|
|
$handle = $validData['handle'];
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
if ($parts = split_handle($handle)) {
|
2022-03-04 14:33:48 +00:00
|
|
|
try {
|
|
|
|
$actor = get_or_create_actor($parts['username'], $parts['domain']);
|
|
|
|
} catch (Exception) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2022-01-05 14:58:53 +00:00
|
|
|
->with('error', lang('Fediverse.messages.actorNotFound'));
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 11:40:30 +00:00
|
|
|
model('ActorModel', false)
|
2021-05-19 16:35:13 +00:00
|
|
|
->blockActor($actor->id);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 14:58:53 +00:00
|
|
|
return redirect()->back()
|
|
|
|
->with('message', lang('Fediverse.messages.blockActorSuccess', [
|
|
|
|
'actor' => $handle,
|
|
|
|
]));
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2024-12-18 16:05:25 +00:00
|
|
|
public function unblockActorAction(): RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
2021-06-08 16:57:04 +00:00
|
|
|
'actor_id' => 'required',
|
2021-04-02 17:20:02 +00:00
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2023-08-29 15:42:52 +00:00
|
|
|
$validData = $this->validator->getValidated();
|
|
|
|
|
2022-02-05 11:40:30 +00:00
|
|
|
model('ActorModel', false)
|
2023-08-29 15:42:52 +00:00
|
|
|
->unblockActor((int) $validData['actor_id']);
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2022-01-05 14:58:53 +00:00
|
|
|
return redirect()->back()
|
|
|
|
->with('message', lang('Fediverse.messages.unblockActorSuccess'));
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2024-12-18 16:05:25 +00:00
|
|
|
public function blockDomainAction(): RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
2022-03-04 14:33:48 +00:00
|
|
|
'domain' => 'required|regex_match[/^[\w\-\.]+[\w]+(:[\d]+)?/]',
|
2021-04-02 17:20:02 +00:00
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2023-08-29 15:42:52 +00:00
|
|
|
$validData = $this->validator->getValidated();
|
|
|
|
|
|
|
|
$domain = $validData['domain'];
|
2022-02-05 11:40:30 +00:00
|
|
|
model('BlockedDomainModel', false)
|
2022-01-05 14:58:53 +00:00
|
|
|
->blockDomain($domain);
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2022-01-05 14:58:53 +00:00
|
|
|
return redirect()->back()
|
|
|
|
->with('message', lang('Fediverse.messages.blockDomainSuccess', [
|
|
|
|
'domain' => $domain,
|
|
|
|
]));
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2024-12-18 16:05:25 +00:00
|
|
|
public function unblockDomainAction(): RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'domain' => 'required',
|
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2023-08-29 15:42:52 +00:00
|
|
|
$validData = $this->validator->getValidated();
|
|
|
|
|
|
|
|
$domain = $validData['domain'];
|
2022-02-05 11:40:30 +00:00
|
|
|
model('BlockedDomainModel', false)
|
2022-01-05 14:58:53 +00:00
|
|
|
->unblockDomain($domain);
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2022-01-05 14:58:53 +00:00
|
|
|
return redirect()->back()
|
|
|
|
->with('message', lang('Fediverse.messages.unblockDomainSuccess', [
|
|
|
|
'domain' => $domain,
|
|
|
|
]));
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
}
|