2021-09-21 01:04:24 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-05 01:00:58 +09:00
|
|
|
namespace Plugin\ActivityPub\Util\Model\AS2ToEntity;
|
2021-09-21 01:04:24 +09:00
|
|
|
|
|
|
|
use App\Core\Event;
|
|
|
|
use App\Entity\Actor;
|
|
|
|
use App\Entity\Note;
|
|
|
|
use App\Util\Formatting;
|
|
|
|
use DateTime;
|
|
|
|
|
|
|
|
abstract class AS2ToGSActor
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param array $args
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
*
|
|
|
|
* @return Note
|
|
|
|
*/
|
|
|
|
public static function translate(array $args, ?string $source = null): Actor
|
|
|
|
{
|
|
|
|
$map = [
|
|
|
|
'isLocal' => false,
|
|
|
|
'created' => new DateTime($args['published'] ?? 'now'),
|
|
|
|
'content' => $args['content'] ?? null,
|
|
|
|
'content_type' => 'text/html',
|
|
|
|
'rendered' => null,
|
|
|
|
'modified' => new DateTime(),
|
|
|
|
'source' => $source,
|
|
|
|
];
|
|
|
|
if ($map['content'] !== null) {
|
|
|
|
Event::handle('RenderNoteContent', [
|
|
|
|
$map['content'],
|
|
|
|
$map['content_type'],
|
|
|
|
&$map['rendered'],
|
2021-10-05 01:00:58 +09:00
|
|
|
Actor::getById(1), // just for testing
|
2021-09-21 01:04:24 +09:00
|
|
|
null, // reply to
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = new Note();
|
|
|
|
foreach ($map as $prop => $val) {
|
|
|
|
$set = Formatting::snakeCaseToCamelCase("set_{$prop}");
|
|
|
|
$obj->{$set}($val);
|
|
|
|
}
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
}
|