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];
64 profile_load($a,$which,$profile);
66 $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
67 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
68 $uri = urlencode('acct:' . $a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
69 $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
70 header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"');
73 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
74 foreach($dfrn_pages as $dfrn)
75 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
80 function profile_content(&$a, $update = 0) {
83 require_once("include/bbcode.php");
84 require_once('include/security.php');
92 // Ensure we've got a profile owner if updating.
93 $a->profile['profile_uid'] = $update;
96 if($a->profile['profile_uid'] == local_user())
97 $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
101 $remote_contact = false;
104 $contact_id = $_SESSION['visitor_id'];
105 $groups = init_groups_visitor($contact_id);
106 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
108 intval($a->profile['profile_uid'])
112 $remote_contact = true;
116 if(! $remote_contact) {
118 $contact_id = $_SESSION['cid'];
119 $contact = $a->contact;
123 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
127 $tab = notags(trim($_GET['tab']));
129 $tpl = load_view_file('view/profile_tabs.tpl');
131 $o .= replace_macros($tpl,array(
132 '$url' => $a->get_baseurl() . '/' . $a->cmd,
133 '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname']
137 if($tab === 'profile') {
138 $lang = get_config('system','language');
139 if($lang && file_exists("view/$lang/profile_advanced.php"))
140 require_once("view/$lang/profile_advanced.php");
142 require_once('view/profile_advanced.php');
146 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
147 if(can_write_wall($a,$a->profile['profile_uid'])) {
150 $geotag = (($is_owner && $a->profile['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
152 $tpl = load_view_file('view/jot-header.tpl');
154 $a->page['htmlhead'] .= replace_macros($tpl, array(
155 '$baseurl' => $a->get_baseurl(),
159 require_once('view/acl_selectors.php');
161 $tpl = load_view_file("view/jot.tpl");
162 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']))))
165 $lockstate = 'unlock';
166 $o .= replace_macros($tpl,array(
167 '$baseurl' => $a->get_baseurl(),
168 '$defloc' => (($is_owner) ? $a->user['default-location'] : ''),
169 '$return_path' => $a->cmd,
170 '$visitor' => (($is_owner) ? 'block' : 'none'),
171 '$lockstate' => $lockstate,
173 '$acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
174 '$profile_uid' => $a->profile['profile_uid']
178 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
179 // because browser prefetching might change it on us. We have to deliver it with the page.
181 if($tab === 'posts' && (! $a->pager['start'])) {
182 $o .= '<div id="live-profile"></div>' . "\r\n";
183 $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; </script>\r\n";
188 // Construct permissions
190 // default permissions - anonymous user
192 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
194 // Profile owner - everything is visible
199 // Oh - while we're here... reset the Unseen messages
201 $r = q("UPDATE `item` SET `unseen` = 0
202 WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
203 intval($_SESSION['uid'])
208 // authenticated visitor - here lie dragons
209 // If $remotecontact is true, we know that not only is this a remotely authenticated
210 // person, but that it is *our* contact, which is important in multi-user mode.
212 elseif($remote_contact) {
213 $gs = '<<>>'; // should be impossible to match
215 foreach($groups as $g)
216 $gs .= '|<' . intval($g) . '>';
218 $sql_extra = sprintf(
219 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
220 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
221 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
222 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
224 intval($_SESSION['visitor_id']),
225 intval($_SESSION['visitor_id']),
231 $r = q("SELECT COUNT(*) AS `total`
232 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
233 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
234 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
235 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
237 intval($a->profile['profile_uid'])
242 $a->set_pager_total($r[0]['total']);
244 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
245 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`,
246 `contact`.`thumb`, `contact`.`self`,
247 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
248 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
249 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
250 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
251 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
253 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC LIMIT %d ,%d ",
254 intval($a->profile['profile_uid']),
255 intval($a->pager['start']),
256 intval($a->pager['itemspage'])
261 $cmnt_tpl = load_view_file('view/comment_item.tpl');
263 $like_tpl = load_view_file('view/like.tpl');
265 $tpl = load_view_file('view/wall_item.tpl');
267 $droptpl = load_view_file('view/wall_item_drop.tpl');
268 $fakedrop = load_view_file('view/wall_fake_drop.tpl');
271 $return_url = $_SESSION['return_url'];
273 $return_url = $_SESSION['return_url'] = $a->cmd;
280 foreach($r as $item) {
284 if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) {
286 if(($item['network'] === 'dfrn') && (! $item['self'])) {
287 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
288 $sparkle = ' class="sparkle" ';
290 if(! is_array($alike[$item['parent'] . '-l']))
291 $alike[$item['parent'] . '-l'] = array();
292 $alike[$item['parent']] ++;
293 $alike[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['name'] . '</a>';
295 if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) {
297 if(($item['network'] === 'dfrn') && (! $item['self'])) {
298 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
299 $sparkle = ' class="sparkle" ';
301 if(! is_array($dlike[$item['parent'] . '-l']))
302 $dlike[$item['parent'] . '-l'] = array();
303 $dlike[$item['parent']] ++;
304 $dlike[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['name'] . '</a>';
308 foreach($r as $item) {
316 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
318 if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent']))
321 $lock = (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
322 || strlen($item['deny_cid']) || strlen($item['deny_gid']))
323 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
324 : '<div class="wall-item-lock"></div>');
326 if(can_write_wall($a,$a->profile['profile_uid'])) {
327 if($item['id'] == $item['parent']) {
328 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
330 if($item['last-child']) {
331 $comment = replace_macros($cmnt_tpl,array(
332 '$return_path' => $_SESSION['return_url'],
333 '$type' => 'wall-comment',
334 '$id' => $item['item_id'],
335 '$parent' => $item['parent'],
336 '$profile_uid' => $a->profile['profile_uid'],
337 '$mylink' => $contact['url'],
338 '$mytitle' => t('This is you'),
339 '$myphoto' => $contact['thumb'],
346 $profile_url = $item['url'];
348 // 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,
349 // I can go directly to their profile as an authenticated guest.
351 if(local_user() && ($item['contact-uid'] == $_SESSION['uid'])
352 && ($item['network'] === 'dfrn') && (! $item['self'] )) {
353 $profile_url = $redirect_url;
354 $sparkle = ' sparkle';
359 // We received this post via a remote feed. It's either a wall-to-wall or a remote comment. The author is
360 // known to us and is reflected in the contact-id for this item. We can use the contact url or redirect rather than
361 // use the link in the feed. This is different than on the network page where we may not know the author.
363 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
364 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
365 $profile_link = $profile_url;
370 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == $_SESSION['uid']))
373 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id']));
376 $like = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
377 $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
378 $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
379 $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
382 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
384 $location = '<span class="smalltext">' . $coord . '</span>';
387 $o .= replace_macros($template,array(
388 '$id' => $item['item_id'],
389 '$profile_url' => $profile_link,
390 '$name' => $profile_name,
391 '$thumb' => $profile_avatar,
392 '$sparkle' => $sparkle,
393 '$title' => $item['title'],
394 '$body' => bbcode($item['body']),
395 '$ago' => relative_date($item['created']),
397 '$location' => $location,
398 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
401 '$vote' => $likebuttons,
402 '$dislike' => $dislike,
403 '$comment' => $comment