]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
Merge pull request #1338 from annando/1501-global-contacts
[friendica.git] / mod / directory.php
1 <?php
2
3 function directory_init(&$a) {
4         $a->set_pager_itemspage(60);
5
6         if(local_user()) {
7                 require_once('include/contact_widgets.php');
8
9                 $a->page['aside'] .= findpeople_widget();
10
11         }
12         else {
13                 unset($_SESSION['theme']);
14                 unset($_SESSION['mobile-theme']);
15         }
16
17
18 }
19
20
21 function directory_post(&$a) {
22         if(x($_POST,'search'))
23                 $a->data['search'] = $_POST['search'];
24 }
25
26
27
28 function directory_content(&$a) {
29
30         require_once("mod/proxy.php");
31
32         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
33                 notice( t('Public access denied.') . EOL);
34                 return;
35         }
36
37         $o = '';
38         nav_set_selected('directory');
39
40         if(x($a->data,'search'))
41                 $search = notags(trim($a->data['search']));
42         else
43                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
44
45         $tpl = get_markup_template('directory_header.tpl');
46
47         $globaldir = '';
48         $gdirpath = dirname(get_config('system','directory_submit_url'));
49         if(strlen($gdirpath)) {
50                 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
51                 . zrl($gdirpath,true) . '">' . t('Global Directory') . '</a></div></li></ul>';
52         }
53
54         $admin = '';
55
56         $o .= replace_macros($tpl, array(
57                 '$search' => $search,
58                 '$globaldir' => $globaldir,
59                 '$desc' => t('Find on this site'),
60                 '$admin' => $admin,
61                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
62                 '$sitedir' => t('Site Directory'),
63                 '$submit' => t('Find')
64         ));
65
66         if($search)
67                 $search = dbesc($search);
68         $sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`pub_keywords`,`prv_keywords` ) AGAINST ('$search' IN BOOLEAN MODE) " : "");
69
70         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
71
72
73         $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
74         if(count($r))
75                 $a->set_pager_total($r[0]['total']);
76
77         $order = " ORDER BY `name` ASC "; 
78
79
80         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
81                 intval($a->pager['start']),
82                 intval($a->pager['itemspage'])
83         );
84         if(count($r)) {
85
86                 if(in_array('small', $a->argv))
87                         $photo = 'thumb';
88                 else
89                         $photo = 'photo';
90
91                 foreach($r as $rr) {
92
93
94                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
95
96                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
97
98                         $details = '';
99                         if(strlen($rr['locality']))
100                                 $details .= $rr['locality'];
101                         if(strlen($rr['region'])) {
102                                 if(strlen($rr['locality']))
103                                         $details .= ', ';
104                                 $details .= $rr['region'];
105                         }
106                         if(strlen($rr['country-name'])) {
107                                 if(strlen($details))
108                                         $details .= ', ';
109                                 $details .= $rr['country-name'];
110                         }
111                         if(strlen($rr['dob'])) {
112                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
113                                         $details .= '<br />' . t('Age: ') . $years ; 
114                         }
115                         if(strlen($rr['gender']))
116                                 $details .= '<br />' . t('Gender: ') . $rr['gender'];
117
118                         if($rr['page-flags'] == PAGE_NORMAL)
119                                 $page_type = "Personal Profile";
120                         if($rr['page-flags'] == PAGE_SOAPBOX)
121                                 $page_type = "Fan Page";
122                         if($rr['page-flags'] == PAGE_COMMUNITY)
123                                 $page_type = "Community Forum";
124                         if($rr['page-flags'] == PAGE_FREELOVE)
125                                 $page_type = "Open Forum";
126                         if($rr['page-flags'] == PAGE_PRVGROUP)
127                                 $page_type = "Private Group";
128
129                         $profile = $rr;
130
131                         if((x($profile,'address') == 1)
132                                 || (x($profile,'locality') == 1)
133                                 || (x($profile,'region') == 1)
134                                 || (x($profile,'postal-code') == 1)
135                                 || (x($profile,'country-name') == 1))
136                         $location = t('Location:');
137
138                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
139
140                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
141
142                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
143
144                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
145
146                         $tpl = get_markup_template('directory_item.tpl');
147
148                         if($a->theme['template_engine'] === 'internal') {
149                                 $location_e = template_escape($location);
150                         }
151                         else {
152                                 $location_e = $location;
153                         }
154
155                         $entry = replace_macros($tpl,array(
156                                 '$id' => $rr['id'],
157                                 '$profile_link' => $profile_link,
158                                 '$photo' => proxy_url($a->get_cached_avatar_image($rr[$photo])),
159                                 '$alt_text' => $rr['name'],
160                                 '$name' => $rr['name'],
161                                 '$details' => $pdesc . $details,
162                                 '$page_type' => $page_type,
163                                 '$profile' => $profile,
164                                 '$location' => $location_e,
165                                 '$gender'   => $gender,
166                                 '$pdesc'        => $pdesc,
167                                 '$marital'  => $marital,
168                                 '$homepage' => $homepage,
169                                 '$about' => $about,
170
171                         ));
172
173                         $arr = array('contact' => $rr, 'entry' => $entry);
174
175                         call_hooks('directory_item', $arr);
176
177                         unset($profile);
178                         unset($location);
179
180                         $o .= $entry;
181
182                 }
183
184                 $o .= "<div class=\"directory-end\" ></div>\r\n";
185                 $o .= paginate($a);
186
187         }
188         else
189                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
190
191         return $o;
192 }