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