]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
display contact information in contact and directory according to the other contact...
[friendica.git] / mod / directory.php
1 <?php
2
3 function directory_init(&$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(&$a) {
24         if(x($_POST,'search'))
25                 $a->data['search'] = $_POST['search'];
26 }
27
28
29
30 function directory_content(&$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                                 (`pdesc` LIKE '%$search%') OR
61                                 (`locality` LIKE '%$search%') OR
62                                 (`region` LIKE '%$search%') OR
63                                 (`country-name` LIKE '%$search%') OR
64                                 (`gender` LIKE '%$search%') OR
65                                 (`marital` LIKE '%$search%') OR
66                                 (`sexual` LIKE '%$search%') OR
67                                 (`about` LIKE '%$search%') OR
68                                 (`romance` LIKE '%$search%') OR
69                                 (`work` LIKE '%$search%') OR
70                                 (`education` LIKE '%$search%') OR
71                                 (`pub_keywords` LIKE '%$search%') OR
72                                 (`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(count($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` FROM `profile`
89                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
90                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT ".$limit);
91         if(count($r)) {
92
93                 if(in_array('small', $a->argv))
94                         $photo = 'thumb';
95                 else
96                         $photo = 'photo';
97
98                 foreach($r as $rr) {
99
100                         $community = '';
101
102                         // get the friendica address and the profile url of the user
103                         $p = q("SELECT `addr` AS faddr, `url` AS profile_url FROM `contact` WHERE `uid` = %d AND `self`",
104                                 intval($rr['uid'])
105                         );
106
107                         if(count($p))
108                                 $itemurl = (($p['0']['faddr'] != "") ? $p['0']['faddr'] : $p['0']['profile_url']);
109
110                         $profile_link = z_root() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
111
112                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
113
114                         $details = '';
115                         if(strlen($rr['locality']))
116                                 $details .= $rr['locality'];
117                         if(strlen($rr['region'])) {
118                                 if(strlen($rr['locality']))
119                                         $details .= ', ';
120                                 $details .= $rr['region'];
121                         }
122                         if(strlen($rr['country-name'])) {
123                                 if(strlen($details))
124                                         $details .= ', ';
125                                 $details .= $rr['country-name'];
126                         }
127 //                      if(strlen($rr['dob'])) {
128 //                              if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
129 //                                      $details .= '<br />' . t('Age: ') . $years ; 
130 //                      }
131 //                      if(strlen($rr['gender']))
132 //                              $details .= '<br />' . t('Gender: ') . $rr['gender'];
133
134
135                         // show if account is a community account
136                         // ToDo the other should be also respected, but first we need a good translatiion
137                         // and systemwide consistency for displaying the page type
138                         if(intval($rr['page-flags']) == PAGE_COMMUNITY OR intval($rr['page-flags']) == PAGE_PRVGROUP)
139                                 $community = true;
140
141                         $profile = $rr;
142
143                         if((x($profile,'address') == 1)
144                                 || (x($profile,'locality') == 1)
145                                 || (x($profile,'region') == 1)
146                                 || (x($profile,'postal-code') == 1)
147                                 || (x($profile,'country-name') == 1))
148                         $location = t('Location:');
149
150                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
151
152                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
153
154                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
155
156                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
157
158                         if($a->theme['template_engine'] === 'internal') {
159                                 $location_e = template_escape($location);
160                         }
161                         else {
162                                 $location_e = $location;
163                         }
164                         
165                         $photo_menu = array(array(t("View Profile"), zrl($profile_link)));
166
167                         $entry = array(
168                                 'id' => $rr['id'],
169                                 'url' => $profile_link,
170                                 'itemurl' => $itemurl,
171                                 'thumb' => proxy_url($a->get_cached_avatar_image($rr[$photo]), false, PROXY_SIZE_THUMB),
172                                 'img_hover' => $rr['name'],
173                                 'name' => $rr['name'],
174                                 'details' => $details,
175                                 'account_type' => ($community ? t('Forum') : ''),
176                                 'profile' => $profile,
177                                 'location' => $location_e,
178                                 'tags' => $rr['pub_keywords'],
179                                 'gender'   => $gender,
180                                 'pdesc' => $pdesc,
181                                 'marital'  => $marital,
182                                 'homepage' => $homepage,
183                                 'about' => $about,
184                                 'photo_menu' => $photo_menu,
185
186                         );
187
188                         $arr = array('contact' => $rr, 'entry' => $entry);
189
190                         call_hooks('directory_item', $arr);
191
192                         unset($profile);
193                         unset($location);
194
195                         if(! $arr['entry'])
196                                 continue;
197
198                         $entries[] = $arr['entry'];
199
200                 }
201
202                 $tpl = get_markup_template('directory_header.tpl');
203
204                 $o .= replace_macros($tpl, array(
205                         '$search' => $search,
206                         '$globaldir' => t('Global Directory'),
207                         '$gdirpath' => $gdirpath,
208                         '$desc' => t('Find on this site'),
209                         '$contacts' => $entries,
210                         '$finding' => t('Finding:'),
211                         '$findterm' => (strlen($search) ? $search : ""),
212                         '$title' => t('Site Directory'),
213                         '$submit' => t('Find'),
214                         '$paginate' => paginate($a),
215                 ));
216
217         }
218         else
219                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
220
221         return $o;
222 }