]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
the rest of the english html templates except for htconfig
[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                         require_once('include/profile_advanced.php');
110                         $o .= advanced_profile($a);
111                         call_hooks('profile_advanced',$o);
112                         return $o;
113                 }
114
115                 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
116                 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
117
118                 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
119
120                 if(can_write_wall($a,$a->profile['profile_uid'])) {
121
122                         $geotag = ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
123
124                         $tpl = load_view_file('view/jot-header.tpl');
125         
126                         $a->page['htmlhead'] .= replace_macros($tpl, array(
127                                 '$baseurl' => $a->get_baseurl(),
128                                 '$geotag'  => $geotag,
129                                 '$nickname' => $a->profile['nickname'],
130                                 '$linkurl' => t('Please enter a link URL:'),
131                                 '$utubeurl' => t('Please enter a YouTube link:'),
132                                 '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
133                                 '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
134                                 '$whereareu' => t('Where are you right now?'),
135                                 '$title' => t('Enter a title for this item') 
136                         ));
137
138                         require_once('include/acl_selectors.php');
139
140                         $tpl = load_view_file('view/jot.tpl');
141
142                         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']))))
143                                 $lockstate = 'lock';
144                         else
145                                 $lockstate = 'unlock';
146        
147                         $jotplugins = '';
148                         $jotnets = '';
149                         call_hooks('jot_tool', $jotplugins); 
150
151                         call_hooks('jot_networks', $jotnets);
152
153                         $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
154
155                         $o .= replace_macros($tpl,array(
156                                 '$baseurl' => $a->get_baseurl(),
157                                 '$action' => 'item',
158                                 '$share' => t('Share'),
159                                 '$upload' => t('Upload photo'),
160                                 '$weblink' => t('Insert web link'),
161                                 '$youtube' => t('Insert YouTube video'),
162                                 '$video' => t('Insert Vorbis [.ogg] video'),
163                                 '$audio' => t('Insert Vorbis [.ogg] audio'),
164                                 '$setloc' => t('Set your location'),
165                                 '$noloc' => t('Clear browser location'),
166                                 '$title' => t('Set title'),
167                                 '$wait' => t('Please wait'),
168                                 '$permset' => t('Permission settings'),
169                                 '$content' => '',
170                                 '$post_id' => '',
171                                 '$defloc' => (($is_owner) ? $a->user['default-location'] : ''),
172                                 '$return_path' => $a->cmd,
173                                 '$visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
174                                 '$lockstate' => $lockstate,
175                                 '$emailcc' => t('CC: email addresses'),
176                                 '$jotnets' => $jotnets,
177                                 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
178                                 '$bang' => '',
179                                 '$acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
180                                 '$profile_uid' => $a->profile['profile_uid']
181                         ));
182                 }
183
184                 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
185                 // because browser prefetching might change it on us. We have to deliver it with the page.
186
187                 if($tab === 'posts') {
188                         $o .= '<div id="live-profile"></div>' . "\r\n";
189                         $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] 
190                                 . "; var netargs = ''; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
191                 }
192         }
193
194         // Construct permissions
195
196         // default permissions - anonymous user
197
198         $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
199
200         // Profile owner - everything is visible
201
202         if($is_owner) {
203                 $sql_extra = ''; 
204                 
205                 // Oh - while we're here... reset the Unseen messages
206
207                 $r = q("UPDATE `item` SET `unseen` = 0 
208                         WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
209                         intval($_SESSION['uid'])
210                 );
211
212         }
213
214         // authenticated visitor - here lie dragons
215         // If $remotecontact is true, we know that not only is this a remotely authenticated
216         // person, but that it is *our* contact, which is important in multi-user mode.
217
218         elseif($remote_contact) {
219                 $gs = '<<>>'; // should be impossible to match
220                 if(count($groups)) {
221                         foreach($groups as $g)
222                                 $gs .= '|<' . intval($g) . '>';
223                 } 
224                 $sql_extra = sprintf(
225                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
226                           AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
227                           AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
228                           AND ( `deny_gid`  = '' OR NOT `deny_gid` REGEXP '%s') ",
229
230                         intval($_SESSION['visitor_id']),
231                         intval($_SESSION['visitor_id']),
232                         dbesc($gs),
233                         dbesc($gs)
234                 );
235         }
236
237         $r = q("SELECT COUNT(*) AS `total`
238                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
239                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
240                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
241                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
242                 $sql_extra ",
243                 intval($a->profile['profile_uid'])
244
245         );
246
247         if(count($r)) {
248                 $a->set_pager_total($r[0]['total']);
249                 $a->set_pager_itemspage(40);
250         }
251
252         $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
253                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
254                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
255                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
256                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
257                 $sql_extra
258                 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
259                 intval($a->profile['profile_uid']),
260                 intval($a->pager['start']),
261                 intval($a->pager['itemspage'])
262
263         );
264
265         $parents_arr = array();
266         $parents_str = '';
267
268         if(count($r)) {
269                 foreach($r as $rr)
270                         $parents_arr[] = $rr['item_id'];
271                 $parents_str = implode(', ', $parents_arr);
272  
273                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
274                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`, 
275                         `contact`.`thumb`, `contact`.`self`, 
276                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
277                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
278                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
279                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
280                         AND `item`.`parent` IN ( %s )
281                         $sql_extra
282                         ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ",
283                         intval($a->profile['profile_uid']),
284                         dbesc($parents_str)
285                 );
286         }
287
288         if($is_owner && ! $update)
289                 $o .= get_birthdays();
290
291         $cmnt_tpl = load_view_file('view/comment_item.tpl');
292
293         $like_tpl = load_view_file('view/like.tpl');
294         $noshare_tpl = load_view_file('view/like_noshare.tpl');
295
296         $tpl = load_view_file('view/wall_item.tpl');
297
298         $droptpl = load_view_file('view/wall_item_drop.tpl');
299         $fakedrop = load_view_file('view/wall_fake_drop.tpl');
300
301         if($update)
302                 $return_url = $_SESSION['return_url'];
303         else
304                 $return_url = $_SESSION['return_url'] = $a->cmd;
305
306         $alike = array();
307         $dlike = array();
308
309         if($r !== false && count($r)) {
310
311                 $comments = array();
312                 foreach($r as $rr) {
313                         if(intval($rr['gravity']) == 6) {
314                                 if(! x($comments,$rr['parent']))
315                                         $comments[$rr['parent']] = 1;
316                                 else
317                                         $comments[$rr['parent']] += 1;
318                         }
319                 }
320
321                 foreach($r as $item) {
322                         like_puller($a,$item,$alike,'like');
323                         like_puller($a,$item,$dlike,'dislike');
324                 }
325
326                 $comments_collapsed = false;
327
328                 foreach($r as $item) {
329
330                         $sparkle = '';          
331                         $comment = '';
332                         $likebuttons = '';
333
334                         $template = $tpl;
335                         
336                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
337
338                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
339                                 && ($item['id'] != $item['parent']))
340                                 continue;
341
342                         if($item['id'] == $item['parent']) {
343                                 $comments_seen = 0;
344                                 $comments_collapsed = false;
345                         }
346                         else
347                                 $comments_seen ++;
348
349
350                         if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
351                                 if(! $comments_collapsed) {
352                                         $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>';
353                                         $o .= '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
354                                         $comments_collapsed = true;
355                                 }
356                         }
357                         if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
358                                 $o .= '</div></div>';
359                         }
360
361                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
362                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
363                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
364                                 : '<div class="wall-item-lock"></div>');
365
366                         if(can_write_wall($a,$a->profile['profile_uid'])) {
367                                 if($item['id'] == $item['parent']) {
368                                         $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
369                                                 '$id' => $item['id'],
370                                                 '$likethis' => t("I like this \x28toggle\x29"),
371                                                 '$nolike' => t("I don't like this \x28toggle\x29"),
372                                                 '$share' => t('Share'),
373                                                 '$wait' => t('Please wait') 
374                                         ));
375                                 }
376                                 if($item['last-child']) {
377                                         $comment = replace_macros($cmnt_tpl,array(
378                                                 '$return_path' => '', 
379                                                 '$jsreload' => '', // $_SESSION['return_url'],
380                                                 '$type' => 'wall-comment',
381                                                 '$id' => $item['item_id'],
382                                                 '$parent' => $item['parent'],
383                                                 '$profile_uid' =>  $a->profile['profile_uid'],
384                                                 '$mylink' => $contact['url'],
385                                                 '$mytitle' => t('This is you'),
386                                                 '$myphoto' => $contact['thumb'],
387                                                 '$comment' => t('Comment'),
388                                                 '$submit' => t('Submit'),
389                                                 '$ww' => ''
390                                         ));
391                                 }
392                         }
393
394
395                         $profile_url = $item['url'];
396
397                         // 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,
398                         // I can go directly to their profile as an authenticated guest.
399
400                         if(local_user() && ($item['contact-uid'] == local_user()) 
401                                 && ($item['network'] === 'dfrn') && (! $item['self'] )) {
402                                 $profile_url = $redirect_url;
403                                 $sparkle = ' sparkle';
404                         }
405                         else
406                                 $sparkle = '';
407
408
409                         $edpost = '';
410                         if((local_user()) && ($a->profile['profile_uid'] == local_user()) && ($item['id'] == $item['parent']) && (intval($item['wall']) == 1)) 
411                                 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
412
413
414                         // We would prefer to use our own avatar link for this item because the one in the author-avatar might reference a 
415                         // remote site (which could be down). We will use author-avatar if we haven't got something stored locally.
416                         // 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 
417                         // local contact info at all. In this module you should never encounter a third-party author, but we still will do
418                         // the right thing if you ever do. 
419
420                         $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
421
422                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
423                         $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
424
425                         $profile_link = $profile_url;
426
427                         $drop = '';
428                         $dropping = false;
429
430                         if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
431                                 $dropping = true;
432
433                         $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
434
435
436                         $like    = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
437                         $dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
438                         $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
439                         $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
440                         if($coord) {
441                                 if($location)
442                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
443                                 else
444                                         $location = '<span class="smalltext">' . $coord . '</span>';
445                         }
446
447                         $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
448
449                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
450                                 $indent .= ' shiny'; 
451
452
453                         $tmp_item = replace_macros($template,array(
454                                 '$id' => $item['item_id'],
455                                 '$linktitle' => t('View $name\'s profile'),
456                                 '$profile_url' => $profile_link,
457                                 '$item_photo_menu' => item_photo_menu($item),                           
458                                 '$name' => $profile_name,
459                                 '$thumb' => $profile_avatar,
460                                 '$sparkle' => $sparkle,
461                                 '$title' => $item['title'],
462                                 '$body' => smilies(bbcode($item['body'])),
463                                 '$ago' => relative_date($item['created']),
464                                 '$lock' => $lock,
465                                 '$location' => $location, 
466                                 '$indent' => $indent, 
467                                 '$plink' => get_plink($item),
468                                 '$edpost' => $edpost,
469                                 '$drop' => $drop,
470                                 '$like' => $like,
471                                 '$vote' => $likebuttons,
472                                 '$dislike' => $dislike,
473                                 '$comment' => $comment
474                         ));
475
476                         $arr = array('item' => $item, 'output' => $tmp_item);
477                         call_hooks('display_item', $arr);
478
479                         $o .= $arr['output'];
480                         
481                 }
482         }
483
484         if($update) {
485                 return $o;
486         }
487                 
488         $o .= paginate($a);
489         $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>';
490
491         return $o;
492 }