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