]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
missing salmon key? report it.
[friendica.git] / mod / profile.php
1 <?php
2
3 function profile_init(&$a) {
4
5         $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
6
7         if($a->argc > 1)
8                 $which = $a->argv[1];
9         else {
10                 notice( t('No profile') . EOL );
11                 $a->error = 404;
12                 return;
13         }
14
15         $profile = 0;
16         if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
17                 $which = $a->user['nickname'];
18                 $profile = $a->argv[1];         
19         }
20
21         profile_load($a,$which,$profile);
22
23         if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) {
24                 $a->page['htmlhead'] .= '<meta name="friendika.community" content="true" />';
25         }
26         if(x($a->profile,'openidserver'))                               
27                 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
28         if(x($a->profile,'openid')) {
29                 $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
30                 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
31         }
32
33         if(! $blocked) {
34                 $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
35                 $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords);
36                 if(strlen($keywords))
37                         $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
38         }
39
40         $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
41         $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
42         $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
43         $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
44         header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
45         
46         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
47         foreach($dfrn_pages as $dfrn)
48                 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
49
50 }
51
52
53 function profile_content(&$a, $update = 0) {
54
55         if(get_config('system','block_public') && (! local_user()) && (! remote_user())) {
56                 return login();
57         }
58
59         require_once("include/bbcode.php");
60         require_once('include/security.php');
61         require_once('include/conversation.php');
62         require_once('include/acl_selectors.php');
63         $groups = array();
64
65         $tab = 'posts';
66         $o = '';
67
68         if($update) {
69                 // Ensure we've got a profile owner if updating.
70                 $a->profile['profile_uid'] = $update;
71         }
72         else {
73                 if($a->profile['profile_uid'] == local_user())          
74                         $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
75         }
76
77         $contact = null;
78         $remote_contact = false;
79
80         if(remote_user()) {
81                 $contact_id = $_SESSION['visitor_id'];
82                 $groups = init_groups_visitor($contact_id);
83                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
84                         intval($contact_id),
85                         intval($a->profile['profile_uid'])
86                 );
87                 if(count($r)) {
88                         $contact = $r[0];
89                         $remote_contact = true;
90                 }
91         }
92
93         if(! $remote_contact) {
94                 if(local_user()) {
95                         $contact_id = $_SESSION['cid'];
96                         $contact = $a->contact;
97                 }
98         }
99
100         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
101
102         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
103                 notice( t('Access to this profile has been restricted.') . EOL);
104                 return;
105         }
106
107         
108         if(! $update) {
109                 if(x($_GET,'tab'))
110                         $tab = notags(trim($_GET['tab']));
111
112                 $tpl = get_markup_template('profile_tabs.tpl');
113
114                 $o .= replace_macros($tpl,array(
115                         '$url' => $a->get_baseurl() . '/' . $a->cmd,
116                         '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname'],
117                         '$status' => t('Status'),
118                         '$profile' => t('Profile'),
119                         '$photos' => t('Photos'),
120                         '$events' => (($is_owner) ? t('Events') : ''),
121                         '$notes' => (($is_owner) ?      t('Personal Notes') : ''),
122                         '$activetab' => $tab,
123                 ));
124
125
126                 if($tab === 'profile') {
127                         require_once('include/profile_advanced.php');
128                         $o .= advanced_profile($a);
129                         call_hooks('profile_advanced',$o);
130                         return $o;
131                 }
132
133                 if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
134                         $o .= '<a href="newmember">' . t('Tips for New Members') . '</a>' . EOL;
135
136                 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
137                 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
138
139                 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
140
141                 if(can_write_wall($a,$a->profile['profile_uid'])) {
142
143                         $x = array(
144                                 'is_owner' => $is_owner,
145                 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
146                     'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
147                 'nickname' => $a->profile['nickname'],
148                     'lockstate' => (((is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
149                 'acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
150                     'bang' => '',
151                 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
152                     'profile_uid' => $a->profile['profile_uid']
153                 );
154
155                 $o .= status_editor($a,$x);
156                 }
157
158                 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
159                 // because browser prefetching might change it on us. We have to deliver it with the page.
160
161                 if($tab === 'posts') {
162                         $o .= '<div id="live-profile"></div>' . "\r\n";
163                         $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] 
164                                 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
165                 }
166         }
167
168         if($is_owner) {
169                 $r = q("UPDATE `item` SET `unseen` = 0 
170                         WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d",
171                         intval(local_user())
172                 );
173         }
174
175         /**
176          * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
177          */
178
179         $sql_extra = permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
180
181
182         $r = q("SELECT COUNT(*) AS `total`
183                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
184                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
185                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
186                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
187                 $sql_extra ",
188                 intval($a->profile['profile_uid'])
189
190         );
191
192         if(count($r)) {
193                 $a->set_pager_total($r[0]['total']);
194                 $a->set_pager_itemspage(40);
195         }
196
197         $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
198                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
199                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
200                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
201                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
202                 $sql_extra
203                 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
204                 intval($a->profile['profile_uid']),
205                 intval($a->pager['start']),
206                 intval($a->pager['itemspage'])
207
208         );
209
210         $parents_arr = array();
211         $parents_str = '';
212
213         if(count($r)) {
214                 foreach($r as $rr)
215                         $parents_arr[] = $rr['item_id'];
216                 $parents_str = implode(', ', $parents_arr);
217  
218                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
219                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`, 
220                         `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
221                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
222                         FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent` = `p`.`id`) AS `parentitem`, `contact`
223                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
224                         AND `contact`.`id` = `item`.`contact-id`
225                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
226                         AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
227                         $sql_extra
228                         ORDER BY `parentitem`.`created` DESC, `gravity` ASC, `item`.`created` ASC ",
229                         intval($a->profile['profile_uid']),
230                         dbesc($parents_str)
231                 );
232         }
233
234         if($is_owner && ! $update)
235                 $o .= get_birthdays();
236
237         $o .= conversation($a,$r,'profile',$update);
238
239         if(! $update) {
240                 $o .= paginate($a);
241                 $o .= cc_license();
242         }
243
244         return $o;
245 }