3 * @copyright Copyright (C) 2010-2021, 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;
32 use Friendica\Database\DBA;
34 use Friendica\Model\Contact;
35 use Friendica\Model\Item;
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\Strings;
43 use Friendica\Util\Temporal;
51 private $template = null;
52 private $available_templates = [
53 'wall' => 'wall_thread.tpl',
54 'wall2wall' => 'wallwall_thread.tpl'
56 private $comment_box_template = 'comment_item.tpl';
57 private $toplevel = false;
58 private $writable = false;
62 private $children = [];
63 private $parent = null;
68 private $thread = null;
69 private $redirect_url = null;
70 private $owner_url = '';
71 private $owner_photo = '';
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 (!visible_activity($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 * Get data in a form usable by a conversation template
127 * @param array $conv_responses conversation responses
128 * @param integer $thread_level default = 1
130 * @return mixed The data requested on success
132 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
133 * @throws \ImagickException
135 public function getTemplateData(array $conv_responses, $thread_level = 1)
139 $item = $this->getData();
141 // If the time between "created" and "edited" differs we add
142 // a notice that the post was edited.
143 // Note: In some networks reshared items seem to have (sometimes) a difference
144 // between creation time and edit time of a second. Thats why we add the notice
145 // only if the difference is more than 1 second.
146 if (strtotime($item['edited']) - strtotime($item['created']) > 1) {
148 'label' => DI::l10n()->t('This entry was edited'),
149 'date' => DateTimeFormat::local($item['edited'], 'r'),
150 'relative' => Temporal::getRelativeDate($item['edited'])
165 $ispinned = "unpinned";
166 $isstarred = "unstarred";
170 $total_children = $this->countDescendants();
172 $conv = $this->getThread();
174 $lock = ((($item['private'] == Item::PRIVATE) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
175 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
176 ? DI::l10n()->t('Private Message')
179 $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
180 $announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]);
182 // On Diaspora only toplevel posts can be reshared
183 if ($announceable && ($item['network'] == Protocol::DIASPORA) && ($item['gravity'] != GRAVITY_PARENT)) {
184 $announceable = false;
190 if (Strings::compareLink($a->contact['url'], $item['author-link'])) {
191 if ($item["event-id"] != 0) {
192 $edpost = ["events/event/" . $item['event-id'], DI::l10n()->t("Edit")];
194 $edpost = ["editpost/" . $item['id'], DI::l10n()->t("Edit")];
197 $dropping = in_array($item['uid'], [0, local_user()]);
200 // Editing on items of not subscribed users isn't currently possible
201 // There are some issues on editing that prevent this.
202 // But also it is an issue of the supported protocols that doesn't allow editing at all.
203 if ($item['uid'] == 0) {
207 if (($this->getDataValue('uid') == local_user()) || $this->isVisiting()) {
211 $origin = $item['origin'] || $item['parent-origin'];
213 if ($item['pinned']) {
214 $pinned = DI::l10n()->t('pinned item');
217 // Showing the one or the other text, depending upon if we can only hide it or really delete it.
218 $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
224 'dropping' => $dropping,
225 'pagedrop' => $item['pagedrop'],
226 'select' => DI::l10n()->t('Select'),
231 if (!$item['self']) {
234 'block' => DI::l10n()->t('Block %s', $item['author-name']),
235 'author_id' => $item['author-id'],
239 $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? DI::l10n()->t("save to folder") : false);
241 $profile_name = $item['author-name'];
242 if (!empty($item['author-link']) && empty($item['author-name'])) {
243 $profile_name = $item['author-link'];
246 if (Session::isAuthenticated()) {
247 $author = ['uid' => 0, 'id' => $item['author-id'],
248 'network' => $item['author-network'], 'url' => $item['author-link']];
249 $profile_link = Contact::magicLinkByContact($author);
251 $profile_link = $item['author-link'];
254 if (strpos($profile_link, 'redir/') === 0) {
255 $sparkle = ' sparkle';
258 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
259 Hook::callAll('render_location', $locate);
260 $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
262 // process action responses - e.g. like/dislike/attend/agree/whatever
263 $response_verbs = ['like', 'dislike', 'announce'];
267 if ($item['object-type'] === Activity\ObjectType::EVENT) {
268 $response_verbs[] = 'attendyes';
269 $response_verbs[] = 'attendno';
270 $response_verbs[] = 'attendmaybe';
271 if ($conv->isWritable()) {
273 $attend = [DI::l10n()->t('I will attend'), DI::l10n()->t('I will not attend'), DI::l10n()->t('I might attend')];
278 foreach ($response_verbs as $value => $verb) {
279 $responses[$verb] = [
280 'self' => $conv_responses[$verb][$item['uri-id']]['self'] ?? 0,
281 'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? format_activity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '',
286 * We should avoid doing this all the time, but it depends on the conversation mode
287 * And the conv mode may change when we change the conv, or it changes its mode
288 * Maybe we should establish a way to be notified about conversation changes
290 $this->checkWallToWall();
292 if ($this->isWallToWall() && ($this->getOwnerUrl() == $this->getRedirectUrl())) {
293 $osparkle = ' sparkle';
298 if ($this->isToplevel()) {
300 $ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], local_user());
301 if ($item['mention'] || $ignored) {
303 'do' => DI::l10n()->t("ignore thread"),
304 'undo' => DI::l10n()->t("unignore thread"),
305 'toggle' => DI::l10n()->t("toggle ignore status"),
306 'classdo' => $ignored ? "hidden" : "",
307 'classundo' => $ignored ? "" : "hidden",
308 'ignored' => DI::l10n()->t('ignored'),
312 if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
314 $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
317 'do' => DI::l10n()->t('pin'),
318 'undo' => DI::l10n()->t('unpin'),
319 'toggle' => DI::l10n()->t('toggle pin status'),
320 'classdo' => $item['pinned'] ? 'hidden' : '',
321 'classundo' => $item['pinned'] ? '' : 'hidden',
322 'pinned' => DI::l10n()->t('pinned'),
326 $isstarred = (($item['starred']) ? "starred" : "unstarred");
329 'do' => DI::l10n()->t("add star"),
330 'undo' => DI::l10n()->t("remove star"),
331 'toggle' => DI::l10n()->t("toggle star status"),
332 'classdo' => $item['starred'] ? "hidden" : "",
333 'classundo' => $item['starred'] ? "" : "hidden",
334 'starred' => DI::l10n()->t('starred'),
338 'add' => DI::l10n()->t("add tag"),
347 if ($conv->isWritable()) {
348 $buttons['like'] = [DI::l10n()->t("I like this \x28toggle\x29") , DI::l10n()->t("like")];
349 $buttons['dislike'] = [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t("dislike")];
351 $buttons['share'] = [DI::l10n()->t('Quote share this'), DI::l10n()->t('Quote Share')];
354 $buttons['announce'] = [DI::l10n()->t('Reshare this'), DI::l10n()->t('Reshare')];
355 $buttons['unannounce'] = [DI::l10n()->t('Cancel your Reshare'), DI::l10n()->t('Unshare')];
359 $comment_html = $this->getCommentBox($indent);
361 if (strcmp(DateTimeFormat::utc($item['created']), DateTimeFormat::utc('now - 12 hours')) > 0) {
365 localize_item($item);
367 $body_html = Item::prepareBody($item, true);
369 list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
371 if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
372 $title = ucfirst($item['content-warning']);
374 $title = $item['title'];
377 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
378 $buttons['dislike'] = false;
381 // Disable features that aren't available in several networks
382 if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
383 if ($buttons["dislike"]) {
384 $buttons["dislike"] = false;
391 if ($buttons["like"] && in_array($item["network"], [Protocol::FEED, Protocol::MAIL])) {
392 $buttons["like"] = false;
395 $tags = Tag::populateFromItem($item);
397 $ago = Temporal::getRelativeDate($item['created']);
398 $ago_received = Temporal::getRelativeDate($item['received']);
399 if (DI::config()->get('system', 'show_received') && (abs(strtotime($item['created']) - strtotime($item['received'])) > DI::config()->get('system', 'show_received_seconds')) && ($ago != $ago_received)) {
400 $ago = DI::l10n()->t('%s (Received %s)', $ago, $ago_received);
403 // Fetching of Diaspora posts doesn't always work. There are issues with reshares and possibly comments
404 if (($item['network'] != Protocol::DIASPORA) && empty($comment) && !empty(Session::get('remote_comment'))) {
405 $remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('remote comment'),
406 str_replace('{uri}', urlencode($item['uri']), Session::get('remote_comment'))];
408 $remote_comment = '';
412 if (!empty($item['direction'])) {
413 $direction = $item['direction'];
414 } elseif (DI::config()->get('debug', 'show_direction')) {
415 $conversation = DBA::selectFirst('conversation', ['direction'], ['item-uri' => $item['uri']]);
416 if (!empty($conversation['direction']) && in_array($conversation['direction'], [1, 2])) {
417 $direction_title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')];
418 $direction = ['direction' => $conversation['direction'], 'title' => $direction_title[$conversation['direction']]];
423 if (!empty($item['language'])) {
424 $languages = [DI::l10n()->t('Languages'), Item::getLanguageMessage($item)];
428 'template' => $this->getTemplate(),
429 'type' => implode("", array_slice(explode("/", $item['verb']), -1)),
430 'suppress_tags' => DI::config()->get('system', 'suppress_tags'),
431 'tags' => $tags['tags'],
432 'hashtags' => $tags['hashtags'],
433 'mentions' => $tags['mentions'],
434 'implicit_mentions' => $tags['implicit_mentions'],
435 'txt_cats' => DI::l10n()->t('Categories:'),
436 'txt_folders' => DI::l10n()->t('Filed under:'),
437 'has_cats' => ((count($categories)) ? 'true' : ''),
438 'has_folders' => ((count($folders)) ? 'true' : ''),
439 'categories' => $categories,
440 'folders' => $folders,
441 'body_html' => $body_html,
442 'text' => strip_tags($body_html),
443 'id' => $this->getId(),
444 'guid' => urlencode($item['guid']),
445 'isevent' => $isevent,
447 'linktitle' => DI::l10n()->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
448 'olinktitle' => DI::l10n()->t('View %s\'s profile @ %s', $this->getOwnerName(), $item['owner-link']),
449 'to' => DI::l10n()->t('to'),
450 'via' => DI::l10n()->t('via'),
451 'wall' => DI::l10n()->t('Wall-to-Wall'),
452 'vwall' => DI::l10n()->t('via Wall-To-Wall:'),
453 'profile_url' => $profile_link,
454 'name' => $profile_name,
455 'item_photo_menu_html' => item_photo_menu($item),
456 'thumb' => DI::baseUrl()->remove($item['author-avatar']),
457 'osparkle' => $osparkle,
458 'sparkle' => $sparkle,
460 'localtime' => DateTimeFormat::local($item['created'], 'r'),
461 'ago' => $item['app'] ? DI::l10n()->t('%s from %s', $ago, $item['app']) : $ago,
462 'app' => $item['app'],
465 'location_html' => $location_html,
468 'owner_self' => $item['author-link'] == Session::get('my_url'),
469 'owner_url' => $this->getOwnerUrl(),
470 'owner_photo' => DI::baseUrl()->remove($item['owner-avatar']),
471 'owner_name' => $this->getOwnerName(),
472 'plink' => Item::getPlink($item),
474 'ispinned' => $ispinned,
477 'isstarred' => $isstarred,
482 'language' => $languages,
486 'like_html' => $responses['like']['output'],
487 'dislike_html' => $responses['dislike']['output'],
488 'responses' => $responses,
489 'switchcomment' => DI::l10n()->t('Comment'),
490 'reply_label' => DI::l10n()->t('Reply to %s', $profile_name),
491 'comment_html' => $comment_html,
492 'remote_comment' => $remote_comment,
493 'menu' => DI::l10n()->t('More'),
494 'previewing' => $conv->isPreview() ? ' preview ' : '',
495 'wait' => DI::l10n()->t('Please wait'),
496 'thread_level' => $thread_level,
498 'network' => $item["network"],
499 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
500 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),
501 'received' => $item['received'],
502 'commented' => $item['commented'],
503 'created_date' => $item['created'],
504 'uriid' => $item['uri-id'],
505 'return' => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '',
506 'direction' => $direction,
507 'reshared' => $item['reshared'] ?? '',
509 'queue_count' => $item['delivery_queue_count'],
510 'queue_done' => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
511 'notifier_pending' => DI::l10n()->t('Notifier task is pending'),
512 'delivery_pending' => DI::l10n()->t('Delivery to remote servers is pending'),
513 'delivery_underway' => DI::l10n()->t('Delivery to remote servers is underway'),
514 'delivery_almost' => DI::l10n()->t('Delivery to remote servers is mostly done'),
515 'delivery_done' => DI::l10n()->t('Delivery to remote servers is done'),
519 $arr = ['item' => $item, 'output' => $tmp_item];
520 Hook::callAll('display_item', $arr);
522 $result = $arr['output'];
524 $result['children'] = [];
525 $children = $this->getChildren();
526 $nb_children = count($children);
527 if ($nb_children > 0) {
528 foreach ($children as $child) {
529 $result['children'][] = $child->getTemplateData($conv_responses, $thread_level + 1);
533 if (($nb_children > 2) || ($thread_level > 1)) {
534 $result['children'][0]['comment_firstcollapsed'] = true;
535 $result['children'][0]['num_comments'] = DI::l10n()->tt('%d comment', '%d comments', $total_children);
536 $result['children'][0]['show_text'] = DI::l10n()->t('Show more');
537 $result['children'][0]['hide_text'] = DI::l10n()->t('Show fewer');
538 if ($thread_level > 1) {
539 $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
541 $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
546 if ($this->isToplevel()) {
547 $result['total_comments_num'] = "$total_children";
548 $result['total_comments_text'] = DI::l10n()->tt('comment', 'comments', $total_children);
551 $result['private'] = $item['private'];
552 $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
554 if ($this->isThreaded()) {
555 $result['flatten'] = false;
556 $result['threaded'] = true;
558 $result['flatten'] = true;
559 $result['threaded'] = false;
568 public function getId()
570 return $this->getDataValue('id');
576 public function isThreaded()
578 return $this->threaded;
584 * @param Post $item The child item to add
589 public function addChild(Post $item)
591 $item_id = $item->getId();
593 Logger::log('[ERROR] Post::addChild : Item has no ID!!', Logger::DEBUG);
595 } elseif ($this->getChild($item->getId())) {
596 Logger::log('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', Logger::DEBUG);
600 $activity = DI::activity();
603 * Only add what will be displayed
605 if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
607 } elseif ($activity->match($item->getDataValue('verb'), Activity::LIKE) ||
608 $activity->match($item->getDataValue('verb'), Activity::DISLIKE)) {
612 $item->setParent($this);
613 $this->children[] = $item;
615 return end($this->children);
619 * Get a child by its ID
621 * @param integer $id The child id
625 public function getChild($id)
627 foreach ($this->getChildren() as $child) {
628 if ($child->getId() == $id) {
637 * Get all our children
641 public function getChildren()
643 return $this->children;
649 * @param Post $item The item to set as parent
653 protected function setParent(Post $item)
655 $parent = $this->getParent();
657 $parent->removeChild($this);
660 $this->parent = $item;
661 $this->setThread($item->getThread());
669 protected function removeParent()
671 $this->parent = null;
672 $this->thread = null;
678 * @param Post $item The child to be removed
680 * @return boolean Success or failure
683 public function removeChild(Post $item)
685 $id = $item->getId();
686 foreach ($this->getChildren() as $key => $child) {
687 if ($child->getId() == $id) {
688 $child->removeParent();
689 unset($this->children[$key]);
690 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
691 $this->children = array_values($this->children);
695 Logger::log('[WARN] Item::removeChild : Item is not a child (' . $id . ').', Logger::DEBUG);
704 protected function getParent()
706 return $this->parent;
710 * Set conversation thread
712 * @param Thread $thread
716 public function setThread(Thread $thread = null)
718 $this->thread = $thread;
720 // Set it on our children too
721 foreach ($this->getChildren() as $child) {
722 $child->setThread($thread);
731 public function getThread()
733 return $this->thread;
739 * We shouldn't need this
743 public function getData()
751 * @param string $name key
753 * @return mixed value on success
756 public function getDataValue($name)
758 if (!isset($this->data[$name])) {
759 // Logger::log('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".', Logger::DEBUG);
763 return $this->data[$name];
769 * @param string $name template name
773 private function setTemplate($name)
775 if (empty($this->available_templates[$name])) {
776 Logger::log('[ERROR] Item::setTemplate : Template not available ("' . $name . '").', Logger::DEBUG);
780 $this->template = $this->available_templates[$name];
790 private function getTemplate()
792 return $this->template;
796 * Check if this is a toplevel post
800 private function isToplevel()
802 return $this->toplevel;
806 * Check if this is writable
810 private function isWritable()
812 $conv = $this->getThread();
815 // This will allow us to comment on wall-to-wall items owned by our friends
816 // and community forums even if somebody else wrote the post.
817 // bug #517 - this fixes for conversation owner
818 if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == local_user()) {
822 // this fixes for visitors
823 return ($this->writable || ($this->isVisiting() && $conv->getMode() == 'profile'));
825 return $this->writable;
829 * Count the total of our descendants
833 private function countDescendants()
835 $children = $this->getChildren();
836 $total = count($children);
838 foreach ($children as $child) {
839 $total += $child->countDescendants();
847 * Get the template for the comment box
851 private function getCommentBoxTemplate()
853 return $this->comment_box_template;
857 * Get default text for the comment box
860 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
862 private function getDefaultText()
870 $owner = User::getOwnerDataById($a->user['uid']);
872 if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
876 $item = PostModel::selectFirst(['author-addr', 'uri-id', 'network', 'gravity'], ['id' => $this->getId()]);
877 if (!DBA::isResult($item) || empty($item['author-addr'])) {
882 if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
883 $text = '@' . $item['author-addr'] . ' ';
888 $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
889 foreach ($terms as $term) {
891 DI::logger()->warning('Mention term with no URL', ['term' => $term]);
895 $profile = Contact::getByURL($term['url'], false, ['addr', 'contact-type']);
896 if (!empty($profile['addr']) && (($profile['contact-type'] ?? Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) &&
897 ($profile['addr'] != $owner['addr']) && !strstr($text, $profile['addr'])) {
898 $text .= '@' . $profile['addr'] . ' ';
906 * Get the comment box
908 * @param string $indent Indent value
910 * @return mixed The comment box string (empty if no comment box)
914 private function getCommentBox($indent)
919 $conv = $this->getThread();
921 if ($conv->isWritable() && $this->isWritable()) {
923 * Hmmm, code depending on the presence of a particular addon?
924 * This should be better if done by a hook
927 if (Addon::isEnabled('qcomment')) {
928 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
929 $qcomment = $words ? explode("\n", $words) : [];
932 // Fetch the user id from the parent when the owner user is empty
933 $uid = $conv->getProfileOwner();
934 $parent_uid = $this->getDataValue('uid');
936 $default_text = $this->getDefaultText();
938 if (!is_null($parent_uid) && ($uid != $parent_uid)) {
942 $template = Renderer::getMarkupTemplate($this->getCommentBoxTemplate());
943 $comment_box = Renderer::replaceMacros($template, [
944 '$return_path' => DI::args()->getQueryString(),
945 '$threaded' => $this->isThreaded(),
947 '$wall' => ($conv->getMode() === 'profile'),
948 '$id' => $this->getId(),
949 '$parent' => $this->getId(),
950 '$qcomment' => $qcomment,
951 '$default' => $default_text,
952 '$profile_uid' => $uid,
953 '$mylink' => DI::baseUrl()->remove($a->contact['url']),
954 '$mytitle' => DI::l10n()->t('This is you'),
955 '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']),
956 '$comment' => DI::l10n()->t('Comment'),
957 '$submit' => DI::l10n()->t('Submit'),
958 '$loading' => DI::l10n()->t('Loading...'),
959 '$edbold' => DI::l10n()->t('Bold'),
960 '$editalic' => DI::l10n()->t('Italic'),
961 '$eduline' => DI::l10n()->t('Underline'),
962 '$edquote' => DI::l10n()->t('Quote'),
963 '$edcode' => DI::l10n()->t('Code'),
964 '$edimg' => DI::l10n()->t('Image'),
965 '$edurl' => DI::l10n()->t('Link'),
966 '$edattach' => DI::l10n()->t('Link or Media'),
967 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
968 '$preview' => DI::l10n()->t('Preview'),
969 '$indent' => $indent,
970 '$sourceapp' => DI::l10n()->t($a->sourcename),
971 '$rand_num' => Crypto::randomDigits(12)
981 private function getRedirectUrl()
983 return $this->redirect_url;
987 * Check if we are a wall to wall item and set the relevant properties
992 protected function checkWallToWall()
995 $conv = $this->getThread();
996 $this->wall_to_wall = false;
998 if ($this->isToplevel()) {
999 if ($conv->getMode() !== 'profile') {
1000 if ($this->getDataValue('wall') && !$this->getDataValue('self') && !empty($a->page_contact)) {
1001 // On the network page, I am the owner. On the display page it will be the profile owner.
1002 // This will have been stored in $a->page_contact by our calling page.
1003 // Put this person as the wall owner of the wall-to-wall notice.
1005 $this->owner_url = Contact::magicLinkByContact($a->page_contact);
1006 $this->owner_photo = $a->page_contact['thumb'];
1007 $this->owner_name = $a->page_contact['name'];
1008 $this->wall_to_wall = true;
1009 } elseif ($this->getDataValue('owner-link')) {
1010 $owner_linkmatch = (($this->getDataValue('owner-link')) && Strings::compareLink($this->getDataValue('owner-link'), $this->getDataValue('author-link')));
1011 $alias_linkmatch = (($this->getDataValue('alias')) && Strings::compareLink($this->getDataValue('alias'), $this->getDataValue('author-link')));
1012 $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
1014 if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) {
1015 // The author url doesn't match the owner (typically the contact)
1016 // and also doesn't match the contact alias.
1017 // The name match is a hack to catch several weird cases where URLs are
1018 // all over the park. It can be tricked, but this prevents you from
1019 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
1020 // well that it's the same Bob Smith.
1021 // But it could be somebody else with the same name. It just isn't highly likely.
1024 $this->owner_photo = $this->getDataValue('owner-avatar');
1025 $this->owner_name = $this->getDataValue('owner-name');
1026 $this->wall_to_wall = true;
1028 $owner = ['uid' => 0, 'id' => $this->getDataValue('owner-id'),
1029 'network' => $this->getDataValue('owner-network'),
1030 'url' => $this->getDataValue('owner-link')];
1031 $this->owner_url = Contact::magicLinkByContact($owner);
1037 if (!$this->wall_to_wall) {
1038 $this->setTemplate('wall');
1039 $this->owner_url = '';
1040 $this->owner_photo = '';
1041 $this->owner_name = '';
1048 private function isWallToWall()
1050 return $this->wall_to_wall;
1056 private function getOwnerUrl()
1058 return $this->owner_url;
1064 private function getOwnerName()
1066 return $this->owner_name;
1072 private function isVisiting()
1074 return $this->visiting;