]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
Merge remote-tracking branch 'upstream/develop' into develop
[friendica.git] / mod / directory.php
1 <?php
2
3 use Friendica\App;
4
5 function directory_init(App $a) {
6         $a->set_pager_itemspage(60);
7
8         if(local_user()) {
9                 require_once('include/contact_widgets.php');
10
11                 $a->page['aside'] .= findpeople_widget();
12
13                 $a->page['aside'] .= follow_widget();
14         }
15         else {
16                 unset($_SESSION['theme']);
17                 unset($_SESSION['mobile-theme']);
18         }
19 }
20
21 function directory_post(App $a) {
22         if(x($_POST,'search'))
23                 $a->data['search'] = $_POST['search'];
24 }
25
26 function directory_content(App $a) {
27         global $db;
28
29         require_once("mod/proxy.php");
30
31         if((get_config('system','block_public')) && (! local_user()) && (! remote_user()) ||
32                 (get_config('system','block_local_dir')) && (! 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         $gdirpath = '';
46         $dirurl = get_config('system','directory');
47         if(strlen($dirurl)) {
48                 $gdirpath = zrl($dirurl,true);
49         }
50
51         if($search) {
52                 $search = dbesc($search);
53
54                 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
55                                 (`user`.`nickname` LIKE '%$search%') OR
56                                 (`profile`.`pdesc` LIKE '%$search%') OR
57                                 (`profile`.`locality` LIKE '%$search%') OR
58                                 (`profile`.`region` LIKE '%$search%') OR
59                                 (`profile`.`country-name` LIKE '%$search%') OR
60                                 (`profile`.`gender` LIKE '%$search%') OR
61                                 (`profile`.`marital` LIKE '%$search%') OR
62                                 (`profile`.`sexual` LIKE '%$search%') OR
63                                 (`profile`.`about` LIKE '%$search%') OR
64                                 (`profile`.`romance` LIKE '%$search%') OR
65                                 (`profile`.`work` LIKE '%$search%') OR
66                                 (`profile`.`education` LIKE '%$search%') OR
67                                 (`profile`.`pub_keywords` LIKE '%$search%') OR
68                                 (`profile`.`prv_keywords` LIKE '%$search%'))";
69         }
70
71         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
72
73
74         $r = q("SELECT COUNT(*) AS `total` FROM `profile`
75                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
76                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
77         if (dbm::is_result($r))
78                 $a->set_pager_total($r[0]['total']);
79
80         $order = " ORDER BY `name` ASC ";
81
82         $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']);
83
84         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
85                         `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
86                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
87                         LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
88                         WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit);
89         if (dbm::is_result($r)) {
90
91                 if (in_array('small', $a->argv)) {
92                         $photo = 'thumb';
93                 }
94                 else {
95                         $photo = 'photo';
96                 }
97
98                 foreach ($r as $rr) {
99
100                         $itemurl= '';
101
102                         $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
103
104                         $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
105
106                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
107
108                         $details = '';
109                         if(strlen($rr['locality']))
110                                 $details .= $rr['locality'];
111                         if(strlen($rr['region'])) {
112                                 if(strlen($rr['locality']))
113                                         $details .= ', ';
114                                 $details .= $rr['region'];
115                         }
116                         if(strlen($rr['country-name'])) {
117                                 if(strlen($details))
118                                         $details .= ', ';
119                                 $details .= $rr['country-name'];
120                         }
121 //                      if(strlen($rr['dob'])) {
122 //                              if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
123 //                                      $details .= '<br />' . t('Age: ') . $years ;
124 //                      }
125 //                      if(strlen($rr['gender']))
126 //                              $details .= '<br />' . t('Gender: ') . $rr['gender'];
127
128                         $profile = $rr;
129
130                         if((x($profile,'address') == 1)
131                                 || (x($profile,'locality') == 1)
132                                 || (x($profile,'region') == 1)
133                                 || (x($profile,'postal-code') == 1)
134                                 || (x($profile,'country-name') == 1))
135                         $location = t('Location:');
136
137                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
138
139                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
140
141                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
142
143                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
144
145                         if($a->theme['template_engine'] === 'internal') {
146                                 $location_e = template_escape($location);
147                         }
148                         else {
149                                 $location_e = $location;
150                         }
151
152                         $photo_menu = array(
153                                 'profile' => array(t("View Profile"), zrl($profile_link))
154                         );
155
156                         $entry = array(
157                                 'id' => $rr['id'],
158                                 'url' => $profile_link,
159                                 'itemurl' => $itemurl,
160                                 'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
161                                 'img_hover' => $rr['name'],
162                                 'name' => $rr['name'],
163                                 'details' => $details,
164                                 'account_type' => account_type($rr),
165                                 'profile' => $profile,
166                                 'location' => $location_e,
167                                 'tags' => $rr['pub_keywords'],
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('Results for:'),
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 }