<?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
*
// Only add will be displayed
if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
continue;
- } elseif (!visible_activity($item)) {
+ } elseif (!DI::contentItem()->visibleActivity($item)) {
continue;
}
}
}
+ /**
+ * Fetch the privacy of the post
+ *
+ * @param array $item
+ * @return string
+ */
+ private function fetchPrivacy(array $item):string
+ {
+ switch ($item['private']) {
+ case Item::PRIVATE:
+ $output = DI::l10n()->t('Private Message');
+ break;
+ case Item::PUBLIC:
+ $output = DI::l10n()->t('Public Message');
+ break;
+ case Item::UNLISTED:
+ $output = DI::l10n()->t('Unlisted Message');
+ break;
+ }
+
+ return $output;
+ }
+
/**
* Get data in a form usable by a conversation template
*
* @param array $conv_responses conversation responses
+ * @param string $formSecurityToken A security Token to avoid CSF attacks
* @param integer $thread_level default = 1
*
* @return mixed The data requested on success
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public function getTemplateData(array $conv_responses, $thread_level = 1)
+ public function getTemplateData(array $conv_responses, string $formSecurityToken, $thread_level = 1)
{
- $a = DI::app();
-
$item = $this->getData();
$edited = false;
// If the time between "created" and "edited" differs we add
$conv = $this->getThread();
- $lock = ((($item['private'] == Item::PRIVATE) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
- || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
- ? DI::l10n()->t('Private Message')
- : false);
+ $privacy = $this->fetchPrivacy($item);
+ $lock = ($item['private'] == Item::PRIVATE) ? $privacy : false;
+ $connector = !in_array($item['network'], Protocol::NATIVE_SUPPORT) ? DI::l10n()->t('Connector Message') : false;
$shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
$announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]);
$edpost = false;
if (local_user()) {
- if (Strings::compareLink($a->contact['url'], $item['author-link'])) {
+ if (Strings::compareLink(Session::get('my_url'), $item['author-link'])) {
if ($item["event-id"] != 0) {
$edpost = ["events/event/" . $item['event-id'], DI::l10n()->t("Edit")];
} else {
];
}
- $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? DI::l10n()->t('Save to folder') : false);
+ $filer = local_user() ? DI::l10n()->t('Save to folder') : false;
$profile_name = $item['author-name'];
if (!empty($item['author-link']) && empty($item['author-name'])) {
foreach ($response_verbs as $value => $verb) {
$responses[$verb] = [
'self' => $conv_responses[$verb][$item['uri-id']]['self'] ?? 0,
- 'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? format_activity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '',
+ 'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? DI::conversation()->formatActivity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '',
];
}
$tagger = '';
if ($this->isToplevel()) {
- if(local_user()) {
+ if (local_user()) {
$ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], local_user());
if ($item['mention'] || $ignored) {
$ignore = [
];
}
+ $isstarred = (($item['starred']) ? "starred" : "unstarred");
+
+ $star = [
+ 'do' => DI::l10n()->t('Add star'),
+ 'undo' => DI::l10n()->t('Remove star'),
+ 'toggle' => DI::l10n()->t('Toggle star status'),
+ 'classdo' => $item['starred'] ? "hidden" : "",
+ 'classundo' => $item['starred'] ? "" : "hidden",
+ 'starred' => DI::l10n()->t('Starred'),
+ ];
+
if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
if ($origin) {
$ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
];
}
- $isstarred = (($item['starred']) ? "starred" : "unstarred");
-
- $star = [
- 'do' => DI::l10n()->t('Add star'),
- 'undo' => DI::l10n()->t('Remove star'),
- 'toggle' => DI::l10n()->t('Toggle star status'),
- 'classdo' => $item['starred'] ? "hidden" : "",
- 'classundo' => $item['starred'] ? "" : "hidden",
- 'starred' => DI::l10n()->t('Starred'),
- ];
-
$tagger = [
'add' => DI::l10n()->t('Add tag'),
'class' => "",
$shiny = 'shiny';
}
- localize_item($item);
+ DI::contentItem()->localize($item);
$body_html = Item::prepareBody($item, true);
- list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
+ list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, local_user());
- if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
+ if (!empty($item['title'])) {
+ $title = $item['title'];
+ } elseif (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
$title = ucfirst($item['content-warning']);
} else {
- $title = $item['title'];
+ $title = '';
}
if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
$direction = [];
if (!empty($item['direction'])) {
$direction = $item['direction'];
- } elseif (DI::config()->get('debug', 'show_direction')) {
- $conversation = DBA::selectFirst('conversation', ['direction'], ['item-uri' => $item['uri']]);
- if (!empty($conversation['direction']) && in_array($conversation['direction'], [1, 2])) {
- $direction_title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')];
- $direction = ['direction' => $conversation['direction'], 'title' => $direction_title[$conversation['direction']]];
- }
}
$languages = [];
'vwall' => DI::l10n()->t('via Wall-To-Wall:'),
'profile_url' => $profile_link,
'name' => $profile_name,
- 'item_photo_menu_html' => item_photo_menu($item),
+ 'item_photo_menu_html' => DI::contentItem()->photoMenu($item, $formSecurityToken),
'thumb' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['author-link'], $item['uid'], Proxy::SIZE_THUMB)),
'osparkle' => $osparkle,
'sparkle' => $sparkle,
'app' => $item['app'],
'created' => $ago,
'lock' => $lock,
+ 'private' => $item['private'],
+ 'privacy' => $privacy,
+ 'connector' => $connector,
'location_html' => $location_html,
'indent' => $indent,
'shiny' => $shiny,
'owner_photo' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['owner-link'], $item['uid'], Proxy::SIZE_THUMB)),
'owner_name' => $this->getOwnerName(),
'plink' => Item::getPlink($item),
+ 'browsershare' => DI::l10n()->t('Share'),
'edpost' => $edpost,
'ispinned' => $ispinned,
'pin' => $pin,
$nb_children = count($children);
if ($nb_children > 0) {
foreach ($children as $child) {
- $result['children'][] = $child->getTemplateData($conv_responses, $thread_level + 1);
+ $result['children'][] = $child->getTemplateData($conv_responses, $formSecurityToken, $thread_level + 1);
}
// Collapse
{
$item_id = $item->getId();
if (!$item_id) {
- Logger::log('[ERROR] Post::addChild : Item has no ID!!', Logger::DEBUG);
+ Logger::info('[ERROR] Post::addChild : Item has no ID!!');
return false;
} elseif ($this->getChild($item->getId())) {
- Logger::log('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', Logger::DEBUG);
+ Logger::info('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').');
return false;
}
return true;
}
}
- Logger::log('[WARN] Item::removeChild : Item is not a child (' . $id . ').', Logger::DEBUG);
+ Logger::info('[WARN] Item::removeChild : Item is not a child (' . $id . ').');
return false;
}
public function getDataValue($name)
{
if (!isset($this->data[$name])) {
- // Logger::log('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".', Logger::DEBUG);
+ // Logger::info('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".');
return false;
}
private function setTemplate($name)
{
if (empty($this->available_templates[$name])) {
- Logger::log('[ERROR] Item::setTemplate : Template not available ("' . $name . '").', Logger::DEBUG);
+ Logger::info('[ERROR] Item::setTemplate : Template not available ("' . $name . '").');
return false;
}
return '';
}
- $owner = User::getOwnerDataById($a->user['uid']);
-
- if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
- return '';
- }
+ $owner = User::getOwnerDataById($a->getLoggedInUserId());
- $item = PostModel::selectFirst(['author-addr', 'uri-id', 'network', 'gravity'], ['id' => $this->getId()]);
+ $item = PostModel::selectFirst(['author-addr', 'uri-id', 'network', 'gravity', 'content-warning'], ['id' => $this->getId()]);
if (!DBA::isResult($item) || empty($item['author-addr'])) {
// Should not happen
return '';
}
- if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
- $text = '@' . $item['author-addr'] . ' ';
+ if (!empty($item['content-warning']) && Feature::isEnabled(local_user(), 'add_abstract')) {
+ $text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n";
} else {
$text = '';
}
+ if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
+ return $text;
+ }
+
+ if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
+ $text .= '@' . $item['author-addr'] . ' ';
+ }
+
$terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
foreach ($terms as $term) {
if (!$term['url']) {
$uid = $conv->getProfileOwner();
$parent_uid = $this->getDataValue('uid');
+ $contact = Contact::getById($a->getContactId());
+
$default_text = $this->getDefaultText();
if (!is_null($parent_uid) && ($uid != $parent_uid)) {
'$qcomment' => $qcomment,
'$default' => $default_text,
'$profile_uid' => $uid,
- '$mylink' => DI::baseUrl()->remove($a->contact['url'] ?? ''),
+ '$mylink' => DI::baseUrl()->remove($contact['url'] ?? ''),
'$mytitle' => DI::l10n()->t('This is you'),
- '$myphoto' => DI::baseUrl()->remove($a->contact['thumb'] ?? ''),
+ '$myphoto' => DI::baseUrl()->remove($contact['thumb'] ?? ''),
'$comment' => DI::l10n()->t('Comment'),
'$submit' => DI::l10n()->t('Submit'),
'$loading' => DI::l10n()->t('Loading...'),
'$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
'$preview' => DI::l10n()->t('Preview'),
'$indent' => $indent,
- '$sourceapp' => DI::l10n()->t($a->sourcename),
'$rand_num' => Crypto::randomDigits(12)
]);
}
if ($this->isToplevel()) {
if ($conv->getMode() !== 'profile') {
- if ($this->getDataValue('wall') && !$this->getDataValue('self') && !empty($a->page_contact)) {
- // On the network page, I am the owner. On the display page it will be the profile owner.
- // This will have been stored in $a->page_contact by our calling page.
- // Put this person as the wall owner of the wall-to-wall notice.
-
- $this->owner_url = Contact::magicLinkByContact($a->page_contact);
- $this->owner_name = $a->page_contact['name'];
- $this->wall_to_wall = true;
- } elseif ($this->getDataValue('owner-link')) {
+ if ($this->getDataValue('owner-link')) {
$owner_linkmatch = (($this->getDataValue('owner-link')) && Strings::compareLink($this->getDataValue('owner-link'), $this->getDataValue('author-link')));
$alias_linkmatch = (($this->getDataValue('alias')) && Strings::compareLink($this->getDataValue('alias'), $this->getDataValue('author-link')));
$owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));