]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
Don't show the local community page on single user instances
[friendica.git] / mod / directory.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Config;
5 use Friendica\Database\DBM;
6 use Friendica\Model\Contact;
7
8 function directory_init(App $a) {
9         $a->set_pager_itemspage(60);
10
11         if(local_user()) {
12                 require_once('include/contact_widgets.php');
13
14                 $a->page['aside'] .= findpeople_widget();
15
16                 $a->page['aside'] .= follow_widget();
17         }
18         else {
19                 unset($_SESSION['theme']);
20                 unset($_SESSION['mobile-theme']);
21         }
22 }
23
24 function directory_post(App $a) {
25         if(x($_POST,'search'))
26                 $a->data['search'] = $_POST['search'];
27 }
28
29 function directory_content(App $a) {
30         require_once("mod/proxy.php");
31
32         if((Config::get('system','block_public')) && (! local_user()) && (! remote_user()) ||
33                 (Config::get('system','block_local_dir')) && (! local_user()) && (! remote_user())) {
34                 notice( t('Public access denied.') . EOL);
35                 return;
36         }
37
38         $o = '';
39         nav_set_selected('directory');
40
41         if(x($a->data,'search'))
42                 $search = notags(trim($a->data['search']));
43         else
44                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
45
46         $gdirpath = '';
47         $dirurl = Config::get('system','directory');
48         if(strlen($dirurl)) {
49                 $gdirpath = zrl($dirurl,true);
50         }
51
52         if($search) {
53                 $search = dbesc($search);
54
55                 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
56                                 (`user`.`nickname` LIKE '%$search%') OR
57                                 (`profile`.`pdesc` LIKE '%$search%') OR
58                                 (`profile`.`locality` LIKE '%$search%') OR
59                                 (`profile`.`region` LIKE '%$search%') OR
60                                 (`profile`.`country-name` LIKE '%$search%') OR
61                                 (`profile`.`gender` LIKE '%$search%') OR
62                                 (`profile`.`marital` LIKE '%$search%') OR
63                                 (`profile`.`sexual` LIKE '%$search%') OR
64                                 (`profile`.`about` LIKE '%$search%') OR
65                                 (`profile`.`romance` LIKE '%$search%') OR
66                                 (`profile`.`work` LIKE '%$search%') OR
67                                 (`profile`.`education` LIKE '%$search%') OR
68                                 (`profile`.`pub_keywords` LIKE '%$search%') OR
69                                 (`profile`.`prv_keywords` LIKE '%$search%'))";
70         }
71
72         $publish = ((Config::get('system','publish_all')) ? '' : " AND `publish` = 1 " );
73
74
75         $r = q("SELECT COUNT(*) AS `total` FROM `profile`
76                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
77                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
78         if (DBM::is_result($r))
79                 $a->set_pager_total($r[0]['total']);
80
81         $order = " ORDER BY `name` ASC ";
82
83         $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']);
84
85         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
86                         `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
87                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
88                         LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
89                         WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit);
90         if (DBM::is_result($r)) {
91
92                 if (in_array('small', $a->argv)) {
93                         $photo = 'thumb';
94                 }
95                 else {
96                         $photo = 'photo';
97                 }
98
99                 foreach ($r as $rr) {
100
101                         $itemurl= '';
102
103                         $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
104
105                         $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
106
107                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
108
109                         $details = '';
110                         if(strlen($rr['locality']))
111                                 $details .= $rr['locality'];
112                         if(strlen($rr['region'])) {
113                                 if(strlen($rr['locality']))
114                                         $details .= ', ';
115                                 $details .= $rr['region'];
116                         }
117                         if(strlen($rr['country-name'])) {
118                                 if(strlen($details))
119                                         $details .= ', ';
120                                 $details .= $rr['country-name'];
121                         }
122 //                      if(strlen($rr['dob'])) {
123 //                              if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
124 //                                      $details .= '<br />' . t('Age: ') . $years ;
125 //                      }
126 //                      if(strlen($rr['gender']))
127 //                              $details .= '<br />' . t('Gender: ') . $rr['gender'];
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                         $location_e = $location;
147
148                         $photo_menu = array(
149                                 'profile' => array(t("View Profile"), zrl($profile_link))
150                         );
151
152                         $entry = array(
153                                 'id' => $rr['id'],
154                                 'url' => $profile_link,
155                                 'itemurl' => $itemurl,
156                                 'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
157                                 'img_hover' => $rr['name'],
158                                 'name' => $rr['name'],
159                                 'details' => $details,
160                                 'account_type' => Contact::getAccountType($rr),
161                                 'profile' => $profile,
162                                 'location' => $location_e,
163                                 'tags' => $rr['pub_keywords'],
164                                 'gender'   => $gender,
165                                 'pdesc' => $pdesc,
166                                 'marital'  => $marital,
167                                 'homepage' => $homepage,
168                                 'about' => $about,
169                                 'photo_menu' => $photo_menu,
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                         if(! $arr['entry'])
181                                 continue;
182
183                         $entries[] = $arr['entry'];
184
185                 }
186
187                 $tpl = get_markup_template('directory_header.tpl');
188
189                 $o .= replace_macros($tpl, array(
190                         '$search' => $search,
191                         '$globaldir' => t('Global Directory'),
192                         '$gdirpath' => $gdirpath,
193                         '$desc' => t('Find on this site'),
194                         '$contacts' => $entries,
195                         '$finding' => t('Results for:'),
196                         '$findterm' => (strlen($search) ? $search : ""),
197                         '$title' => t('Site Directory'),
198                         '$submit' => t('Find'),
199                         '$paginate' => paginate($a),
200                 ));
201
202         }
203         else
204                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
205
206         return $o;
207 }