[ActivityStreamsTwo] Further work on routes and use render event on note's content
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace Plugin\ActivityStreamsTwo\Util\Model\AS2ToEntity;
|
||||
|
||||
use App\Core\Security;
|
||||
use App\Core\Event;
|
||||
use App\Entity\Actor;
|
||||
use App\Entity\Note;
|
||||
use App\Util\Formatting;
|
||||
use DateTime;
|
||||
|
||||
abstract class AS2ToNote
|
||||
@@ -15,21 +17,30 @@ abstract class AS2ToNote
|
||||
*
|
||||
* @return Note
|
||||
*/
|
||||
public static function translate(array $args): Note
|
||||
public static function translate(array $args, ?string $source = null): Note
|
||||
{
|
||||
$map = [
|
||||
'isLocal' => false,
|
||||
'created' => new DateTime($args['published'] ?? 'now'),
|
||||
'rendered' => $args['content'] ?? null,
|
||||
'modified' => new DateTime(),
|
||||
'isLocal' => false,
|
||||
'created' => new DateTime($args['published'] ?? 'now'),
|
||||
'content' => $args['content'] ?? null,
|
||||
'content_type' => 'text/html',
|
||||
'rendered' => null,
|
||||
'modified' => new DateTime(),
|
||||
'source' => $source,
|
||||
];
|
||||
if (!is_null($map['rendered'])) {
|
||||
$map['content'] = Security::sanitize($map['rendered']);
|
||||
if ($map['content'] !== null) {
|
||||
Event::handle('RenderNoteContent', [
|
||||
$map['content'],
|
||||
$map['content_type'],
|
||||
&$map['rendered'],
|
||||
Actor::getFromId(1), // just for testing
|
||||
null, // reply to
|
||||
]);
|
||||
}
|
||||
|
||||
$obj = new Note();
|
||||
foreach ($map as $prop => $val) {
|
||||
$set = "set{$prop}";
|
||||
$set = Formatting::snakeCaseToCamelCase("set_{$prop}");
|
||||
$obj->{$set}($val);
|
||||
}
|
||||
return $obj;
|
||||
|
Reference in New Issue
Block a user