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