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