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\Term;
37 use Friendica\Model\User;
38 use Friendica\Protocol\Activity;
39 use Friendica\Util\Crypto;
40 use Friendica\Util\DateTimeFormat;
41 use Friendica\Util\Proxy as ProxyUtils;
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'])
164 $ispinned = "unpinned";
165 $isstarred = "unstarred";
169 $total_children = $this->countDescendants();
171 $conv = $this->getThread();
173 $lock = ((($item['private'] == Item::PRIVATE) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
174 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
175 ? DI::l10n()->t('Private Message')
178 $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
183 if (Strings::compareLink($a->contact['url'], $item['author-link'])) {
184 if ($item["event-id"] != 0) {
185 $edpost = ["events/event/" . $item['event-id'], DI::l10n()->t("Edit")];
187 $edpost = ["editpost/" . $item['id'], DI::l10n()->t("Edit")];
190 $dropping = in_array($item['uid'], [0, local_user()]);
193 // Editing on items of not subscribed users isn't currently possible
194 // There are some issues on editing that prevent this.
195 // But also it is an issue of the supported protocols that doesn't allow editing at all.
196 if ($item['uid'] == 0) {
200 if (($this->getDataValue('uid') == local_user()) || $this->isVisiting()) {
204 $origin = $item['origin'];
207 /// @todo This shouldn't be done as query here, but better during the data creation.
208 // it is now done here, since during the RC phase we shouldn't make to intense changes.
209 $parent = Item::selectFirst(['origin'], ['id' => $item['parent']]);
210 if (DBA::isResult($parent)) {
211 $origin = $parent['origin'];
213 } elseif ($item['pinned']) {
214 $pinned = DI::l10n()->t('pinned item');
217 if ($origin && ($item['id'] != $item['parent']) && ($item['network'] == Protocol::ACTIVITYPUB)) {
218 // ActivityPub doesn't allow removal of remote comments
219 $delete = DI::l10n()->t('Delete locally');
221 // Showing the one or the other text, depending upon if we can only hide it or really delete it.
222 $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
226 'dropping' => $dropping,
227 'pagedrop' => $item['pagedrop'],
228 'select' => DI::l10n()->t('Select'),
236 $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? DI::l10n()->t("save to folder") : false);
238 $profile_name = $item['author-name'];
239 if (!empty($item['author-link']) && empty($item['author-name'])) {
240 $profile_name = $item['author-link'];
243 $author = ['uid' => 0, 'id' => $item['author-id'],
244 'network' => $item['author-network'], 'url' => $item['author-link']];
246 if (Session::isAuthenticated()) {
247 $profile_link = Contact::magicLinkByContact($author);
249 $profile_link = $item['author-link'];
252 if (strpos($profile_link, 'redir/') === 0) {
253 $sparkle = ' sparkle';
256 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
257 Hook::callAll('render_location', $locate);
258 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
260 // process action responses - e.g. like/dislike/attend/agree/whatever
261 $response_verbs = ['like', 'dislike', 'announce'];
265 if ($item['object-type'] === Activity\ObjectType::EVENT) {
266 $response_verbs[] = 'attendyes';
267 $response_verbs[] = 'attendno';
268 $response_verbs[] = 'attendmaybe';
269 if ($conv->isWritable()) {
271 $attend = [DI::l10n()->t('I will attend'), DI::l10n()->t('I will not attend'), DI::l10n()->t('I might attend')];
276 foreach ($response_verbs as $value => $verb) {
277 $responses[$verb] = [
278 'self' => $conv_responses[$verb][$item['uri'] . '-self'] ?? 0,
279 'output' => !empty($conv_responses[$verb][$item['uri']]) ? format_like($conv_responses[$verb][$item['uri']], $conv_responses[$verb][$item['uri'] . '-l'], $verb, $item['uri']) : '',
284 * We should avoid doing this all the time, but it depends on the conversation mode
285 * And the conv mode may change when we change the conv, or it changes its mode
286 * Maybe we should establish a way to be notified about conversation changes
288 $this->checkWallToWall();
290 if ($this->isWallToWall() && ($this->getOwnerUrl() == $this->getRedirectUrl())) {
291 $osparkle = ' sparkle';
296 if ($this->isToplevel()) {
298 $thread = Item::selectFirstThreadForUser(local_user(), ['ignored'], ['iid' => $item['id']]);
299 if (DBA::isResult($thread)) {
301 'do' => DI::l10n()->t("ignore thread"),
302 'undo' => DI::l10n()->t("unignore thread"),
303 'toggle' => DI::l10n()->t("toggle ignore status"),
304 'classdo' => $thread['ignored'] ? "hidden" : "",
305 'classundo' => $thread['ignored'] ? "" : "hidden",
306 'ignored' => DI::l10n()->t('ignored'),
310 if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
312 $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
315 'do' => DI::l10n()->t('pin'),
316 'undo' => DI::l10n()->t('unpin'),
317 'toggle' => DI::l10n()->t('toggle pin status'),
318 'classdo' => $item['pinned'] ? 'hidden' : '',
319 'classundo' => $item['pinned'] ? '' : 'hidden',
320 'pinned' => DI::l10n()->t('pinned'),
324 $isstarred = (($item['starred']) ? "starred" : "unstarred");
327 'do' => DI::l10n()->t("add star"),
328 'undo' => DI::l10n()->t("remove star"),
329 'toggle' => DI::l10n()->t("toggle star status"),
330 'classdo' => $item['starred'] ? "hidden" : "",
331 'classundo' => $item['starred'] ? "" : "hidden",
332 'starred' => DI::l10n()->t('starred'),
336 'add' => DI::l10n()->t("add tag"),
345 if ($conv->isWritable()) {
346 $buttons['like'] = [DI::l10n()->t("I like this \x28toggle\x29") , DI::l10n()->t("like")];
347 $buttons['dislike'] = [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t("dislike")];
349 $buttons['share'] = [DI::l10n()->t('Share this'), DI::l10n()->t('share')];
353 $comment = $this->getCommentBox($indent);
355 if (strcmp(DateTimeFormat::utc($item['created']), DateTimeFormat::utc('now - 12 hours')) > 0) {
359 localize_item($item);
361 $body = Item::prepareBody($item, true);
363 list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
366 $text_e = strip_tags($body);
367 $name_e = $profile_name;
369 if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
370 $title_e = ucfirst($item['content-warning']);
372 $title_e = $item['title'];
375 $location_e = $location;
376 $owner_name_e = $this->getOwnerName();
378 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
379 $buttons['dislike'] = false;
382 // Disable features that aren't available in several networks
383 if ($buttons["dislike"] && !in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
384 $buttons["dislike"] = false;
389 if ($buttons["like"] && in_array($item["network"], [Protocol::FEED, Protocol::MAIL])) {
390 $buttons["like"] = false;
393 $tags = Term::populateTagsFromItem($item);
395 $ago = Temporal::getRelativeDate($item['created']);
396 $ago_received = Temporal::getRelativeDate($item['received']);
397 if (DI::config()->get('system', 'show_received') && (abs(strtotime($item['created']) - strtotime($item['received'])) > DI::config()->get('system', 'show_received_seconds')) && ($ago != $ago_received)) {
398 $ago = DI::l10n()->t('%s (Received %s)', $ago, $ago_received);
401 // Fetching of Diaspora posts doesn't always work. There are issues with reshares and possibly comments
402 if (($item['network'] != Protocol::DIASPORA) && empty($comment) && !empty(Session::get('remote_comment'))) {
403 $remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('remote comment'),
404 str_replace('{uri}', urlencode($item['uri']), Session::get('remote_comment'))];
406 $remote_comment = '';
410 if (DI::config()->get('debug', 'show_direction')) {
411 $conversation = DBA::selectFirst('conversation', ['direction'], ['item-uri' => $item['uri']]);
412 if (!empty($conversation['direction']) && in_array($conversation['direction'], [1, 2])) {
413 $title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')];
414 $direction = ['direction' => $conversation['direction'], 'title' => $title[$conversation['direction']]];
419 'template' => $this->getTemplate(),
420 'type' => implode("", array_slice(explode("/", $item['verb']), -1)),
421 'suppress_tags' => DI::config()->get('system', 'suppress_tags'),
422 'tags' => $tags['tags'],
423 'hashtags' => $tags['hashtags'],
424 'mentions' => $tags['mentions'],
425 'implicit_mentions' => $tags['implicit_mentions'],
426 'txt_cats' => DI::l10n()->t('Categories:'),
427 'txt_folders' => DI::l10n()->t('Filed under:'),
428 'has_cats' => ((count($categories)) ? 'true' : ''),
429 'has_folders' => ((count($folders)) ? 'true' : ''),
430 'categories' => $categories,
431 'folders' => $folders,
434 'id' => $this->getId(),
435 'guid' => urlencode($item['guid']),
436 'isevent' => $isevent,
438 'linktitle' => DI::l10n()->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
439 'olinktitle' => DI::l10n()->t('View %s\'s profile @ %s', $this->getOwnerName(), $item['owner-link']),
440 'to' => DI::l10n()->t('to'),
441 'via' => DI::l10n()->t('via'),
442 'wall' => DI::l10n()->t('Wall-to-Wall'),
443 'vwall' => DI::l10n()->t('via Wall-To-Wall:'),
444 'profile_url' => $profile_link,
445 'item_photo_menu' => item_photo_menu($item),
447 'thumb' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)),
448 'osparkle' => $osparkle,
449 'sparkle' => $sparkle,
451 'localtime' => DateTimeFormat::local($item['created'], 'r'),
452 'ago' => $item['app'] ? DI::l10n()->t('%s from %s', $ago, $item['app']) : $ago,
453 'app' => $item['app'],
456 'location' => $location_e,
459 'owner_self' => $item['author-link'] == Session::get('my_url'),
460 'owner_url' => $this->getOwnerUrl(),
461 'owner_photo' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)),
462 'owner_name' => $owner_name_e,
463 'plink' => Item::getPlink($item),
465 'ispinned' => $ispinned,
468 'isstarred' => $isstarred,
475 'like' => $responses['like']['output'],
476 'dislike' => $responses['dislike']['output'],
477 'responses' => $responses,
478 'switchcomment' => DI::l10n()->t('Comment'),
479 'reply_label' => DI::l10n()->t('Reply to %s', $name_e),
480 'comment' => $comment,
481 'remote_comment' => $remote_comment,
482 'menu' => DI::l10n()->t('More'),
483 'previewing' => $conv->isPreview() ? ' preview ' : '',
484 'wait' => DI::l10n()->t('Please wait'),
485 'thread_level' => $thread_level,
487 'network' => $item["network"],
488 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
489 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),
490 'received' => $item['received'],
491 'commented' => $item['commented'],
492 'created_date' => $item['created'],
493 'return' => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '',
494 'direction' => $direction,
496 'queue_count' => $item['delivery_queue_count'],
497 'queue_done' => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
498 'notifier_pending' => DI::l10n()->t('Notifier task is pending'),
499 'delivery_pending' => DI::l10n()->t('Delivery to remote servers is pending'),
500 'delivery_underway' => DI::l10n()->t('Delivery to remote servers is underway'),
501 'delivery_almost' => DI::l10n()->t('Delivery to remote servers is mostly done'),
502 'delivery_done' => DI::l10n()->t('Delivery to remote servers is done'),
506 $arr = ['item' => $item, 'output' => $tmp_item];
507 Hook::callAll('display_item', $arr);
509 $result = $arr['output'];
511 $result['children'] = [];
512 $children = $this->getChildren();
513 $nb_children = count($children);
514 if ($nb_children > 0) {
515 foreach ($children as $child) {
516 $result['children'][] = $child->getTemplateData($conv_responses, $thread_level + 1);
520 if (($nb_children > 2) || ($thread_level > 1)) {
521 $result['children'][0]['comment_firstcollapsed'] = true;
522 $result['children'][0]['num_comments'] = DI::l10n()->tt('%d comment', '%d comments', $total_children);
523 $result['children'][0]['show_text'] = DI::l10n()->t('Show more');
524 $result['children'][0]['hide_text'] = DI::l10n()->t('Show fewer');
525 if ($thread_level > 1) {
526 $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
528 $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
533 if ($this->isToplevel()) {
534 $result['total_comments_num'] = "$total_children";
535 $result['total_comments_text'] = DI::l10n()->tt('comment', 'comments', $total_children);
538 $result['private'] = $item['private'];
539 $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
541 if ($this->isThreaded()) {
542 $result['flatten'] = false;
543 $result['threaded'] = true;
545 $result['flatten'] = true;
546 $result['threaded'] = false;
555 public function getId()
557 return $this->getDataValue('id');
563 public function isThreaded()
565 return $this->threaded;
571 * @param Post $item The child item to add
576 public function addChild(Post $item)
578 $item_id = $item->getId();
580 Logger::log('[ERROR] Post::addChild : Item has no ID!!', Logger::DEBUG);
582 } elseif ($this->getChild($item->getId())) {
583 Logger::log('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', Logger::DEBUG);
587 $activity = DI::activity();
590 * Only add what will be displayed
592 if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
594 } elseif ($activity->match($item->getDataValue('verb'), Activity::LIKE) ||
595 $activity->match($item->getDataValue('verb'), Activity::DISLIKE)) {
599 $item->setParent($this);
600 $this->children[] = $item;
602 return end($this->children);
606 * Get a child by its ID
608 * @param integer $id The child id
612 public function getChild($id)
614 foreach ($this->getChildren() as $child) {
615 if ($child->getId() == $id) {
624 * Get all our children
628 public function getChildren()
630 return $this->children;
636 * @param Post $item The item to set as parent
640 protected function setParent(Post $item)
642 $parent = $this->getParent();
644 $parent->removeChild($this);
647 $this->parent = $item;
648 $this->setThread($item->getThread());
656 protected function removeParent()
658 $this->parent = null;
659 $this->thread = null;
665 * @param Post $item The child to be removed
667 * @return boolean Success or failure
670 public function removeChild(Post $item)
672 $id = $item->getId();
673 foreach ($this->getChildren() as $key => $child) {
674 if ($child->getId() == $id) {
675 $child->removeParent();
676 unset($this->children[$key]);
677 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
678 $this->children = array_values($this->children);
682 Logger::log('[WARN] Item::removeChild : Item is not a child (' . $id . ').', Logger::DEBUG);
691 protected function getParent()
693 return $this->parent;
697 * Set conversation thread
699 * @param Thread $thread
703 public function setThread(Thread $thread = null)
705 $this->thread = $thread;
707 // Set it on our children too
708 foreach ($this->getChildren() as $child) {
709 $child->setThread($thread);
718 public function getThread()
720 return $this->thread;
726 * We shouldn't need this
730 public function getData()
738 * @param string $name key
740 * @return mixed value on success
743 public function getDataValue($name)
745 if (!isset($this->data[$name])) {
746 // Logger::log('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".', Logger::DEBUG);
750 return $this->data[$name];
756 * @param string $name template name
760 private function setTemplate($name)
762 if (empty($this->available_templates[$name])) {
763 Logger::log('[ERROR] Item::setTemplate : Template not available ("' . $name . '").', Logger::DEBUG);
767 $this->template = $this->available_templates[$name];
777 private function getTemplate()
779 return $this->template;
783 * Check if this is a toplevel post
787 private function isToplevel()
789 return $this->toplevel;
793 * Check if this is writable
797 private function isWritable()
799 $conv = $this->getThread();
802 // This will allow us to comment on wall-to-wall items owned by our friends
803 // and community forums even if somebody else wrote the post.
804 // bug #517 - this fixes for conversation owner
805 if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == local_user()) {
809 // this fixes for visitors
810 return ($this->writable || ($this->isVisiting() && $conv->getMode() == 'profile'));
812 return $this->writable;
816 * Count the total of our descendants
820 private function countDescendants()
822 $children = $this->getChildren();
823 $total = count($children);
825 foreach ($children as $child) {
826 $total += $child->countDescendants();
834 * Get the template for the comment box
838 private function getCommentBoxTemplate()
840 return $this->comment_box_template;
844 * Get default text for the comment box
847 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
849 private function getDefaultText()
857 $owner = User::getOwnerDataById($a->user['uid']);
859 if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
863 $item = Item::selectFirst(['author-addr'], ['id' => $this->getId()]);
864 if (!DBA::isResult($item) || empty($item['author-addr'])) {
869 if ($item['author-addr'] != $owner['addr']) {
870 $text = '@' . $item['author-addr'] . ' ';
875 $terms = Term::tagArrayFromItemId($this->getId(), [Term::MENTION, Term::IMPLICIT_MENTION]);
876 foreach ($terms as $term) {
877 $profile = Contact::getDetailsByURL($term['url']);
878 if (!empty($profile['addr']) && ((($profile['contact-type'] ?? '') ?: Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) &&
879 ($profile['addr'] != $owner['addr']) && !strstr($text, $profile['addr'])) {
880 $text .= '@' . $profile['addr'] . ' ';
888 * Get the comment box
890 * @param string $indent Indent value
892 * @return mixed The comment box string (empty if no comment box)
896 private function getCommentBox($indent)
901 $conv = $this->getThread();
903 if (($conv->getMode() === 'network') && $this->isWallToWall()) {
907 if ($conv->isWritable() && $this->isWritable()) {
911 * Hmmm, code depending on the presence of a particular addon?
912 * This should be better if done by a hook
914 if (Addon::isEnabled('qcomment')) {
915 $qc = ((local_user()) ? DI::pConfig()->get(local_user(), 'qcomment', 'words') : null);
916 $qcomment = (($qc) ? explode("\n", $qc) : null);
919 // Fetch the user id from the parent when the owner user is empty
920 $uid = $conv->getProfileOwner();
921 $parent_uid = $this->getDataValue('uid');
923 $default_text = $this->getDefaultText();
925 if (!is_null($parent_uid) && ($uid != $parent_uid)) {
929 $template = Renderer::getMarkupTemplate($this->getCommentBoxTemplate());
930 $comment_box = Renderer::replaceMacros($template, [
931 '$return_path' => DI::args()->getQueryString(),
932 '$threaded' => $this->isThreaded(),
934 '$wall' => ($conv->getMode() === 'profile'),
935 '$id' => $this->getId(),
936 '$parent' => $this->getId(),
937 '$qcomment' => $qcomment,
938 '$default' => $default_text,
939 '$profile_uid' => $uid,
940 '$mylink' => DI::baseUrl()->remove($a->contact['url']),
941 '$mytitle' => DI::l10n()->t('This is you'),
942 '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']),
943 '$comment' => DI::l10n()->t('Comment'),
944 '$submit' => DI::l10n()->t('Submit'),
945 '$loading' => DI::l10n()->t('Loading...'),
946 '$edbold' => DI::l10n()->t('Bold'),
947 '$editalic' => DI::l10n()->t('Italic'),
948 '$eduline' => DI::l10n()->t('Underline'),
949 '$edquote' => DI::l10n()->t('Quote'),
950 '$edcode' => DI::l10n()->t('Code'),
951 '$edimg' => DI::l10n()->t('Image'),
952 '$edurl' => DI::l10n()->t('Link'),
953 '$edattach' => DI::l10n()->t('Link or Media'),
954 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
955 '$preview' => DI::l10n()->t('Preview'),
956 '$indent' => $indent,
957 '$sourceapp' => DI::l10n()->t($a->sourcename),
958 '$ww' => $conv->getMode() === 'network' ? $ww : '',
959 '$rand_num' => Crypto::randomDigits(12)
969 private function getRedirectUrl()
971 return $this->redirect_url;
975 * Check if we are a wall to wall item and set the relevant properties
980 protected function checkWallToWall()
983 $conv = $this->getThread();
984 $this->wall_to_wall = false;
986 if ($this->isToplevel()) {
987 if ($conv->getMode() !== 'profile') {
988 if ($this->getDataValue('wall') && !$this->getDataValue('self')) {
989 // On the network page, I am the owner. On the display page it will be the profile owner.
990 // This will have been stored in $a->page_contact by our calling page.
991 // Put this person as the wall owner of the wall-to-wall notice.
993 $this->owner_url = Contact::magicLink($a->page_contact['url']);
994 $this->owner_photo = $a->page_contact['thumb'];
995 $this->owner_name = $a->page_contact['name'];
996 $this->wall_to_wall = true;
997 } elseif ($this->getDataValue('owner-link')) {
998 $owner_linkmatch = (($this->getDataValue('owner-link')) && Strings::compareLink($this->getDataValue('owner-link'), $this->getDataValue('author-link')));
999 $alias_linkmatch = (($this->getDataValue('alias')) && Strings::compareLink($this->getDataValue('alias'), $this->getDataValue('author-link')));
1000 $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
1002 if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) {
1003 // The author url doesn't match the owner (typically the contact)
1004 // and also doesn't match the contact alias.
1005 // The name match is a hack to catch several weird cases where URLs are
1006 // all over the park. It can be tricked, but this prevents you from
1007 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
1008 // well that it's the same Bob Smith.
1009 // But it could be somebody else with the same name. It just isn't highly likely.
1012 $this->owner_photo = $this->getDataValue('owner-avatar');
1013 $this->owner_name = $this->getDataValue('owner-name');
1014 $this->wall_to_wall = true;
1016 $owner = ['uid' => 0, 'id' => $this->getDataValue('owner-id'),
1017 'network' => $this->getDataValue('owner-network'),
1018 'url' => $this->getDataValue('owner-link')];
1019 $this->owner_url = Contact::magicLinkByContact($owner);
1025 if (!$this->wall_to_wall) {
1026 $this->setTemplate('wall');
1027 $this->owner_url = '';
1028 $this->owner_photo = '';
1029 $this->owner_name = '';
1036 private function isWallToWall()
1038 return $this->wall_to_wall;
1044 private function getOwnerUrl()
1046 return $this->owner_url;
1052 private function getOwnerName()
1054 return $this->owner_name;
1060 private function isVisiting()
1062 return $this->visiting;