]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
Merge remote-tracking branch 'friendika-master/master'
[friendica.git] / mod / profile.php
1 <?php
2
3 function profile_init(&$a) {
4
5         if($a->argc > 1)
6                 $which = $a->argv[1];
7         else {
8                 notice( t('No profile') . EOL );
9                 $a->error = 404;
10                 return;
11         }
12
13         $profile = 0;
14         if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
15                 $which = $a->user['nickname'];
16                 $profile = $a->argv[1];         
17         }
18
19         profile_load($a,$which,$profile);
20
21         if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] & PAGE_COMMUNITY)) {
22                 $a->page['htmlhead'] .= '<meta name="friendika.community" content="true" />';
23         }
24         if(x($a->profile,'openidserver'))                               
25                 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
26         if(x($a->profile,'openid')) {
27                 $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
28                 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
29         }
30
31         $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
32         $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords);
33         if(strlen($keywords))
34                 $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
35
36         $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
37         $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
38         $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
39         $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
40         header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
41         
42         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
43         foreach($dfrn_pages as $dfrn)
44                 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
45
46 }
47
48
49 function profile_content(&$a, $update = 0) {
50
51         require_once("include/bbcode.php");
52         require_once('include/security.php');
53
54         $groups = array();
55
56         $tab = 'posts';
57         $o = '';
58
59         if($update) {
60                 // Ensure we've got a profile owner if updating.
61                 $a->profile['profile_uid'] = $update;
62         }
63         else {
64                 if($a->profile['profile_uid'] == local_user())          
65                         $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
66         }
67
68         $contact = null;
69         $remote_contact = false;
70
71         if(remote_user()) {
72                 $contact_id = $_SESSION['visitor_id'];
73                 $groups = init_groups_visitor($contact_id);
74                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
75                         intval($contact_id),
76                         intval($a->profile['profile_uid'])
77                 );
78                 if(count($r)) {
79                         $contact = $r[0];
80                         $remote_contact = true;
81                 }
82         }
83
84         if(! $remote_contact) {
85                 if(local_user()) {
86                         $contact_id = $_SESSION['cid'];
87                         $contact = $a->contact;
88                 }
89         }
90
91         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
92         
93         if(! $update) {
94                 if(x($_GET,'tab'))
95                         $tab = notags(trim($_GET['tab']));
96
97                 $tpl = load_view_file('view/profile_tabs.tpl');
98
99                 $o .= replace_macros($tpl,array(
100                         '$url' => $a->get_baseurl() . '/' . $a->cmd,
101                         '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname'],
102                         '$status' => t('Status'),
103                         '$profile' => t('Profile'),
104                         '$photos' => t('Photos')
105                 ));
106
107
108                 if($tab === 'profile') {
109                         $profile_lang = get_config('system','language');
110                         if(! $profile_lang)
111                                 $profile_lang = 'en';
112                         if(file_exists("view/$profile_lang/profile_advanced.php"))
113                                 require_once("view/$profile_lang/profile_advanced.php");
114                         else
115                                 require_once('view/profile_advanced.php');
116
117                         call_hooks('profile_advanced',$o);
118
119                         return $o;
120                 }
121
122                 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
123                 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
124
125                 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
126
127                 if(can_write_wall($a,$a->profile['profile_uid'])) {
128
129                         $geotag = ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
130
131                         $tpl = load_view_file('view/jot-header.tpl');
132         
133                         $a->page['htmlhead'] .= replace_macros($tpl, array(
134                                 '$baseurl' => $a->get_baseurl(),
135                                 '$geotag'  => $geotag,
136                                 '$nickname' => $a->profile['nickname'],
137                                 '$linkurl' => t('Please enter a link URL:'),
138                                 '$utubeurl' => t('Please enter a YouTube link:'),
139                                 '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
140                                 '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
141                                 '$whereareu' => t('Where are you right now?'),
142                                 '$title' => t('Enter a title for this item') 
143                         ));
144
145                         require_once('include/acl_selectors.php');
146
147                         $tpl = load_view_file('view/jot.tpl');
148
149                         if(is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))
150                                 $lockstate = 'lock';
151                         else
152                                 $lockstate = 'unlock';
153        
154                         $jotplugins = '';
155                         $jotnets = '';
156                         call_hooks('jot_tool', $jotplugins); 
157
158                         call_hooks('jot_networks', $jotnets);
159
160                         $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
161
162                         $o .= replace_macros($tpl,array(
163                                 '$baseurl' => $a->get_baseurl(),
164                                 '$action' => 'item',
165                                 '$share' => t('Share'),
166                                 '$upload' => t('Upload photo'),
167                                 '$weblink' => t('Insert web link'),
168                                 '$youtube' => t('Insert YouTube video'),
169                                 '$video' => t('Insert Vorbis [.ogg] video'),
170                                 '$audio' => t('Insert Vorbis [.ogg] audio'),
171                                 '$setloc' => t('Set your location'),
172                                 '$noloc' => t('Clear browser location'),
173                                 '$title' => t('Set title'),
174                                 '$wait' => t('Please wait'),
175                                 '$permset' => t('Permission settings'),
176                                 '$content' => '',
177                                 '$post_id' => '',
178                                 '$defloc' => (($is_owner) ? $a->user['default-location'] : ''),
179                                 '$return_path' => $a->cmd,
180                                 '$visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
181                                 '$lockstate' => $lockstate,
182                                 '$emailcc' => t('CC: email addresses'),
183                                 '$jotnets' => $jotnets,
184                                 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
185                                 '$bang' => '',
186                                 '$acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
187                                 '$profile_uid' => $a->profile['profile_uid']
188                         ));
189                 }
190
191                 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
192                 // because browser prefetching might change it on us. We have to deliver it with the page.
193
194                 if($tab === 'posts') {
195                         $o .= '<div id="live-profile"></div>' . "\r\n";
196                         $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] 
197                                 . "; var netargs = ''; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
198                 }
199         }
200
201         // Construct permissions
202
203         // default permissions - anonymous user
204
205         $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
206
207         // Profile owner - everything is visible
208
209         if($is_owner) {
210                 $sql_extra = ''; 
211                 
212                 // Oh - while we're here... reset the Unseen messages
213
214                 $r = q("UPDATE `item` SET `unseen` = 0 
215                         WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
216                         intval($_SESSION['uid'])
217                 );
218
219         }
220
221         // authenticated visitor - here lie dragons
222         // If $remotecontact is true, we know that not only is this a remotely authenticated
223         // person, but that it is *our* contact, which is important in multi-user mode.
224
225         elseif($remote_contact) {
226                 $gs = '<<>>'; // should be impossible to match
227                 if(count($groups)) {
228                         foreach($groups as $g)
229                                 $gs .= '|<' . intval($g) . '>';
230                 } 
231                 $sql_extra = sprintf(
232                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
233                           AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
234                           AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
235                           AND ( `deny_gid`  = '' OR NOT `deny_gid` REGEXP '%s') ",
236
237                         intval($_SESSION['visitor_id']),
238                         intval($_SESSION['visitor_id']),
239                         dbesc($gs),
240                         dbesc($gs)
241                 );
242         }
243
244         $r = q("SELECT COUNT(*) AS `total`
245                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
246                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
247                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
248                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
249                 $sql_extra ",
250                 intval($a->profile['profile_uid'])
251
252         );
253
254         if(count($r)) {
255                 $a->set_pager_total($r[0]['total']);
256                 $a->set_pager_itemspage(40);
257         }
258
259         $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
260                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
261                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
262                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
263                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
264                 $sql_extra
265                 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
266                 intval($a->profile['profile_uid']),
267                 intval($a->pager['start']),
268                 intval($a->pager['itemspage'])
269
270         );
271
272         $parents_arr = array();
273         $parents_str = '';
274
275         if(count($r)) {
276                 foreach($r as $rr)
277                         $parents_arr[] = $rr['item_id'];
278                 $parents_str = implode(', ', $parents_arr);
279  
280                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
281                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`, 
282                         `contact`.`thumb`, `contact`.`self`, 
283                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
284                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
285                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
286                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
287                         AND `item`.`parent` IN ( %s )
288                         $sql_extra
289                         ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ",
290                         intval($a->profile['profile_uid']),
291                         dbesc($parents_str)
292                 );
293         }
294
295         if($is_owner && ! $update)
296                 $o .= get_birthdays();
297
298         $cmnt_tpl = load_view_file('view/comment_item.tpl');
299
300         $like_tpl = load_view_file('view/like.tpl');
301         $noshare_tpl = load_view_file('view/like_noshare.tpl');
302
303         $tpl = load_view_file('view/wall_item.tpl');
304
305         $droptpl = load_view_file('view/wall_item_drop.tpl');
306         $fakedrop = load_view_file('view/wall_fake_drop.tpl');
307
308         if($update)
309                 $return_url = $_SESSION['return_url'];
310         else
311                 $return_url = $_SESSION['return_url'] = $a->cmd;
312
313         $alike = array();
314         $dlike = array();
315
316         if($r !== false && count($r)) {
317
318                 $comments = array();
319                 foreach($r as $rr) {
320                         if(intval($rr['gravity']) == 6) {
321                                 if(! x($comments,$rr['parent']))
322                                         $comments[$rr['parent']] = 1;
323                                 else
324                                         $comments[$rr['parent']] += 1;
325                         }
326                 }
327
328                 foreach($r as $item) {
329                         like_puller($a,$item,$alike,'like');
330                         like_puller($a,$item,$dlike,'dislike');
331                 }
332
333                 $comments_collapsed = false;
334
335                 foreach($r as $item) {
336
337                         $sparkle = '';          
338                         $comment = '';
339                         $likebuttons = '';
340
341                         $template = $tpl;
342                         
343                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
344
345                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
346                                 && ($item['id'] != $item['parent']))
347                                 continue;
348
349                         if($item['id'] == $item['parent']) {
350                                 $comments_seen = 0;
351                                 $comments_collapsed = false;
352                         }
353                         else
354                                 $comments_seen ++;
355
356
357                         if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
358                                 if(! $comments_collapsed) {
359                                         $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent'] . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\');" >' . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>';
360                                         $o .= '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
361                                         $comments_collapsed = true;
362                                 }
363                         }
364                         if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
365                                 $o .= '</div></div>';
366                         }
367
368                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
369                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
370                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
371                                 : '<div class="wall-item-lock"></div>');
372
373                         if(can_write_wall($a,$a->profile['profile_uid'])) {
374                                 if($item['id'] == $item['parent']) {
375                                         $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
376                                                 '$id' => $item['id'],
377                                                 '$likethis' => t("I like this \x28toggle\x29"),
378                                                 '$nolike' => t("I don't like this \x28toggle\x29"),
379                                                 '$share' => t('Share'),
380                                                 '$wait' => t('Please wait') 
381                                         ));
382                                 }
383                                 if($item['last-child']) {
384                                         $comment = replace_macros($cmnt_tpl,array(
385                                                 '$return_path' => '', 
386                                                 '$jsreload' => '', // $_SESSION['return_url'],
387                                                 '$type' => 'wall-comment',
388                                                 '$id' => $item['item_id'],
389                                                 '$parent' => $item['parent'],
390                                                 '$profile_uid' =>  $a->profile['profile_uid'],
391                                                 '$mylink' => $contact['url'],
392                                                 '$mytitle' => t('This is you'),
393                                                 '$myphoto' => $contact['thumb'],
394                                                 '$ww' => ''
395                                         ));
396                                 }
397                         }
398
399
400                         $profile_url = $item['url'];
401
402                         // This is my profile page but I'm not the author of this post/comment. If it's somebody that's a fan or mutual friend,
403                         // I can go directly to their profile as an authenticated guest.
404
405                         if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) 
406                                 && ($item['network'] === 'dfrn') && (! $item['self'] )) {
407                                 $profile_url = $redirect_url;
408                                 $sparkle = ' sparkle';
409                         }
410                         else
411                                 $sparkle = '';
412
413
414                         $edpost = '';
415                         if((local_user()) && ($a->profile['profile_uid'] == local_user()) && ($item['id'] == $item['parent']) && (intval($item['wall']) == 1)) 
416                                 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
417
418
419                         // We would prefer to use our own avatar link for this item because the one in the author-avatar might reference a 
420                         // remote site (which could be down). We will use author-avatar if we haven't got something stored locally.
421                         // We use this same logic block in mod/network.php to determine it this is a third party post and we don't have any 
422                         // local contact info at all. In this module you should never encounter a third-party author, but we still will do
423                         // the right thing if you ever do. 
424
425                         $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
426
427                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
428                         $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
429
430                         $profile_link = $profile_url;
431
432                         $drop = '';
433                         $dropping = false;
434
435                         if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
436                                 $dropping = true;
437
438                         $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
439
440
441                         $like    = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
442                         $dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
443                         $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
444                         $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
445                         if($coord) {
446                                 if($location)
447                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
448                                 else
449                                         $location = '<span class="smalltext">' . $coord . '</span>';
450                         }
451
452                         $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
453
454                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
455                                 $indent .= ' shiny'; 
456
457                         $tmp_item = replace_macros($template,array(
458                                 '$id' => $item['item_id'],
459                                 '$linktitle' => t('View $name\'s profile'),
460                                 '$profile_url' => $profile_link,
461                                 '$name' => $profile_name,
462                                 '$thumb' => $profile_avatar,
463                                 '$sparkle' => $sparkle,
464                                 '$title' => $item['title'],
465                                 '$body' => smilies(bbcode($item['body'])),
466                                 '$ago' => relative_date($item['created']),
467                                 '$lock' => $lock,
468                                 '$location' => $location, 
469                                 '$indent' => $indent, 
470                                 '$plink' => get_plink($item),
471                                 '$edpost' => $edpost,
472                                 '$drop' => $drop,
473                                 '$like' => $like,
474                                 '$vote' => $likebuttons,
475                                 '$dislike' => $dislike,
476                                 '$comment' => $comment
477                         ));
478
479                         $arr = array('item' => $item, 'output' => $tmp_item);
480                         call_hooks('display_item', $arr);
481
482                         $o .= $arr['output'];
483                         
484                 }
485         }
486
487         if($update) {
488                 return $o;
489         }
490                 
491         $o .= paginate($a);
492         $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
493
494         return $o;
495 }