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