]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
allow users to set categories on their posts
[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                         $which = $r[0]['nickname'];
18                 }
19                 else {
20                         notice( t('Requested profile is not available.') . EOL );
21                         $a->error = 404;
22                         return;
23                 }
24         }
25
26         $profile = 0;
27         if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
28                 $which = $a->user['nickname'];
29                 $profile = $a->argv[1];         
30         }
31
32         profile_load($a,$which,$profile);
33
34         if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) {
35                 $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
36         }
37         if(x($a->profile,'openidserver'))                               
38                 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
39         if(x($a->profile,'openid')) {
40                 $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
41                 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
42         }
43
44         if(! $blocked) {
45                 $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
46                 $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
47                 if(strlen($keywords))
48                         $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
49         }
50
51         $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
52         $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
53         $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
54         $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
55         header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
56         
57         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
58         foreach($dfrn_pages as $dfrn)
59                 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
60         $a->page['htmlhead'] .= "<link rel=\"dfrn-poco\" href=\"".$a->get_baseurl()."/poco/{$which}\" />\r\n";
61
62 }
63
64
65 function profile_content(&$a, $update = 0) {
66
67         if (x($a->category)) {
68                 $category = $a->category;
69         }
70         else {
71                 $category = ((x($_GET,'category')) ? $_GET['category'] : '');
72         }
73
74         if(get_config('system','block_public') && (! local_user()) && (! remote_user())) {
75                 return login();
76         }
77
78         require_once("include/bbcode.php");
79         require_once('include/security.php');
80         require_once('include/conversation.php');
81         require_once('include/acl_selectors.php');
82         $groups = array();
83
84         $tab = 'posts';
85         $o = '';
86
87         if($update) {
88                 // Ensure we've got a profile owner if updating.
89                 $a->profile['profile_uid'] = $update;
90         }
91         else {
92                 if($a->profile['profile_uid'] == local_user()) {
93                         nav_set_selected('home');
94                 }
95         }
96
97         $contact = null;
98         $remote_contact = false;
99
100         if(remote_user()) {
101                 $contact_id = $_SESSION['visitor_id'];
102                 $groups = init_groups_visitor($contact_id);
103                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
104                         intval($contact_id),
105                         intval($a->profile['profile_uid'])
106                 );
107                 if(count($r)) {
108                         $contact = $r[0];
109                         $remote_contact = true;
110                 }
111         }
112
113         if(! $remote_contact) {
114                 if(local_user()) {
115                         $contact_id = $_SESSION['cid'];
116                         $contact = $a->contact;
117                 }
118         }
119
120         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
121
122         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
123                 notice( t('Access to this profile has been restricted.') . EOL);
124                 return;
125         }
126
127         $a->page['aside'] .= categories_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'],(x($category) ? xmlify($category) : ''));
128
129         if(! $update) {
130                 if(x($_GET,'tab'))
131                         $tab = notags(trim($_GET['tab']));
132
133                 $o.=profile_tabs($a, $is_owner, $a->profile['nickname']);
134
135
136                 if($tab === 'profile') {
137                         require_once('include/profile_advanced.php');
138                         $o .= advanced_profile($a);
139                         call_hooks('profile_advanced',$o);
140                         return $o;
141                 }
142
143                 if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
144                         $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
145
146                 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
147                 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
148
149                 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
150
151
152                 if(can_write_wall($a,$a->profile['profile_uid'])) {
153
154                         $x = array(
155                                 'is_owner' => $is_owner,
156                 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
157                     'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
158                 'nickname' => $a->profile['nickname'],
159                     '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'),
160                 'acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
161                     'bang' => '',
162                 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
163                     'profile_uid' => $a->profile['profile_uid']
164                 );
165
166                 $o .= status_editor($a,$x);
167                 }
168
169         }
170
171
172         /**
173          * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
174          */
175
176         $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
177
178
179         if($update) {
180
181                 $r = q("SELECT distinct(parent) AS `item_id`, `contact`.`uid` AS `contact-uid`
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 `item`.`moderated` = 0 and `item`.`unseen` = 1
185                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
186                         AND `item`.`wall` = 1
187                         $sql_extra
188                         ORDER BY `item`.`created` DESC",
189                         intval($a->profile['profile_uid'])
190                 );
191
192         }
193         else {
194
195                 if(x($category)) {
196                         $sql_extra .= file_tag_file_query('item',$category,'category');
197                 }
198
199                 $r = q("SELECT COUNT(*) AS `total`
200                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
201                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
202                         and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
203                         AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
204                         $sql_extra ",
205                         intval($a->profile['profile_uid'])
206                 );
207
208                 if(count($r)) {
209                         $a->set_pager_total($r[0]['total']);
210                         $a->set_pager_itemspage(40);
211                 }
212
213                 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
214
215                 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
216                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
217                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
218                         and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
219                         AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
220                         $sql_extra
221                         ORDER BY `item`.`created` DESC $pager_sql ",
222                         intval($a->profile['profile_uid'])
223
224                 );
225
226         }
227
228         $parents_arr = array();
229         $parents_str = '';
230
231         if(count($r)) {
232                 foreach($r as $rr)
233                         $parents_arr[] = $rr['item_id'];
234                 $parents_str = implode(', ', $parents_arr);
235  
236                 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
237                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`, 
238                         `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
239                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
240                         FROM `item`, `contact`
241                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
242                         and `item`.`moderated` = 0
243                         AND `contact`.`id` = `item`.`contact-id`
244                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
245                         AND `item`.`parent` IN ( %s )
246                         $sql_extra ",
247                         intval($a->profile['profile_uid']),
248                         dbesc($parents_str)
249                 );
250                 
251                 $items = conv_sort($items,'created');
252         } else {
253                 $items = array();
254         }
255
256         if($is_owner && ! $update) {
257                 $o .= get_birthdays();
258                 $o .= get_events();
259         }
260
261         if((! $update) && ($tab === 'posts')) {
262
263                 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
264                 // because browser prefetching might change it on us. We have to deliver it with the page.
265
266                 $o .= '<div id="live-profile"></div>' . "\r\n";
267                 $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] 
268                         . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
269         }
270
271
272         if($is_owner) {
273                 $r = q("UPDATE `item` SET `unseen` = 0 
274                         WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d",
275                         intval(local_user())
276                 );
277         }
278
279         $o .= conversation($a,$items,'profile',$update);
280
281         if(! $update) {
282                 $o .= paginate($a);
283         }
284
285         return $o;
286 }