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( t('No profile') . EOL );
34 $a->page['template'] = 'profile';
36 $a->page['title'] = $a->profile['name'];
37 $_SESSION['theme'] = $a->profile['theme'];
42 function profile_init(&$a) {
47 notice( t('No profile') . EOL );
53 if((local_user()) && ($a->argc > 2) && ($a->argv[2] == 'view')) {
54 $which = $a->user['nickname'];
55 $profile = $a->argv[1];
57 profile_load($a,$which,$profile);
58 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
60 $a->page['htmlhead'] .= '<meta name="dfrn-template" content="' . $a->get_baseurl() . "/profile/%s" . '" />' . "\r\n" ;
61 $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
64 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
65 foreach($dfrn_pages as $dfrn)
66 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
71 function profile_content(&$a, $update = false) {
73 require_once("include/bbcode.php");
74 require_once('include/security.php');
82 // Ensure we've got a profile owner if updating.
83 $a->profile['profile_uid'] = $_SESSION['profile_uid'];
86 // set the uid so we can pick it up during update
87 $_SESSION['profile_uid'] = $a->profile['uid'];
91 $remote_contact = false;
94 $contact_id = $_SESSION['visitor_id'];
95 $groups = init_groups_visitor($contact_id);
96 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
98 intval($a->profile['profile_uid'])
102 $remote_contact = true;
106 if(! $remote_contact) {
108 $contact_id = $_SESSION['cid'];
109 $contact = $a->contact;
115 $tab = notags(trim($_GET['tab']));
117 $tpl = file_get_contents('view/profile_tabs.tpl');
119 $o .= replace_macros($tpl,array(
120 '$url' => $a->get_baseurl() . '/' . $a->cmd,
121 '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname']
125 if($tab == 'profile') {
126 require_once('view/profile_advanced.php');
130 if(can_write_wall($a,$a->profile['profile_uid'])) {
131 $tpl = file_get_contents('view/jot-header.tpl');
133 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
134 require_once('view/acl_selectors.php');
136 $tpl = file_get_contents("view/jot.tpl");
137 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']))))
140 $lockstate = 'unlock';
141 $o .= replace_macros($tpl,array(
142 '$baseurl' => $a->get_baseurl(),
143 '$defloc' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? $a->user['default-location'] : ''),
144 '$return_path' => $a->cmd,
145 '$visitor' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? 'block' : 'none'),
146 '$lockstate' => $lockstate,
147 '$acl' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? populate_acl($a->user) : ''),
148 '$profile_uid' => $a->profile['profile_uid']
152 if($tab == 'posts' && (! $a->pager['start']))
153 $o .= '<div id="live-profile"></div>' . "\r\n";
156 // TODO alter registration and settings and profile to update contact table when names and photos change.
158 // default permissions - anonymous user
160 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
165 // Profile owner - everything is visible
167 if(local_user() && ($_SESSION['uid'] == $a->profile['profile_uid'])) {
170 // Oh - while we're here... reset the Unseen messages
172 $r = q("UPDATE `item` SET `unseen` = 0
173 WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
174 intval($_SESSION['uid'])
179 // authenticated visitor - here lie dragons
180 // If $remotecontact is true, we know that not only is this a remotely authenticated
181 // person, but that it is *our* contact, which is important in multi-user mode.
183 elseif($remote_contact) {
184 $gs = '<<>>'; // should be impossible to match
186 foreach($groups as $g)
187 $gs .= '|<' . intval($g) . '>';
189 $sql_extra = sprintf(
190 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
191 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
192 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
193 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
195 intval($_SESSION['visitor_id']),
196 intval($_SESSION['visitor_id']),
202 $r = q("SELECT COUNT(*) AS `total`
203 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
204 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
205 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
206 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `type` != 'remote')
208 intval($a->profile['profile_uid'])
213 $a->set_pager_total($r[0]['total']);
215 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
216 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
217 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
218 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
219 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
220 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
221 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
222 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `type` != 'remote')
224 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
225 intval($a->profile['profile_uid']),
226 intval($a->pager['start']),
227 intval($a->pager['itemspage'])
232 $cmnt_tpl = file_get_contents('view/comment_item.tpl');
234 $tpl = file_get_contents('view/wall_item.tpl');
237 $return_url = $_SESSION['return_url'];
239 $return_url = $_SESSION['return_url'] = $a->cmd;
242 foreach($r as $item) {
246 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
249 if(can_write_wall($a,$a->profile['profile_uid'])) {
250 if($item['last-child']) {
251 $comment = replace_macros($cmnt_tpl,array(
252 '$return_path' => $_SESSION['return_url'],
253 '$type' => 'wall-comment',
254 '$id' => $item['item_id'],
255 '$parent' => $item['parent'],
256 '$profile_uid' => $a->profile['profile_uid'],
257 '$mylink' => $contact['url'],
258 '$mytitle' => t('Me'),
259 '$myphoto' => $contact['thumb'],
266 $profile_url = $item['url'];
268 // 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,
269 // I can go directly to their profile as an authenticated guest.
271 if(local_user() && ($item['contact-uid'] == $_SESSION['uid'])
272 && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH) && (! $item['self'] ))
273 $profile_url = $redirect_url;
276 // We received this post via a remote feed. It's either a wall-to-wall or a remote comment. The author is
277 // known to us and is reflected in the contact-id for this item. We can use the contact url or redirect rather than
278 // use the link in the feed. This is different than on the network page where we may not know the author.
280 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
281 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
282 $profile_link = $profile_url;
286 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == $_SESSION['uid']))
287 $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
290 $o .= replace_macros($template,array(
291 '$id' => $item['item_id'],
292 '$profile_url' => $profile_link,
293 '$name' => $profile_name,
294 '$thumb' => $profile_avatar,
295 '$title' => $item['title'],
296 '$body' => bbcode($item['body']),
297 '$ago' => relative_date($item['created']),
298 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
299 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
301 '$comment' => $comment