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