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