]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
b37d6487ccbd26b97d0d702894e887aa742152ef
[friendica.git] / mod / profile.php
1 <?php
2
3 if(! function_exists('profile_load')) {
4 function profile_load(&$a,$uid,$profile = 0) {
5
6         $sql_extra = (($uid) && (intval($uid)) 
7                 ? " WHERE `user`.`uid` = " . intval($uid) 
8                 : " WHERE `user`.`nickname` = '" . dbesc($uid) . "' " ); 
9
10         if(remote_user()) {
11                 $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
12                         intval($_SESSION['visitor_id']));
13                 if(count($r))
14                         $profile = $r[0]['profile-id'];
15         } 
16
17         if($profile) {
18                 $profile_int = intval($profile);
19                 $sql_which = " AND `profile`.`id` = $profile_int ";
20         }
21         else
22                 $sql_which = " AND `profile`.`is-default` = 1 "; 
23
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"
27         );
28
29         if(($r === false) || (! count($r))) {
30                 $_SESSION['sysmsg'] .= "No profile" . EOL ;
31                 $a->error = 404;
32                 return;
33         }
34
35         $a->profile = $r[0];
36
37         $a->page['template'] = 'profile';
38
39         $a->page['title'] = $a->profile['name'];
40
41         return;
42 }}
43
44 function profile_init(&$a) {
45
46         if($_SESSION['authenticated']) {
47
48                 // choose which page to show (could be remote auth)
49
50         }
51
52         if($a->argc > 1)
53                 $which = $a->argv[1];
54         else {
55                 $_SESSION['sysmsg'] .= "No profile" . EOL ;
56                 $a->error = 404;
57                 return;
58         }
59
60         profile_load($a,$which);
61         
62         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
63         foreach($dfrn_pages as $dfrn)
64                 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
65 }
66
67 function item_display($item,$template) {
68
69         $o .= replace_macros($template,array(
70                 '$id' => $item['item_id'],
71                 '$profile_url' => $item['url'],
72                 '$name' => $item['name'],
73                 '$thumb' => $item['thumb'],
74                 '$body' => bbcode($item['body']),
75                 '$ago' => relative_date($item['created'])
76         ));
77
78
79         return $o;
80 }
81
82
83
84 function profile_content(&$a) {
85
86         require_once("include/bbcode.php");
87         require_once('include/security.php');
88
89 //      $tpl = file_get_contents('view/profile_tabs.tpl');
90
91
92         if(can_write_wall($a,$a->profile['profile_uid'])) {
93                 $tpl = file_get_contents('view/jot-header.tpl');
94         
95                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
96
97                 $tpl = file_get_contents("view/jot.tpl");
98                 $o .= replace_macros($tpl,array(
99                         '$baseurl' => $a->get_baseurl(),
100                         '$profile_uid' => $a->profile['profile_uid']
101                 ));
102         }
103
104
105         if($a->profile['is-default']) {
106
107                 // TODO left join with contact which will carry names and photos. (done)Store local users in contact as well as user.(done)
108                 // Alter registration and settings 
109                 // and profile to update contact table when names and  photos change.  
110                 // work on item_display and can_write_wall
111
112                 // Add comments. 
113
114                 $r = q("SELECT `item`.*, `contact`.`name`, `contact`.`photo`, `contact`.`thumb`, `contact`.`id` AS `cid`
115                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
116                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1
117                         AND `contact`.`blocked` = 0
118                         AND `allow_uid` = '' AND `allow_gid` = '' AND `deny_uid` = '' AND `deny_gid` = ''
119                         GROUP BY `item`.`parent`, `item`.`id`
120                         ORDER BY `created` DESC LIMIT 0,30 ",
121                         intval($a->profile['uid'])
122                 );
123
124                 $tpl = file_get_contents('view/wall_item.tpl');
125
126                 if(count($r)) {
127                         foreach($r as $rr) {
128                                 $o .= item_display($rr,$tpl);
129                         }
130                 }
131         }
132
133         return $o;
134
135
136 }