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