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