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