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