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