3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Object;
24 use Friendica\Content\ContactSelector;
25 use Friendica\Content\Feature;
26 use Friendica\Core\Addon;
27 use Friendica\Core\Hook;
28 use Friendica\Core\Logger;
29 use Friendica\Core\Protocol;
30 use Friendica\Core\Renderer;
31 use Friendica\Core\Session;
33 use Friendica\Model\Contact;
34 use Friendica\Model\Item;
35 use Friendica\Model\Photo;
36 use Friendica\Model\Post as PostModel;
37 use Friendica\Model\Tag;
38 use Friendica\Model\User;
39 use Friendica\Protocol\Activity;
40 use Friendica\Util\Crypto;
41 use Friendica\Util\DateTimeFormat;
42 use Friendica\Util\Proxy;
43 use Friendica\Util\Strings;
44 use Friendica\Util\Temporal;
52 private $template = null;
53 private $available_templates = [
54 'wall' => 'wall_thread.tpl',
55 'wall2wall' => 'wallwall_thread.tpl'
57 private $comment_box_template = 'comment_item.tpl';
58 private $toplevel = false;
59 private $writable = false;
63 private $children = [];
64 private $parent = null;
69 private $thread = null;
70 private $redirect_url = null;
71 private $owner_url = '';
72 private $owner_name = '';
73 private $wall_to_wall = false;
74 private $threaded = false;
75 private $visiting = false;
80 * @param array $data data array
83 public function __construct(array $data)
86 $this->setTemplate('wall');
87 $this->toplevel = $this->getId() == $this->getDataValue('parent');
89 if (!empty(Session::getUserIDForVisitorContactID($this->getDataValue('contact-id')))) {
90 $this->visiting = true;
93 $this->writable = $this->getDataValue('writable') || $this->getDataValue('self');
94 $author = ['uid' => 0, 'id' => $this->getDataValue('author-id'),
95 'network' => $this->getDataValue('author-network'),
96 'url' => $this->getDataValue('author-link')];
97 $this->redirect_url = Contact::magicLinkByContact($author);
98 if (!$this->isToplevel()) {
99 $this->threaded = true;
102 // Prepare the children
103 if (!empty($data['children'])) {
104 foreach ($data['children'] as $item) {
105 // Only add will be displayed
106 if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
108 } elseif (!DI::contentItem()->visibleActivity($item)) {
112 // You can always comment on Diaspora and OStatus items
113 if (in_array($item['network'], [Protocol::OSTATUS, Protocol::DIASPORA]) && (local_user() == $item['uid'])) {
114 $item['writable'] = true;
117 $item['pagedrop'] = $data['pagedrop'];
118 $child = new Post($item);
119 $this->addChild($child);
125 * Fetch the privacy of the post
130 private function fetchPrivacy(array $item):string
132 switch ($item['private']) {
134 $output = DI::l10n()->t('Private Message');
137 $output = DI::l10n()->t('Public Message');
140 $output = DI::l10n()->t('Unlisted Message');
148 * Get data in a form usable by a conversation template
150 * @param array $conv_responses conversation responses
151 * @param string $formSecurityToken A security Token to avoid CSF attacks
152 * @param integer $thread_level default = 1
154 * @return mixed The data requested on success
156 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
157 * @throws \ImagickException
159 public function getTemplateData(array $conv_responses, string $formSecurityToken, $thread_level = 1)
161 $item = $this->getData();
163 // If the time between "created" and "edited" differs we add
164 // a notice that the post was edited.
165 // Note: In some networks reshared items seem to have (sometimes) a difference
166 // between creation time and edit time of a second. Thats why we add the notice
167 // only if the difference is more than 1 second.
168 if (strtotime($item['edited']) - strtotime($item['created']) > 1) {
170 'label' => DI::l10n()->t('This entry was edited'),
171 'date' => DateTimeFormat::local($item['edited'], 'r'),
172 'relative' => Temporal::getRelativeDate($item['edited'])
187 $ispinned = "unpinned";
188 $isstarred = "unstarred";
192 $total_children = $this->countDescendants();
194 $conv = $this->getThread();
196 $privacy = $this->fetchPrivacy($item);
197 $lock = ($item['private'] == Item::PRIVATE) ? $privacy : false;
198 $connector = !in_array($item['network'], Protocol::NATIVE_SUPPORT) ? DI::l10n()->t('Connector Message') : false;
200 $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
201 $announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]);
203 // On Diaspora only toplevel posts can be reshared
204 if ($announceable && ($item['network'] == Protocol::DIASPORA) && ($item['gravity'] != GRAVITY_PARENT)) {
205 $announceable = false;
211 if (Strings::compareLink(Session::get('my_url'), $item['author-link'])) {
212 if ($item["event-id"] != 0) {
213 $edpost = ["events/event/" . $item['event-id'], DI::l10n()->t("Edit")];
215 $edpost = ["editpost/" . $item['id'], DI::l10n()->t("Edit")];
218 $dropping = in_array($item['uid'], [0, local_user()]);
221 // Editing on items of not subscribed users isn't currently possible
222 // There are some issues on editing that prevent this.
223 // But also it is an issue of the supported protocols that doesn't allow editing at all.
224 if ($item['uid'] == 0) {
228 if (($this->getDataValue('uid') == local_user()) || $this->isVisiting()) {
232 $origin = $item['origin'] || $item['parent-origin'];
234 if (!empty($item['featured'])) {
235 $pinned = DI::l10n()->t('Pinned item');
238 // Showing the one or the other text, depending upon if we can only hide it or really delete it.
239 $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
245 'dropping' => $dropping,
246 'pagedrop' => $item['pagedrop'],
247 'select' => DI::l10n()->t('Select'),
252 if (!$item['self'] && local_user()) {
255 'block' => DI::l10n()->t('Block %s', $item['author-name']),
256 'author_id' => $item['author-id'],
260 $filer = local_user() ? DI::l10n()->t('Save to folder') : false;
262 $profile_name = $item['author-name'];
263 if (!empty($item['author-link']) && empty($item['author-name'])) {
264 $profile_name = $item['author-link'];
267 if (Session::isAuthenticated()) {
268 $author = ['uid' => 0, 'id' => $item['author-id'],
269 'network' => $item['author-network'], 'url' => $item['author-link']];
270 $profile_link = Contact::magicLinkByContact($author);
272 $profile_link = $item['author-link'];
275 if (strpos($profile_link, 'redir/') === 0) {
276 $sparkle = ' sparkle';
279 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
280 Hook::callAll('render_location', $locate);
281 $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
283 // process action responses - e.g. like/dislike/attend/agree/whatever
284 $response_verbs = ['like', 'dislike', 'announce'];
288 if ($item['object-type'] === Activity\ObjectType::EVENT) {
289 $response_verbs[] = 'attendyes';
290 $response_verbs[] = 'attendno';
291 $response_verbs[] = 'attendmaybe';
292 if ($conv->isWritable()) {
294 $attend = [DI::l10n()->t('I will attend'), DI::l10n()->t('I will not attend'), DI::l10n()->t('I might attend')];
299 foreach ($response_verbs as $value => $verb) {
300 $responses[$verb] = [
301 'self' => $conv_responses[$verb][$item['uri-id']]['self'] ?? 0,
302 'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? DI::conversation()->formatActivity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '',
307 * We should avoid doing this all the time, but it depends on the conversation mode
308 * And the conv mode may change when we change the conv, or it changes its mode
309 * Maybe we should establish a way to be notified about conversation changes
311 $this->checkWallToWall();
313 if ($this->isWallToWall() && ($this->getOwnerUrl() == $this->getRedirectUrl())) {
314 $osparkle = ' sparkle';
319 if ($this->isToplevel()) {
321 $ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], local_user());
322 if ($item['mention'] || $ignored) {
324 'do' => DI::l10n()->t('Ignore thread'),
325 'undo' => DI::l10n()->t('Unignore thread'),
326 'toggle' => DI::l10n()->t('Toggle ignore status'),
327 'classdo' => $ignored ? "hidden" : "",
328 'classundo' => $ignored ? "" : "hidden",
329 'ignored' => DI::l10n()->t('Ignored'),
333 $isstarred = (($item['starred']) ? "starred" : "unstarred");
336 'do' => DI::l10n()->t('Add star'),
337 'undo' => DI::l10n()->t('Remove star'),
338 'toggle' => DI::l10n()->t('Toggle star status'),
339 'classdo' => $item['starred'] ? "hidden" : "",
340 'classundo' => $item['starred'] ? "" : "hidden",
341 'starred' => DI::l10n()->t('Starred'),
344 if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
345 if ($origin && in_array($item['private'], [Item::PUBLIC, Item::UNLISTED])) {
346 $ispinned = ($item['featured'] ? 'pinned' : 'unpinned');
349 'do' => DI::l10n()->t('Pin'),
350 'undo' => DI::l10n()->t('Unpin'),
351 'toggle' => DI::l10n()->t('Toggle pin status'),
352 'classdo' => $item['featured'] ? 'hidden' : '',
353 'classundo' => $item['featured'] ? '' : 'hidden',
354 'pinned' => DI::l10n()->t('Pinned'),
359 'add' => DI::l10n()->t('Add tag'),
368 if ($conv->isWritable()) {
369 $buttons['like'] = [DI::l10n()->t("I like this \x28toggle\x29") , DI::l10n()->t('Like')];
370 $buttons['dislike'] = [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t('Dislike')];
372 $buttons['share'] = [DI::l10n()->t('Quote share this'), DI::l10n()->t('Quote Share')];
375 $buttons['announce'] = [DI::l10n()->t('Reshare this'), DI::l10n()->t('Reshare')];
376 $buttons['unannounce'] = [DI::l10n()->t('Cancel your Reshare'), DI::l10n()->t('Unshare')];
380 $comment_html = $this->getCommentBox($indent);
382 if (strcmp(DateTimeFormat::utc($item['created']), DateTimeFormat::utc('now - 12 hours')) > 0) {
386 DI::contentItem()->localize($item);
388 $body_html = Item::prepareBody($item, true);
390 list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, local_user());
392 if (!empty($item['title'])) {
393 $title = $item['title'];
394 } elseif (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
395 $title = ucfirst($item['content-warning']);
400 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
401 $buttons['dislike'] = false;
404 // Disable features that aren't available in several networks
405 if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
406 if ($buttons["dislike"]) {
407 $buttons["dislike"] = false;
414 if ($buttons["like"] && in_array($item["network"], [Protocol::FEED, Protocol::MAIL])) {
415 $buttons["like"] = false;
418 $tags = Tag::populateFromItem($item);
420 $ago = Temporal::getRelativeDate($item['created']);
421 $ago_received = Temporal::getRelativeDate($item['received']);
422 if (DI::config()->get('system', 'show_received') && (abs(strtotime($item['created']) - strtotime($item['received'])) > DI::config()->get('system', 'show_received_seconds')) && ($ago != $ago_received)) {
423 $ago = DI::l10n()->t('%s (Received %s)', $ago, $ago_received);
426 // Fetching of Diaspora posts doesn't always work. There are issues with reshares and possibly comments
427 if (!local_user() && ($item['network'] != Protocol::DIASPORA) && !empty(Session::get('remote_comment'))) {
428 $remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('Remote comment'),
429 str_replace('{uri}', urlencode($item['uri']), Session::get('remote_comment'))];
431 // Ensure to either display the remote comment or the local activities
435 $remote_comment = '';
439 if (!empty($item['direction'])) {
440 $direction = $item['direction'];
444 if (!empty($item['language'])) {
445 $languages = [DI::l10n()->t('Languages'), Item::getLanguageMessage($item)];
448 if (in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($item['network'], Protocol::FEDERATED)) {
449 $browsershare = [DI::l10n()->t('Share via ...'), DI::l10n()->t('Share via external services')];
451 $browsershare = null;
455 'template' => $this->getTemplate(),
456 'type' => implode("", array_slice(explode("/", $item['verb']), -1)),
457 'comment_firstcollapsed' => false,
458 'comment_lastcollapsed' => false,
459 'suppress_tags' => DI::config()->get('system', 'suppress_tags'),
460 'tags' => $tags['tags'],
461 'hashtags' => $tags['hashtags'],
462 'mentions' => $tags['mentions'],
463 'implicit_mentions' => $tags['implicit_mentions'],
464 'txt_cats' => DI::l10n()->t('Categories:'),
465 'txt_folders' => DI::l10n()->t('Filed under:'),
466 'has_cats' => ((count($categories)) ? 'true' : ''),
467 'has_folders' => ((count($folders)) ? 'true' : ''),
468 'categories' => $categories,
469 'folders' => $folders,
470 'body_html' => $body_html,
471 'text' => strip_tags($body_html),
472 'id' => $this->getId(),
473 'guid' => urlencode($item['guid']),
474 'isevent' => $isevent,
476 'linktitle' => DI::l10n()->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
477 'olinktitle' => DI::l10n()->t('View %s\'s profile @ %s', $this->getOwnerName(), $item['owner-link']),
478 'to' => DI::l10n()->t('to'),
479 'via' => DI::l10n()->t('via'),
480 'wall' => DI::l10n()->t('Wall-to-Wall'),
481 'vwall' => DI::l10n()->t('via Wall-To-Wall:'),
482 'profile_url' => $profile_link,
483 'name' => $profile_name,
484 'item_photo_menu_html' => DI::contentItem()->photoMenu($item, $formSecurityToken),
485 'thumb' => DI::baseUrl()->remove(DI::contentItem()->getAuthorAvatar($item)),
486 'osparkle' => $osparkle,
487 'sparkle' => $sparkle,
489 'localtime' => DateTimeFormat::local($item['created'], 'r'),
490 'ago' => $item['app'] ? DI::l10n()->t('%s from %s', $ago, $item['app']) : $ago,
491 'app' => $item['app'],
494 'private' => $item['private'],
495 'privacy' => $privacy,
496 'connector' => $connector,
497 'location_html' => $location_html,
500 'owner_self' => $item['author-link'] == Session::get('my_url'),
501 'owner_url' => $this->getOwnerUrl(),
502 'owner_photo' => DI::baseUrl()->remove(DI::contentItem()->getOwnerAvatar($item)),
503 'owner_name' => $this->getOwnerName(),
504 'plink' => Item::getPlink($item),
505 'browsershare' => $browsershare,
507 'ispinned' => $ispinned,
510 'isstarred' => $isstarred,
515 'language' => $languages,
519 'like_html' => $responses['like']['output'],
520 'dislike_html' => $responses['dislike']['output'],
521 'responses' => $responses,
522 'switchcomment' => DI::l10n()->t('Comment'),
523 'reply_label' => DI::l10n()->t('Reply to %s', $profile_name),
524 'comment_html' => $comment_html,
525 'remote_comment' => $remote_comment,
526 'menu' => DI::l10n()->t('More'),
527 'previewing' => $conv->isPreview() ? ' preview ' : '',
528 'wait' => DI::l10n()->t('Please wait'),
529 'thread_level' => $thread_level,
531 'network' => $item["network"],
532 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
533 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
534 'received' => $item['received'],
535 'commented' => $item['commented'],
536 'created_date' => $item['created'],
537 'uriid' => $item['uri-id'],
538 'return' => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '',
539 'direction' => $direction,
540 'reshared' => $item['reshared'] ?? '',
542 'queue_count' => $item['delivery_queue_count'],
543 'queue_done' => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
544 'notifier_pending' => DI::l10n()->t('Notifier task is pending'),
545 'delivery_pending' => DI::l10n()->t('Delivery to remote servers is pending'),
546 'delivery_underway' => DI::l10n()->t('Delivery to remote servers is underway'),
547 'delivery_almost' => DI::l10n()->t('Delivery to remote servers is mostly done'),
548 'delivery_done' => DI::l10n()->t('Delivery to remote servers is done'),
552 $arr = ['item' => $item, 'output' => $tmp_item];
553 Hook::callAll('display_item', $arr);
555 $result = $arr['output'];
557 $result['children'] = [];
558 $children = $this->getChildren();
559 $nb_children = count($children);
560 if ($nb_children > 0) {
561 foreach ($children as $child) {
562 $result['children'][] = $child->getTemplateData($conv_responses, $formSecurityToken, $thread_level + 1);
566 if (($nb_children > 2) || ($thread_level > 1)) {
567 $result['children'][0]['comment_firstcollapsed'] = true;
568 $result['children'][0]['num_comments'] = DI::l10n()->tt('%d comment', '%d comments', $total_children);
569 $result['children'][0]['show_text'] = DI::l10n()->t('Show more');
570 $result['children'][0]['hide_text'] = DI::l10n()->t('Show fewer');
571 if ($thread_level > 1) {
572 $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
574 $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
579 $result['total_comments_num'] = $this->isToplevel() ? $total_children : 0;
581 $result['private'] = $item['private'];
582 $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
584 if ($this->isThreaded()) {
585 $result['flatten'] = false;
586 $result['threaded'] = true;
588 $result['flatten'] = true;
589 $result['threaded'] = false;
598 public function getId()
600 return $this->getDataValue('id');
606 public function isThreaded()
608 return $this->threaded;
614 * @param Post $item The child item to add
619 public function addChild(Post $item)
621 $item_id = $item->getId();
623 Logger::info('[ERROR] Post::addChild : Item has no ID!!');
625 } elseif ($this->getChild($item->getId())) {
626 Logger::info('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').');
630 $activity = DI::activity();
633 * Only add what will be displayed
635 if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
637 } elseif ($activity->match($item->getDataValue('verb'), Activity::LIKE) ||
638 $activity->match($item->getDataValue('verb'), Activity::DISLIKE)) {
642 $item->setParent($this);
643 $this->children[] = $item;
645 return end($this->children);
649 * Get a child by its ID
651 * @param integer $id The child id
655 public function getChild($id)
657 foreach ($this->getChildren() as $child) {
658 if ($child->getId() == $id) {
667 * Get all our children
671 public function getChildren()
673 return $this->children;
679 * @param Post $item The item to set as parent
683 protected function setParent(Post $item)
685 $parent = $this->getParent();
687 $parent->removeChild($this);
690 $this->parent = $item;
691 $this->setThread($item->getThread());
699 protected function removeParent()
701 $this->parent = null;
702 $this->thread = null;
708 * @param Post $item The child to be removed
710 * @return boolean Success or failure
713 public function removeChild(Post $item)
715 $id = $item->getId();
716 foreach ($this->getChildren() as $key => $child) {
717 if ($child->getId() == $id) {
718 $child->removeParent();
719 unset($this->children[$key]);
720 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
721 $this->children = array_values($this->children);
725 Logger::info('[WARN] Item::removeChild : Item is not a child (' . $id . ').');
734 protected function getParent()
736 return $this->parent;
740 * Set conversation thread
742 * @param Thread $thread
746 public function setThread(Thread $thread = null)
748 $this->thread = $thread;
750 // Set it on our children too
751 foreach ($this->getChildren() as $child) {
752 $child->setThread($thread);
761 public function getThread()
763 return $this->thread;
769 * We shouldn't need this
773 public function getData()
781 * @param string $name key
783 * @return mixed value on success
786 public function getDataValue($name)
788 if (!isset($this->data[$name])) {
789 // Logger::info('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".');
793 return $this->data[$name];
799 * @param string $name template name
803 private function setTemplate($name)
805 if (empty($this->available_templates[$name])) {
806 Logger::info('[ERROR] Item::setTemplate : Template not available ("' . $name . '").');
810 $this->template = $this->available_templates[$name];
820 private function getTemplate()
822 return $this->template;
826 * Check if this is a toplevel post
830 private function isToplevel()
832 return $this->toplevel;
836 * Check if this is writable
840 private function isWritable()
842 $conv = $this->getThread();
845 // This will allow us to comment on wall-to-wall items owned by our friends
846 // and community forums even if somebody else wrote the post.
847 // bug #517 - this fixes for conversation owner
848 if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == local_user()) {
852 // this fixes for visitors
853 return ($this->writable || ($this->isVisiting() && $conv->getMode() == 'profile'));
855 return $this->writable;
859 * Count the total of our descendants
863 private function countDescendants()
865 $children = $this->getChildren();
866 $total = count($children);
868 foreach ($children as $child) {
869 $total += $child->countDescendants();
877 * Get the template for the comment box
881 private function getCommentBoxTemplate()
883 return $this->comment_box_template;
887 * Get default text for the comment box
890 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
892 private function getDefaultText()
900 $owner = User::getOwnerDataById($a->getLoggedInUserId());
901 $item = $this->getData();
903 if (!empty($item['content-warning']) && Feature::isEnabled(local_user(), 'add_abstract')) {
904 $text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n";
909 if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
913 if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
914 $text .= '@' . $item['author-addr'] . ' ';
917 $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
918 foreach ($terms as $term) {
920 DI::logger()->warning('Mention term with no URL', ['term' => $term]);
924 $profile = Contact::getByURL($term['url'], false, ['addr', 'contact-type']);
925 if (!empty($profile['addr']) && (($profile['contact-type'] ?? Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) &&
926 ($profile['addr'] != $owner['addr']) && !strstr($text, $profile['addr'])) {
927 $text .= '@' . $profile['addr'] . ' ';
935 * Get the comment box
937 * @param string $indent Indent value
939 * @return mixed The comment box string (empty if no comment box)
943 private function getCommentBox($indent)
948 $conv = $this->getThread();
950 if ($conv->isWritable() && $this->isWritable()) {
952 * Hmmm, code depending on the presence of a particular addon?
953 * This should be better if done by a hook
956 if (Addon::isEnabled('qcomment')) {
957 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
958 $qcomment = $words ? explode("\n", $words) : [];
961 // Fetch the user id from the parent when the owner user is empty
962 $uid = $conv->getProfileOwner();
963 $parent_uid = $this->getDataValue('uid');
965 $owner = User::getOwnerDataById($a->getLoggedInUserId());
967 $default_text = $this->getDefaultText();
969 if (!is_null($parent_uid) && ($uid != $parent_uid)) {
973 $template = Renderer::getMarkupTemplate($this->getCommentBoxTemplate());
974 $comment_box = Renderer::replaceMacros($template, [
975 '$return_path' => DI::args()->getQueryString(),
976 '$threaded' => $this->isThreaded(),
978 '$wall' => ($conv->getMode() === 'profile'),
979 '$id' => $this->getId(),
980 '$parent' => $this->getId(),
981 '$qcomment' => $qcomment,
982 '$default' => $default_text,
983 '$profile_uid' => $uid,
984 '$mylink' => DI::baseUrl()->remove($owner['url'] ?? ''),
985 '$mytitle' => DI::l10n()->t('This is you'),
986 '$myphoto' => DI::baseUrl()->remove($owner['thumb'] ?? ''),
987 '$comment' => DI::l10n()->t('Comment'),
988 '$submit' => DI::l10n()->t('Submit'),
989 '$loading' => DI::l10n()->t('Loading...'),
990 '$edbold' => DI::l10n()->t('Bold'),
991 '$editalic' => DI::l10n()->t('Italic'),
992 '$eduline' => DI::l10n()->t('Underline'),
993 '$edquote' => DI::l10n()->t('Quote'),
994 '$edcode' => DI::l10n()->t('Code'),
995 '$edimg' => DI::l10n()->t('Image'),
996 '$edurl' => DI::l10n()->t('Link'),
997 '$edattach' => DI::l10n()->t('Link or Media'),
998 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
999 '$preview' => DI::l10n()->t('Preview'),
1000 '$indent' => $indent,
1001 '$rand_num' => Crypto::randomDigits(12)
1005 return $comment_box;
1011 private function getRedirectUrl()
1013 return $this->redirect_url;
1017 * Check if we are a wall to wall item and set the relevant properties
1020 * @throws \Exception
1022 protected function checkWallToWall()
1025 $conv = $this->getThread();
1026 $this->wall_to_wall = false;
1028 if ($this->isToplevel()) {
1029 if ($conv->getMode() !== 'profile') {
1030 if ($this->getDataValue('owner-link')) {
1031 $owner_linkmatch = (($this->getDataValue('owner-link')) && Strings::compareLink($this->getDataValue('owner-link'), $this->getDataValue('author-link')));
1032 $alias_linkmatch = (($this->getDataValue('alias')) && Strings::compareLink($this->getDataValue('alias'), $this->getDataValue('author-link')));
1033 $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
1035 if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) {
1036 // The author url doesn't match the owner (typically the contact)
1037 // and also doesn't match the contact alias.
1038 // The name match is a hack to catch several weird cases where URLs are
1039 // all over the park. It can be tricked, but this prevents you from
1040 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
1041 // well that it's the same Bob Smith.
1042 // But it could be somebody else with the same name. It just isn't highly likely.
1045 $this->owner_name = $this->getDataValue('owner-name');
1046 $this->wall_to_wall = true;
1048 $owner = ['uid' => 0, 'id' => $this->getDataValue('owner-id'),
1049 'network' => $this->getDataValue('owner-network'),
1050 'url' => $this->getDataValue('owner-link')];
1051 $this->owner_url = Contact::magicLinkByContact($owner);
1057 if (!$this->wall_to_wall) {
1058 $this->setTemplate('wall');
1059 $this->owner_url = '';
1060 $this->owner_name = '';
1067 private function isWallToWall()
1069 return $this->wall_to_wall;
1075 private function getOwnerUrl()
1077 return $this->owner_url;
1083 private function getOwnerName()
1085 return $this->owner_name;
1091 private function isVisiting()
1093 return $this->visiting;