]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
2ac8fe586deefa181f5c27463d9f5b753c6e25be
[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         $category = $datequery = $datequery2 = '';
71
72         if($a->argc > 2) {
73                 for($x = 2; $x < $a->argc; $x ++) {
74                         if(is_a_date_arg($a->argv[$x])) {
75                                 if($datequery)
76                                         $datequery2 = escape_tags($a->argv[$x]);
77                                 else
78                                         $datequery = escape_tags($a->argv[$x]);
79                         }
80                         else
81                                 $category = $a->argv[$x];
82                 }
83         }
84
85         if(! x($category)) {
86                 $category = ((x($_GET,'category')) ? $_GET['category'] : '');
87         }
88
89         if(get_config('system','block_public') && (! local_user()) && (! remote_user())) {
90                 return login();
91         }
92
93         require_once("include/bbcode.php");
94         require_once('include/security.php');
95         require_once('include/conversation.php');
96         require_once('include/acl_selectors.php');
97         $groups = array();
98
99         $tab = 'posts';
100         $o = '';
101
102         if($update) {
103                 // Ensure we've got a profile owner if updating.
104                 $a->profile['profile_uid'] = $update;
105         }
106         else {
107                 if($a->profile['profile_uid'] == local_user()) {
108                         nav_set_selected('home');
109                 }
110         }
111
112
113         $contact = null;
114         $remote_contact = false;
115
116         if(remote_user()) {
117                 $contact_id = $_SESSION['visitor_id'];
118                 $groups = init_groups_visitor($contact_id);
119                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
120                         intval($contact_id),
121                         intval($a->profile['profile_uid'])
122                 );
123                 if(count($r)) {
124                         $contact = $r[0];
125                         $remote_contact = true;
126                 }
127         }
128
129         if(! $remote_contact) {
130                 if(local_user()) {
131                         $contact_id = $_SESSION['cid'];
132                         $contact = $a->contact;
133                 }
134         }
135
136         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
137
138         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
139                 notice( t('Access to this profile has been restricted.') . EOL);
140                 return;
141         }
142
143         if(! $update) {
144
145
146                 if(x($_GET,'tab'))
147                         $tab = notags(trim($_GET['tab']));
148
149                 $o.=profile_tabs($a, $is_owner, $a->profile['nickname']);
150
151
152                 if($tab === 'profile') {
153                         require_once('include/profile_advanced.php');
154                         $o .= advanced_profile($a);
155                         call_hooks('profile_advanced',$o);
156                         return $o;
157                 }
158
159
160                 $o .= common_friends_visitor_widget($a->profile['profile_uid']);
161
162
163                 if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
164                         $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
165
166                 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
167                 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
168
169                 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
170
171                 $a->page['aside'] .= categories_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'],(x($category) ? xmlify($category) : ''));
172
173                 if(can_write_wall($a,$a->profile['profile_uid'])) {
174
175                         $x = array(
176                                 'is_owner' => $is_owner,
177                 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
178                     'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
179                 'nickname' => $a->profile['nickname'],
180                     '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'),
181                 'acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
182                     'bang' => '',
183                 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
184                     'profile_uid' => $a->profile['profile_uid']
185                 );
186
187                 $o .= status_editor($a,$x);
188                 }
189
190         }
191
192
193         /**
194          * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
195          */
196
197         $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
198
199
200         if($update) {
201
202                 $r = q("SELECT distinct(parent) AS `item_id`, `contact`.`uid` AS `contact-uid`
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 `item`.`moderated` = 0 and `item`.`unseen` = 1
206                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
207                         AND `item`.`wall` = 1
208                         $sql_extra
209                         ORDER BY `item`.`created` DESC",
210                         intval($a->profile['profile_uid'])
211                 );
212
213         }
214         else {
215
216                 if(x($category)) {
217                         $sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
218                 }
219
220                 if($datequery) {
221                         $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert('','',$datequery))));
222                 }
223                 if($datequery2) {
224                         $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert('','',$datequery2))));
225                 }
226
227
228                 $r = q("SELECT COUNT(*) AS `total`
229                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
230                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
231                         and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
232                         AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
233                         $sql_extra $sql_extra2 ",
234                         intval($a->profile['profile_uid'])
235                 );
236
237                 if(count($r)) {
238                         $a->set_pager_total($r[0]['total']);
239                         $a->set_pager_itemspage(40);
240                 }
241
242                 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
243
244                 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
245                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
246                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
247                         and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
248                         AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
249                         $sql_extra $sql_extra2
250                         ORDER BY `item`.`created` DESC $pager_sql ",
251                         intval($a->profile['profile_uid'])
252
253                 );
254
255         }
256
257         $parents_arr = array();
258         $parents_str = '';
259
260         if(count($r)) {
261                 foreach($r as $rr)
262                         $parents_arr[] = $rr['item_id'];
263                 $parents_str = implode(', ', $parents_arr);
264  
265                 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
266                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`, 
267                         `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
268                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
269                         FROM `item`, `contact`
270                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
271                         and `item`.`moderated` = 0
272                         AND `contact`.`id` = `item`.`contact-id`
273                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
274                         AND `item`.`parent` IN ( %s )
275                         $sql_extra ",
276                         intval($a->profile['profile_uid']),
277                         dbesc($parents_str)
278                 );
279                 
280                 $items = conv_sort($items,'created');
281         } else {
282                 $items = array();
283         }
284
285         if($is_owner && ! $update) {
286                 $o .= get_birthdays();
287                 $o .= get_events();
288         }
289
290         if((! $update) && ($tab === 'posts')) {
291
292                 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
293                 // because browser prefetching might change it on us. We have to deliver it with the page.
294
295                 $o .= '<div id="live-profile"></div>' . "\r\n";
296                 $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] 
297                         . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
298         }
299
300
301         if($is_owner) {
302                 $r = q("UPDATE `item` SET `unseen` = 0 
303                         WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d",
304                         intval(local_user())
305                 );
306         }
307
308         $o .= conversation($a,$items,'profile',$update);
309
310         if(! $update) {
311                 $o .= paginate($a);
312         }
313
314         return $o;
315 }