]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
The central item fetch does work now and the API now uses these functions
[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 {
17         $a->set_pager_itemspage(60);
18
19         if (local_user()) {
20                 $a->page['aside'] .= Widget::findPeople();
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 {
30         if (x($_POST, 'search')) {
31                 $a->data['search'] = $_POST['search'];
32         }
33 }
34
35 function directory_content(App $a)
36 {
37         require_once("mod/proxy.php");
38
39         if ((Config::get('system', 'block_public') && !local_user() && !remote_user())
40                 || (Config::get('system', 'block_local_dir') && !local_user() && !remote_user())
41         ) {
42                 notice(L10n::t('Public access denied.') . EOL);
43                 return;
44         }
45
46         $o = '';
47         Nav::setSelected('directory');
48
49         if (x($a->data, 'search')) {
50                 $search = notags(trim($a->data['search']));
51         } else {
52                 $search = ((x($_GET, 'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
53         }
54
55         $gdirpath = '';
56         $dirurl = Config::get('system', 'directory');
57         if (strlen($dirurl)) {
58                 $gdirpath = Profile::zrl($dirurl, true);
59         }
60
61         if ($search) {
62                 $search = dbesc($search);
63
64                 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
65                                 (`user`.`nickname` LIKE '%$search%') OR
66                                 (`profile`.`pdesc` LIKE '%$search%') OR
67                                 (`profile`.`locality` LIKE '%$search%') OR
68                                 (`profile`.`region` LIKE '%$search%') OR
69                                 (`profile`.`country-name` LIKE '%$search%') OR
70                                 (`profile`.`gender` LIKE '%$search%') OR
71                                 (`profile`.`marital` LIKE '%$search%') OR
72                                 (`profile`.`sexual` LIKE '%$search%') OR
73                                 (`profile`.`about` LIKE '%$search%') OR
74                                 (`profile`.`romance` LIKE '%$search%') OR
75                                 (`profile`.`work` LIKE '%$search%') OR
76                                 (`profile`.`education` LIKE '%$search%') OR
77                                 (`profile`.`pub_keywords` LIKE '%$search%') OR
78                                 (`profile`.`prv_keywords` LIKE '%$search%'))";
79         }
80
81         $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " );
82
83
84         $cnt = dba::fetch_first("SELECT COUNT(*) AS `total` FROM `profile`
85                                 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
86                                 WHERE `is-default` $publish AND NOT `user`.`blocked` $sql_extra");
87         if (DBM::is_result($cnt)) {
88                 $a->set_pager_total($cnt['total']);
89         }
90
91         $order = " ORDER BY `name` ASC ";
92
93         $limit = intval($a->pager['start'])."," . intval($a->pager['itemspage']);
94
95         $r = dba::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
96                         `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
97                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
98                         LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
99                         WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit
100         );
101         if (DBM::is_result($r)) {
102                 if (in_array('small', $a->argv)) {
103                         $photo = 'thumb';
104                 } else {
105                         $photo = 'photo';
106                 }
107
108                 while ($rr = dba::fetch($r)) {
109                         $itemurl= '';
110
111                         $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
112
113                         $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
114
115                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
116
117                         $details = '';
118                         if (strlen($rr['locality'])) {
119                                 $details .= $rr['locality'];
120                         }
121                         if (strlen($rr['region'])) {
122                                 if (strlen($rr['locality'])) {
123                                         $details .= ', ';
124                                 }
125                                 $details .= $rr['region'];
126                         }
127                         if (strlen($rr['country-name'])) {
128                                 if (strlen($details)) {
129                                         $details .= ', ';
130                                 }
131                                 $details .= $rr['country-name'];
132                         }
133 //                      if(strlen($rr['dob'])) {
134 //                              if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
135 //                                      $details .= '<br />' . L10n::t('Age: ') . $years ;
136 //                      }
137 //                      if(strlen($rr['gender']))
138 //                              $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
139
140                         $profile = $rr;
141
142                         if ((x($profile, 'address')             == 1)
143                                 || (x($profile, 'locality')     == 1)
144                                 || (x($profile, 'region')       == 1)
145                                 || (x($profile, 'postal-code')  == 1)
146                                 || (x($profile, 'country-name') == 1)
147                         ) {
148                                 $location = L10n::t('Location:');
149                         }
150
151                         $gender   = ((x($profile, 'gender')   == 1) ? L10n::t('Gender:')   : false);
152                         $marital  = ((x($profile, 'marital')  == 1) ? L10n::t('Status:')   : false);
153                         $homepage = ((x($profile, 'homepage') == 1) ? L10n::t('Homepage:') : false);
154                         $about    = ((x($profile, 'about')    == 1) ? L10n::t('About:')    : false);
155
156                         $location_e = $location;
157
158                         $photo_menu = [
159                                 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
160                         ];
161
162                         $entry = [
163                                 'id'           => $rr['id'],
164                                 'url'          => $profile_link,
165                                 'itemurl'      => $itemurl,
166                                 'thumb'        => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
167                                 'img_hover'    => $rr['name'],
168                                 'name'         => $rr['name'],
169                                 'details'      => $details,
170                                 'account_type' => Contact::getAccountType($rr),
171                                 'profile'      => $profile,
172                                 'location'     => $location_e,
173                                 'tags'         => $rr['pub_keywords'],
174                                 'gender'       => $gender,
175                                 'pdesc'        => $pdesc,
176                                 'marital'      => $marital,
177                                 'homepage'     => $homepage,
178                                 'about'        => $about,
179                                 'photo_menu'   => $photo_menu,
180
181                         ];
182
183                         $arr = ['contact' => $rr, 'entry' => $entry];
184
185                         Addon::callHooks('directory_item', $arr);
186
187                         unset($profile);
188                         unset($location);
189
190                         if (!$arr['entry']) {
191                                 continue;
192                         }
193
194                         $entries[] = $arr['entry'];
195                 }
196                 dba::close($r);
197
198                 $tpl = get_markup_template('directory_header.tpl');
199
200                 $o .= replace_macros($tpl, [
201                         '$search'    => $search,
202                         '$globaldir' => L10n::t('Global Directory'),
203                         '$gdirpath'  => $gdirpath,
204                         '$desc'      => L10n::t('Find on this site'),
205                         '$contacts'  => $entries,
206                         '$finding'   => L10n::t('Results for:'),
207                         '$findterm'  => (strlen($search) ? $search : ""),
208                         '$title'     => L10n::t('Site Directory'),
209                         '$submit'    => L10n::t('Find'),
210                         '$paginate'  => paginate($a),
211                 ]);
212         } else {
213                 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);
214         }
215
216         return $o;
217 }