3 if(! function_exists('profile_load')) {
4 function profile_load(&$a,$uid,$profile = 0) {
6 $sql_extra = (($uid) && (intval($uid))
7 ? " WHERE `user`.`uid` = " . intval($uid)
8 : " WHERE `user`.`nickname` = '" . dbesc($uid) . "' " );
11 $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
12 intval($_SESSION['visitor_id']));
14 $profile = $r[0]['profile-id'];
18 $profile_int = intval($profile);
19 $sql_which = " AND `profile`.`id` = $profile_int ";
22 $sql_which = " AND `profile`.`is-default` = 1 ";
24 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
25 LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
26 $sql_extra $sql_which LIMIT 1"
29 if(($r === false) || (! count($r))) {
30 $_SESSION['sysmsg'] .= "No profile" . EOL ;
37 $a->page['template'] = 'profile';
39 $a->page['title'] = $a->profile['name'];
44 function profile_init(&$a) {
46 if($_SESSION['authenticated']) {
48 // choose which page to show (could be remote auth)
55 $_SESSION['sysmsg'] .= "No profile" . EOL ;
60 profile_load($a,$which);
61 $a->page['htmlhead'] .= "<meta name=\"dfrn-template\" content=\"" . $a->get_baseurl() . "/profile/%s" . "\" />\r\n";
63 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
64 foreach($dfrn_pages as $dfrn)
65 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
69 function item_display(&$a, $item,$template,$comment) {
72 $profile_url = $item['url'];
74 if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
75 $profile_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
77 $photo = (($item['self']) ? $a->profile['photo'] : $item['photo']);
78 $thumb = (($item['self']) ? $a->profile['thumb'] : $item['thumb']);
80 $o .= replace_macros($template,array(
81 '$id' => $item['item_id'],
82 '$profile_url' => $profile_url,
83 '$name' => $item['name'],
85 '$body' => bbcode($item['body']),
86 '$ago' => relative_date($item['created']),
87 '$comment' => $comment
96 function profile_content(&$a) {
98 require_once("include/bbcode.php");
99 require_once('include/security.php');
101 // $tpl = file_get_contents('view/profile_tabs.tpl');
105 $contact_id = $_SESSION['visitor_id'];
107 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
111 $contact_id = $r[0]['id'];
115 if(can_write_wall($a,$a->profile['profile_uid'])) {
116 $tpl = file_get_contents('view/jot-header.tpl');
118 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
120 $tpl = file_get_contents("view/jot.tpl");
121 $o .= replace_macros($tpl,array(
122 '$baseurl' => $a->get_baseurl(),
123 '$profile_uid' => $a->profile['profile_uid']
128 if($a->profile['is-default']) {
130 // TODO left join with contact which will carry names and photos. (done)Store local users in contact as well as user.(done)
131 // Alter registration and settings
132 // and profile to update contact table when names and photos change.
133 // work on item_display and can_write_wall
137 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`,
138 `contact`.`uid` AS `contact-uid`
139 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
140 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
141 AND `contact`.`blocked` = 0
142 AND `allow_uid` = '' AND `allow_gid` = '' AND `deny_uid` = '' AND `deny_gid` = ''
143 GROUP BY `item`.`parent`, `item`.`id`
144 ORDER BY `created` DESC LIMIT 0,30 ",
145 intval($a->profile['uid'])
148 $template = file_get_contents('view/comment_item.tpl');
153 $tpl = file_get_contents('view/wall_item.tpl');
157 if(can_write_wall($a,$a->profile['profile_uid'])) {
158 $comment = replace_macros($template,array(
159 '$id' => $rr['item_id'],
160 '$profile_uid' => $a->profile['profile_uid']
167 $o .= item_display($a,$rr,$tpl,$comment);