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'];
14 $profile_int = intval($profile);
15 $sql_which = " AND `profile`.`id` = $profile_int ";
18 $sql_which = " AND `profile`.`is-default` = 1 ";
20 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
21 LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
22 WHERE `user`.`nickname` = '%s' $sql_which LIMIT 1",
26 if(($r === false) || (! count($r))) {
27 notice("No profile" . EOL );
34 $a->page['template'] = 'profile';
36 $a->page['title'] = $a->profile['name'];
41 function profile_init(&$a) {
46 notice("No profile" . EOL );
51 if((remote_user()) && ($a->argc > 2) && ($a->argv[2] == 'visit'))
52 $_SESSION['is_visitor'] = 1;
54 unset($_SESSION['is_visitor']);
55 unset($_SESSION['visitor_id']);
56 if(! $_SESSION['uid'])
57 unset($_SESSION['authenticated']);
61 if((local_user()) && ($a->argc > 2) && ($a->argv[2] == 'view')) {
62 $which = $a->user['nickname'];
63 $profile = $a->argv[1];
65 profile_load($a,$which,$profile);
66 $a->page['htmlhead'] .= "<meta name=\"dfrn-template\" content=\"" . $a->get_baseurl() . "/profile/%s" . "\" />\r\n";
68 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
69 foreach($dfrn_pages as $dfrn)
70 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
75 function profile_content(&$a, $update = false) {
77 require_once("include/bbcode.php");
78 require_once('include/security.php');
86 $_SESSION['profile_uid'] = $a->profile['uid'];
90 $contact_id = $_SESSION['visitor_id'];
91 $groups = init_groups_visitor($contact_id);
94 $contact_id = $_SESSION['cid'];
98 // Ensure we've got a profile owner if updating.
99 $a->profile['profile_uid'] = $_SESSION['profile_uid'];
104 $tab = notags(trim($_GET['tab']));
106 $tpl = file_get_contents('view/profile_tabs.tpl');
108 $o .= replace_macros($tpl,array(
109 '$url' => $a->get_baseurl() . '/' . $a->cmd,
110 '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname']
114 if($tab == 'profile') {
115 require_once('view/profile_advanced.php');
119 if(can_write_wall($a,$a->profile['profile_uid'])) {
120 $tpl = file_get_contents('view/jot-header.tpl');
122 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
123 require_once('view/acl_selectors.php');
125 $tpl = file_get_contents("view/jot.tpl");
127 $o .= replace_macros($tpl,array(
128 '$baseurl' => $a->get_baseurl(),
129 '$return_path' => $a->cmd,
130 '$visitor' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? 'block' : 'none'),
131 '$lockstate' => 'unlock',
132 '$acl' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? populate_acl() : ''),
133 '$profile_uid' => $a->profile['profile_uid']
137 if($tab == 'posts' && (! $a->pager['start']))
138 $o .= '<div id="live-profile"></div>' . "\r\n";
141 // TODO alter registration and settings and profile to update contact table when names and photos change.
143 // default permissions - anonymous user
145 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
147 // Profile owner - everything is visible
149 if(local_user() && ($_SESSION['uid'] == $a->profile['uid'])) {
152 // Oh - while we're here... reset the Unseen messages
154 $r = q("UPDATE `item` SET `unseen` = 0
155 WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
156 intval($_SESSION['uid'])
161 // authenticated visitor - here lie dragons
162 elseif(remote_user()) {
163 $gs = '<<>>'; // should be impossible to match
165 foreach($groups as $g)
166 $gs .= '|<' . intval($g) . '>';
168 $sql_extra = sprintf(
169 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
170 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
171 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
172 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
174 intval($_SESSION['visitor_id']),
175 intval($_SESSION['visitor_id']),
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 NOT `item`.`type` IN ( 'remote', 'net-comment') AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
186 intval($a->profile['uid'])
191 $a->set_pager_total($r[0]['total']);
194 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
195 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
196 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
197 `contact`.`id` AS `cid`, `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 NOT `item`.`type` IN ( 'remote', 'net-comment') AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
202 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
203 intval($a->profile['uid']),
204 intval($a->pager['start']),
205 intval($a->pager['itemspage'])
210 $cmnt_tpl = file_get_contents('view/comment_item.tpl');
212 $tpl = file_get_contents('view/wall_item.tpl');
215 $return_url = $_SESSION['return_url'];
217 $return_url = $_SESSION['return_url'] = $a->cmd;
220 foreach($r as $item) {
224 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
228 if(can_write_wall($a,$a->profile['uid'])) {
229 if($item['last-child']) {
230 $comment = replace_macros($cmnt_tpl,array(
231 '$return_path' => $_SESSION['return_url'],
232 '$type' => 'wall-comment',
233 '$id' => $item['item_id'],
234 '$parent' => $item['parent'],
235 '$profile_uid' => $a->profile['uid'],
242 $profile_url = $item['url'];
244 // 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,
245 // I can go directly to their profile as an authenticated guest.
247 if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
248 $profile_url = $redirect_url;
250 // FIXME tryng to solve the mishmash of profile photos.
252 // $photo = (($item['self']) ? $a->profile['photo'] : $item['photo']);
253 // $thumb = (($item['self']) ? $a->profile['thumb'] : $item['thumb']);
256 // We received this post via a remote feed. It's either a wall-to-wall or a remote comment. The author is
257 // known to us and is reflected in the contact-id for this item. We can use the contact url or redirect rather than
258 // use the link in the feed. This is different than on the network page where we may not know the author.
260 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
261 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
262 $profile_link = $profile_url;
266 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == $_SESSION['uid']))
267 $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
272 $o .= replace_macros($template,array(
273 '$id' => $item['item_id'],
274 '$profile_url' => $profile_link,
275 '$name' => $profile_name,
276 '$thumb' => $profile_avatar,
277 '$title' => $item['title'],
278 '$body' => bbcode($item['body']),
279 '$ago' => relative_date($item['created']),
280 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
282 '$comment' => $comment