]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
39d1b7c6a5eafad330296078ea0dacf3ae1a6686
[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         $a->page['htmlhead'] .= "<meta name=\"dfrn-template\" content=\"" . $a->get_baseurl() . "/profile/%s" . "\" />\r\n";
62         
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";
66
67 }
68
69 function item_display(&$a, $item,$template,$comment) {
70
71
72         $profile_url = $item['url'];
73
74         if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
75                 $profile_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
76
77         $photo = (($item['self']) ? $a->profile['photo'] : $item['photo']);
78         $thumb = (($item['self']) ? $a->profile['thumb'] : $item['thumb']);
79
80         $o .= replace_macros($template,array(
81                 '$id' => $item['item_id'],
82                 '$profile_url' => $profile_url,
83                 '$name' => $item['name'],
84                 '$thumb' => $thumb,
85                 '$body' => bbcode($item['body']),
86                 '$ago' => relative_date($item['created']),
87                 '$indent' => (($item['parent'] != $item['item_id']) ? 'comment-' : ''),
88                 '$comment' => $comment
89         ));
90
91
92         return $o;
93 }
94
95
96 function profile_content(&$a) {
97
98         require_once("include/bbcode.php");
99         require_once('include/security.php');
100
101         $a->page['htmlhead'] .= '<script type="text/javascript" src="include/jquery.js" ></script>';
102         $groups = array();
103
104         $tab = 'posts';
105
106         if(x($_GET,'tab'))
107                 $tab = notags(trim($_GET['tab']));
108
109         $tpl = file_get_contents('view/profile_tabs.tpl');
110
111         $o .= replace_macros($tpl,array(
112                 '$url' => $a->get_baseurl() . '/' . $a->cmd
113         ));
114
115
116         if(remote_user()) {
117                 $contact_id = $_SESSION['visitor_id'];
118                 $groups = init_groups_visitor($contact_id);
119         }
120         if(local_user()) {
121                 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
122                         $_SESSION['uid']
123                 );
124                 if(count($r))
125                         $contact_id = $r[0]['id'];
126         }
127
128         if($tab == 'profile') {
129
130                 require_once('view/profile_advanced.php');
131
132                 return $o;
133         }
134         if(can_write_wall($a,$a->profile['profile_uid'])) {
135                 $tpl = file_get_contents('view/jot-header.tpl');
136         
137                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
138
139                 $tpl = file_get_contents("view/jot.tpl");
140                 $o .= replace_macros($tpl,array(
141                         '$baseurl' => $a->get_baseurl(),
142                         '$profile_uid' => $a->profile['profile_uid']
143                 ));
144         }
145
146
147         // TODO 
148         // Alter registration and settings 
149         // and profile to update contact table when names and  photos change.  
150         // work on item_display and can_write_wall
151
152         // Add comments. 
153
154         // default - anonymous user
155
156         $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
157
158         // Profile owner - everything is visible
159
160         if(local_user() && ($_SESSION['uid'] == $a->profile['profile_uid']))
161                 $sql_extra = ''; 
162
163         // authenticated visitor - here lie dragons
164
165         elseif(remote_user()) {
166                 $gs = '<<>>'; // should be impossible to match
167                 if(count($groups)) {
168                         foreach($groups as $g)
169                                 $gs .= '|<' . dbesc($g) . '>';
170                 } 
171                 $sql_extra = sprintf(
172                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
173                         AND ( `deny_cid` = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
174                         AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
175                         AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
176
177                         intval($visitor_id),
178                         intval($visitor_id),
179                         $gs,
180                         $gs
181                 );
182         }
183
184         $r = q("SELECT COUNT(*) AS `total`
185                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
186                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
187                 AND `contact`.`blocked` = 0 
188                 $sql_extra ",
189                 intval($a->profile['uid'])
190
191         );
192
193         if(count($r))
194                 $a->set_pager_total($r[0]['total']);
195
196
197         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
198                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, 
199                 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
200                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
201                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
202                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
203                 AND `contact`.`blocked` = 0 
204                 $sql_extra
205                 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
206                 intval($a->profile['uid']),
207                 intval($a->pager['start']),
208                 intval($a->pager['itemspage'])
209
210         );
211
212
213         $template = file_get_contents('view/comment_item.tpl');
214
215
216         $tpl = file_get_contents('view/wall_item.tpl');
217         if(count($r)) {
218                 foreach($r as $rr) {
219                         $comment = '';
220                         if(can_write_wall($a,$a->profile['profile_uid'])) {
221                                 if($rr['last-child']) {
222                                         $comment = replace_macros($template,array(
223                                                 '$id' => $rr['item_id'],
224                                                 '$parent' => $rr['parent'],
225                                                 '$profile_uid' =>  $a->profile['profile_uid']
226                                         ));
227                                 }
228                         }
229                         $o .= item_display($a,$rr,$tpl,$comment);
230                 }
231         }
232
233         $o .= paginate($a);
234
235         return $o;
236
237
238 }