extract validating item data into separate method
This commit is contained in:
parent
92ae748498
commit
2a7f7af02c
1 changed files with 73 additions and 66 deletions
|
@ -928,45 +928,6 @@ class Item
|
|||
|
||||
$defined_permissions = isset($item['allow_cid']) && isset($item['allow_gid']) && isset($item['deny_cid']) && isset($item['deny_gid']) && isset($item['private']);
|
||||
|
||||
$item['wall'] = intval($item['wall'] ?? 0);
|
||||
$item['extid'] = trim($item['extid'] ?? '');
|
||||
$item['author-name'] = trim($item['author-name'] ?? '');
|
||||
$item['author-link'] = trim($item['author-link'] ?? '');
|
||||
$item['author-avatar'] = trim($item['author-avatar'] ?? '');
|
||||
$item['owner-name'] = trim($item['owner-name'] ?? '');
|
||||
$item['owner-link'] = trim($item['owner-link'] ?? '');
|
||||
$item['owner-avatar'] = trim($item['owner-avatar'] ?? '');
|
||||
$item['received'] = (isset($item['received']) ? DateTimeFormat::utc($item['received']) : DateTimeFormat::utcNow());
|
||||
$item['created'] = (isset($item['created']) ? DateTimeFormat::utc($item['created']) : $item['received']);
|
||||
$item['edited'] = (isset($item['edited']) ? DateTimeFormat::utc($item['edited']) : $item['created']);
|
||||
$item['changed'] = (isset($item['changed']) ? DateTimeFormat::utc($item['changed']) : $item['created']);
|
||||
$item['commented'] = (isset($item['commented']) ? DateTimeFormat::utc($item['commented']) : $item['created']);
|
||||
$item['title'] = substr(trim($item['title'] ?? ''), 0, 255);
|
||||
$item['location'] = trim($item['location'] ?? '');
|
||||
$item['coord'] = trim($item['coord'] ?? '');
|
||||
$item['visible'] = (isset($item['visible']) ? intval($item['visible']) : 1);
|
||||
$item['deleted'] = 0;
|
||||
$item['verb'] = trim($item['verb'] ?? '');
|
||||
$item['object-type'] = trim($item['object-type'] ?? '');
|
||||
$item['object'] = trim($item['object'] ?? '');
|
||||
$item['target-type'] = trim($item['target-type'] ?? '');
|
||||
$item['target'] = trim($item['target'] ?? '');
|
||||
$item['plink'] = substr(trim($item['plink'] ?? ''), 0, 255);
|
||||
$item['allow_cid'] = trim($item['allow_cid'] ?? '');
|
||||
$item['allow_gid'] = trim($item['allow_gid'] ?? '');
|
||||
$item['deny_cid'] = trim($item['deny_cid'] ?? '');
|
||||
$item['deny_gid'] = trim($item['deny_gid'] ?? '');
|
||||
$item['private'] = intval($item['private'] ?? self::PUBLIC);
|
||||
$item['body'] = trim($item['body'] ?? '');
|
||||
$item['raw-body'] = trim($item['raw-body'] ?? $item['body']);
|
||||
$item['app'] = trim($item['app'] ?? '');
|
||||
$item['origin'] = intval($item['origin'] ?? 0);
|
||||
$item['postopts'] = trim($item['postopts'] ?? '');
|
||||
$item['resource-id'] = trim($item['resource-id'] ?? '');
|
||||
$item['event-id'] = intval($item['event-id'] ?? 0);
|
||||
$item['inform'] = trim($item['inform'] ?? '');
|
||||
$item['file'] = trim($item['file'] ?? '');
|
||||
|
||||
// Communities aren't working with the Diaspora protocol
|
||||
if (($uid != 0) && ($item['network'] == Protocol::DIASPORA)) {
|
||||
$user = User::getById($uid, ['account-type']);
|
||||
|
@ -976,33 +937,7 @@ class Item
|
|||
}
|
||||
}
|
||||
|
||||
// Items cannot be stored before they happen ...
|
||||
if ($item['created'] > DateTimeFormat::utcNow()) {
|
||||
$item['created'] = DateTimeFormat::utcNow();
|
||||
}
|
||||
|
||||
// We haven't invented time travel by now.
|
||||
if ($item['edited'] > DateTimeFormat::utcNow()) {
|
||||
$item['edited'] = DateTimeFormat::utcNow();
|
||||
}
|
||||
|
||||
$item['plink'] = ($item['plink'] ?? '') ?: DI::baseUrl() . '/display/' . urlencode($item['guid']);
|
||||
|
||||
$item['gravity'] = self::getGravity($item);
|
||||
|
||||
$default = [
|
||||
'url' => $item['author-link'], 'name' => $item['author-name'],
|
||||
'photo' => $item['author-avatar'], 'network' => $item['network']
|
||||
];
|
||||
$item['author-id'] = ($item['author-id'] ?? 0) ?: Contact::getIdForURL($item['author-link'], 0, null, $default);
|
||||
|
||||
$default = [
|
||||
'url' => $item['owner-link'], 'name' => $item['owner-name'],
|
||||
'photo' => $item['owner-avatar'], 'network' => $item['network']
|
||||
];
|
||||
$item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
|
||||
|
||||
$item['post-reason'] = self::getPostReason($item);
|
||||
$item = self::validateItemData($item);
|
||||
|
||||
// Ensure that there is an avatar cache
|
||||
Contact::checkAvatarCache($item['author-id']);
|
||||
|
@ -1490,6 +1425,78 @@ class Item
|
|||
return $post_user_id;
|
||||
}
|
||||
|
||||
private static function validateItemData(array $item): array
|
||||
{
|
||||
$item['wall'] = intval($item['wall'] ?? 0);
|
||||
$item['extid'] = trim($item['extid'] ?? '');
|
||||
$item['author-name'] = trim($item['author-name'] ?? '');
|
||||
$item['author-link'] = trim($item['author-link'] ?? '');
|
||||
$item['author-avatar'] = trim($item['author-avatar'] ?? '');
|
||||
$item['owner-name'] = trim($item['owner-name'] ?? '');
|
||||
$item['owner-link'] = trim($item['owner-link'] ?? '');
|
||||
$item['owner-avatar'] = trim($item['owner-avatar'] ?? '');
|
||||
$item['received'] = (isset($item['received']) ? DateTimeFormat::utc($item['received']) : DateTimeFormat::utcNow());
|
||||
$item['created'] = (isset($item['created']) ? DateTimeFormat::utc($item['created']) : $item['received']);
|
||||
$item['edited'] = (isset($item['edited']) ? DateTimeFormat::utc($item['edited']) : $item['created']);
|
||||
$item['changed'] = (isset($item['changed']) ? DateTimeFormat::utc($item['changed']) : $item['created']);
|
||||
$item['commented'] = (isset($item['commented']) ? DateTimeFormat::utc($item['commented']) : $item['created']);
|
||||
$item['title'] = substr(trim($item['title'] ?? ''), 0, 255);
|
||||
$item['location'] = trim($item['location'] ?? '');
|
||||
$item['coord'] = trim($item['coord'] ?? '');
|
||||
$item['visible'] = (isset($item['visible']) ? intval($item['visible']) : 1);
|
||||
$item['deleted'] = 0;
|
||||
$item['verb'] = trim($item['verb'] ?? '');
|
||||
$item['object-type'] = trim($item['object-type'] ?? '');
|
||||
$item['object'] = trim($item['object'] ?? '');
|
||||
$item['target-type'] = trim($item['target-type'] ?? '');
|
||||
$item['target'] = trim($item['target'] ?? '');
|
||||
$item['plink'] = substr(trim($item['plink'] ?? ''), 0, 255);
|
||||
$item['allow_cid'] = trim($item['allow_cid'] ?? '');
|
||||
$item['allow_gid'] = trim($item['allow_gid'] ?? '');
|
||||
$item['deny_cid'] = trim($item['deny_cid'] ?? '');
|
||||
$item['deny_gid'] = trim($item['deny_gid'] ?? '');
|
||||
$item['private'] = intval($item['private'] ?? self::PUBLIC);
|
||||
$item['body'] = trim($item['body'] ?? '');
|
||||
$item['raw-body'] = trim($item['raw-body'] ?? $item['body']);
|
||||
$item['app'] = trim($item['app'] ?? '');
|
||||
$item['origin'] = intval($item['origin'] ?? 0);
|
||||
$item['postopts'] = trim($item['postopts'] ?? '');
|
||||
$item['resource-id'] = trim($item['resource-id'] ?? '');
|
||||
$item['event-id'] = intval($item['event-id'] ?? 0);
|
||||
$item['inform'] = trim($item['inform'] ?? '');
|
||||
$item['file'] = trim($item['file'] ?? '');
|
||||
|
||||
// Items cannot be stored before they happen ...
|
||||
if ($item['created'] > DateTimeFormat::utcNow()) {
|
||||
$item['created'] = DateTimeFormat::utcNow();
|
||||
}
|
||||
|
||||
// We haven't invented time travel by now.
|
||||
if ($item['edited'] > DateTimeFormat::utcNow()) {
|
||||
$item['edited'] = DateTimeFormat::utcNow();
|
||||
}
|
||||
|
||||
$item['plink'] = ($item['plink'] ?? '') ?: DI::baseUrl() . '/display/' . urlencode($item['guid']);
|
||||
|
||||
$item['gravity'] = self::getGravity($item);
|
||||
|
||||
$default = [
|
||||
'url' => $item['author-link'], 'name' => $item['author-name'],
|
||||
'photo' => $item['author-avatar'], 'network' => $item['network']
|
||||
];
|
||||
$item['author-id'] = ($item['author-id'] ?? 0) ?: Contact::getIdForURL($item['author-link'], 0, null, $default);
|
||||
|
||||
$default = [
|
||||
'url' => $item['owner-link'], 'name' => $item['owner-name'],
|
||||
'photo' => $item['owner-avatar'], 'network' => $item['network']
|
||||
];
|
||||
$item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
|
||||
|
||||
$item['post-reason'] = self::getPostReason($item);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
private static function hasRestrictions(array $item, int $author_id, int $restrictions = null): bool
|
||||
{
|
||||
if (empty($restrictions) || ($author_id == $item['author-id'])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue