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