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