<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
public static function guid($item, $notify)
{
if (!empty($item['guid'])) {
- return Strings::escapeTags(trim($item['guid']));
+ return trim($item['guid']);
}
if ($notify) {
// We use "microtime" to keep the arrival order and "mt_rand" to avoid duplicates
$file = 'item-' . round(microtime(true) * 10000) . '-' . mt_rand() . '.msg';
- $spoolpath = get_spoolpath();
+ $spoolpath = System::getSpoolPath();
if ($spoolpath != "") {
$spool = $spoolpath . '/' . $file;
$item['parent'] = $parent_id;
// Trigger automatic reactions for addons
- $item['api_source'] = true;
+ if (!isset($item['api_source'])) {
+ $item['api_source'] = true;
+ }
// We have to tell the hooks who we are - this really should be improved
if (!local_user()) {
}
if (!empty($item['cancel'])) {
- Logger::log('post cancelled by addon.');
+ Logger::notice('post cancelled by addon.');
return 0;
}
foreach ($matches as $mtch) {
if (Strings::compareLink($link, $mtch[1]) || Strings::compareLink($dlink, $mtch[1])) {
$mention = true;
- Logger::log('mention found: ' . $mtch[2]);
+ Logger::notice('mention found', ['mention' => $mtch[2]]);
}
}
}
$condition[] = $network;
}
- $condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
- $condition[] = $days;
+ $condition[0] .= " AND `received` < ?";
+ $condition[] = DateTimeFormat::utc('now - ' . $days . ' day');
$items = Post::select(['resource-id', 'starred', 'id', 'post-type', 'uid', 'uri-id'], $condition);
++$expired;
}
DBA::close($items);
- Logger::log('User ' . $uid . ": expired $expired items; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos");
+ Logger::notice('User ' . $uid . ": expired $expired items; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos");
}
public static function firstPostDate($uid, $wall = false)
$item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $item_id]);
if (!DBA::isResult($item)) {
- Logger::log('like: unknown item ' . $item_id);
+ Logger::notice('like: unknown item', ['id' => $item_id]);
return false;
}
private static function addLinkAttachment(int $uriid, array $attachments, string $body, string $content, bool $shared, array $ignore_links)
{
DI::profiler()->startRecording('rendering');
- // @ToDo Check only for audio and video
- $preview = empty($attachments['visual']);
+ // Don't show a preview when there is a visual attachment (audio or video)
+ $types = array_column($attachments['visual'], 'type');
+ $preview = !in_array(Post\Media::IMAGE, $types) && !in_array(Post\Media::VIDEO, $types);
if (!empty($attachments['link'])) {
foreach ($attachments['link'] as $link) {
return $item_id;
}
+ $hookData = [
+ 'uri' => $uri,
+ 'uid' => $uid,
+ 'item_id' => null,
+ ];
+
+ Hook::callAll('item_by_link', $hookData);
+
+ if (isset($hookData['item_id'])) {
+ return is_numeric($hookData['item_id']) ? $hookData['item_id'] : 0;
+ }
+
if ($fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri)) {
$item_id = self::searchByLink($fetched_uri, $uid);
} else {
$body = $shared_item['body'];
}
- $item['body'] = preg_replace("/\[share ([^\[\]]*)\].*\[\/share\]/ism", '[share $1]' . $body . '[/share]', $item['body']);
+ $item['body'] = preg_replace("/\[share ([^\[\]]*)\].*\[\/share\]/ism", '[share $1]' . str_replace('$', '\$', $body) . '[/share]', $item['body']);
unset($shared_item['body']);
return array_merge($item, $shared_item);