'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
'event-summary', 'event-desc', 'event-location', 'event-type',
'event-nofinish', 'event-adjust', 'event-ignore', 'event-id',
- 'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed', 'activity'
+ 'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed'
];
// Field list that is used to deliver items via the protocols
}
}
+ if (array_key_exists('vid', $row) && is_null($row['vid']) && !empty($row['verb'])) {
+ $row['vid'] = Verb::getID($row['verb']);
+ }
+
if (!array_key_exists('verb', $row) || in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) {
// Build the file string out of the term entries
if (array_key_exists('file', $row) && empty($row['file'])) {
$fields['parent-item'] = ['guid' => 'parent-guid', 'network' => 'parent-network'];
- $fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name'];
+ $fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name',
+ 'network' => 'parent-author-network'];
$fields['event'] = ['created' => 'event-created', 'edited' => 'event-edited',
'start' => 'event-start','finish' => 'event-finish',
$joins .= " LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`";
}
- if ((strpos($sql_commands, "`parent-item`.") !== false) || (strpos($sql_commands, "`parent-author`.") !== false)) {
+ if ((strpos($sql_commands, "`parent-item`.") !== false) || (strpos($sql_commands, "`parent-item-author`.") !== false)) {
$joins .= " STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`";
- }
- if (strpos($sql_commands, "`parent-item-author`.") !== false) {
- $joins .= " STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`";
+ if (strpos($sql_commands, "`parent-item-author`.") !== false) {
+ $joins .= " STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`";
+ }
}
return $joins;
$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, false, $default);
+ $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, false, $default);
+ $item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
// The contact-id should be set before "self::insert" was called - but there seems to be issues sometimes
$item["contact-id"] = self::contactId($item);
// Check for hashtags in the body and repair or add hashtag links
- self::setHashtags($item);
-
+ $item['body'] = self::setHashtags($item['body']);
+
// Fill the cache field
self::putInCache($item);
}
$body = $item['body'];
-
+
// We just remove everything that is content
foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
unset($item[$field]);
}
+ unset($item['activity']);
+
// Filling item related side tables
// Diaspora signature
if (!Tag::existsForPost($item['uri-id'])) {
Tag::storeFromBody($item['uri-id'], $body);
}
-
+
$ret = DBA::insert('item', $item);
// When the item was successfully stored we fetch the ID of the item.
}
if (empty($fields)) {
- // when there are no fields at all, just use the condition
- // This is to ensure that we always store content.
- $fields = $condition;
+ return;
}
DBA::update('item-content', $fields, $condition, true);
$distributed = self::insert($item, $notify, true);
if (!$distributed) {
- Logger::log("Distributed public item " . $itemid . " for user " . $uid . " wasn't stored", Logger::DEBUG);
+ Logger::info("Distributed public item wasn't stored", ['id' => $itemid, 'user' => $uid]);
} else {
- Logger::log("Distributed public item " . $itemid . " for user " . $uid . " with id " . $distributed, Logger::DEBUG);
+ Logger::info('Distributed public item was stored', ['id' => $itemid, 'user' => $uid, 'stored' => $distributed]);
}
}
$public_shadow = self::insert($item, false, true);
- Logger::log("Stored public shadow for thread ".$itemid." under id ".$public_shadow, Logger::DEBUG);
+ Logger::info('Stored public shadow', ['thread' => $itemid, 'id' => $public_shadow]);
}
}
$public_shadow = self::insert($item, false, true);
- Logger::log("Stored public shadow for comment ".$item['uri']." under id ".$public_shadow, Logger::DEBUG);
+ Logger::info('Stored public shadow', ['uri' => $item['uri'], 'id' => $public_shadow]);
// If this was a comment to a Diaspora post we don't get our comment back.
// This means that we have to distribute the comment by ourselves.
}
}
- public static function setHashtags(&$item)
+ public static function setHashtags($body)
{
- $tags = BBCode::getTags($item["body"]);
+ $body = BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code'], function ($body) {
+ $tags = BBCode::getTags($body);
- // No hashtags?
- if (!count($tags)) {
- return false;
- }
+ // No hashtags?
+ if (!count($tags)) {
+ return $body;
+ }
- // What happens in [code], stays in [code]!
- // escape the # and the [
- // hint: we will also get in trouble with #tags, when we want markdown in posts -> ### Headline 3
- $item["body"] = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism",
- function ($match) {
- // we truly ESCape all # and [ to prevent gettin weird tags in [code] blocks
- $find = ['#', '['];
- $replace = [chr(27).'sharp', chr(27).'leftsquarebracket'];
- return ("[code" . $match[1] . "]" . str_replace($find, $replace, $match[2]) . "[/code]");
- }, $item["body"]);
-
- // This sorting is important when there are hashtags that are part of other hashtags
- // Otherwise there could be problems with hashtags like #test and #test2
- // Because of this we are sorting from the longest to the shortest tag.
- usort($tags, function($a, $b) {
- return strlen($b) <=> strlen($a);
- });
+ // This sorting is important when there are hashtags that are part of other hashtags
+ // Otherwise there could be problems with hashtags like #test and #test2
+ // Because of this we are sorting from the longest to the shortest tag.
+ usort($tags, function ($a, $b) {
+ return strlen($b) <=> strlen($a);
+ });
- $URLSearchString = "^\[\]";
+ $URLSearchString = "^\[\]";
- // All hashtags should point to the home server if "local_tags" is activated
- if (DI::config()->get('system', 'local_tags')) {
- $item["body"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- "#[url=".DI::baseUrl()."/search?tag=$2]$2[/url]", $item["body"]);
- }
+ // All hashtags should point to the home server if "local_tags" is activated
+ if (DI::config()->get('system', 'local_tags')) {
+ $body = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
+ "#[url=" . DI::baseUrl() . "/search?tag=$2]$2[/url]", $body);
+ }
- // mask hashtags inside of url, bookmarks and attachments to avoid urls in urls
- $item["body"] = preg_replace_callback("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- function ($match) {
- return ("[url=" . str_replace("#", "#", $match[1]) . "]" . str_replace("#", "#", $match[2]) . "[/url]");
- }, $item["body"]);
+ // mask hashtags inside of url, bookmarks and attachments to avoid urls in urls
+ $body = preg_replace_callback("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
+ function ($match) {
+ return ("[url=" . str_replace("#", "#", $match[1]) . "]" . str_replace("#", "#", $match[2]) . "[/url]");
+ }, $body);
- $item["body"] = preg_replace_callback("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism",
- function ($match) {
- return ("[bookmark=" . str_replace("#", "#", $match[1]) . "]" . str_replace("#", "#", $match[2]) . "[/bookmark]");
- }, $item["body"]);
+ $body = preg_replace_callback("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism",
+ function ($match) {
+ return ("[bookmark=" . str_replace("#", "#", $match[1]) . "]" . str_replace("#", "#", $match[2]) . "[/bookmark]");
+ }, $body);
- $item["body"] = preg_replace_callback("/\[attachment (.*)\](.*?)\[\/attachment\]/ism",
- function ($match) {
- return ("[attachment " . str_replace("#", "#", $match[1]) . "]" . $match[2] . "[/attachment]");
- }, $item["body"]);
+ $body = preg_replace_callback("/\[attachment (.*)\](.*?)\[\/attachment\]/ism",
+ function ($match) {
+ return ("[attachment " . str_replace("#", "#", $match[1]) . "]" . $match[2] . "[/attachment]");
+ }, $body);
- // Repair recursive urls
- $item["body"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- "#$2", $item["body"]);
+ // Repair recursive urls
+ $body = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
+ "#$2", $body);
- foreach ($tags as $tag) {
- if ((strpos($tag, '#') !== 0) || strpos($tag, '[url=') || strlen($tag) < 2 || $tag[1] == '#') {
- continue;
- }
+ foreach ($tags as $tag) {
+ if ((strpos($tag, '#') !== 0) || strpos($tag, '[url=') || strlen($tag) < 2 || $tag[1] == '#') {
+ continue;
+ }
- $basetag = str_replace('_',' ',substr($tag,1));
- $newtag = '#[url=' . DI::baseUrl() . '/search?tag=' . $basetag . ']' . $basetag . '[/url]';
+ $basetag = str_replace('_', ' ', substr($tag, 1));
+ $newtag = '#[url=' . DI::baseUrl() . '/search?tag=' . $basetag . ']' . $basetag . '[/url]';
- $item["body"] = str_replace($tag, $newtag, $item["body"]);
- }
+ $body = str_replace($tag, $newtag, $body);
+ }
- // Convert back the masked hashtags
- $item["body"] = str_replace("#", "#", $item["body"]);
+ // Convert back the masked hashtags
+ $body = str_replace("#", "#", $body);
+
+ return $body;
+ });
- // Remember! What happens in [code], stays in [code]
- // roleback the # and [
- $item["body"] = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism",
- function ($match) {
- // we truly unESCape all sharp and leftsquarebracket
- $find = [chr(27).'sharp', chr(27).'leftsquarebracket'];
- $replace = ['#', '['];
- return ("[code" . $match[1] . "]" . str_replace($find, $replace, $match[2]) . "[/code]");
- }, $item["body"]);
+ return $body;
}
/**
// Prevent the forwarding of posts that are forwarded
if (!empty($datarray["extid"]) && ($datarray["extid"] == Protocol::DFRN)) {
- Logger::log('Already forwarded', Logger::DEBUG);
+ Logger::info('Already forwarded');
return false;
}
// Prevent to forward already forwarded posts
if ($datarray["app"] == DI::baseUrl()->getHostname()) {
- Logger::log('Already forwarded (second test)', Logger::DEBUG);
+ Logger::info('Already forwarded (second test)');
return false;
}
// Only forward posts
if ($datarray["verb"] != Activity::POST) {
- Logger::log('No post', Logger::DEBUG);
+ Logger::info('No post');
return false;
}
if (($contact['network'] != Protocol::FEED) && ($datarray['private'] == self::PRIVATE)) {
- Logger::log('Not public', Logger::DEBUG);
+ Logger::info('Not public');
return false;
}
$datarray2 = $datarray;
- Logger::log('remote-self start - Contact '.$contact['url'].' - '.$contact['remote_self'].' Item '.print_r($datarray, true), Logger::DEBUG);
+ Logger::info('remote-self start', ['contact' => $contact['url'], 'remote_self'=> $contact['remote_self'], 'item' => $datarray]);
if ($contact['remote_self'] == 2) {
$self = DBA::selectFirst('contact', ['id', 'name', 'url', 'thumb'],
['uid' => $contact['uid'], 'self' => true]);
if ($contact['network'] != Protocol::FEED) {
// Store the original post
$result = self::insert($datarray2);
- Logger::log('remote-self post original item - Contact '.$contact['url'].' return '.$result.' Item '.print_r($datarray2, true), Logger::DEBUG);
+ Logger::info('remote-self post original item', ['contact' => $contact['url'], 'result'=> $result, 'item' => $datarray2]);
} else {
$datarray["app"] = "Feed";
$result = true;
return $s;
}
- Logger::log('check for photos', Logger::DEBUG);
+ Logger::info('check for photos');
$site = substr(DI::baseUrl(), strpos(DI::baseUrl(), '://'));
$orig_body = $s;
$img_st_close++; // make it point to AFTER the closing bracket
$image = substr($orig_body, $img_start + $img_st_close, $img_len);
- Logger::log('found photo ' . $image, Logger::DEBUG);
+ Logger::info('found photo', ['image' => $image]);
if (stristr($image, $site . '/photo/')) {
// Only embed locally hosted photos
$photo_img = Photo::getImageForPhoto($photo);
// If a custom width and height were specified, apply before embedding
if (preg_match("/\[img\=([0-9]*)x([0-9]*)\]/is", substr($orig_body, $img_start, $img_st_close), $match)) {
- Logger::log('scaling photo', Logger::DEBUG);
+ Logger::info('scaling photo');
$width = intval($match[1]);
$height = intval($match[2]);
$data = $photo_img->asString();
$type = $photo_img->getType();
- Logger::log('replacing photo', Logger::DEBUG);
+ Logger::info('replacing photo');
$image = 'data:' . $type . ';base64,' . base64_encode($data);
- Logger::log('replaced: ' . $image, Logger::DATA);
+ Logger::debug('replaced', ['image' => $image]);
}
}
}
if (local_user() == $uid) {
$item_contact_id = $owner_self_contact['id'];
} else {
- $item_contact_id = Contact::getIdForURL($author_contact['url'], $uid, true);
+ $item_contact_id = Contact::getIdForURL($author_contact['url'], $uid, false);
$item_contact = DBA::selectFirst('contact', [], ['id' => $item_contact_id]);
if (!DBA::isResult($item_contact)) {
Logger::log('like: unknown item contact ' . $item_contact_id);
if (!$onlyshadow) {
$result = DBA::insert('thread', $item);
- Logger::log("Add thread for item ".$itemid." - ".print_r($result, true), Logger::DEBUG);
+ Logger::info('Add thread', ['item' => $itemid, 'result' => $result]);
}
}
$result = DBA::update('thread', $fields, ['iid' => $itemid]);
- Logger::log("Update thread for item ".$itemid." - guid ".$item["guid"]." - ".(int)$result, Logger::DEBUG);
+ Logger::info('Update thread', ['item' => $itemid, 'guid' => $item["guid"], 'result' => $result]);
}
private static function deleteThread($itemid, $itemuri = "")
{
$item = DBA::selectFirst('thread', ['uid'], ['iid' => $itemid]);
if (!DBA::isResult($item)) {
- Logger::log('No thread found for id '.$itemid, Logger::DEBUG);
+ Logger::info('No thread found', ['id' => $itemid]);
return;
}
$result = DBA::delete('thread', ['iid' => $itemid], ['cascade' => false]);
- Logger::log("deleteThread: Deleted thread for item ".$itemid." - ".print_r($result, true), Logger::DEBUG);
+ Logger::info('Deleted thread', ['item' => $itemid, 'result' => $result]);
if ($itemuri != "") {
$condition = ["`uri` = ? AND NOT `deleted` AND NOT (`uid` IN (?, 0))", $itemuri, $item["uid"]];
*/
public static function getPlink($item)
{
- $a = DI::app();
-
- if ($a->user['nickname'] != "") {
+ if (local_user()) {
$ret = [
'href' => "display/" . $item['guid'],
'orig' => "display/" . $item['guid'],
$ret["href"] = DI::baseUrl()->remove($item['plink']);
$ret["title"] = DI::l10n()->t('link to source');
}
-
} elseif (!empty($item['plink']) && ($item['private'] != self::PRIVATE)) {
$ret = [
'href' => $item['plink'],