]> git.mxchange.org Git - friendica.git/blob - src/Object/Post.php
Merge remote-tracking branch 'upstream/develop' into community
[friendica.git] / src / Object / Post.php
1 <?php
2
3 /**
4  * @file src/Object/Post.php
5  */
6
7 namespace Friendica\Object;
8
9 use Friendica\BaseObject;
10 use Friendica\Content\Feature;
11 use Friendica\Core\PConfig;
12 use Friendica\Database\DBM;
13 use Friendica\Model\Contact;
14 use dba;
15
16 require_once 'include/dba.php';
17 require_once 'include/text.php';
18 require_once 'boot.php';
19 require_once 'include/conversation.php';
20
21 /**
22  * An item
23  */
24 class Post extends BaseObject
25 {
26         private $data = array();
27         private $template = null;
28         private $available_templates = array(
29                 'wall' => 'wall_thread.tpl',
30                 'wall2wall' => 'wallwall_thread.tpl'
31         );
32         private $comment_box_template = 'comment_item.tpl';
33         private $toplevel = false;
34         private $writable = false;
35         private $children = array();
36         private $parent = null;
37         private $thread = null;
38         private $redirect_url = null;
39         private $owner_url = '';
40         private $owner_photo = '';
41         private $owner_name = '';
42         private $wall_to_wall = false;
43         private $threaded = false;
44         private $visiting = false;
45
46         /**
47          * Constructor
48          *
49          * @param array $data data array
50          */
51         public function __construct(array $data)
52         {
53                 $a = self::getApp();
54
55                 $this->data = $data;
56                 $this->setTemplate('wall');
57                 $this->toplevel = $this->getId() == $this->getDataValue('parent');
58
59                 if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
60                         foreach ($_SESSION['remote'] as $visitor) {
61                                 if ($visitor['cid'] == $this->getDataValue('contact-id')) {
62                                         $this->visiting = true;
63                                         break;
64                                 }
65                         }
66                 }
67
68                 $this->writable = $this->getDataValue('writable') || $this->getDataValue('self');
69                 $this->redirect_url = 'redir/' . $this->getDataValue('cid');
70
71                 if (!$this->isToplevel()) {
72                         $this->threaded = true;
73                 }
74
75                 // Prepare the children
76                 if (count($data['children'])) {
77                         foreach ($data['children'] as $item) {
78                                 // Only add will be displayed
79                                 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
80                                         continue;
81                                 } elseif (!visible_activity($item)) {
82                                         continue;
83                                 }
84
85                                 // You can always comment on Diaspora items
86                                 if (($item['network'] == NETWORK_DIASPORA) && (local_user() == $item['uid'])) {
87                                         $item['writable'] = true;
88                                 }
89
90                                 $item['pagedrop'] = $data['pagedrop'];
91                                 $child = new Post($item);
92                                 $this->addChild($child);
93                         }
94                 }
95         }
96
97         /**
98          * Get data in a form usable by a conversation template
99          *
100          * @param object  $conv_responses conversation responses
101          * @param integer $thread_level   default = 1
102          *
103          * @return mixed The data requested on success
104          *               false on failure
105          */
106         public function getTemplateData($conv_responses, $thread_level = 1)
107         {
108                 require_once "mod/proxy.php";
109
110                 $result = array();
111
112                 $a = self::getApp();
113
114                 $item = $this->getData();
115                 $edited = false;
116                 // If the time between "created" and "edited" differs we add
117                 // a notice that the post was edited.
118                 // Note: In some networks reshared items seem to have (sometimes) a difference
119                 // between creation time and edit time of a second. Thats why we add the notice
120                 // only if the difference is more than 1 second.
121                 if (strtotime($item['edited']) - strtotime($item['created']) > 1) {
122                         $edited = array(
123                                 'label'    => t('This entry was edited'),
124                                 'date'     => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
125                                 'relative' => relative_date($item['edited'])
126                         );
127                 }
128                 $commentww = '';
129                 $sparkle = '';
130                 $buttons = '';
131                 $dropping = false;
132                 $star = false;
133                 $ignore = false;
134                 $isstarred = "unstarred";
135                 $indent = '';
136                 $shiny = '';
137                 $osparkle = '';
138                 $total_children = $this->countDescendants();
139
140                 $conv = $this->getThread();
141
142                 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
143                         || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
144                         ? t('Private Message')
145                         : false);
146                 $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != 1;
147
148                 if (local_user() && link_compare($a->contact['url'], $item['author-link'])) {
149                         if ($item["event-id"] != 0) {
150                                 $edpost = array("events/event/" . $item['event-id'], t("Edit"));
151                         } else {
152                                 $edpost = array("editpost/" . $item['id'], t("Edit"));
153                         }
154                 } else {
155                         $edpost = false;
156                 }
157
158                 if (($this->getDataValue('uid') == local_user()) || $this->isVisiting()) {
159                         $dropping = true;
160                 }
161
162                 $drop = array(
163                         'dropping' => $dropping,
164                         'pagedrop' => ((Feature::isEnabled($conv->getProfileOwner(), 'multi_delete')) ? $item['pagedrop'] : ''),
165                         'select'   => t('Select'),
166                         'delete'   => t('Delete'),
167                 );
168
169                 $filer = (($conv->getProfileOwner() == local_user()) ? t("save to folder") : false);
170
171                 $diff_author = !link_compare($item['url'], $item['author-link']);
172                 $profile_name = htmlentities(((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
173                 if ($item['author-link'] && (!$item['author-name'])) {
174                         $profile_name = $item['author-link'];
175                 }
176
177                 $sp = false;
178                 $profile_link = best_link_url($item, $sp);
179                 if ($profile_link === 'mailbox') {
180                         $profile_link = '';
181                 }
182
183                 if ($sp) {
184                         $sparkle = ' sparkle';
185                 } else {
186                         $profile_link = zrl($profile_link);
187                 }
188
189                 if (!isset($item['author-thumb']) || ($item['author-thumb'] == "")) {
190                         $author_contact = Contact::getDetailsByURL($item['author-link'], $conv->getProfileOwner());
191                         if ($author_contact["thumb"]) {
192                                 $item['author-thumb'] = $author_contact["thumb"];
193                         } else {
194                                 $item['author-thumb'] = $item['author-avatar'];
195                         }
196                 }
197
198                 if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
199                         $owner_contact = Contact::getDetailsByURL($item['owner-link'], $conv->getProfileOwner());
200                         if ($owner_contact["thumb"]) {
201                                 $item['owner-thumb'] = $owner_contact["thumb"];
202                         } else {
203                                 $item['owner-thumb'] = $item['owner-avatar'];
204                         }
205                 }
206
207                 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
208                 call_hooks('render_location', $locate);
209                 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
210
211                 // process action responses - e.g. like/dislike/attend/agree/whatever
212                 $response_verbs = array('like', 'dislike');
213
214                 $isevent = false;
215                 $attend = [];
216                 if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
217                         $response_verbs[] = 'attendyes';
218                         $response_verbs[] = 'attendno';
219                         $response_verbs[] = 'attendmaybe';
220                         if ($conv->isWritable()) {
221                                 $isevent = true;
222                                 $attend = array(t('I will attend'), t('I will not attend'), t('I might attend'));
223                         }
224                 }
225
226                 $responses = get_responses($conv_responses, $response_verbs, $this, $item);
227
228                 foreach ($response_verbs as $value => $verbs) {
229                         $responses[$verbs]['output'] = x($conv_responses[$verbs], $item['uri']) ? format_like($conv_responses[$verbs][$item['uri']], $conv_responses[$verbs][$item['uri'] . '-l'], $verbs, $item['uri']) : '';
230                 }
231
232                 /*
233                  * We should avoid doing this all the time, but it depends on the conversation mode
234                  * And the conv mode may change when we change the conv, or it changes its mode
235                  * Maybe we should establish a way to be notified about conversation changes
236                  */
237                 $this->checkWallToWall();
238
239                 if ($this->isWallToWall() && ($this->getOwnerUrl() == $this->getRedirectUrl())) {
240                         $osparkle = ' sparkle';
241                 }
242
243                 $tagger = '';
244
245                 if ($this->isToplevel()) {
246                         if ($conv->getProfileOwner() == local_user()) {
247                                 $isstarred = (($item['starred']) ? "starred" : "unstarred");
248
249                                 $star = array(
250                                         'do'        => t("add star"),
251                                         'undo'      => t("remove star"),
252                                         'toggle'    => t("toggle star status"),
253                                         'classdo'   => $item['starred'] ? "hidden" : "",
254                                         'classundo' => $item['starred'] ? "" : "hidden",
255                                         'starred'   => t('starred'),
256                                 );
257                                 $r = dba::select('thread', array('ignored'), array('uid' => $item['uid'], 'iid' => $item['id']), array('limit' => 1));
258                                 if (DBM::is_result($r)) {
259                                         $ignore = array(
260                                                 'do'        => t("ignore thread"),
261                                                 'undo'      => t("unignore thread"),
262                                                 'toggle'    => t("toggle ignore status"),
263                                                 'classdo'   => $r['ignored'] ? "hidden" : "",
264                                                 'classundo' => $r['ignored'] ? "" : "hidden",
265                                                 'ignored'   => t('ignored'),
266                                         );
267                                 }
268
269                                 if (Feature::isEnabled($conv->getProfileOwner(), 'commtag')) {
270                                         $tagger = array(
271                                                 'add'   => t("add tag"),
272                                                 'class' => "",
273                                         );
274                                 }
275                         }
276                 } else {
277                         $indent = 'comment';
278                 }
279
280                 if ($conv->isWritable()) {
281                         $buttons = array(
282                                 'like'    => array(t("I like this \x28toggle\x29"), t("like")),
283                                 'dislike' => Feature::isEnabled($conv->getProfileOwner(), 'dislike') ? array(t("I don't like this \x28toggle\x29"), t("dislike")) : '',
284                         );
285                         if ($shareable) {
286                                 $buttons['share'] = array(t('Share this'), t('share'));
287                         }
288                 }
289
290                 $comment = $this->getCommentBox($indent);
291
292                 if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) {
293                         $shiny = 'shiny';
294                 }
295
296                 localize_item($item);
297
298                 $body = prepare_body($item, true);
299
300                 list($categories, $folders) = get_cats_and_terms($item);
301
302                 $body_e       = $body;
303                 $text_e       = strip_tags($body);
304                 $name_e       = $profile_name;
305                 $title_e      = $item['title'];
306                 $location_e   = $location;
307                 $owner_name_e = $this->getOwnerName();
308
309                 // Disable features that aren't available in several networks
310                 /// @todo Add NETWORK_DIASPORA when it will pass this information
311                 if (!in_array($item["item_network"], array(NETWORK_DFRN)) && isset($buttons["dislike"])) {
312                         unset($buttons["dislike"]);
313                         $isevent = false;
314                         $tagger = '';
315                 }
316
317                 if (($item["item_network"] == NETWORK_FEED) && isset($buttons["like"])) {
318                         unset($buttons["like"]);
319                 }
320
321                 if (($item["item_network"] == NETWORK_MAIL) && isset($buttons["like"])) {
322                         unset($buttons["like"]);
323                 }
324
325                 $tmp_item = array(
326                         'template'        => $this->getTemplate(),
327                         'type'            => implode("", array_slice(explode("/", $item['verb']), -1)),
328                         'tags'            => $item['tags'],
329                         'hashtags'        => $item['hashtags'],
330                         'mentions'        => $item['mentions'],
331                         'txt_cats'        => t('Categories:'),
332                         'txt_folders'     => t('Filed under:'),
333                         'has_cats'        => ((count($categories)) ? 'true' : ''),
334                         'has_folders'     => ((count($folders)) ? 'true' : ''),
335                         'categories'      => $categories,
336                         'folders'         => $folders,
337                         'body'            => $body_e,
338                         'text'            => $text_e,
339                         'id'              => $this->getId(),
340                         'guid'            => urlencode($item['guid']),
341                         'isevent'         => $isevent,
342                         'attend'          => $attend,
343                         'linktitle'       => t('View %s\'s profile @ %s', $profile_name, defaults($item, 'author-link', $item['url'])),
344                         'olinktitle'      => t('View %s\'s profile @ %s', htmlentities($this->getOwnerName()), defaults($item, 'owner-link', $item['url'])),
345                         'to'              => t('to'),
346                         'via'             => t('via'),
347                         'wall'            => t('Wall-to-Wall'),
348                         'vwall'           => t('via Wall-To-Wall:'),
349                         'profile_url'     => $profile_link,
350                         'item_photo_menu' => item_photo_menu($item),
351                         'name'            => $name_e,
352                         'thumb'           => $a->remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
353                         'osparkle'        => $osparkle,
354                         'sparkle'         => $sparkle,
355                         'title'           => $title_e,
356                         'localtime'       => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
357                         'ago'             => $item['app'] ? t('%s from %s', relative_date($item['created']), $item['app']) : relative_date($item['created']),
358                         'app'             => $item['app'],
359                         'created'         => relative_date($item['created']),
360                         'lock'            => $lock,
361                         'location'        => $location_e,
362                         'indent'          => $indent,
363                         'shiny'           => $shiny,
364                         'owner_url'       => $this->getOwnerUrl(),
365                         'owner_photo'     => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
366                         'owner_name'      => htmlentities($owner_name_e),
367                         'plink'           => get_plink($item),
368                         'edpost'          => Feature::isEnabled($conv->getProfileOwner(), 'edit_posts') ? $edpost : '',
369                         'isstarred'       => $isstarred,
370                         'star'            => Feature::isEnabled($conv->getProfileOwner(), 'star_posts') ? $star : '',
371                         'ignore'          => Feature::isEnabled($conv->getProfileOwner(), 'ignore_posts') ? $ignore : '',
372                         'tagger'          => $tagger,
373                         'filer'           => Feature::isEnabled($conv->getProfileOwner(), 'filing') ? $filer : '',
374                         'drop'            => $drop,
375                         'vote'            => $buttons,
376                         'like'            => $responses['like']['output'],
377                         'dislike'         => $responses['dislike']['output'],
378                         'responses'       => $responses,
379                         'switchcomment'   => t('Comment'),
380                         'comment'         => $comment,
381                         'previewing'      => $conv->isPreview() ? ' preview ' : '',
382                         'wait'            => t('Please wait'),
383                         'thread_level'    => $thread_level,
384                         'edited'          => $edited,
385                         'network'         => $item["item_network"],
386                         'network_name'    => network_to_name($item['item_network'], $profile_link),
387                         'received'        => $item['received'],
388                         'commented'       => $item['commented'],
389                         'created_date'    => $item['created'],
390                 );
391
392                 $arr = array('item' => $item, 'output' => $tmp_item);
393                 call_hooks('display_item', $arr);
394
395                 $result = $arr['output'];
396
397                 $result['children'] = array();
398                 $children = $this->getChildren();
399                 $nb_children = count($children);
400                 if ($nb_children > 0) {
401                         foreach ($children as $child) {
402                                 $result['children'][] = $child->getTemplateData($conv_responses, $thread_level + 1);
403                         }
404                         // Collapse
405                         if (($nb_children > 2) || ($thread_level > 1)) {
406                                 $result['children'][0]['comment_firstcollapsed'] = true;
407                                 $result['children'][0]['num_comments'] = tt('%d comment', '%d comments', $total_children);
408                                 $result['children'][0]['hidden_comments_num'] = $total_children;
409                                 $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
410                                 $result['children'][0]['hide_text'] = t('show more');
411                                 if ($thread_level > 1) {
412                                         $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
413                                 } else {
414                                         $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
415                                 }
416                         }
417                 }
418
419                 if ($this->isToplevel()) {
420                         $result['total_comments_num'] = "$total_children";
421                         $result['total_comments_text'] = tt('comment', 'comments', $total_children);
422                 }
423
424                 $result['private'] = $item['private'];
425                 $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
426
427                 if ($this->isThreaded()) {
428                         $result['flatten'] = false;
429                         $result['threaded'] = true;
430                 } else {
431                         $result['flatten'] = true;
432                         $result['threaded'] = false;
433                 }
434
435                 return $result;
436         }
437
438         /**
439          * @return integer
440          */
441         public function getId()
442         {
443                 return $this->getDataValue('id');
444         }
445
446         /**
447          * @return boolean
448          */
449         public function isThreaded()
450         {
451                 return $this->threaded;
452         }
453
454         /**
455          * Add a child item
456          *
457          * @param object $item The child item to add
458          *
459          * @return mixed
460          */
461         public function addChild(Post $item)
462         {
463                 $item_id = $item->getId();
464                 if (!$item_id) {
465                         logger('[ERROR] Post::addChild : Item has no ID!!', LOGGER_DEBUG);
466                         return false;
467                 } elseif ($this->getChild($item->getId())) {
468                         logger('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', LOGGER_DEBUG);
469                         return false;
470                 }
471                 /*
472                  * Only add what will be displayed
473                  */
474                 if ($item->getDataValue('network') === NETWORK_MAIL && local_user() != $item->getDataValue('uid')) {
475                         return false;
476                 } elseif (activity_match($item->getDataValue('verb'), ACTIVITY_LIKE) || activity_match($item->getDataValue('verb'), ACTIVITY_DISLIKE)) {
477                         return false;
478                 }
479
480                 $item->setParent($this);
481                 $this->children[] = $item;
482
483                 return end($this->children);
484         }
485
486         /**
487          * Get a child by its ID
488          *
489          * @param integer $id The child id
490          *
491          * @return mixed
492          */
493         public function getChild($id)
494         {
495                 foreach ($this->getChildren() as $child) {
496                         if ($child->getId() == $id) {
497                                 return $child;
498                         }
499                 }
500
501                 return null;
502         }
503
504         /**
505          * Get all our children
506          *
507          * @return object
508          */
509         public function getChildren()
510         {
511                 return $this->children;
512         }
513
514         /**
515          * Set our parent
516          *
517          * @param object $item The item to set as parent
518          *
519          * @return void
520          */
521         protected function setParent($item)
522         {
523                 $parent = $this->getParent();
524                 if ($parent) {
525                         $parent->removeChild($this);
526                 }
527
528                 $this->parent = $item;
529                 $this->setThread($item->getThread());
530         }
531
532         /**
533          * Remove our parent
534          *
535          * @return void
536          */
537         protected function removeParent()
538         {
539                 $this->parent = null;
540                 $this->thread = null;
541         }
542
543         /**
544          * Remove a child
545          *
546          * @param object $item The child to be removed
547          *
548          * @return boolean Success or failure
549          */
550         public function removeChild($item)
551         {
552                 $id = $item->getId();
553                 foreach ($this->getChildren() as $key => $child) {
554                         if ($child->getId() == $id) {
555                                 $child->removeParent();
556                                 unset($this->children[$key]);
557                                 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
558                                 $this->children = array_values($this->children);
559                                 return true;
560                         }
561                 }
562                 logger('[WARN] Item::removeChild : Item is not a child (' . $id . ').', LOGGER_DEBUG);
563                 return false;
564         }
565
566         /**
567          * Get parent item
568          *
569          * @return object
570          */
571         protected function getParent()
572         {
573                 return $this->parent;
574         }
575
576         /**
577          * Set conversation
578          *
579          * @param object $conv The conversation
580          *
581          * @return void
582          */
583         public function setThread($conv)
584         {
585                 $previous_mode = ($this->thread ? $this->thread->getMode() : '');
586
587                 $this->thread = $conv;
588
589                 // Set it on our children too
590                 foreach ($this->getChildren() as $child) {
591                         $child->setThread($conv);
592                 }
593         }
594
595         /**
596          * Get conversation
597          *
598          * @return object
599          */
600         public function getThread()
601         {
602                 return $this->thread;
603         }
604
605         /**
606          * Get raw data
607          *
608          * We shouldn't need this
609          *
610          * @return array
611          */
612         public function getData()
613         {
614                 return $this->data;
615         }
616
617         /**
618          * Get a data value
619          *
620          * @param object $name key
621          *
622          * @return mixed value on success
623          *               false on failure
624          */
625         public function getDataValue($name)
626         {
627                 if (!isset($this->data[$name])) {
628                         // logger('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".', LOGGER_DEBUG);
629                         return false;
630                 }
631
632                 return $this->data[$name];
633         }
634
635         /**
636          * Set template
637          *
638          * @param object $name template name
639          *
640          * @return void
641          */
642         private function setTemplate($name)
643         {
644                 if (!x($this->available_templates, $name)) {
645                         logger('[ERROR] Item::setTemplate : Template not available ("' . $name . '").', LOGGER_DEBUG);
646                         return false;
647                 }
648
649                 $this->template = $this->available_templates[$name];
650         }
651
652         /**
653          * Get template
654          *
655          * @return object
656          */
657         private function getTemplate()
658         {
659                 return $this->template;
660         }
661
662         /**
663          * Check if this is a toplevel post
664          *
665          * @return boolean
666          */
667         private function isToplevel()
668         {
669                 return $this->toplevel;
670         }
671
672         /**
673          * Check if this is writable
674          *
675          * @return boolean
676          */
677         private function isWritable()
678         {
679                 $conv = $this->getThread();
680
681                 if ($conv) {
682                         // This will allow us to comment on wall-to-wall items owned by our friends
683                         // and community forums even if somebody else wrote the post.
684                         // bug #517 - this fixes for conversation owner
685                         if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == local_user()) {
686                                 return true;
687                         }
688
689                         // this fixes for visitors
690                         return ($this->writable || ($this->isVisiting() && $conv->getMode() == 'profile'));
691                 }
692                 return $this->writable;
693         }
694
695         /**
696          * Count the total of our descendants
697          *
698          * @return integer
699          */
700         private function countDescendants()
701         {
702                 $children = $this->getChildren();
703                 $total = count($children);
704                 if ($total > 0) {
705                         foreach ($children as $child) {
706                                 $total += $child->countDescendants();
707                         }
708                 }
709
710                 return $total;
711         }
712
713         /**
714          * Get the template for the comment box
715          *
716          * @return string
717          */
718         private function getCommentBoxTemplate()
719         {
720                 return $this->comment_box_template;
721         }
722
723         /**
724          * Get the comment box
725          *
726          * @param string $indent Indent value
727          *
728          * @return mixed The comment box string (empty if no comment box)
729          *               false on failure
730          */
731         private function getCommentBox($indent)
732         {
733                 $a = self::getApp();
734
735                 $comment_box = '';
736                 $conv = $this->getThread();
737                 $ww = '';
738                 if (($conv->getMode() === 'network') && $this->isWallToWall()) {
739                         $ww = 'ww';
740                 }
741
742                 if ($conv->isWritable() && $this->isWritable()) {
743                         $qc = $qcomment = null;
744
745                         /*
746                          * Hmmm, code depending on the presence of a particular plugin?
747                          * This should be better if done by a hook
748                          */
749                         if (in_array('qcomment', $a->plugins)) {
750                                 $qc = ((local_user()) ? PConfig::get(local_user(), 'qcomment', 'words') : null);
751                                 $qcomment = (($qc) ? explode("\n", $qc) : null);
752                         }
753
754                         $template = get_markup_template($this->getCommentBoxTemplate());
755                         $comment_box = replace_macros($template, array(
756                                 '$return_path' => $a->query_string,
757                                 '$threaded'    => $this->isThreaded(),
758                                 '$jsreload'    => '',
759                                 '$type'        => $conv->getMode() === 'profile' ? 'wall-comment' : 'net-comment',
760                                 '$id'          => $this->getId(),
761                                 '$parent'      => $this->getId(),
762                                 '$qcomment'    => $qcomment,
763                                 '$profile_uid' => $conv->getProfileOwner(),
764                                 '$mylink'      => $a->remove_baseurl($a->contact['url']),
765                                 '$mytitle'     => t('This is you'),
766                                 '$myphoto'     => $a->remove_baseurl($a->contact['thumb']),
767                                 '$comment'     => t('Comment'),
768                                 '$submit'      => t('Submit'),
769                                 '$edbold'      => t('Bold'),
770                                 '$editalic'    => t('Italic'),
771                                 '$eduline'     => t('Underline'),
772                                 '$edquote'     => t('Quote'),
773                                 '$edcode'      => t('Code'),
774                                 '$edimg'       => t('Image'),
775                                 '$edurl'       => t('Link'),
776                                 '$edvideo'     => t('Video'),
777                                 '$preview'     => ((Feature::isEnabled($conv->getProfileOwner(), 'preview')) ? t('Preview') : ''),
778                                 '$indent'      => $indent,
779                                 '$sourceapp'   => t($a->sourcename),
780                                 '$ww'          => $conv->getMode() === 'network' ? $ww : '',
781                                 '$rand_num'    => random_digits(12)
782                         ));
783                 }
784
785                 return $comment_box;
786         }
787
788         /**
789          * @return string
790          */
791         private function getRedirectUrl()
792         {
793                 return $this->redirect_url;
794         }
795
796         /**
797          * Check if we are a wall to wall item and set the relevant properties
798          *
799          * @return void
800          */
801         protected function checkWallToWall()
802         {
803                 $a = self::getApp();
804                 $conv = $this->getThread();
805                 $this->wall_to_wall = false;
806
807                 if ($this->isToplevel()) {
808                         if ($conv->getMode() !== 'profile') {
809                                 if ($this->getDataValue('wall') && !$this->getDataValue('self')) {
810                                         // On the network page, I am the owner. On the display page it will be the profile owner.
811                                         // This will have been stored in $a->page_contact by our calling page.
812                                         // Put this person as the wall owner of the wall-to-wall notice.
813
814                                         $this->owner_url = zrl($a->page_contact['url']);
815                                         $this->owner_photo = $a->page_contact['thumb'];
816                                         $this->owner_name = $a->page_contact['name'];
817                                         $this->wall_to_wall = true;
818                                 } elseif ($this->getDataValue('owner-link')) {
819                                         $owner_linkmatch = (($this->getDataValue('owner-link')) && link_compare($this->getDataValue('owner-link'), $this->getDataValue('author-link')));
820                                         $alias_linkmatch = (($this->getDataValue('alias')) && link_compare($this->getDataValue('alias'), $this->getDataValue('author-link')));
821                                         $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
822
823                                         if ((!$owner_linkmatch) && (!$alias_linkmatch) && (!$owner_namematch)) {
824                                                 // The author url doesn't match the owner (typically the contact)
825                                                 // and also doesn't match the contact alias.
826                                                 // The name match is a hack to catch several weird cases where URLs are
827                                                 // all over the park. It can be tricked, but this prevents you from
828                                                 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
829                                                 // well that it's the same Bob Smith.
830                                                 // But it could be somebody else with the same name. It just isn't highly likely.
831
832
833                                                 $this->owner_photo = $this->getDataValue('owner-avatar');
834                                                 $this->owner_name = $this->getDataValue('owner-name');
835                                                 $this->wall_to_wall = true;
836                                                 // If it is our contact, use a friendly redirect link
837                                                 if ($this->getDataValue('network') === NETWORK_DFRN
838                                                         && link_compare($this->getDataValue('owner-link'), $this->getDataValue('url'))
839                                                 ) {
840                                                         $this->owner_url = $this->getRedirectUrl();
841                                                 } else {
842                                                         $this->owner_url = zrl($this->getDataValue('owner-link'));
843                                                 }
844                                         }
845                                 }
846                         }
847                 }
848
849                 if (!$this->wall_to_wall) {
850                         $this->setTemplate('wall');
851                         $this->owner_url = '';
852                         $this->owner_photo = '';
853                         $this->owner_name = '';
854                 }
855         }
856
857         /**
858          * @return boolean
859          */
860         private function isWallToWall()
861         {
862                 return $this->wall_to_wall;
863         }
864
865         /**
866          * @return string
867          */
868         private function getOwnerUrl()
869         {
870                 return $this->owner_url;
871         }
872
873         /**
874          * @return string
875          */
876         private function getOwnerName()
877         {
878                 return $this->owner_name;
879         }
880
881         /**
882          * @return boolean
883          */
884         private function isVisiting()
885         {
886                 return $this->visiting;
887         }
888 }