]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
Merge branch 'develop' into rewrites/dbm_is_result
[friendica.git] / mod / directory.php
1 <?php
2
3 function directory_init(App &$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(App &$a) {
24         if(x($_POST,'search'))
25                 $a->data['search'] = $_POST['search'];
26 }
27
28
29
30 function directory_content(App &$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                                 (`profile`.`pdesc` LIKE '%$search%') OR
61                                 (`profile`.`locality` LIKE '%$search%') OR
62                                 (`profile`.`region` LIKE '%$search%') OR
63                                 (`profile`.`country-name` LIKE '%$search%') OR
64                                 (`profile`.`gender` LIKE '%$search%') OR
65                                 (`profile`.`marital` LIKE '%$search%') OR
66                                 (`profile`.`sexual` LIKE '%$search%') OR
67                                 (`profile`.`about` LIKE '%$search%') OR
68                                 (`profile`.`romance` LIKE '%$search%') OR
69                                 (`profile`.`work` LIKE '%$search%') OR
70                                 (`profile`.`education` LIKE '%$search%') OR
71                                 (`profile`.`pub_keywords` LIKE '%$search%') OR
72                                 (`profile`.`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`
79                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
80                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
81         if (dbm::is_result($r))
82                 $a->set_pager_total($r[0]['total']);
83
84         $order = " ORDER BY `name` ASC ";
85
86         $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']);
87
88         $r = $db->q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
89                         `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
90                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
91                         LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
92                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit);
93         if (dbm::is_result($r)) {
94
95                 if (in_array('small', $a->argv)) {
96                         $photo = 'thumb';
97                 }
98                 else {
99                         $photo = 'photo';
100                 }
101
102                 foreach ($r as $rr) {
103
104                         $itemurl= '';
105
106                         $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
107
108                         $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
109
110                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
111
112                         $details = '';
113                         if(strlen($rr['locality']))
114                                 $details .= $rr['locality'];
115                         if(strlen($rr['region'])) {
116                                 if(strlen($rr['locality']))
117                                         $details .= ', ';
118                                 $details .= $rr['region'];
119                         }
120                         if(strlen($rr['country-name'])) {
121                                 if(strlen($details))
122                                         $details .= ', ';
123                                 $details .= $rr['country-name'];
124                         }
125 //                      if(strlen($rr['dob'])) {
126 //                              if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
127 //                                      $details .= '<br />' . t('Age: ') . $years ; 
128 //                      }
129 //                      if(strlen($rr['gender']))
130 //                              $details .= '<br />' . t('Gender: ') . $rr['gender'];
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(
157                                 'profile' => array(t("View Profile"), zrl($profile_link))
158                         );
159
160                         $entry = array(
161                                 'id' => $rr['id'],
162                                 'url' => $profile_link,
163                                 'itemurl' => $itemurl,
164                                 'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
165                                 'img_hover' => $rr['name'],
166                                 'name' => $rr['name'],
167                                 'details' => $details,
168                                 'account_type' => account_type($rr),
169                                 'profile' => $profile,
170                                 'location' => $location_e,
171                                 'tags' => $rr['pub_keywords'],
172                                 'gender'   => $gender,
173                                 'pdesc' => $pdesc,
174                                 'marital'  => $marital,
175                                 'homepage' => $homepage,
176                                 'about' => $about,
177                                 'photo_menu' => $photo_menu,
178
179                         );
180
181                         $arr = array('contact' => $rr, 'entry' => $entry);
182
183                         call_hooks('directory_item', $arr);
184
185                         unset($profile);
186                         unset($location);
187
188                         if(! $arr['entry'])
189                                 continue;
190
191                         $entries[] = $arr['entry'];
192
193                 }
194
195                 $tpl = get_markup_template('directory_header.tpl');
196
197                 $o .= replace_macros($tpl, array(
198                         '$search' => $search,
199                         '$globaldir' => t('Global Directory'),
200                         '$gdirpath' => $gdirpath,
201                         '$desc' => t('Find on this site'),
202                         '$contacts' => $entries,
203                         '$finding' => t('Results for:'),
204                         '$findterm' => (strlen($search) ? $search : ""),
205                         '$title' => t('Site Directory'),
206                         '$submit' => t('Find'),
207                         '$paginate' => paginate($a),
208                 ));
209
210         }
211         else
212                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
213
214         return $o;
215 }