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