3 * @copyright Copyright (C) 2020, Friendica
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\Tag;
37 use Friendica\Model\User;
38 use Friendica\Protocol\Activity;
39 use Friendica\Util\Crypto;
40 use Friendica\Util\DateTimeFormat;
41 use Friendica\Util\Strings;
42 use Friendica\Util\Temporal;
50 private $template = null;
51 private $available_templates = [
52 'wall' => 'wall_thread.tpl',
53 'wall2wall' => 'wallwall_thread.tpl'
55 private $comment_box_template = 'comment_item.tpl';
56 private $toplevel = false;
57 private $writable = false;
61 private $children = [];
62 private $parent = null;
67 private $thread = null;
68 private $redirect_url = null;
69 private $owner_url = '';
70 private $owner_photo = '';
71 private $owner_name = '';
72 private $wall_to_wall = false;
73 private $threaded = false;
74 private $visiting = false;
79 * @param array $data data array
82 public function __construct(array $data)
85 $this->setTemplate('wall');
86 $this->toplevel = $this->getId() == $this->getDataValue('parent');
88 if (!empty(Session::getUserIDForVisitorContactID($this->getDataValue('contact-id')))) {
89 $this->visiting = true;
92 $this->writable = $this->getDataValue('writable') || $this->getDataValue('self');
93 $author = ['uid' => 0, 'id' => $this->getDataValue('author-id'),
94 'network' => $this->getDataValue('author-network'),
95 'url' => $this->getDataValue('author-link')];
96 $this->redirect_url = Contact::magicLinkByContact($author);
97 if (!$this->isToplevel()) {
98 $this->threaded = true;
101 // Prepare the children
102 if (!empty($data['children'])) {
103 foreach ($data['children'] as $item) {
104 // Only add will be displayed
105 if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
107 } elseif (!visible_activity($item)) {
111 // You can always comment on Diaspora and OStatus items
112 if (in_array($item['network'], [Protocol::OSTATUS, Protocol::DIASPORA]) && (local_user() == $item['uid'])) {
113 $item['writable'] = true;
116 $item['pagedrop'] = $data['pagedrop'];
117 $child = new Post($item);
118 $this->addChild($child);
124 * Get data in a form usable by a conversation template
126 * @param array $conv_responses conversation responses
127 * @param integer $thread_level default = 1
129 * @return mixed The data requested on success
131 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
132 * @throws \ImagickException
134 public function getTemplateData(array $conv_responses, $thread_level = 1)
138 $item = $this->getData();
140 // If the time between "created" and "edited" differs we add
141 // a notice that the post was edited.
142 // Note: In some networks reshared items seem to have (sometimes) a difference
143 // between creation time and edit time of a second. Thats why we add the notice
144 // only if the difference is more than 1 second.
145 if (strtotime($item['edited']) - strtotime($item['created']) > 1) {
147 'label' => DI::l10n()->t('This entry was edited'),
148 'date' => DateTimeFormat::local($item['edited'], 'r'),
149 'relative' => Temporal::getRelativeDate($item['edited'])
163 $ispinned = "unpinned";
164 $isstarred = "unstarred";
168 $total_children = $this->countDescendants();
170 $conv = $this->getThread();
172 $lock = ((($item['private'] == Item::PRIVATE) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
173 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
174 ? DI::l10n()->t('Private Message')
177 $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
182 if (Strings::compareLink($a->contact['url'], $item['author-link'])) {
183 if ($item["event-id"] != 0) {
184 $edpost = ["events/event/" . $item['event-id'], DI::l10n()->t("Edit")];
186 $edpost = ["editpost/" . $item['id'], DI::l10n()->t("Edit")];
189 $dropping = in_array($item['uid'], [0, local_user()]);
192 // Editing on items of not subscribed users isn't currently possible
193 // There are some issues on editing that prevent this.
194 // But also it is an issue of the supported protocols that doesn't allow editing at all.
195 if ($item['uid'] == 0) {
199 if (($this->getDataValue('uid') == local_user()) || $this->isVisiting()) {
203 $origin = $item['origin'];
206 /// @todo This shouldn't be done as query here, but better during the data creation.
207 // it is now done here, since during the RC phase we shouldn't make to intense changes.
208 $parent = Item::selectFirst(['origin'], ['id' => $item['parent']]);
209 if (DBA::isResult($parent)) {
210 $origin = $parent['origin'];
212 } elseif ($item['pinned']) {
213 $pinned = DI::l10n()->t('pinned item');
216 if ($origin && ($item['gravity'] != GRAVITY_PARENT) && ($item['network'] == Protocol::ACTIVITYPUB)) {
217 // ActivityPub doesn't allow removal of remote comments
218 $delete = DI::l10n()->t('Delete locally');
220 // Showing the one or the other text, depending upon if we can only hide it or really delete it.
221 $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
225 'dropping' => $dropping,
226 'pagedrop' => $item['pagedrop'],
227 'select' => DI::l10n()->t('Select'),
235 $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? DI::l10n()->t("save to folder") : false);
237 $profile_name = $item['author-name'];
238 if (!empty($item['author-link']) && empty($item['author-name'])) {
239 $profile_name = $item['author-link'];
242 $author = ['uid' => 0, 'id' => $item['author-id'],
243 'network' => $item['author-network'], 'url' => $item['author-link']];
245 if (Session::isAuthenticated()) {
246 $profile_link = Contact::magicLinkByContact($author);
248 $profile_link = $item['author-link'];
251 if (strpos($profile_link, 'redir/') === 0) {
252 $sparkle = ' sparkle';
255 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
256 Hook::callAll('render_location', $locate);
257 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
259 // process action responses - e.g. like/dislike/attend/agree/whatever
260 $response_verbs = ['like', 'dislike', 'announce'];
264 if ($item['object-type'] === Activity\ObjectType::EVENT) {
265 $response_verbs[] = 'attendyes';
266 $response_verbs[] = 'attendno';
267 $response_verbs[] = 'attendmaybe';
268 if ($conv->isWritable()) {
270 $attend = [DI::l10n()->t('I will attend'), DI::l10n()->t('I will not attend'), DI::l10n()->t('I might attend')];
275 foreach ($response_verbs as $value => $verb) {
276 $responses[$verb] = [
277 'self' => $conv_responses[$verb][$item['uri'] . '-self'] ?? 0,
278 'output' => !empty($conv_responses[$verb][$item['uri']]) ? format_like($conv_responses[$verb][$item['uri']], $conv_responses[$verb][$item['uri'] . '-l'], $verb, $item['uri']) : '',
283 * We should avoid doing this all the time, but it depends on the conversation mode
284 * And the conv mode may change when we change the conv, or it changes its mode
285 * Maybe we should establish a way to be notified about conversation changes
287 $this->checkWallToWall();
289 if ($this->isWallToWall() && ($this->getOwnerUrl() == $this->getRedirectUrl())) {
290 $osparkle = ' sparkle';
295 if ($this->isToplevel()) {
297 $thread = Item::selectFirstThreadForUser(local_user(), ['ignored'], ['iid' => $item['id']]);
298 if (DBA::isResult($thread)) {
300 'do' => DI::l10n()->t("ignore thread"),
301 'undo' => DI::l10n()->t("unignore thread"),
302 'toggle' => DI::l10n()->t("toggle ignore status"),
303 'classdo' => $thread['ignored'] ? "hidden" : "",
304 'classundo' => $thread['ignored'] ? "" : "hidden",
305 'ignored' => DI::l10n()->t('ignored'),
309 if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
311 $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
314 'do' => DI::l10n()->t('pin'),
315 'undo' => DI::l10n()->t('unpin'),
316 'toggle' => DI::l10n()->t('toggle pin status'),
317 'classdo' => $item['pinned'] ? 'hidden' : '',
318 'classundo' => $item['pinned'] ? '' : 'hidden',
319 'pinned' => DI::l10n()->t('pinned'),
323 $isstarred = (($item['starred']) ? "starred" : "unstarred");
326 'do' => DI::l10n()->t("add star"),
327 'undo' => DI::l10n()->t("remove star"),
328 'toggle' => DI::l10n()->t("toggle star status"),
329 'classdo' => $item['starred'] ? "hidden" : "",
330 'classundo' => $item['starred'] ? "" : "hidden",
331 'starred' => DI::l10n()->t('starred'),
335 'add' => DI::l10n()->t("add tag"),
344 if ($conv->isWritable()) {
345 $buttons['like'] = [DI::l10n()->t("I like this \x28toggle\x29") , DI::l10n()->t("like")];
346 $buttons['dislike'] = [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t("dislike")];
348 $buttons['share'] = [DI::l10n()->t('Share this'), DI::l10n()->t('share')];
352 $comment = $this->getCommentBox($indent);
354 if (strcmp(DateTimeFormat::utc($item['created']), DateTimeFormat::utc('now - 12 hours')) > 0) {
358 localize_item($item);
360 $body = Item::prepareBody($item, true);
362 list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
365 $text_e = strip_tags($body);
366 $name_e = $profile_name;
368 if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
369 $title_e = ucfirst($item['content-warning']);
371 $title_e = $item['title'];
374 $location_e = $location;
375 $owner_name_e = $this->getOwnerName();
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 $title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')];
418 $direction = ['direction' => $conversation['direction'], 'title' => $title[$conversation['direction']]];
422 if (!empty($item['reshared'])) {
423 $reshared = $item['reshared'];
429 'template' => $this->getTemplate(),
430 'type' => implode("", array_slice(explode("/", $item['verb']), -1)),
431 'suppress_tags' => DI::config()->get('system', 'suppress_tags'),
432 'tags' => $tags['tags'],
433 'hashtags' => $tags['hashtags'],
434 'mentions' => $tags['mentions'],
435 'implicit_mentions' => $tags['implicit_mentions'],
436 'txt_cats' => DI::l10n()->t('Categories:'),
437 'txt_folders' => DI::l10n()->t('Filed under:'),
438 'has_cats' => ((count($categories)) ? 'true' : ''),
439 'has_folders' => ((count($folders)) ? 'true' : ''),
440 'categories' => $categories,
441 'folders' => $folders,
444 'id' => $this->getId(),
445 'guid' => urlencode($item['guid']),
446 'isevent' => $isevent,
448 'linktitle' => DI::l10n()->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
449 'olinktitle' => DI::l10n()->t('View %s\'s profile @ %s', $this->getOwnerName(), $item['owner-link']),
450 'to' => DI::l10n()->t('to'),
451 'via' => DI::l10n()->t('via'),
452 'wall' => DI::l10n()->t('Wall-to-Wall'),
453 'vwall' => DI::l10n()->t('via Wall-To-Wall:'),
454 'profile_url' => $profile_link,
455 'item_photo_menu' => item_photo_menu($item),
457 'thumb' => DI::baseUrl()->remove($item['author-avatar']),
458 'osparkle' => $osparkle,
459 'sparkle' => $sparkle,
461 'localtime' => DateTimeFormat::local($item['created'], 'r'),
462 'ago' => $item['app'] ? DI::l10n()->t('%s from %s', $ago, $item['app']) : $ago,
463 'app' => $item['app'],
466 'location' => $location_e,
469 'owner_self' => $item['author-link'] == Session::get('my_url'),
470 'owner_url' => $this->getOwnerUrl(),
471 'owner_photo' => DI::baseUrl()->remove($item['owner-avatar']),
472 'owner_name' => $owner_name_e,
473 'plink' => Item::getPlink($item),
475 'ispinned' => $ispinned,
478 'isstarred' => $isstarred,
485 'like' => $responses['like']['output'],
486 'dislike' => $responses['dislike']['output'],
487 'responses' => $responses,
488 'switchcomment' => DI::l10n()->t('Comment'),
489 'reply_label' => DI::l10n()->t('Reply to %s', $name_e),
490 'comment' => $comment,
491 'remote_comment' => $remote_comment,
492 'menu' => DI::l10n()->t('More'),
493 'previewing' => $conv->isPreview() ? ' preview ' : '',
494 'wait' => DI::l10n()->t('Please wait'),
495 'thread_level' => $thread_level,
497 'network' => $item["network"],
498 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
499 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),
500 'received' => $item['received'],
501 'commented' => $item['commented'],
502 'created_date' => $item['created'],
503 'uriid' => $item['uri-id'],
504 'return' => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '',
505 'direction' => $direction,
506 'reshared' => $reshared,
508 'queue_count' => $item['delivery_queue_count'],
509 'queue_done' => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
510 'notifier_pending' => DI::l10n()->t('Notifier task is pending'),
511 'delivery_pending' => DI::l10n()->t('Delivery to remote servers is pending'),
512 'delivery_underway' => DI::l10n()->t('Delivery to remote servers is underway'),
513 'delivery_almost' => DI::l10n()->t('Delivery to remote servers is mostly done'),
514 'delivery_done' => DI::l10n()->t('Delivery to remote servers is done'),
518 $arr = ['item' => $item, 'output' => $tmp_item];
519 Hook::callAll('display_item', $arr);
521 $result = $arr['output'];
523 $result['children'] = [];
524 $children = $this->getChildren();
525 $nb_children = count($children);
526 if ($nb_children > 0) {
527 foreach ($children as $child) {
528 $result['children'][] = $child->getTemplateData($conv_responses, $thread_level + 1);
532 if (($nb_children > 2) || ($thread_level > 1)) {
533 $result['children'][0]['comment_firstcollapsed'] = true;
534 $result['children'][0]['num_comments'] = DI::l10n()->tt('%d comment', '%d comments', $total_children);
535 $result['children'][0]['show_text'] = DI::l10n()->t('Show more');
536 $result['children'][0]['hide_text'] = DI::l10n()->t('Show fewer');
537 if ($thread_level > 1) {
538 $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
540 $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
545 if ($this->isToplevel()) {
546 $result['total_comments_num'] = "$total_children";
547 $result['total_comments_text'] = DI::l10n()->tt('comment', 'comments', $total_children);
550 $result['private'] = $item['private'];
551 $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
553 if ($this->isThreaded()) {
554 $result['flatten'] = false;
555 $result['threaded'] = true;
557 $result['flatten'] = true;
558 $result['threaded'] = false;
567 public function getId()
569 return $this->getDataValue('id');
575 public function isThreaded()
577 return $this->threaded;
583 * @param Post $item The child item to add
588 public function addChild(Post $item)
590 $item_id = $item->getId();
592 Logger::log('[ERROR] Post::addChild : Item has no ID!!', Logger::DEBUG);
594 } elseif ($this->getChild($item->getId())) {
595 Logger::log('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', Logger::DEBUG);
599 $activity = DI::activity();
602 * Only add what will be displayed
604 if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
606 } elseif ($activity->match($item->getDataValue('verb'), Activity::LIKE) ||
607 $activity->match($item->getDataValue('verb'), Activity::DISLIKE)) {
611 $item->setParent($this);
612 $this->children[] = $item;
614 return end($this->children);
618 * Get a child by its ID
620 * @param integer $id The child id
624 public function getChild($id)
626 foreach ($this->getChildren() as $child) {
627 if ($child->getId() == $id) {
636 * Get all our children
640 public function getChildren()
642 return $this->children;
648 * @param Post $item The item to set as parent
652 protected function setParent(Post $item)
654 $parent = $this->getParent();
656 $parent->removeChild($this);
659 $this->parent = $item;
660 $this->setThread($item->getThread());
668 protected function removeParent()
670 $this->parent = null;
671 $this->thread = null;
677 * @param Post $item The child to be removed
679 * @return boolean Success or failure
682 public function removeChild(Post $item)
684 $id = $item->getId();
685 foreach ($this->getChildren() as $key => $child) {
686 if ($child->getId() == $id) {
687 $child->removeParent();
688 unset($this->children[$key]);
689 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
690 $this->children = array_values($this->children);
694 Logger::log('[WARN] Item::removeChild : Item is not a child (' . $id . ').', Logger::DEBUG);
703 protected function getParent()
705 return $this->parent;
709 * Set conversation thread
711 * @param Thread $thread
715 public function setThread(Thread $thread = null)
717 $this->thread = $thread;
719 // Set it on our children too
720 foreach ($this->getChildren() as $child) {
721 $child->setThread($thread);
730 public function getThread()
732 return $this->thread;
738 * We shouldn't need this
742 public function getData()
750 * @param string $name key
752 * @return mixed value on success
755 public function getDataValue($name)
757 if (!isset($this->data[$name])) {
758 // Logger::log('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".', Logger::DEBUG);
762 return $this->data[$name];
768 * @param string $name template name
772 private function setTemplate($name)
774 if (empty($this->available_templates[$name])) {
775 Logger::log('[ERROR] Item::setTemplate : Template not available ("' . $name . '").', Logger::DEBUG);
779 $this->template = $this->available_templates[$name];
789 private function getTemplate()
791 return $this->template;
795 * Check if this is a toplevel post
799 private function isToplevel()
801 return $this->toplevel;
805 * Check if this is writable
809 private function isWritable()
811 $conv = $this->getThread();
814 // This will allow us to comment on wall-to-wall items owned by our friends
815 // and community forums even if somebody else wrote the post.
816 // bug #517 - this fixes for conversation owner
817 if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == local_user()) {
821 // this fixes for visitors
822 return ($this->writable || ($this->isVisiting() && $conv->getMode() == 'profile'));
824 return $this->writable;
828 * Count the total of our descendants
832 private function countDescendants()
834 $children = $this->getChildren();
835 $total = count($children);
837 foreach ($children as $child) {
838 $total += $child->countDescendants();
846 * Get the template for the comment box
850 private function getCommentBoxTemplate()
852 return $this->comment_box_template;
856 * Get default text for the comment box
859 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
861 private function getDefaultText()
869 $owner = User::getOwnerDataById($a->user['uid']);
871 if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
875 $item = Item::selectFirst(['author-addr', 'uri-id'], ['id' => $this->getId()]);
876 if (!DBA::isResult($item) || empty($item['author-addr'])) {
881 if ($item['author-addr'] != $owner['addr']) {
882 $text = '@' . $item['author-addr'] . ' ';
887 $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
888 foreach ($terms as $term) {
889 $profile = Contact::getByURL($term['url'], false, ['addr', 'contact-type']);
890 if (!empty($profile['addr']) && ((($profile['contact-type'] ?? '') ?: Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) &&
891 ($profile['addr'] != $owner['addr']) && !strstr($text, $profile['addr'])) {
892 $text .= '@' . $profile['addr'] . ' ';
900 * Get the comment box
902 * @param string $indent Indent value
904 * @return mixed The comment box string (empty if no comment box)
908 private function getCommentBox($indent)
913 $conv = $this->getThread();
915 if (($conv->getMode() === 'network') && $this->isWallToWall()) {
919 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
926 if (Addon::isEnabled('qcomment')) {
927 $qc = ((local_user()) ? DI::pConfig()->get(local_user(), 'qcomment', 'words') : null);
928 $qcomment = (($qc) ? explode("\n", $qc) : null);
931 // Fetch the user id from the parent when the owner user is empty
932 $uid = $conv->getProfileOwner();
933 $parent_uid = $this->getDataValue('uid');
935 $default_text = $this->getDefaultText();
937 if (!is_null($parent_uid) && ($uid != $parent_uid)) {
941 $template = Renderer::getMarkupTemplate($this->getCommentBoxTemplate());
942 $comment_box = Renderer::replaceMacros($template, [
943 '$return_path' => DI::args()->getQueryString(),
944 '$threaded' => $this->isThreaded(),
946 '$wall' => ($conv->getMode() === 'profile'),
947 '$id' => $this->getId(),
948 '$parent' => $this->getId(),
949 '$qcomment' => $qcomment,
950 '$default' => $default_text,
951 '$profile_uid' => $uid,
952 '$mylink' => DI::baseUrl()->remove($a->contact['url']),
953 '$mytitle' => DI::l10n()->t('This is you'),
954 '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']),
955 '$comment' => DI::l10n()->t('Comment'),
956 '$submit' => DI::l10n()->t('Submit'),
957 '$loading' => DI::l10n()->t('Loading...'),
958 '$edbold' => DI::l10n()->t('Bold'),
959 '$editalic' => DI::l10n()->t('Italic'),
960 '$eduline' => DI::l10n()->t('Underline'),
961 '$edquote' => DI::l10n()->t('Quote'),
962 '$edcode' => DI::l10n()->t('Code'),
963 '$edimg' => DI::l10n()->t('Image'),
964 '$edurl' => DI::l10n()->t('Link'),
965 '$edattach' => DI::l10n()->t('Link or Media'),
966 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
967 '$preview' => DI::l10n()->t('Preview'),
968 '$indent' => $indent,
969 '$sourceapp' => DI::l10n()->t($a->sourcename),
970 '$ww' => $conv->getMode() === 'network' ? $ww : '',
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')) {
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::magicLink($a->page_contact['url']);
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;