]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
46d13298e004e6eb22c35f1401be1f6c41f4437d
[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,'openidserver'))                               
22                 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
23         if(x($a->profile,'openid')) {
24                 $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
25                 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
26         }
27
28         $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
29         $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
30         $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
31         $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
32         header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
33         
34         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
35         foreach($dfrn_pages as $dfrn)
36                 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
37
38 }
39
40
41 function profile_content(&$a, $update = 0) {
42
43         require_once("include/bbcode.php");
44         require_once('include/security.php');
45
46         $groups = array();
47
48         $tab = 'posts';
49         $o = '';
50
51         if($update) {
52                 // Ensure we've got a profile owner if updating.
53                 $a->profile['profile_uid'] = $update;
54         }
55         else {
56                 if($a->profile['profile_uid'] == local_user())          
57                         $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
58         }
59
60         $contact = null;
61         $remote_contact = false;
62
63         if(remote_user()) {
64                 $contact_id = $_SESSION['visitor_id'];
65                 $groups = init_groups_visitor($contact_id);
66                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
67                         intval($contact_id),
68                         intval($a->profile['profile_uid'])
69                 );
70                 if(count($r)) {
71                         $contact = $r[0];
72                         $remote_contact = true;
73                 }
74         }
75
76         if(! $remote_contact) {
77                 if(local_user()) {
78                         $contact_id = $_SESSION['cid'];
79                         $contact = $a->contact;
80                 }
81         }
82
83         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
84         
85         if(! $update) {
86                 if(x($_GET,'tab'))
87                         $tab = notags(trim($_GET['tab']));
88
89                 $tpl = load_view_file('view/profile_tabs.tpl');
90
91                 $o .= replace_macros($tpl,array(
92                         '$url' => $a->get_baseurl() . '/' . $a->cmd,
93                         '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname']
94                 ));
95
96
97                 if($tab === 'profile') {
98                         $profile_lang = get_config('system','language');
99                         if(! $profile_lang)
100                                 $profile_lang = 'en';
101                         if(file_exists("view/$profile_lang/profile_advanced.php"))
102                                 require_once("view/$profile_lang/profile_advanced.php");
103                         else
104                                 require_once('view/profile_advanced.php');
105
106                         call_hooks('profile_advanced',$o);
107
108                         return $o;
109                 }
110
111                 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
112                 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
113
114                 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
115
116                 if(can_write_wall($a,$a->profile['profile_uid'])) {
117
118                         $geotag = ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
119
120                         $tpl = load_view_file('view/jot-header.tpl');
121         
122                         $a->page['htmlhead'] .= replace_macros($tpl, array(
123                                 '$baseurl' => $a->get_baseurl(),
124                                 '$geotag'  => $geotag,
125                                 '$nickname' => $a->profile['nickname']
126                         ));
127
128                         require_once('include/acl_selectors.php');
129
130                         $tpl = load_view_file('view/jot.tpl');
131
132                         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']))))
133                                 $lockstate = 'lock';
134                         else
135                                 $lockstate = 'unlock';
136        
137                         $jotplugins = '';
138                         $jotnets = '';
139                         call_hooks('jot_tool', $jotplugins); 
140
141                         call_hooks('jot_networks', $jotnets);
142
143                         $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
144
145                         $o .= replace_macros($tpl,array(
146                                 '$baseurl' => $a->get_baseurl(),
147                                 '$defloc' => (($is_owner) ? $a->user['default-location'] : ''),
148                                 '$return_path' => $a->cmd,
149                                 '$visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
150                                 '$lockstate' => $lockstate,
151                                 '$emailcc' => t('CC: email addresses'),
152                                 '$jotnets' => $jotnets,
153                                 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
154                                 '$bang' => '',
155                                 '$acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
156                                 '$profile_uid' => $a->profile['profile_uid']
157                         ));
158                 }
159
160                 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
161                 // because browser prefetching might change it on us. We have to deliver it with the page.
162
163                 if($tab === 'posts') {
164                         $o .= '<div id="live-profile"></div>' . "\r\n";
165                         $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] 
166                                 . "; var netargs = ''; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
167                 }
168         }
169
170         // Construct permissions
171
172         // default permissions - anonymous user
173
174         $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
175
176         // Profile owner - everything is visible
177
178         if($is_owner) {
179                 $sql_extra = ''; 
180                 
181                 // Oh - while we're here... reset the Unseen messages
182
183                 $r = q("UPDATE `item` SET `unseen` = 0 
184                         WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
185                         intval($_SESSION['uid'])
186                 );
187
188         }
189
190         // authenticated visitor - here lie dragons
191         // If $remotecontact is true, we know that not only is this a remotely authenticated
192         // person, but that it is *our* contact, which is important in multi-user mode.
193
194         elseif($remote_contact) {
195                 $gs = '<<>>'; // should be impossible to match
196                 if(count($groups)) {
197                         foreach($groups as $g)
198                                 $gs .= '|<' . intval($g) . '>';
199                 } 
200                 $sql_extra = sprintf(
201                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
202                           AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
203                           AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
204                           AND ( `deny_gid`  = '' OR NOT `deny_gid` REGEXP '%s') ",
205
206                         intval($_SESSION['visitor_id']),
207                         intval($_SESSION['visitor_id']),
208                         dbesc($gs),
209                         dbesc($gs)
210                 );
211         }
212
213         $r = q("SELECT COUNT(*) AS `total`
214                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
215                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
216                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
217                 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
218                 $sql_extra ",
219                 intval($a->profile['profile_uid'])
220
221         );
222
223         if(count($r))
224                 $a->set_pager_total($r[0]['total']);
225
226         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
227                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`, 
228                 `contact`.`thumb`, `contact`.`self`, 
229                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
230                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
231                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
232                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
233                 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
234                 $sql_extra
235                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC LIMIT %d ,%d ",
236                 intval($a->profile['profile_uid']),
237                 intval($a->pager['start']),
238                 intval($a->pager['itemspage'])
239
240         );
241
242
243         if($is_owner && ! $update)
244                 $o .= get_birthdays();
245
246         $cmnt_tpl = load_view_file('view/comment_item.tpl');
247
248         $like_tpl = load_view_file('view/like.tpl');
249
250         $tpl = load_view_file('view/wall_item.tpl');
251
252         $droptpl = load_view_file('view/wall_item_drop.tpl');
253         $fakedrop = load_view_file('view/wall_fake_drop.tpl');
254
255         if($update)
256                 $return_url = $_SESSION['return_url'];
257         else
258                 $return_url = $_SESSION['return_url'] = $a->cmd;
259
260         $alike = array();
261         $dlike = array();
262
263         if($r !== false && count($r)) {
264
265                 foreach($r as $item) {
266                         like_puller($a,$item,$alike,'like');
267                         like_puller($a,$item,$dlike,'dislike');
268                 }
269
270                 foreach($r as $item) {
271
272                         $sparkle = '';          
273                         $comment = '';
274                         $likebuttons = '';
275
276                         $template = $tpl;
277                         
278                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
279
280                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
281                                 && ($item['id'] != $item['parent']))
282                                 continue;
283
284                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
285                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
286                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
287                                 : '<div class="wall-item-lock"></div>');
288
289                         if(can_write_wall($a,$a->profile['profile_uid'])) {
290                                 if($item['id'] == $item['parent']) {
291                                         $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
292                                 }
293                                 if($item['last-child']) {
294                                         $comment = replace_macros($cmnt_tpl,array(
295                                                 '$return_path' => '', 
296                                                 '$jsreload' => '', // $_SESSION['return_url'],
297                                                 '$type' => 'wall-comment',
298                                                 '$id' => $item['item_id'],
299                                                 '$parent' => $item['parent'],
300                                                 '$profile_uid' =>  $a->profile['profile_uid'],
301                                                 '$mylink' => $contact['url'],
302                                                 '$mytitle' => t('This is you'),
303                                                 '$myphoto' => $contact['thumb'],
304                                                 '$ww' => ''
305                                         ));
306                                 }
307                         }
308
309
310                         $profile_url = $item['url'];
311
312                         // 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,
313                         // I can go directly to their profile as an authenticated guest.
314
315                         if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) 
316                                 && ($item['network'] === 'dfrn') && (! $item['self'] )) {
317                                 $profile_url = $redirect_url;
318                                 $sparkle = ' sparkle';
319                         }
320                         else
321                                 $sparkle = '';
322
323                         // We would prefer to use our own avatar link for this item because the one in the author-avatar might reference a 
324                         // remote site (which could be down). We will use author-avatar if we haven't got something stored locally.
325                         // 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 
326                         // local contact info at all. In this module you should never encounter a third-party author, but we still will do
327                         // the right thing if you ever do. 
328
329                         $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
330
331                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
332                         $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
333
334                         $profile_link = $profile_url;
335
336                         $drop = '';
337                         $dropping = false;
338
339                         if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
340                                 $dropping = true;
341
342                         $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id']));
343
344
345                         $like    = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
346                         $dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
347                         $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
348                         $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
349                         if($coord) {
350                                 if($location)
351                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
352                                 else
353                                         $location = '<span class="smalltext">' . $coord . '</span>';
354                         }
355
356                         $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
357
358                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
359                                 $indent .= ' shiny'; 
360
361                         $tmp_item = replace_macros($template,array(
362                                 '$id' => $item['item_id'],
363                                 '$title' => t('View $name\'s profile'),
364                                 '$profile_url' => $profile_link,
365                                 '$name' => $profile_name,
366                                 '$thumb' => $profile_avatar,
367                                 '$sparkle' => $sparkle,
368                                 '$title' => $item['title'],
369                                 '$body' => smilies(bbcode($item['body'])),
370                                 '$ago' => relative_date($item['created']),
371                                 '$lock' => $lock,
372                                 '$location' => $location, 
373                                 '$indent' => $indent, 
374                                 '$plink' => get_plink($item),
375                                 '$drop' => $drop,
376                                 '$like' => $like,
377                                 '$vote' => $likebuttons,
378                                 '$dislike' => $dislike,
379                                 '$comment' => $comment
380                         ));
381
382                         $arr = array('item' => $item, 'output' => $tmp_item);
383                         call_hooks('display_item', $arr);
384
385                         $o .= $arr['output'];
386                         
387                 }
388         }
389
390         if($update) {
391                 return $o;
392         }
393                 
394         $o .= paginate($a);
395         $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>';
396
397
398         return $o;
399 }