3 function profile_init(&$a) {
5 $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
10 $r = q("select nickname from user where blocked = 0 and account_expired = 0 and verified = 1 order by rand() limit 1");
12 $which = $r[0]['nickname'];
15 notice( t('Requested profile is not available.') . EOL );
22 if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
23 $which = $a->user['nickname'];
24 $profile = $a->argv[1];
27 profile_load($a,$which,$profile);
29 if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) {
30 $a->page['htmlhead'] .= '<meta name="friendika.community" content="true" />';
32 if(x($a->profile,'openidserver'))
33 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
34 if(x($a->profile,'openid')) {
35 $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
36 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
40 $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
41 $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
43 $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
46 $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
47 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
48 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
49 $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
50 header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
52 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
53 foreach($dfrn_pages as $dfrn)
54 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
55 $a->page['htmlhead'] .= "<link rel=\"dfrn-poco\" href=\"".$a->get_baseurl()."/poco/{$which}\" />\r\n";
60 function profile_content(&$a, $update = 0) {
62 if(get_config('system','block_public') && (! local_user()) && (! remote_user())) {
66 require_once("include/bbcode.php");
67 require_once('include/security.php');
68 require_once('include/conversation.php');
69 require_once('include/acl_selectors.php');
76 // Ensure we've got a profile owner if updating.
77 $a->profile['profile_uid'] = $update;
80 if($a->profile['profile_uid'] == local_user()) {
81 nav_set_selected('home');
86 $remote_contact = false;
89 $contact_id = $_SESSION['visitor_id'];
90 $groups = init_groups_visitor($contact_id);
91 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
93 intval($a->profile['profile_uid'])
97 $remote_contact = true;
101 if(! $remote_contact) {
103 $contact_id = $_SESSION['cid'];
104 $contact = $a->contact;
108 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
110 if($a->user['hidewall'] && (! $is_owner) && (! $remote_contact)) {
111 notice( t('Access to this profile has been restricted.') . EOL);
118 $tab = notags(trim($_GET['tab']));
120 $o.=profile_tabs($a, $is_owner, $a->profile['nickname']);
123 if($tab === 'profile') {
124 require_once('include/profile_advanced.php');
125 $o .= advanced_profile($a);
126 call_hooks('profile_advanced',$o);
130 if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
131 $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
133 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
134 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
136 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
138 if(can_write_wall($a,$a->profile['profile_uid'])) {
141 'is_owner' => $is_owner,
142 'allow_location' => ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? true : false),
143 'default_location' => (($is_owner) ? $a->user['default-location'] : ''),
144 'nickname' => $a->profile['nickname'],
145 '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'),
146 'acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
148 'visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
149 'profile_uid' => $a->profile['profile_uid']
152 $o .= status_editor($a,$x);
159 * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
162 $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
167 $r = q("SELECT distinct(parent) AS `item_id`, `contact`.`uid` AS `contact-uid`
168 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
169 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
170 and `item`.`moderated` = 0 and `item`.`unseen` = 1
171 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
172 AND `item`.`wall` = 1
174 ORDER BY `item`.`created` DESC",
175 intval($a->profile['profile_uid'])
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 `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
185 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
187 intval($a->profile['profile_uid'])
191 $a->set_pager_total($r[0]['total']);
192 $a->set_pager_itemspage(40);
195 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
197 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
198 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
199 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
200 and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
201 AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1
203 ORDER BY `item`.`created` DESC $pager_sql ",
204 intval($a->profile['profile_uid'])
209 $parents_arr = array();
214 $parents_arr[] = $rr['item_id'];
215 $parents_str = implode(', ', $parents_arr);
217 $items = 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`, `contact`
222 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
223 and `item`.`moderated` = 0
224 AND `contact`.`id` = `item`.`contact-id`
225 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
226 AND `item`.`parent` IN ( %s )
228 intval($a->profile['profile_uid']),
232 $items = conv_sort($items,'created');
237 if($is_owner && ! $update) {
238 $o .= get_birthdays();
242 if((! $update) && ($tab === 'posts')) {
244 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
245 // because browser prefetching might change it on us. We have to deliver it with the page.
247 $o .= '<div id="live-profile"></div>' . "\r\n";
248 $o .= "<script> var profile_uid = " . $a->profile['profile_uid']
249 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
254 $r = q("UPDATE `item` SET `unseen` = 0
255 WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d",
260 $o .= conversation($a,$items,'profile',$update);