]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
Merge pull request #1663 from rabuzarus/vier-remote-link
[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         }
12         else {
13                 unset($_SESSION['theme']);
14                 unset($_SESSION['mobile-theme']);
15         }
16
17
18 }
19
20
21 function directory_post(&$a) {
22         if(x($_POST,'search'))
23                 $a->data['search'] = $_POST['search'];
24 }
25
26
27
28 function directory_content(&$a) {
29         global $db;
30
31         require_once("mod/proxy.php");
32
33         if((get_config('system','block_public')) && (! local_user()) && (! remote_user()) || 
34                 (get_config('system','block_local_dir')) && (! local_user()) && (! remote_user())) {
35                 notice( t('Public access denied.') . EOL);
36                 return;
37         }
38
39         $o = '';
40         nav_set_selected('directory');
41
42         if(x($a->data,'search'))
43                 $search = notags(trim($a->data['search']));
44         else
45                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
46
47         $tpl = get_markup_template('directory_header.tpl');
48
49         $globaldir = '';
50         $gdirpath = dirname(get_config('system','directory_submit_url'));
51         if(strlen($gdirpath)) {
52                 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
53                 . zrl($gdirpath,true) . '">' . t('Global Directory') . '</a></div></li></ul>';
54         }
55
56         $admin = '';
57
58         $o .= replace_macros($tpl, array(
59                 '$search' => $search,
60                 '$globaldir' => $globaldir,
61                 '$desc' => t('Find on this site'),
62                 '$admin' => $admin,
63                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
64                 '$sitedir' => t('Site Directory'),
65                 '$submit' => t('Find')
66         ));
67
68         if($search) {
69                 $search = dbesc($search);
70
71                 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
72                                 (`user`.`nickname` LIKE '%$search%') OR
73                                 (`pdesc` LIKE '%$search%') OR
74                                 (`locality` LIKE '%$search%') OR
75                                 (`region` LIKE '%$search%') OR
76                                 (`country-name` LIKE '%$search%') OR
77                                 (`gender` LIKE '%$search%') OR
78                                 (`marital` LIKE '%$search%') OR
79                                 (`sexual` LIKE '%$search%') OR
80                                 (`about` LIKE '%$search%') OR
81                                 (`romance` LIKE '%$search%') OR
82                                 (`work` LIKE '%$search%') OR
83                                 (`education` LIKE '%$search%') OR
84                                 (`pub_keywords` LIKE '%$search%') OR
85                                 (`prv_keywords` LIKE '%$search%'))";
86         }
87
88         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
89
90
91         $r = $db->q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
92         if(count($r))
93                 $a->set_pager_total($r[0]['total']);
94
95         $order = " ORDER BY `name` ASC ";
96
97         $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']);
98
99         $r = $db->q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT ".$limit);
100         if(count($r)) {
101
102                 if(in_array('small', $a->argv))
103                         $photo = 'thumb';
104                 else
105                         $photo = 'photo';
106
107                 foreach($r as $rr) {
108
109
110                         $profile_link = $a->get_baseurl() . '/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                         if($rr['page-flags'] == PAGE_NORMAL)
135                                 $page_type = "Personal Profile";
136                         if($rr['page-flags'] == PAGE_SOAPBOX)
137                                 $page_type = "Fan Page";
138                         if($rr['page-flags'] == PAGE_COMMUNITY)
139                                 $page_type = "Community Forum";
140                         if($rr['page-flags'] == PAGE_FREELOVE)
141                                 $page_type = "Open Forum";
142                         if($rr['page-flags'] == PAGE_PRVGROUP)
143                                 $page_type = "Private Group";
144
145                         $profile = $rr;
146
147                         if((x($profile,'address') == 1)
148                                 || (x($profile,'locality') == 1)
149                                 || (x($profile,'region') == 1)
150                                 || (x($profile,'postal-code') == 1)
151                                 || (x($profile,'country-name') == 1))
152                         $location = t('Location:');
153
154                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
155
156                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
157
158                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
159
160                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
161
162                         $tpl = get_markup_template('directory_item.tpl');
163
164                         if($a->theme['template_engine'] === 'internal') {
165                                 $location_e = template_escape($location);
166                         }
167                         else {
168                                 $location_e = $location;
169                         }
170
171                         $entry = replace_macros($tpl,array(
172                                 '$id' => $rr['id'],
173                                 '$profile_link' => $profile_link,
174                                 '$photo' => proxy_url($a->get_cached_avatar_image($rr[$photo])),
175                                 '$alt_text' => $rr['name'],
176                                 '$name' => $rr['name'],
177                                 '$details' => $pdesc . $details,
178                                 '$page_type' => $page_type,
179                                 '$profile' => $profile,
180                                 '$location' => $location_e,
181                                 '$gender'   => $gender,
182                                 '$pdesc'        => $pdesc,
183                                 '$marital'  => $marital,
184                                 '$homepage' => $homepage,
185                                 '$about' => $about,
186
187                         ));
188
189                         $arr = array('contact' => $rr, 'entry' => $entry);
190
191                         call_hooks('directory_item', $arr);
192
193                         unset($profile);
194                         unset($location);
195
196                         $o .= $entry;
197
198                 }
199
200                 $o .= "<div class=\"directory-end\" ></div>\r\n";
201                 $o .= paginate($a);
202
203         }
204         else
205                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
206
207         return $o;
208 }