]> git.mxchange.org Git - friendica.git/blob - object/Item.php
Merge pull request #1929 from rabuzarus/event-attendance
[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 = $a->get_baseurl($ssl_state) . '/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                 // Prepare the children
59                 if(count($data['children'])) {
60                         foreach($data['children'] as $item) {
61                                 /*
62                                  * Only add will be displayed
63                                  */
64                                 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
65                                         continue;
66                                 }
67                                 if(! visible_activity($item)) {
68                                         continue;
69                                 }
70                                 $item['pagedrop'] = $data['pagedrop'];
71                                 $child = new Item($item);
72                                 $this->add_child($child);
73                         }
74                 }
75         }
76
77         /**
78          * Get data in a form usable by a conversation template
79          *
80          * Returns:
81          *      _ The data requested on success
82          *      _ false on failure
83          */
84         public function get_template_data($conv_responses, $thread_level=1) {
85                 require_once("mod/proxy.php");
86
87                 $result = array();
88
89                 $a = $this->get_app();
90
91                 $item = $this->get_data();
92                 $edited = false;
93                 if (strcmp($item['created'], $item['edited'])<>0) {
94                       $edited = array(
95                           'label' => t('This entry was edited'),
96                           'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
97                           'relative' => relative_date($item['edited'])
98                       );
99                 }
100                 $commentww = '';
101                 $sparkle = '';
102                 $buttons = '';
103                 $dropping = false;
104                 $star = false;
105                 $ignore = false;
106                 $isstarred = "unstarred";
107                 $indent = '';
108                 $shiny = '';
109                 $osparkle = '';
110                 $total_children = $this->count_descendants();
111
112                 $conv = $this->get_conversation();
113
114
115                 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
116                         || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
117                         ? t('Private Message')
118                         : false);
119                 $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false);
120                 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
121                         $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
122                 else
123                         $edpost = false;
124                 if(($this->get_data_value('uid') == local_user()) || $this->is_visiting())
125                         $dropping = true;
126
127                 $drop = array(
128                         'dropping' => $dropping,
129                         'pagedrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $item['pagedrop'] : ''),
130                         'select' => t('Select'),
131                         'delete' => t('Delete'),
132                 );
133
134                 $filer = (($conv->get_profile_owner() == local_user()) ? t("save to folder") : false);
135
136                 $diff_author    = ((link_compare($item['url'],$item['author-link'])) ? false : true);
137                 $profile_name   = htmlentities(((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
138                 if($item['author-link'] && (! $item['author-name']))
139                         $profile_name = $item['author-link'];
140
141                 $sp = false;
142                 $profile_link = best_link_url($item,$sp);
143                 if($profile_link === 'mailbox')
144                         $profile_link = '';
145                 if($sp)
146                         $sparkle = ' sparkle';
147                 else
148                         $profile_link = zrl($profile_link);
149
150                 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
151                 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
152                         $profile_avatar = $a->contacts[$normalised]['thumb'];
153                 else
154                         $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($this->get_data_value('thumb')));
155
156                 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
157                 call_hooks('render_location',$locate);
158                 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
159
160                 $searchpath = $a->get_baseurl()."/search?tag=";
161                 $tags=array();
162                 $hashtags = array();
163                 $mentions = array();
164
165
166                 /*foreach(explode(',',$item['tag']) as $tag){
167                         $tag = trim($tag);
168                         if ($tag!="") {
169                                 $t = bbcode($tag);
170                                 $tags[] = $t;
171                                 if($t[0] == '#')
172                                         $hashtags[] = $t;
173                                 elseif($t[0] == '@')
174                                         $mentions[] = $t;
175                         }
176                 }*/
177
178                 // process action responses - e.g. like/dislike/attend/agree/whatever
179                 $response_verbs = array('like');
180                 if(feature_enabled($conv->get_profile_owner(),'dislike'))
181                         $response_verbs[] = 'dislike';
182                 if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
183                         $response_verbs[] = 'attendyes';
184                         $response_verbs[] = 'attendno';
185                         $response_verbs[] = 'attendmaybe';
186                         if($conv->is_writable()) {
187                                 $isevent = true;
188                                 $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
189                         }
190                 }
191
192                 $responses = get_responses($conv_responses,$response_verbs,$this,$item);
193
194                 foreach ($response_verbs as $value=>$verbs) {
195                         $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']) : '');
196
197                 }
198
199                 /*
200                  * We should avoid doing this all the time, but it depends on the conversation mode
201                  * And the conv mode may change when we change the conv, or it changes its mode
202                  * Maybe we should establish a way to be notified about conversation changes
203                  */
204                 $this->check_wall_to_wall();
205
206                 if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url()))
207                         $osparkle = ' sparkle';
208
209                 if($this->is_toplevel()) {
210                         if($conv->get_profile_owner() == local_user()) {
211                                 $isstarred = (($item['starred']) ? "starred" : "unstarred");
212
213                                 $star = array(
214                                         'do' => t("add star"),
215                                         'undo' => t("remove star"),
216                                         'toggle' => t("toggle star status"),
217                                         'classdo' => (($item['starred']) ? "hidden" : ""),
218                                         'classundo' => (($item['starred']) ? "" : "hidden"),
219                                         'starred' =>  t('starred'),
220                                 );
221                                 $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
222                                         intval($item['uid']),
223                                         intval($item['id'])
224                                 );
225                                 if (count($r)) {
226                                         $ignore = array(
227                                                 'do' => t("ignore thread"),
228                                                 'undo' => t("unignore thread"),
229                                                 'toggle' => t("toggle ignore status"),
230                                                 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
231                                                 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
232                                                 'ignored' =>  t('ignored'),
233                                         );
234                                 }
235
236                                 $tagger = '';
237                                 if(feature_enabled($conv->get_profile_owner(),'commtag')) {
238                                         $tagger = array(
239                                                 'add' => t("add tag"),
240                                                 'class' => "",
241                                         );
242                                 }
243                         }
244                 } else {
245                         $indent = 'comment';
246                 }
247
248                 if($conv->is_writable()) {
249                         $buttons = array(
250                                 'like' => array( t("I like this \x28toggle\x29"), t("like")),
251                                 'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''),
252                         );
253                         if ($shareable) $buttons['share'] = array( t('Share this'), t('share'));
254                 }
255
256                 $comment = $this->get_comment_box($indent);
257
258                 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0){
259                         $shiny = 'shiny';
260                 }
261
262                 localize_item($item);
263
264                 if ($item["postopts"] and !get_config("system", "suppress_language")) {
265                         //$langdata = explode(";", $item["postopts"]);
266                         //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)";
267                         $langstr = "";
268                         if (substr($item["postopts"], 0, 5) == "lang=") {
269                                 $postopts = substr($item["postopts"], 5);
270
271                                 $languages = explode(":", $postopts);
272
273                                 if (sizeof($languages) == 1) {
274                                         $languages = array();
275                                         $languages[] = $postopts;
276                                 }
277
278                                 foreach ($languages as $language) {
279                                         $langdata = explode(";", $language);
280                                         if ($langstr != "")
281                                                 $langstr .= ", ";
282
283                                         //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
284                                         $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0];
285                                 }
286                         }
287                 }
288
289                 $body = prepare_body($item,true);
290
291                 list($categories, $folders) = get_cats_and_terms($item);
292
293                 if($a->theme['template_engine'] === 'internal') {
294                         $body_e = template_escape($body);
295                         $text_e = strip_tags(template_escape($body));
296                         $name_e = template_escape($profile_name);
297                         $title_e = template_escape($item['title']);
298                         $location_e = template_escape($location);
299                         $owner_name_e = template_escape($this->get_owner_name());
300                 }
301                 else {
302                         $body_e = $body;
303                         $text_e = strip_tags($body);
304                         $name_e = $profile_name;
305                         $title_e = $item['title'];
306                         $location_e = $location;
307                         $owner_name_e = $this->get_owner_name();
308                 }
309
310                 // Disable features that aren't available in several networks
311                 if (($item["item_network"] != NETWORK_DFRN) AND isset($buttons["dislike"])) {
312                         unset($buttons["dislike"],$isevent);
313                         $tagger = '';
314                 }
315
316                 if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"]))
317                         unset($buttons["like"]);
318
319                 if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"]))
320                         unset($buttons["like"]);
321
322                 // Diaspora isn't able to do likes on comments - but red does
323                 if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
324                         !diaspora_is_redmatrix($item["owner-link"]) AND isset($buttons["like"]))
325                         unset($buttons["like"]);
326
327                 // Diaspora doesn't has multithreaded comments
328                 if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment'))
329                         unset($comment);
330
331                 // Facebook can like comments - but it isn't programmed in the connector yet.
332                 if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"]))
333                         unset($buttons["like"]);
334
335                 $tmp_item = array(
336                         'template' => $this->get_template(),
337
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' => proxy_url($profile_avatar, 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' => proxy_url($this->get_owner_photo(), 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                         'postopts' => $langstr,
396                         'edited' => $edited,
397                         'network' => $item["item_network"],
398                         'network_name' => network_to_name($item['item_network'], $profile_link),
399                 );
400
401                 $arr = array('item' => $item, 'output' => $tmp_item);
402                 call_hooks('display_item', $arr);
403
404                 $result = $arr['output'];
405
406                 $result['children'] = array();
407                 $children = $this->get_children();
408                 $nb_children = count($children);
409                 if($nb_children > 0) {
410                         foreach($children as $child) {
411                                 $result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1);
412                         }
413                         // Collapse
414                         if(($nb_children > 2) || ($thread_level > 1)) {
415                                 $result['children'][0]['comment_firstcollapsed'] = true;
416                                 $result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children );
417                                 $result['children'][0]['hidden_comments_num'] = $total_children;
418                                 $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
419                                 $result['children'][0]['hide_text'] = t('show more');
420                                 if($thread_level > 1) {
421                                         $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
422                                 }
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                 }
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) {
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                 }
466                 if($this->get_child($item->get_id())) {
467                         logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG);
468                         return false;
469                 }
470                 /*
471                  * Only add what will be displayed
472                  */
473                 if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
474                         return false;
475                 }
476                 if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
477                         return false;
478                 }
479
480                 $item->set_parent($this);
481                 $this->children[] = $item;
482                 return end($this->children);
483         }
484
485         /**
486          * Get a child by its ID
487          */
488         public function get_child($id) {
489                 foreach($this->get_children() as $child) {
490                         if($child->get_id() == $id)
491                                 return $child;
492                 }
493                 return null;
494         }
495
496         /**
497          * Get all ou children
498          */
499         public function get_children() {
500                 return $this->children;
501         }
502
503         /**
504          * Set our parent
505          */
506         protected function set_parent($item) {
507                 $parent = $this->get_parent();
508                 if($parent) {
509                         $parent->remove_child($this);
510                 }
511                 $this->parent = $item;
512                 $this->set_conversation($item->get_conversation());
513         }
514
515         /**
516          * Remove our parent
517          */
518         protected function remove_parent() {
519                 $this->parent = null;
520                 $this->conversation = null;
521         }
522
523         /**
524          * Remove a child
525          */
526         public function remove_child($item) {
527                 $id = $item->get_id();
528                 foreach($this->get_children() as $key => $child) {
529                         if($child->get_id() == $id) {
530                                 $child->remove_parent();
531                                 unset($this->children[$key]);
532                                 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
533                                 $this->children = array_values($this->children);
534                                 return true;
535                         }
536                 }
537                 logger('[WARN] Item::remove_child : Item is not a child ('. $id .').', LOGGER_DEBUG);
538                 return false;
539         }
540
541         /**
542          * Get parent item
543          */
544         protected function get_parent() {
545                 return $this->parent;
546         }
547
548         /**
549          * set conversation
550          */
551         public function set_conversation($conv) {
552                 $previous_mode = ($this->conversation ? $this->conversation->get_mode() : '');
553
554                 $this->conversation = $conv;
555
556                 // Set it on our children too
557                 foreach($this->get_children() as $child)
558                         $child->set_conversation($conv);
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                 $a = get_app();
598
599                 if(!x($this->available_templates, $name)) {
600                         logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG);
601                         return false;
602                 }
603
604                 $this->template = $this->available_templates[$name];
605         }
606
607         /**
608          * Get template
609          */
610         private function get_template() {
611                 return $this->template;
612         }
613
614         /**
615          * Check if this is a toplevel post
616          */
617         private function is_toplevel() {
618                 return $this->toplevel;
619         }
620
621         /**
622          * Check if this is writable
623          */
624         private function is_writable() {
625                 $conv = $this->get_conversation();
626
627                 if($conv) {
628                         // This will allow us to comment on wall-to-wall items owned by our friends
629                         // and community forums even if somebody else wrote the post.
630
631                         // bug #517 - this fixes for conversation owner
632                         if($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user())
633                                 return true; 
634
635                         // this fixes for visitors
636                         return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile'));
637                 }
638                 return $this->writable;
639         }
640
641         /**
642          * Count the total of our descendants
643          */
644         private function count_descendants() {
645                 $children = $this->get_children();
646                 $total = count($children);
647                 if($total > 0) {
648                         foreach($children as $child) {
649                                 $total += $child->count_descendants();
650                         }
651                 }
652                 return $total;
653         }
654
655         /**
656          * Get the template for the comment box
657          */
658         private function get_comment_box_template() {
659                 return $this->comment_box_template;
660         }
661
662         /**
663          * Get the comment box
664          *
665          * Returns:
666          *      _ The comment box string (empty if no comment box)
667          *      _ false on failure
668          */
669         private function get_comment_box($indent) {
670                 $a = $this->get_app();
671                 if(!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) {
672                         return '';
673                 }
674
675                 $comment_box = '';
676                 $conv = $this->get_conversation();
677                 $template = get_markup_template($this->get_comment_box_template());
678                 $ww = '';
679                 if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() )
680                         $ww = 'ww';
681
682                 if($conv->is_writable() && $this->is_writable()) {
683                         $qc = $qcomment =  null;
684
685                         /*
686                          * Hmmm, code depending on the presence of a particular plugin?
687                          * This should be better if done by a hook
688                          */
689                         if(in_array('qcomment',$a->plugins)) {
690                                 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
691                                 $qcomment = (($qc) ? explode("\n",$qc) : null);
692                         }
693                         $comment_box = replace_macros($template,array(
694                                 '$return_path' => $a->query_string,
695                                 '$threaded' => $this->is_threaded(),
696 //                              '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''),
697                                 '$jsreload' => '',
698                                 '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'),
699                                 '$id' => $this->get_id(),
700                                 '$parent' => $this->get_id(),
701                                 '$qcomment' => $qcomment,
702                                 '$profile_uid' =>  $conv->get_profile_owner(),
703                                 '$mylink' => $a->contact['url'],
704                                 '$mytitle' => t('This is you'),
705                                 '$myphoto' => $a->contact['thumb'],
706                                 '$comment' => t('Comment'),
707                                 '$submit' => t('Submit'),
708                                 '$edbold' => t('Bold'),
709                                 '$editalic' => t('Italic'),
710                                 '$eduline' => t('Underline'),
711                                 '$edquote' => t('Quote'),
712                                 '$edcode' => t('Code'),
713                                 '$edimg' => t('Image'),
714                                 '$edurl' => t('Link'),
715                                 '$edvideo' => t('Video'),
716                                 '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''),
717                                 '$indent' => $indent,
718                                 '$sourceapp' => t($a->sourcename),
719                                 '$ww' => (($conv->get_mode() === 'network') ? $ww : ''),
720                                 '$rand_num' => random_digits(12)
721                         ));
722                 }
723
724                 return $comment_box;
725         }
726
727         private function get_redirect_url() {
728                 return $this->redirect_url;
729         }
730
731         /**
732          * Check if we are a wall to wall item and set the relevant properties
733          */
734         protected function check_wall_to_wall() {
735                 $a = $this->get_app();
736                 $conv = $this->get_conversation();
737                 $this->wall_to_wall = false;
738
739                 if($this->is_toplevel()) {
740                         if($conv->get_mode() !== 'profile') {
741                                 if($this->get_data_value('wall') AND !$this->get_data_value('self')) {
742                                         // On the network page, I am the owner. On the display page it will be the profile owner.
743                                         // This will have been stored in $a->page_contact by our calling page.
744                                         // Put this person as the wall owner of the wall-to-wall notice.
745
746                                         $this->owner_url = zrl($a->page_contact['url']);
747                                         $this->owner_photo = $a->page_contact['thumb'];
748                                         $this->owner_name = $a->page_contact['name'];
749                                         $this->wall_to_wall = true;
750                                 }
751                                 else if($this->get_data_value('owner-link')) {
752
753                                         $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link')));
754                                         $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link')));
755                                         $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name'));
756
757                                         if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
758
759                                                 // The author url doesn't match the owner (typically the contact)
760                                                 // and also doesn't match the contact alias. 
761                                                 // The name match is a hack to catch several weird cases where URLs are 
762                                                 // all over the park. It can be tricked, but this prevents you from
763                                                 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
764                                                 // well that it's the same Bob Smith. 
765
766                                                 // But it could be somebody else with the same name. It just isn't highly likely. 
767
768
769                                                 $this->owner_photo = $this->get_data_value('owner-avatar');
770                                                 $this->owner_name = $this->get_data_value('owner-name');
771                                                 $this->wall_to_wall = true;
772                                                 // If it is our contact, use a friendly redirect link
773                                                 if((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) 
774                                                         && ($this->get_data_value('network') === NETWORK_DFRN)) {
775                                                         $this->owner_url = $this->get_redirect_url();
776                                                 }
777                                                 else
778                                                         $this->owner_url = zrl($this->get_data_value('owner-link'));
779                                         }
780                                 }
781                         }
782                 }
783
784                 if(!$this->wall_to_wall) {
785                         $this->set_template('wall');
786                         $this->owner_url = '';
787                         $this->owner_photo = '';
788                         $this->owner_name = '';
789                 }
790         }
791
792         private function is_wall_to_wall() {
793                 return $this->wall_to_wall;
794         }
795
796         private function get_owner_url() {
797                 return $this->owner_url;
798         }
799
800         private function get_owner_photo() {
801                 return $this->owner_photo;
802         }
803
804         private function get_owner_name() {
805                 return $this->owner_name;
806         }
807
808         private function is_visiting() {
809                 return $this->visiting;
810         }
811
812
813
814
815 }
816 ?>