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