]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
9cce167605178ef9b7a322edebff0690614faf94
[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         
13
14         $o .= replace_macros($tpl, array(
15                 '$search' => $search,
16                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : "")
17         ));
18
19         if($search)
20                 $search = dbesc($search);
21         $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) " : "");
22
23
24         $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 ");
25         if(count($r))
26                 $a->set_pager_total($r[0]['total']);
27
28
29
30         $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 ",
31                 intval($a->pager['start']),
32                 intval($a->pager['itemspage'])
33         );
34         if(count($r)) {
35
36                 $tpl = file_get_contents('view/directory_item.tpl');
37
38                 if(in_array('small', $a->argv))
39                         $photo = 'thumb';
40                 else
41                         $photo = 'photo';
42
43                 foreach($r as $rr) {
44
45
46                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
47                         $details = '';
48                         if(strlen($rr['locality']))
49                                 $details .= $rr['locality'];
50                         if(strlen($rr['region'])) {
51                                 if(strlen($rr['locality']))
52                                         $details .= ', ';
53                                 $details .= $rr['region'];
54                         }
55                         if(strlen($rr['country-name'])) {
56                                 if(strlen($details))
57                                         $details .= ', ';
58                                 $details .= $rr['country-name'];
59                         }
60                         if(strlen($rr['dob'])) {
61                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
62                                         $details .= "<br />Age: $years" ; 
63                         }
64                         if(strlen($rr['gender']))
65                                 $details .= '<br />Gender: ' . $rr['gender'];
66
67                         $o .= replace_macros($tpl,array(
68                                 '$id' => $rr['id'],
69                                 '$profile-link' => $profile_link,
70                                 '$photo' => $rr[$photo],
71                                 '$alt-text' => $rr['name'],
72                                 '$name' => $rr['name'],
73                                 '$details' => $details  
74
75
76                         ));
77
78                 }
79                 $o .= "<div class=\"directory-end\" ></div>\r\n";
80                 $o .= paginate($a);
81
82         }
83         else
84                 notice("No entries (some entries may be hidden).");
85
86         return $o;
87 }