3 if(! function_exists('profile_load')) {
4 function profile_load(&$a, $username, $profile = 0) {
7 $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
8 intval($_SESSION['visitor_id']));
10 $profile = $r[0]['profile-id'];
16 $profile_int = intval($profile);
17 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
18 LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
19 WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d LIMIT 1",
25 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
26 LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
27 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 LIMIT 1",
32 if(($r === false) || (! count($r))) {
33 notice( t('No profile') . EOL );
40 $a->page['template'] = 'profile';
42 $a->page['title'] = $a->profile['name'];
43 $_SESSION['theme'] = $a->profile['theme'];
48 function profile_init(&$a) {
53 notice( t('No profile') . EOL );
59 if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
60 $which = $a->user['nickname'];
61 $profile = $a->argv[1];
63 profile_load($a,$which,$profile);
64 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
66 $a->page['htmlhead'] .= '<meta name="dfrn-template" content="' . $a->get_baseurl() . "/profile/%s" . '" />' . "\r\n" ;
67 $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
70 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
71 foreach($dfrn_pages as $dfrn)
72 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
77 function profile_content(&$a, $update = 0) {
80 require_once("include/bbcode.php");
81 require_once('include/security.php');
89 // Ensure we've got a profile owner if updating.
90 $a->profile['profile_uid'] = $update;
93 if($a->profile['profile_uid'] == get_uid())
94 $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
98 $remote_contact = false;
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",
105 intval($a->profile['profile_uid'])
109 $remote_contact = true;
113 if(! $remote_contact) {
115 $contact_id = $_SESSION['cid'];
116 $contact = $a->contact;
122 $tab = notags(trim($_GET['tab']));
124 $tpl = load_view_file('view/profile_tabs.tpl');
126 $o .= replace_macros($tpl,array(
127 '$url' => $a->get_baseurl() . '/' . $a->cmd,
128 '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname']
132 if($tab === 'profile') {
133 $lang = get_config('system','language');
134 if($lang && file_exists("view/$lang/profile_advanced.php"))
135 require_once("view/$lang/profile_advanced.php");
137 require_once('view/profile_advanced.php');
141 if(can_write_wall($a,$a->profile['profile_uid'])) {
142 $tpl = load_view_file('view/jot-header.tpl');
144 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
145 require_once('view/acl_selectors.php');
147 $tpl = load_view_file("view/jot.tpl");
148 if(is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))
151 $lockstate = 'unlock';
152 $o .= replace_macros($tpl,array(
153 '$baseurl' => $a->get_baseurl(),
154 '$defloc' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? $a->user['default-location'] : ''),
155 '$return_path' => $a->cmd,
156 '$visitor' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? 'block' : 'none'),
157 '$lockstate' => $lockstate,
159 '$acl' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? populate_acl($a->user) : ''),
160 '$profile_uid' => $a->profile['profile_uid']
164 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
165 // because browser prefetching might change it on us. We have to deliver it with the page.
167 if($tab === 'posts' && (! $a->pager['start'])) {
168 $o .= '<div id="live-profile"></div>' . "\r\n";
169 $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; </script>\r\n";
174 // TODO alter registration and settings and profile to update contact table when names and photos change.
176 // default permissions - anonymous user
178 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
183 // Profile owner - everything is visible
185 if(local_user() && ($_SESSION['uid'] == $a->profile['profile_uid'])) {
188 // Oh - while we're here... reset the Unseen messages
190 $r = q("UPDATE `item` SET `unseen` = 0
191 WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
192 intval($_SESSION['uid'])
197 // authenticated visitor - here lie dragons
198 // If $remotecontact is true, we know that not only is this a remotely authenticated
199 // person, but that it is *our* contact, which is important in multi-user mode.
201 elseif($remote_contact) {
202 $gs = '<<>>'; // should be impossible to match
204 foreach($groups as $g)
205 $gs .= '|<' . intval($g) . '>';
207 $sql_extra = sprintf(
208 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
209 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
210 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
211 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
213 intval($_SESSION['visitor_id']),
214 intval($_SESSION['visitor_id']),
220 $r = q("SELECT COUNT(*) AS `total`
221 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
222 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
223 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
224 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
226 intval($a->profile['profile_uid'])
231 $a->set_pager_total($r[0]['total']);
233 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
234 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
235 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
236 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
237 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
238 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
239 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
240 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
242 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC LIMIT %d ,%d ",
243 intval($a->profile['profile_uid']),
244 intval($a->pager['start']),
245 intval($a->pager['itemspage'])
250 $cmnt_tpl = load_view_file('view/comment_item.tpl');
252 $like_tpl = load_view_file('view/like.tpl');
254 $tpl = load_view_file('view/wall_item.tpl');
256 $droptpl = load_view_file('view/wall_item_drop.tpl');
257 $fakedrop = load_view_file('view/wall_fake_drop.tpl');
260 $return_url = $_SESSION['return_url'];
262 $return_url = $_SESSION['return_url'] = $a->cmd;
269 foreach($r as $item) {
273 if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) {
275 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) {
276 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
277 $sparkle = ' class="sparkle" ';
279 if(! is_array($alike[$item['parent'] . '-l']))
280 $alike[$item['parent'] . '-l'] = array();
281 $alike[$item['parent']] ++;
282 $alike[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['name'] . '</a>';
284 if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) {
286 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) {
287 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
288 $sparkle = ' class="sparkle" ';
290 if(! is_array($dlike[$item['parent'] . '-l']))
291 $dlike[$item['parent'] . '-l'] = array();
292 $dlike[$item['parent']] ++;
293 $dlike[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['name'] . '</a>';
297 foreach($r as $item) {
305 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
307 if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent']))
310 if(can_write_wall($a,$a->profile['profile_uid'])) {
311 if($item['id'] == $item['parent']) {
312 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
314 if($item['last-child']) {
315 $comment = replace_macros($cmnt_tpl,array(
316 '$return_path' => $_SESSION['return_url'],
317 '$type' => 'wall-comment',
318 '$id' => $item['item_id'],
319 '$parent' => $item['parent'],
320 '$profile_uid' => $a->profile['profile_uid'],
321 '$mylink' => $contact['url'],
322 '$mytitle' => t('This is you'),
323 '$myphoto' => $contact['thumb'],
330 $profile_url = $item['url'];
332 // This is my profile but I'm not the author of this post/comment. If it's somebody that's a fan or mutual friend,
333 // I can go directly to their profile as an authenticated guest.
335 if(local_user() && ($item['contact-uid'] == $_SESSION['uid'])
336 && ($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'] )) {
337 $profile_url = $redirect_url;
338 $sparkle = ' sparkle';
343 // We received this post via a remote feed. It's either a wall-to-wall or a remote comment. The author is
344 // known to us and is reflected in the contact-id for this item. We can use the contact url or redirect rather than
345 // use the link in the feed. This is different than on the network page where we may not know the author.
347 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
348 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
349 $profile_link = $profile_url;
354 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == $_SESSION['uid']))
357 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id']));
360 $like = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
361 $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
364 $o .= replace_macros($template,array(
365 '$id' => $item['item_id'],
366 '$profile_url' => $profile_link,
367 '$name' => $profile_name,
368 '$thumb' => $profile_avatar,
369 '$sparkle' => $sparkle,
370 '$title' => $item['title'],
371 '$body' => bbcode($item['body']),
372 '$ago' => relative_date($item['created']),
373 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
374 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
377 '$vote' => $likebuttons,
378 '$dislike' => $dislike,
379 '$comment' => $comment