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