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'])
160 $ispinned = "unpinned";
161 $isstarred = "unstarred";
165 $total_children = $this->countDescendants();
167 $conv = $this->getThread();
169 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
170 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
171 ? DI::l10n()->t('Private Message')
174 $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != 1;
179 if (Strings::compareLink($a->contact['url'], $item['author-link'])) {
180 if ($item["event-id"] != 0) {
181 $edpost = ["events/event/" . $item['event-id'], DI::l10n()->t("Edit")];
183 $edpost = ["editpost/" . $item['id'], DI::l10n()->t("Edit")];
186 $dropping = in_array($item['uid'], [0, local_user()]);
189 // Editing on items of not subscribed users isn't currently possible
190 // There are some issues on editing that prevent this.
191 // But also it is an issue of the supported protocols that doesn't allow editing at all.
192 if ($item['uid'] == 0) {
196 if (($this->getDataValue('uid') == local_user()) || $this->isVisiting()) {
200 $origin = $item['origin'];
203 /// @todo This shouldn't be done as query here, but better during the data creation.
204 // it is now done here, since during the RC phase we shouldn't make to intense changes.
205 $parent = Item::selectFirst(['origin'], ['id' => $item['parent']]);
206 if (DBA::isResult($parent)) {
207 $origin = $parent['origin'];
209 } elseif ($item['pinned']) {
210 $pinned = DI::l10n()->t('pinned item');
213 if ($origin && ($item['id'] != $item['parent']) && ($item['network'] == Protocol::ACTIVITYPUB)) {
214 // ActivityPub doesn't allow removal of remote comments
215 $delete = DI::l10n()->t('Delete locally');
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');
222 'dropping' => $dropping,
223 'pagedrop' => $item['pagedrop'],
224 'select' => DI::l10n()->t('Select'),
232 $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? DI::l10n()->t("save to folder") : false);
234 $profile_name = $item['author-name'];
235 if (!empty($item['author-link']) && empty($item['author-name'])) {
236 $profile_name = $item['author-link'];
239 $author = ['uid' => 0, 'id' => $item['author-id'],
240 'network' => $item['author-network'], 'url' => $item['author-link']];
242 if (Session::isAuthenticated()) {
243 $profile_link = Contact::magicLinkByContact($author);
245 $profile_link = $item['author-link'];
248 if (strpos($profile_link, 'redir/') === 0) {
249 $sparkle = ' sparkle';
252 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
253 Hook::callAll('render_location', $locate);
254 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
256 // process action responses - e.g. like/dislike/attend/agree/whatever
257 $response_verbs = ['like', 'dislike', 'announce'];
261 if ($item['object-type'] === Activity\ObjectType::EVENT) {
262 $response_verbs[] = 'attendyes';
263 $response_verbs[] = 'attendno';
264 $response_verbs[] = 'attendmaybe';
265 if ($conv->isWritable()) {
267 $attend = [DI::l10n()->t('I will attend'), DI::l10n()->t('I will not attend'), DI::l10n()->t('I might attend')];
271 $responses = get_responses($conv_responses, $response_verbs, $item, $this);
273 foreach ($response_verbs as $value => $verbs) {
274 $responses[$verbs]['output'] = !empty($conv_responses[$verbs][$item['uri']]) ? format_like($conv_responses[$verbs][$item['uri']], $conv_responses[$verbs][$item['uri'] . '-l'], $verbs, $item['uri']) : '';
278 * We should avoid doing this all the time, but it depends on the conversation mode
279 * And the conv mode may change when we change the conv, or it changes its mode
280 * Maybe we should establish a way to be notified about conversation changes
282 $this->checkWallToWall();
284 if ($this->isWallToWall() && ($this->getOwnerUrl() == $this->getRedirectUrl())) {
285 $osparkle = ' sparkle';
290 if ($this->isToplevel()) {
292 $thread = Item::selectFirstThreadForUser(local_user(), ['ignored'], ['iid' => $item['id']]);
293 if (DBA::isResult($thread)) {
295 'do' => DI::l10n()->t("ignore thread"),
296 'undo' => DI::l10n()->t("unignore thread"),
297 'toggle' => DI::l10n()->t("toggle ignore status"),
298 'classdo' => $thread['ignored'] ? "hidden" : "",
299 'classundo' => $thread['ignored'] ? "" : "hidden",
300 'ignored' => DI::l10n()->t('ignored'),
304 if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
306 $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
309 'do' => DI::l10n()->t('pin'),
310 'undo' => DI::l10n()->t('unpin'),
311 'toggle' => DI::l10n()->t('toggle pin status'),
312 'classdo' => $item['pinned'] ? 'hidden' : '',
313 'classundo' => $item['pinned'] ? '' : 'hidden',
314 'pinned' => DI::l10n()->t('pinned'),
318 $isstarred = (($item['starred']) ? "starred" : "unstarred");
321 'do' => DI::l10n()->t("add star"),
322 'undo' => DI::l10n()->t("remove star"),
323 'toggle' => DI::l10n()->t("toggle star status"),
324 'classdo' => $item['starred'] ? "hidden" : "",
325 'classundo' => $item['starred'] ? "" : "hidden",
326 'starred' => DI::l10n()->t('starred'),
330 'add' => DI::l10n()->t("add tag"),
339 if ($conv->isWritable()) {
341 'like' => [DI::l10n()->t("I like this \x28toggle\x29"), DI::l10n()->t("like")],
342 'dislike' => [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t("dislike")],
345 $buttons['share'] = [DI::l10n()->t('Share this'), DI::l10n()->t('share')];
349 $comment = $this->getCommentBox($indent);
351 if (strcmp(DateTimeFormat::utc($item['created']), DateTimeFormat::utc('now - 12 hours')) > 0) {
355 localize_item($item);
357 $body = Item::prepareBody($item, true);
359 list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
362 $text_e = strip_tags($body);
363 $name_e = $profile_name;
365 if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
366 $title_e = ucfirst($item['content-warning']);
368 $title_e = $item['title'];
371 $location_e = $location;
372 $owner_name_e = $this->getOwnerName();
374 // Disable features that aren't available in several networks
375 if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA]) && isset($buttons["dislike"])) {
376 unset($buttons["dislike"]);
381 if (($item["network"] == Protocol::FEED) && isset($buttons["like"])) {
382 unset($buttons["like"]);
385 if (($item["network"] == Protocol::MAIL) && isset($buttons["like"])) {
386 unset($buttons["like"]);
389 $tags = Term::populateTagsFromItem($item);
391 $ago = Temporal::getRelativeDate($item['created']);
392 $ago_received = Temporal::getRelativeDate($item['received']);
393 if (DI::config()->get('system', 'show_received') && (abs(strtotime($item['created']) - strtotime($item['received'])) > DI::config()->get('system', 'show_received_seconds')) && ($ago != $ago_received)) {
394 $ago = DI::l10n()->t('%s (Received %s)', $ago, $ago_received);
398 'template' => $this->getTemplate(),
399 'type' => implode("", array_slice(explode("/", $item['verb']), -1)),
400 'suppress_tags' => DI::config()->get('system', 'suppress_tags'),
401 'tags' => $tags['tags'],
402 'hashtags' => $tags['hashtags'],
403 'mentions' => $tags['mentions'],
404 'implicit_mentions' => $tags['implicit_mentions'],
405 'txt_cats' => DI::l10n()->t('Categories:'),
406 'txt_folders' => DI::l10n()->t('Filed under:'),
407 'has_cats' => ((count($categories)) ? 'true' : ''),
408 'has_folders' => ((count($folders)) ? 'true' : ''),
409 'categories' => $categories,
410 'folders' => $folders,
413 'id' => $this->getId(),
414 'guid' => urlencode($item['guid']),
415 'isevent' => $isevent,
417 'linktitle' => DI::l10n()->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
418 'olinktitle' => DI::l10n()->t('View %s\'s profile @ %s', $this->getOwnerName(), $item['owner-link']),
419 'to' => DI::l10n()->t('to'),
420 'via' => DI::l10n()->t('via'),
421 'wall' => DI::l10n()->t('Wall-to-Wall'),
422 'vwall' => DI::l10n()->t('via Wall-To-Wall:'),
423 'profile_url' => $profile_link,
424 'item_photo_menu' => item_photo_menu($item),
426 'thumb' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)),
427 'osparkle' => $osparkle,
428 'sparkle' => $sparkle,
430 'localtime' => DateTimeFormat::local($item['created'], 'r'),
431 'ago' => $item['app'] ? DI::l10n()->t('%s from %s', $ago, $item['app']) : $ago,
432 'app' => $item['app'],
435 'location' => $location_e,
438 'owner_self' => $item['author-link'] == Session::get('my_url'),
439 'owner_url' => $this->getOwnerUrl(),
440 'owner_photo' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)),
441 'owner_name' => $owner_name_e,
442 'plink' => Item::getPlink($item),
444 'ispinned' => $ispinned,
447 'isstarred' => $isstarred,
454 'like' => $responses['like']['output'],
455 'dislike' => $responses['dislike']['output'],
456 'responses' => $responses,
457 'switchcomment' => DI::l10n()->t('Comment'),
458 'reply_label' => DI::l10n()->t('Reply to %s', $name_e),
459 'comment' => $comment,
460 'menu' => DI::l10n()->t('More'),
461 'previewing' => $conv->isPreview() ? ' preview ' : '',
462 'wait' => DI::l10n()->t('Please wait'),
463 'thread_level' => $thread_level,
465 'network' => $item["network"],
466 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
467 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),
468 'received' => $item['received'],
469 'commented' => $item['commented'],
470 'created_date' => $item['created'],
471 'return' => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '',
473 'queue_count' => $item['delivery_queue_count'],
474 'queue_done' => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
475 'notifier_pending' => DI::l10n()->t('Notifier task is pending'),
476 'delivery_pending' => DI::l10n()->t('Delivery to remote servers is pending'),
477 'delivery_underway' => DI::l10n()->t('Delivery to remote servers is underway'),
478 'delivery_almost' => DI::l10n()->t('Delivery to remote servers is mostly done'),
479 'delivery_done' => DI::l10n()->t('Delivery to remote servers is done'),
483 $arr = ['item' => $item, 'output' => $tmp_item];
484 Hook::callAll('display_item', $arr);
486 $result = $arr['output'];
488 $result['children'] = [];
489 $children = $this->getChildren();
490 $nb_children = count($children);
491 if ($nb_children > 0) {
492 foreach ($children as $child) {
493 $result['children'][] = $child->getTemplateData($conv_responses, $thread_level + 1);
497 if (($nb_children > 2) || ($thread_level > 1)) {
498 $result['children'][0]['comment_firstcollapsed'] = true;
499 $result['children'][0]['num_comments'] = DI::l10n()->tt('%d comment', '%d comments', $total_children);
500 $result['children'][0]['show_text'] = DI::l10n()->t('Show more');
501 $result['children'][0]['hide_text'] = DI::l10n()->t('Show fewer');
502 if ($thread_level > 1) {
503 $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
505 $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
510 if ($this->isToplevel()) {
511 $result['total_comments_num'] = "$total_children";
512 $result['total_comments_text'] = DI::l10n()->tt('comment', 'comments', $total_children);
515 $result['private'] = $item['private'];
516 $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
518 if ($this->isThreaded()) {
519 $result['flatten'] = false;
520 $result['threaded'] = true;
522 $result['flatten'] = true;
523 $result['threaded'] = false;
532 public function getId()
534 return $this->getDataValue('id');
540 public function isThreaded()
542 return $this->threaded;
548 * @param Post $item The child item to add
553 public function addChild(Post $item)
555 $item_id = $item->getId();
557 Logger::log('[ERROR] Post::addChild : Item has no ID!!', Logger::DEBUG);
559 } elseif ($this->getChild($item->getId())) {
560 Logger::log('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', Logger::DEBUG);
564 $activity = DI::activity();
567 * Only add what will be displayed
569 if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
571 } elseif ($activity->match($item->getDataValue('verb'), Activity::LIKE) ||
572 $activity->match($item->getDataValue('verb'), Activity::DISLIKE)) {
576 $item->setParent($this);
577 $this->children[] = $item;
579 return end($this->children);
583 * Get a child by its ID
585 * @param integer $id The child id
589 public function getChild($id)
591 foreach ($this->getChildren() as $child) {
592 if ($child->getId() == $id) {
601 * Get all our children
605 public function getChildren()
607 return $this->children;
613 * @param Post $item The item to set as parent
617 protected function setParent(Post $item)
619 $parent = $this->getParent();
621 $parent->removeChild($this);
624 $this->parent = $item;
625 $this->setThread($item->getThread());
633 protected function removeParent()
635 $this->parent = null;
636 $this->thread = null;
642 * @param Post $item The child to be removed
644 * @return boolean Success or failure
647 public function removeChild(Post $item)
649 $id = $item->getId();
650 foreach ($this->getChildren() as $key => $child) {
651 if ($child->getId() == $id) {
652 $child->removeParent();
653 unset($this->children[$key]);
654 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
655 $this->children = array_values($this->children);
659 Logger::log('[WARN] Item::removeChild : Item is not a child (' . $id . ').', Logger::DEBUG);
668 protected function getParent()
670 return $this->parent;
674 * Set conversation thread
676 * @param Thread $thread
680 public function setThread(Thread $thread = null)
682 $this->thread = $thread;
684 // Set it on our children too
685 foreach ($this->getChildren() as $child) {
686 $child->setThread($thread);
695 public function getThread()
697 return $this->thread;
703 * We shouldn't need this
707 public function getData()
715 * @param string $name key
717 * @return mixed value on success
720 public function getDataValue($name)
722 if (!isset($this->data[$name])) {
723 // Logger::log('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".', Logger::DEBUG);
727 return $this->data[$name];
733 * @param string $name template name
737 private function setTemplate($name)
739 if (empty($this->available_templates[$name])) {
740 Logger::log('[ERROR] Item::setTemplate : Template not available ("' . $name . '").', Logger::DEBUG);
744 $this->template = $this->available_templates[$name];
754 private function getTemplate()
756 return $this->template;
760 * Check if this is a toplevel post
764 private function isToplevel()
766 return $this->toplevel;
770 * Check if this is writable
774 private function isWritable()
776 $conv = $this->getThread();
779 // This will allow us to comment on wall-to-wall items owned by our friends
780 // and community forums even if somebody else wrote the post.
781 // bug #517 - this fixes for conversation owner
782 if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == local_user()) {
786 // this fixes for visitors
787 return ($this->writable || ($this->isVisiting() && $conv->getMode() == 'profile'));
789 return $this->writable;
793 * Count the total of our descendants
797 private function countDescendants()
799 $children = $this->getChildren();
800 $total = count($children);
802 foreach ($children as $child) {
803 $total += $child->countDescendants();
811 * Get the template for the comment box
815 private function getCommentBoxTemplate()
817 return $this->comment_box_template;
821 * Get default text for the comment box
824 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
826 private function getDefaultText()
834 $owner = User::getOwnerDataById($a->user['uid']);
836 if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
840 $item = Item::selectFirst(['author-addr'], ['id' => $this->getId()]);
841 if (!DBA::isResult($item) || empty($item['author-addr'])) {
846 if ($item['author-addr'] != $owner['addr']) {
847 $text = '@' . $item['author-addr'] . ' ';
852 $terms = Term::tagArrayFromItemId($this->getId(), [Term::MENTION, Term::IMPLICIT_MENTION]);
853 foreach ($terms as $term) {
854 $profile = Contact::getDetailsByURL($term['url']);
855 if (!empty($profile['addr']) && ((($profile['contact-type'] ?? '') ?: Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) &&
856 ($profile['addr'] != $owner['addr']) && !strstr($text, $profile['addr'])) {
857 $text .= '@' . $profile['addr'] . ' ';
865 * Get the comment box
867 * @param string $indent Indent value
869 * @return mixed The comment box string (empty if no comment box)
873 private function getCommentBox($indent)
878 $conv = $this->getThread();
880 if (($conv->getMode() === 'network') && $this->isWallToWall()) {
884 if ($conv->isWritable() && $this->isWritable()) {
888 * Hmmm, code depending on the presence of a particular addon?
889 * This should be better if done by a hook
891 if (Addon::isEnabled('qcomment')) {
892 $qc = ((local_user()) ? DI::pConfig()->get(local_user(), 'qcomment', 'words') : null);
893 $qcomment = (($qc) ? explode("\n", $qc) : null);
896 // Fetch the user id from the parent when the owner user is empty
897 $uid = $conv->getProfileOwner();
898 $parent_uid = $this->getDataValue('uid');
900 $default_text = $this->getDefaultText();
902 if (!is_null($parent_uid) && ($uid != $parent_uid)) {
906 $template = Renderer::getMarkupTemplate($this->getCommentBoxTemplate());
907 $comment_box = Renderer::replaceMacros($template, [
908 '$return_path' => DI::args()->getQueryString(),
909 '$threaded' => $this->isThreaded(),
911 '$wall' => ($conv->getMode() === 'profile'),
912 '$id' => $this->getId(),
913 '$parent' => $this->getId(),
914 '$qcomment' => $qcomment,
915 '$default' => $default_text,
916 '$profile_uid' => $uid,
917 '$mylink' => DI::baseUrl()->remove($a->contact['url']),
918 '$mytitle' => DI::l10n()->t('This is you'),
919 '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']),
920 '$comment' => DI::l10n()->t('Comment'),
921 '$submit' => DI::l10n()->t('Submit'),
922 '$edbold' => DI::l10n()->t('Bold'),
923 '$editalic' => DI::l10n()->t('Italic'),
924 '$eduline' => DI::l10n()->t('Underline'),
925 '$edquote' => DI::l10n()->t('Quote'),
926 '$edcode' => DI::l10n()->t('Code'),
927 '$edimg' => DI::l10n()->t('Image'),
928 '$edurl' => DI::l10n()->t('Link'),
929 '$edattach' => DI::l10n()->t('Link or Media'),
930 '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
931 '$preview' => DI::l10n()->t('Preview'),
932 '$indent' => $indent,
933 '$sourceapp' => DI::l10n()->t($a->sourcename),
934 '$ww' => $conv->getMode() === 'network' ? $ww : '',
935 '$rand_num' => Crypto::randomDigits(12)
945 private function getRedirectUrl()
947 return $this->redirect_url;
951 * Check if we are a wall to wall item and set the relevant properties
956 protected function checkWallToWall()
959 $conv = $this->getThread();
960 $this->wall_to_wall = false;
962 if ($this->isToplevel()) {
963 if ($conv->getMode() !== 'profile') {
964 if ($this->getDataValue('wall') && !$this->getDataValue('self')) {
965 // On the network page, I am the owner. On the display page it will be the profile owner.
966 // This will have been stored in $a->page_contact by our calling page.
967 // Put this person as the wall owner of the wall-to-wall notice.
969 $this->owner_url = Contact::magicLink($a->page_contact['url']);
970 $this->owner_photo = $a->page_contact['thumb'];
971 $this->owner_name = $a->page_contact['name'];
972 $this->wall_to_wall = true;
973 } elseif ($this->getDataValue('owner-link')) {
974 $owner_linkmatch = (($this->getDataValue('owner-link')) && Strings::compareLink($this->getDataValue('owner-link'), $this->getDataValue('author-link')));
975 $alias_linkmatch = (($this->getDataValue('alias')) && Strings::compareLink($this->getDataValue('alias'), $this->getDataValue('author-link')));
976 $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
978 if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) {
979 // The author url doesn't match the owner (typically the contact)
980 // and also doesn't match the contact alias.
981 // The name match is a hack to catch several weird cases where URLs are
982 // all over the park. It can be tricked, but this prevents you from
983 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
984 // well that it's the same Bob Smith.
985 // But it could be somebody else with the same name. It just isn't highly likely.
988 $this->owner_photo = $this->getDataValue('owner-avatar');
989 $this->owner_name = $this->getDataValue('owner-name');
990 $this->wall_to_wall = true;
992 $owner = ['uid' => 0, 'id' => $this->getDataValue('owner-id'),
993 'network' => $this->getDataValue('owner-network'),
994 'url' => $this->getDataValue('owner-link')];
995 $this->owner_url = Contact::magicLinkByContact($owner);
1001 if (!$this->wall_to_wall) {
1002 $this->setTemplate('wall');
1003 $this->owner_url = '';
1004 $this->owner_photo = '';
1005 $this->owner_name = '';
1012 private function isWallToWall()
1014 return $this->wall_to_wall;
1020 private function getOwnerUrl()
1022 return $this->owner_url;
1028 private function getOwnerName()
1030 return $this->owner_name;
1036 private function isVisiting()
1038 return $this->visiting;