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