Revert to stable version 3.5.4
[friendica-addons.git] / forumdirectory / forumdirectory.php
1 <?php
2 /**
3 * Name: Forum Directory
4 * Description: Add a directory of forums hosted on your server, with verbose descriptions.
5 * Version: 1.0
6 * Author: Thomas Willingham <https://beardyunixer.com/profile/beardyunixer>
7 */
8
9 function forumdirectory_install() {
10 register_hook('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
11 }
12
13 function forumdirectory_uninstall() {
14 unregister_hook('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
15 }
16
17 function forumdirectory_module() {
18 return;
19 }
20
21 function forumdirectory_app_menu($a,&$b) {
22 $b['app_menu'][] = '<div class="app-title"><a href="forumdirectory">' . t('Forum Directory') . '</a></div>';
23 }
24
25 function forumdirectory_init(&$a) {
26         $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$a->get_baseurl().'/addon/forumdirectory/forumdirectory.css" media="all" />';
27
28         $a->set_pager_itemspage(60);
29
30         if(local_user()) {
31                 require_once('include/contact_widgets.php');
32
33                 $a->page['aside'] .= findpeople_widget();
34
35         }
36         else
37                 unset($_SESSION['theme']);
38
39
40 }
41
42
43 function forumdirectory_post(&$a) {
44         if(x($_POST,'search'))
45                 $a->data['search'] = $_POST['search'];
46 }
47
48
49
50 function forumdirectory_content(&$a) {
51
52         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
53                 notice( t('Public access denied.') . EOL);
54                 return;
55         }
56
57         $o = '';
58         nav_set_selected('directory');
59
60         if(x($a->data,'search'))
61                 $search = notags(trim($a->data['search']));
62         else
63                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
64
65         $tpl = get_markup_template('directory_header.tpl');
66
67         $globaldir = '';
68         $gdirpath = get_config('system','directory');
69         if(strlen($gdirpath)) {
70                 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
71                 . zrl($gdirpath,true) . '">' . t('Global Directory') . '</a></div></li></ul>';
72         }
73
74         $admin = '';
75
76         $o .= replace_macros($tpl, array(
77                 '$search' => $search,
78                 '$globaldir' => $globaldir,
79                 '$desc' => t('Find on this site'),
80                 '$admin' => $admin,
81                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
82                 '$sitedir' => t('Site Directory'),
83                 '$submit' => t('Find')
84         ));
85
86         if($search)
87                 $search = dbesc($search);
88         $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) " : "");
89
90         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
91
92
93         $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 AND `page-flags` = 2 $sql_extra ");
94         if(count($r))
95                 $a->set_pager_total($r[0]['total']);
96
97         $order = " ORDER BY `name` ASC "; 
98
99
100         $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 AND `page-flags` = 2 $sql_extra $order LIMIT %d , %d ",
101                 intval($a->pager['start']),
102                 intval($a->pager['itemspage'])
103         );
104         if(count($r)) {
105
106                 if(in_array('small', $a->argv))
107                         $photo = 'thumb';
108                 else
109                         $photo = 'photo';
110
111                 foreach($r as $rr) {
112
113
114                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
115                 
116                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
117
118                         $details = '';
119                         if(strlen($rr['locality']))
120                                 $details .= $rr['locality'];
121                         if(strlen($rr['region'])) {
122                                 if(strlen($rr['locality']))
123                                         $details .= ', ';
124                                 $details .= $rr['region'];
125                         }
126                         if(strlen($rr['country-name'])) {
127                                 if(strlen($details))
128                                         $details .= ', ';
129                                 $details .= $rr['country-name'];
130                         }
131                         if(strlen($rr['dob'])) {
132                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
133                                         $details .= '<br />' . t('Age: ') . $years ; 
134                         }
135                         if(strlen($rr['gender']))
136                                 $details .= '<br />' . t('Gender: ') . $rr['gender'];
137
138                         if($rr['page-flags'] == PAGE_NORMAL)
139                                 $page_type = "Personal Profile";
140                         if($rr['page-flags'] == PAGE_SOAPBOX)
141                                 $page_type = "Fan Page";
142                         if($rr['page-flags'] == PAGE_COMMUNITY)
143                                 $page_type = "Community Forum";
144                         if($rr['page-flags'] == PAGE_FREELOVE)
145                                 $page_type = "Open Forum";
146                         if($rr['page-flags'] == PAGE_PRVGROUP)
147                                 $page_type = "Private Group";
148
149                         $profile = $rr;
150
151                         if((x($profile,'address') == 1)
152                                 || (x($profile,'locality') == 1)
153                                 || (x($profile,'region') == 1)
154                                 || (x($profile,'postal-code') == 1)
155                                 || (x($profile,'country-name') == 1))
156                         $location = t('Location:');
157
158                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
159
160                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
161
162                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
163
164                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
165                         
166 #                       $tpl = file_get_contents( dirname(__file__).'/forumdirectory_item.tpl');
167                         $tpl = get_markup_template( 'forumdirectory_item.tpl', 'addon/forumdirectory/' );
168
169                         $entry = replace_macros($tpl,array(
170                                 '$id' => $rr['id'],
171                                 '$profile_link' => $profile_link,
172                                 '$photo' => $a->get_cached_avatar_image($rr[$photo]),
173                                 '$alt_text' => $rr['name'],
174                                 '$name' => $rr['name'],
175                                 '$details' => $pdesc . $details,
176                                 '$page_type' => $page_type,
177                                 '$profile' => $profile,
178                                 '$location' => template_escape($location),
179                                 '$gender'   => $gender,
180                                 '$pdesc'        => $pdesc,
181                                 '$marital'  => $marital,
182                                 '$homepage' => $homepage,
183                                 '$about' => $about,
184
185                         ));
186
187                         $arr = array('contact' => $rr, 'entry' => $entry);
188
189                         unset($profile);
190                         unset($location);
191
192                         $o .= $entry;
193
194                 }
195
196                 $o .= "<div class=\"directory-end\" ></div>\r\n";
197                 $o .= paginate($a);
198
199         }
200         else
201                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
202
203         return $o;
204 }