]> git.mxchange.org Git - friendica.git/blob - mod/profile.php
f3ec57329cacc037380383a84b29e2dbe70ac3e4
[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($a->argc > 1)
47                 $which = $a->argv[1];
48         else {
49                 $_SESSION['sysmsg'] .= "No profile" . EOL ;
50                 $a->error = 404;
51                 return;
52         }
53
54         if((remote_user()) && ($a->argc > 2) && ($a->argv[2] == 'visit'))
55                 $_SESSION['is_visitor'] = 1;
56         else {
57                 unset($_SESSION['is_visitor']);
58                 unset($_SESSION['visitor_id']);
59                 if(! $_SESSION['uid'])
60                         unset($_SESSION['authenticated']);
61         }
62
63         profile_load($a,$which);
64         $a->page['htmlhead'] .= "<meta name=\"dfrn-template\" content=\"" . $a->get_baseurl() . "/profile/%s" . "\" />\r\n";
65         
66         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
67         foreach($dfrn_pages as $dfrn)
68                 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
69
70 }
71
72
73 function profile_content(&$a) {
74
75         require_once("include/bbcode.php");
76         require_once('include/security.php');
77
78         $a->page['htmlhead'] .= '<script type="text/javascript" src="include/jquery.js" ></script>';
79         $groups = array();
80
81         $tab = 'posts';
82
83         if(x($_GET,'tab'))
84                 $tab = notags(trim($_GET['tab']));
85
86         $tpl = file_get_contents('view/profile_tabs.tpl');
87
88         $o .= replace_macros($tpl,array(
89                 '$url' => $a->get_baseurl() . '/' . $a->cmd
90         ));
91
92
93         if(remote_user()) {
94                 $contact_id = $_SESSION['visitor_id'];
95                 $groups = init_groups_visitor($contact_id);
96         }
97         if(local_user()) {
98                 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
99                         $_SESSION['uid']
100                 );
101                 if(count($r))
102                         $contact_id = $r[0]['id'];
103         }
104
105         if($tab == 'profile') {
106
107                 require_once('view/profile_advanced.php');
108
109                 return $o;
110         }
111         if(can_write_wall($a,$a->profile['profile_uid'])) {
112                 $tpl = file_get_contents('view/jot-header.tpl');
113         
114                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
115                 require_once('view/acl_selectors.php');
116
117                 $tpl = file_get_contents("view/jot.tpl");
118
119                 $o .= replace_macros($tpl,array(
120                         '$baseurl' => $a->get_baseurl(),
121                         '$return_path' => $a->cmd,
122                         '$visitor' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? 'block' : 'none'),
123                         '$lockstate' => 'unlock',
124                         '$acl' => (($_SESSION['uid'] == $a->profile['profile_uid']) ? populate_acl() : ''),
125                         '$profile_uid' => $a->profile['profile_uid']
126                 ));
127         }
128
129
130         // TODO 
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
134
135         // Add comments. 
136
137         // default - anonymous user
138
139         $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
140
141         // Profile owner - everything is visible
142
143         if(local_user() && ($_SESSION['uid'] == $a->profile['profile_uid']))
144                 $sql_extra = ''; 
145
146         // authenticated visitor - here lie dragons
147         elseif(remote_user()) {
148                 $gs = '<<>>'; // should be impossible to match
149                 if(count($groups)) {
150                         foreach($groups as $g)
151                                 $gs .= '|<' . intval($g) . '>';
152                 } 
153                 $sql_extra = sprintf(
154                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
155                         AND ( `deny_cid` = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
156                         AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
157                         AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
158
159                         intval($_SESSION['visitor_id']),
160                         intval($_SESSION['visitor_id']),
161                         dbesc($gs),
162                         dbesc($gs)
163                 );
164         }
165
166         $r = q("SELECT COUNT(*) AS `total`
167                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
168                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
169                 AND `contact`.`blocked` = 0 
170                 $sql_extra ",
171                 intval($a->profile['uid'])
172
173         );
174
175         if(count($r))
176                 $a->set_pager_total($r[0]['total']);
177 dbg(2);
178
179         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
180                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, 
181                 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
182                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
183                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
184                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
185                 AND `item`.`type` != 'remote' AND `contact`.`blocked` = 0 
186                 $sql_extra
187                 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
188                 intval($a->profile['uid']),
189                 intval($a->pager['start']),
190                 intval($a->pager['itemspage'])
191
192         );
193
194
195         $cmnt_tpl = file_get_contents('view/comment_item.tpl');
196
197         $tpl = file_get_contents('view/wall_item.tpl');
198         $wallwall = file_get_contents('view/wallwall_item.tpl');
199
200
201         if(count($r)) {
202                 foreach($r as $item) {
203                         $comment = '';
204                         $template = $tpl;
205                         $commentww = '';
206                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
207                                 if($item['type'] == 'wall') {
208                                         $owner_url = $a->contact['url'];
209                                         $owner_photo = $a->contact['thumb'];
210                                         $owner_name = $a->contact['name'];
211                                         $template = $wallwall;
212                                         $commentww = 'ww';      
213                                 }
214                                 if($item['type'] == 'remote' && ($item['owner-link'] != $item['remote-link'])) {
215                                         $owner_url = $item['owner-link'];
216                                         $owner_photo = $item['owner-avatar'];
217                                         $owner_name = $item['owner-name'];
218                                         $template = $wallwall;
219                                         $commentww = 'ww';      
220                                 }
221                         }
222
223
224
225                         if(can_write_wall($a,$a->profile['profile_uid'])) {
226                                 if($item['last-child']) {
227                                         $comment = replace_macros($cmnt_tpl,array(
228                                                 '$id' => $item['item_id'],
229                                                 '$parent' => $item['parent'],
230                                                 '$profile_uid' =>  $a->profile['profile_uid'],
231                                                 '$ww' => $commentww
232                                         ));
233                                 }
234                         }
235
236
237                         $profile_url = $item['url'];
238
239                         if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
240                                 $profile_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
241
242                 //      $photo = (($item['self']) ? $a->profile['photo'] : $item['photo']);
243                 //      $thumb = (($item['self']) ? $a->profile['thumb'] : $item['thumb']);
244         
245                         $profile_name = ((strlen($item['remote-name'])) ? $item['remote-name'] : $item['name']);
246                         $profile_link = ((strlen($item['remote-link'])) ? $item['remote-link'] : $profile_url);
247                         $profile_avatar = ((strlen($item['remote-avatar'])) ? $item['remote-avatar'] : $item['thumb']);
248
249
250
251                         $o .= replace_macros($template,array(
252                         '$id' => $item['item_id'],
253                         '$profile_url' => $profile_link,
254                         '$name' => $profile_name,
255                         '$thumb' => $profile_avatar,
256                         '$body' => bbcode($item['body']),
257                         '$ago' => relative_date($item['created']),
258                         '$indent' => (($item['parent'] != $item['item_id']) ? 'comment-' : ''),
259                         '$owner_url' => $owner_url,
260                         '$owner_photo' => $owner_photo,
261                         '$owner_name' => $owner_name,
262                         '$comment' => $comment
263                 ));
264
265
266
267
268
269
270
271
272
273
274                 }
275         }
276
277         $o .= paginate($a);
278
279         return $o;
280
281
282 }