]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
Merge remote branch 'upstream/master'
[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
15
16 }
17
18
19 function directory_post(&$a) {
20         if(x($_POST,'search'))
21                 $a->data['search'] = $_POST['search'];
22 }
23
24
25
26 function directory_content(&$a) {
27
28         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
29                 notice( t('Public access denied.') . EOL);
30                 return;
31         }
32
33         $o = '';
34         nav_set_selected('directory');
35
36         if(x($a->data,'search'))
37                 $search = notags(trim($a->data['search']));
38         else
39                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
40
41         $tpl = get_markup_template('directory_header.tpl');
42
43         $globaldir = '';
44         $gdirpath = dirname(get_config('system','directory_submit_url'));
45         if(strlen($gdirpath)) {
46                 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
47                 . zrl($gdirpath,true) . '">' . t('Global Directory') . '</a></div></li></ul>';
48         }
49
50         $admin = '';
51
52         $o .= replace_macros($tpl, array(
53                 '$search' => $search,
54                 '$globaldir' => $globaldir,
55                 '$desc' => t('Find on this site'),
56                 '$admin' => $admin,
57                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
58                 '$sitedir' => t('Site Directory'),
59                 '$submit' => t('Find')
60         ));
61
62         if($search)
63                 $search = dbesc($search);
64         $sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`pub_keywords`,`prv_keywords` ) AGAINST ('$search' IN BOOLEAN MODE) " : "");
65
66         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
67
68
69         $r = 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 ");
70         if(count($r))
71                 $a->set_pager_total($r[0]['total']);
72
73         $order = " ORDER BY `name` ASC "; 
74
75
76         $r = 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 %d , %d ",
77                 intval($a->pager['start']),
78                 intval($a->pager['itemspage'])
79         );
80         if(count($r)) {
81
82                 if(in_array('small', $a->argv))
83                         $photo = 'thumb';
84                 else
85                         $photo = 'photo';
86
87                 foreach($r as $rr) {
88
89
90                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
91                 
92                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
93
94                         $details = '';
95                         if(strlen($rr['locality']))
96                                 $details .= $rr['locality'];
97                         if(strlen($rr['region'])) {
98                                 if(strlen($rr['locality']))
99                                         $details .= ', ';
100                                 $details .= $rr['region'];
101                         }
102                         if(strlen($rr['country-name'])) {
103                                 if(strlen($details))
104                                         $details .= ', ';
105                                 $details .= $rr['country-name'];
106                         }
107                         if(strlen($rr['dob'])) {
108                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
109                                         $details .= '<br />' . t('Age: ') . $years ; 
110                         }
111                         if(strlen($rr['gender']))
112                                 $details .= '<br />' . t('Gender: ') . $rr['gender'];
113
114                         if($rr['page-flags'] == PAGE_NORMAL)
115                                 $page_type = "Personal Profile";
116                         if($rr['page-flags'] == PAGE_SOAPBOX)
117                                 $page_type = "Fan Page";
118                         if($rr['page-flags'] == PAGE_COMMUNITY)
119                                 $page_type = "Community Forum";
120                         if($rr['page-flags'] == PAGE_FREELOVE)
121                                 $page_type = "Open Forum";
122                         if($rr['page-flags'] == PAGE_PRVGROUP)
123                                 $page_type = "Private Group";
124
125                         $profile = $rr;
126
127                         if((x($profile,'address') == 1)
128                                 || (x($profile,'locality') == 1)
129                                 || (x($profile,'region') == 1)
130                                 || (x($profile,'postal-code') == 1)
131                                 || (x($profile,'country-name') == 1))
132                         $location = t('Location:');
133
134                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
135
136                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
137
138                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
139
140                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
141                         
142                         $tpl = get_markup_template('directory_item.tpl');
143
144                         $entry = replace_macros($tpl,array(
145                                 '$id' => $rr['id'],
146                                 '$profile-link' => $profile_link,
147                                 '$photo' => $a->get_cached_avatar_image($rr[$photo]),
148                                 '$alt-text' => $rr['name'],
149                                 '$name' => $rr['name'],
150                                 '$details' => $pdesc . $details,
151                                 '$page-type' => $page_type,
152                                 '$profile' => $profile,
153                                 '$location' => template_escape($location),
154                                 '$gender'   => $gender,
155                                 '$pdesc'        => $pdesc,
156                                 '$marital'  => $marital,
157                                 '$homepage' => $homepage,
158                                 '$about' => $about,
159
160                         ));
161
162                         $arr = array('contact' => $rr, 'entry' => $entry);
163
164                         call_hooks('directory_item', $arr);
165                         
166                         unset($profile);
167                         unset($location);
168
169                         $o .= $entry;
170
171                 }
172
173                 $o .= "<div class=\"directory-end\" ></div>\r\n";
174                 $o .= paginate($a);
175
176         }
177         else
178                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
179
180         return $o;
181 }