]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
multi-user, do not cache open mbox
[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         if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] & PAGE_COMMUNITY)) {
22                 $a->page['htmlhead'] .= '<meta name="friendika.community" content="true" />';
23         }
24         if(x($a->profile,'openidserver'))                               
25                 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
26         if(x($a->profile,'openid')) {
27                 $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
28                 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
29         }
30
31         $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
32         $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords);
33         if(strlen($keywords))
34                 $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
35
36         $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
37         $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
38         $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
39         $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
40         header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
41         
42         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
43         foreach($dfrn_pages as $dfrn)
44                 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
45
46 }
47
48
49 function profile_content(&$a, $update = 0) {
50
51         require_once("include/bbcode.php");
52         require_once('include/security.php');
53         require_once('include/conversation.php');
54
55         $groups = array();
56
57         $tab = 'posts';
58         $o = '';
59
60         if($update) {
61                 // Ensure we've got a profile owner if updating.
62                 $a->profile['profile_uid'] = $update;
63         }
64         else {
65                 if($a->profile['profile_uid'] == local_user())          
66                         $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
67         }
68
69         $contact = null;
70         $remote_contact = false;
71
72         if(remote_user()) {
73                 $contact_id = $_SESSION['visitor_id'];
74                 $groups = init_groups_visitor($contact_id);
75                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
76                         intval($contact_id),
77                         intval($a->profile['profile_uid'])
78                 );
79                 if(count($r)) {
80                         $contact = $r[0];
81                         $remote_contact = true;
82                 }
83         }
84
85         if(! $remote_contact) {
86                 if(local_user()) {
87                         $contact_id = $_SESSION['cid'];
88                         $contact = $a->contact;
89                 }
90         }
91
92         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
93         
94         if(! $update) {
95                 if(x($_GET,'tab'))
96                         $tab = notags(trim($_GET['tab']));
97
98                 $tpl = load_view_file('view/profile_tabs.tpl');
99
100                 $o .= replace_macros($tpl,array(
101                         '$url' => $a->get_baseurl() . '/' . $a->cmd,
102                         '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname'],
103                         '$status' => t('Status'),
104                         '$profile' => t('Profile'),
105                         '$photos' => t('Photos')
106                 ));
107
108
109                 if($tab === 'profile') {
110                         require_once('include/profile_advanced.php');
111                         $o .= advanced_profile($a);
112                         call_hooks('profile_advanced',$o);
113                         return $o;
114                 }
115
116                 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
117                 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
118
119                 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
120
121                 if(can_write_wall($a,$a->profile['profile_uid'])) {
122
123                         $geotag = ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
124
125                         $tpl = load_view_file('view/jot-header.tpl');
126         
127                         $a->page['htmlhead'] .= replace_macros($tpl, array(
128                                 '$baseurl' => $a->get_baseurl(),
129                                 '$geotag'  => $geotag,
130                                 '$nickname' => $a->profile['nickname'],
131                                 '$linkurl' => t('Please enter a link URL:'),
132                                 '$utubeurl' => t('Please enter a YouTube link:'),
133                                 '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
134                                 '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
135                                 '$whereareu' => t('Where are you right now?'),
136                                 '$title' => t('Enter a title for this item') 
137                         ));
138
139                         require_once('include/acl_selectors.php');
140
141                         $tpl = load_view_file('view/jot.tpl');
142
143                         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']))))
144                                 $lockstate = 'lock';
145                         else
146                                 $lockstate = 'unlock';
147        
148                         $jotplugins = '';
149                         $jotnets = '';
150
151                         $mail_enabled = false;
152                         $pubmail_enabled = false;
153
154                         if($is_owner) {
155                                 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
156                                         intval(local_user())
157                                 );
158                                 if(count($r)) {
159                                         $mail_enabled = true;
160                                         if(intval($r[0]['pubmail']))
161                                                 $pubmail_enabled = true;
162                                 }
163                         }
164                         if($mail_enabled) {
165                        $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
166                                 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
167                 . t("Post to Email") . '</div>';
168                         }
169                                         
170                         call_hooks('jot_tool', $jotplugins); 
171
172                         call_hooks('jot_networks', $jotnets);
173
174                         $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
175
176                         $o .= replace_macros($tpl,array(
177                                 '$baseurl' => $a->get_baseurl(),
178                                 '$action' => 'item',
179                                 '$share' => t('Share'),
180                                 '$upload' => t('Upload photo'),
181                                 '$weblink' => t('Insert web link'),
182                                 '$youtube' => t('Insert YouTube video'),
183                                 '$video' => t('Insert Vorbis [.ogg] video'),
184                                 '$audio' => t('Insert Vorbis [.ogg] audio'),
185                                 '$setloc' => t('Set your location'),
186                                 '$noloc' => t('Clear browser location'),
187                                 '$title' => t('Set title'),
188                                 '$wait' => t('Please wait'),
189                                 '$permset' => t('Permission settings'),
190                                 '$content' => '',
191                                 '$post_id' => '',
192                                 '$defloc' => (($is_owner) ? $a->user['default-location'] : ''),
193                                 '$return_path' => $a->cmd,
194                                 '$visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
195                                 '$lockstate' => $lockstate,
196                                 '$emailcc' => t('CC: email addresses'),
197                                 '$jotnets' => $jotnets,
198                                 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
199                                 '$bang' => '',
200                                 '$acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
201                                 '$profile_uid' => $a->profile['profile_uid']
202                         ));
203                 }
204
205                 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
206                 // because browser prefetching might change it on us. We have to deliver it with the page.
207
208                 if($tab === 'posts') {
209                         $o .= '<div id="live-profile"></div>' . "\r\n";
210                         $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] 
211                                 . "; var netargs = ''; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
212                 }
213         }
214
215         // Construct permissions
216
217         // default permissions - anonymous user
218
219         $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
220
221         // Profile owner - everything is visible
222
223         if($is_owner) {
224                 $sql_extra = ''; 
225                 
226                 // Oh - while we're here... reset the Unseen messages
227
228                 $r = q("UPDATE `item` SET `unseen` = 0 
229                         WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
230                         intval($_SESSION['uid'])
231                 );
232
233         }
234
235         // authenticated visitor - here lie dragons
236         // If $remotecontact is true, we know that not only is this a remotely authenticated
237         // person, but that it is *our* contact, which is important in multi-user mode.
238
239         elseif($remote_contact) {
240                 $gs = '<<>>'; // should be impossible to match
241                 if(count($groups)) {
242                         foreach($groups as $g)
243                                 $gs .= '|<' . intval($g) . '>';
244                 } 
245                 $sql_extra = sprintf(
246                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
247                           AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
248                           AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
249                           AND ( `deny_gid`  = '' OR NOT `deny_gid` REGEXP '%s') ",
250
251                         intval($_SESSION['visitor_id']),
252                         intval($_SESSION['visitor_id']),
253                         dbesc($gs),
254                         dbesc($gs)
255                 );
256         }
257
258         $r = q("SELECT COUNT(*) AS `total`
259                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
260                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
261                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
262                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
263                 $sql_extra ",
264                 intval($a->profile['profile_uid'])
265
266         );
267
268         if(count($r)) {
269                 $a->set_pager_total($r[0]['total']);
270                 $a->set_pager_itemspage(40);
271         }
272
273         $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
274                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
275                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
276                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
277                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
278                 $sql_extra
279                 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
280                 intval($a->profile['profile_uid']),
281                 intval($a->pager['start']),
282                 intval($a->pager['itemspage'])
283
284         );
285
286         $parents_arr = array();
287         $parents_str = '';
288
289         if(count($r)) {
290                 foreach($r as $rr)
291                         $parents_arr[] = $rr['item_id'];
292                 $parents_str = implode(', ', $parents_arr);
293  
294                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
295                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`, 
296                         `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
297                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
298                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
299                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
300                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
301                         AND `item`.`parent` IN ( %s )
302                         $sql_extra
303                         ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ",
304                         intval($a->profile['profile_uid']),
305                         dbesc($parents_str)
306                 );
307         }
308
309         if($is_owner && ! $update)
310                 $o .= get_birthdays();
311
312
313
314         $o .= conversation($a,$r,'profile',$update);
315
316
317         if(! $update) {
318                 
319                 $o .= paginate($a);
320                 $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
321         }
322
323         return $o;
324 }