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