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