]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
094cf028f9a3f4ef0def72085f8481aa20b96b0c
[friendica.git] / mod / directory.php
1 <?php
2 function directory_init(&$a) {
3         $a->set_pager_itemspage(60);
4 }
5
6 function directory_content(&$a) {
7
8         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
9
10         $tpl .= file_get_contents('view/directory_header.tpl');
11
12         $o .= replace_macros($tpl, array(
13                 '$search' => $search,
14                 '$finding' => (strlen($search) ? "<h4>Finding: '$search'</h4>" : "")
15         ));
16
17         if($search)
18                 $search = dbesc($search);
19         $sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, `user`.`nickname`, `locality`,`region`,`country-name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`) AGAINST ('$search' IN BOOLEAN MODE) " : "");
20
21
22         $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `publish` = 1 AND `user`.`blocked` = 0 $sql_extra ");
23         if(count($r))
24                 $a->set_pager_total($r[0]['total']);
25
26
27
28         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `publish` = 1 AND `user`.`blocked` = 0 $sql_extra ORDER BY `name` ASC LIMIT %d , %d ",
29                 intval($a->pager['start']),
30                 intval($a->pager['itemspage'])
31         );
32         if(count($r)) {
33
34                 $tpl = file_get_contents('view/directory_item.tpl');
35
36                 if(in_array('small', $a->argv))
37                         $photo = 'thumb';
38                 else
39                         $photo = 'photo';
40
41                 foreach($r as $rr) {
42
43                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
44                         $details = '';
45                         if(strlen($rr['locality']))
46                                 $details .= $rr['locality'];
47                         if(strlen($rr['region'])) {
48                                 if(strlen($rr['locality']))
49                                         $details .= ', ';
50                                 $details .= $rr['region'];
51                         }
52                         if(strlen($rr['country-name'])) {
53                                 if(strlen($details))
54                                         $details .= ', ';
55                                 $details .= $rr['country-name'];
56                         }
57                         if(strlen($rr['dob'])) {
58                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
59                                         $details .= "<br />Age: $years" ; 
60                         }
61                         if(strlen($rr['gender']))
62                                 $details .= '<br />Gender: ' . $rr['gender'];
63
64                         $o .= replace_macros($tpl,array(
65                                 '$id' => $rr['id'],
66                                 '$profile-link' => $profile_link,
67                                 '$photo' => $rr[$photo],
68                                 '$alt-text' => $rr['name'],
69                                 '$name' => $rr['name'],
70                                 '$details' => $details  
71
72
73                         ));
74
75                 }
76                 $o .= "<div class=\"directory-end\" ></div>\r\n";
77                 $o .= paginate($a);
78
79         }
80         else
81                 notice("No entries (some entries may be hidden).");
82
83         return $o;
84 }