]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
Merge branch 'master' of git://github.com/friendika/friendika
[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                 return login();
56         }
57
58         require_once("include/bbcode.php");
59         require_once('include/security.php');
60         require_once('include/conversation.php');
61         require_once('include/acl_selectors.php');
62         $groups = array();
63
64         $tab = 'posts';
65         $o = '';
66
67         if($update) {
68                 // Ensure we've got a profile owner if updating.
69                 $a->profile['profile_uid'] = $update;
70         }
71         else {
72                 if($a->profile['profile_uid'] == local_user())          
73                         $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
74         }
75
76         $contact = null;
77         $remote_contact = false;
78
79         if(remote_user()) {
80                 $contact_id = $_SESSION['visitor_id'];
81                 $groups = init_groups_visitor($contact_id);
82                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
83                         intval($contact_id),
84                         intval($a->profile['profile_uid'])
85                 );
86                 if(count($r)) {
87                         $contact = $r[0];
88                         $remote_contact = true;
89                 }
90         }
91
92         if(! $remote_contact) {
93                 if(local_user()) {
94                         $contact_id = $_SESSION['cid'];
95                         $contact = $a->contact;
96                 }
97         }
98
99         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
100
101         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
102                 notice( t('Access to this profile has been restricted.') . EOL);
103                 return;
104         }
105
106         
107         if(! $update) {
108                 if(x($_GET,'tab'))
109                         $tab = notags(trim($_GET['tab']));
110
111                 $tpl = get_markup_template('profile_tabs.tpl');
112
113                 $o .= replace_macros($tpl,array(
114                         '$url' => $a->get_baseurl() . '/' . $a->cmd,
115                         '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname'],
116                         '$status' => t('Status'),
117                         '$profile' => t('Profile'),
118                         '$photos' => t('Photos'),
119                         '$events' => (($is_owner) ? t('Events') : ''),
120                         '$notes' => (($is_owner) ?      t('Personal Notes') : ''),
121                         '$activetab' => $tab,
122                 ));
123
124
125                 if($tab === 'profile') {
126                         require_once('include/profile_advanced.php');
127                         $o .= advanced_profile($a);
128                         call_hooks('profile_advanced',$o);
129                         return $o;
130                 }
131
132                 if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
133                         $o .= '<a href="newmember">' . t('Tips for New Members') . '</a>' . EOL;
134
135                 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
136                 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
137
138                 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
139
140                 if(can_write_wall($a,$a->profile['profile_uid'])) {
141
142                         $x = array(
143                                 'is_owner' => $is_owner,
144                 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
145                     'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
146                 'nickname' => $a->profile['nickname'],
147                     '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'),
148                 'acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
149                     'bang' => '',
150                 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
151                     'profile_uid' => $a->profile['profile_uid']
152                 );
153
154                 $o .= status_editor($a,$x);
155                 }
156
157                 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
158                 // because browser prefetching might change it on us. We have to deliver it with the page.
159
160                 if($tab === 'posts') {
161                         $o .= '<div id="live-profile"></div>' . "\r\n";
162                         $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] 
163                                 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
164                 }
165         }
166
167         if($is_owner) {
168                 $r = q("UPDATE `item` SET `unseen` = 0 
169                         WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d",
170                         intval(local_user())
171                 );
172         }
173
174         /**
175          * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
176          */
177
178         $sql_extra = permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
179
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 `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
191         if(count($r)) {
192                 $a->set_pager_total($r[0]['total']);
193                 $a->set_pager_itemspage(40);
194         }
195
196         $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
197                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
198                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
199                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
200                 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
201                 $sql_extra
202                 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
203                 intval($a->profile['profile_uid']),
204                 intval($a->pager['start']),
205                 intval($a->pager['itemspage'])
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                 $r = 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`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent` = `p`.`id`) AS `parentitem`, `contact`
222                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
223                         AND `contact`.`id` = `item`.`contact-id`
224                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
225                         AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
226                         $sql_extra
227                         ORDER BY `parentitem`.`created` DESC, `gravity` ASC, `item`.`created` ASC ",
228                         intval($a->profile['profile_uid']),
229                         dbesc($parents_str)
230                 );
231         }
232
233         if($is_owner && ! $update)
234                 $o .= get_birthdays();
235
236         $o .= conversation($a,$r,'profile',$update);
237
238         if(! $update) {
239                 
240                 $o .= paginate($a);
241                 $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>';
242         }
243
244         return $o;
245 }