4 * Name: Forum Directory
5 * Description: Add a directory of forums hosted on your server, with verbose descriptions.
7 * Author: Thomas Willingham <https://beardyunixer.com/profile/beardyunixer>
10 use Friendica\Content\Nav;
11 use Friendica\Content\Widget;
12 use Friendica\Core\Config;
13 use Friendica\Database\DBM;
15 function forumdirectory_install()
17 register_hook('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
20 function forumdirectory_uninstall()
22 unregister_hook('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
25 function forumdirectory_module()
30 function forumdirectory_app_menu($a, &$b)
32 $b['app_menu'][] = '<div class="app-title"><a href="forumdirectory">' . t('Forum Directory') . '</a></div>';
35 function forumdirectory_init(&$a)
37 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/forumdirectory/forumdirectory.css" media="all" />';
39 $a->set_pager_itemspage(60);
42 $a->page['aside'] .= Widget::findPeople();
44 unset($_SESSION['theme']);
48 function forumdirectory_post(&$a)
50 if (x($_POST, 'search')) {
51 $a->data['search'] = $_POST['search'];
55 function forumdirectory_content(&$a)
57 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
58 notice(t('Public access denied.') . EOL);
63 Nav::setSelected('directory');
65 if (x($a->data, 'search')) {
66 $search = notags(trim($a->data['search']));
68 $search = ((x($_GET, 'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
71 $tpl = get_markup_template('directory_header.tpl');
74 $gdirpath = Config::get('system', 'directory');
75 if (strlen($gdirpath)) {
76 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
77 . zrl($gdirpath, true) . '">' . t('Global Directory') . '</a></div></li></ul>';
82 $o .= replace_macros($tpl, [
84 '$globaldir' => $globaldir,
85 '$desc' => t('Find on this site'),
87 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
88 '$sitedir' => t('Site Directory'),
89 '$submit' => t('Find')
93 if (strlen($search)) {
94 $sql_extra = " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`,"
95 . "`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`pub_keywords`,`prv_keywords` )"
96 . " AGAINST ('" . dbesc($search) . "' IN BOOLEAN MODE) ";
99 $publish = Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ";
101 $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`"
102 . " WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 AND `page-flags` = 2 $sql_extra ");
103 if (DBM::is_result($r)) {
104 $a->set_pager_total($r[0]['total']);
107 $order = " ORDER BY `name` ASC ";
109 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`"
110 . " FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish"
111 . " AND `user`.`blocked` = 0 AND `page-flags` = 2 $sql_extra $order LIMIT %d , %d ",
112 intval($a->pager['start']),
113 intval($a->pager['itemspage'])
115 if (DBM::is_result($r)) {
116 if (in_array('small', $a->argv)) {
122 foreach ($r as $rr) {
123 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
125 $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
128 if (strlen($rr['locality'])) {
129 $details .= $rr['locality'];
132 if (strlen($rr['region'])) {
133 if (strlen($rr['locality'])) {
136 $details .= $rr['region'];
138 if (strlen($rr['country-name'])) {
139 if (strlen($details)) {
142 $details .= $rr['country-name'];
145 if (strlen($rr['dob']) && ($years = age($rr['dob'], $rr['timezone'], '')) != 0) {
146 $details .= '<br />' . t('Age: ') . $years;
149 if (strlen($rr['gender'])) {
150 $details .= '<br />' . t('Gender: ') . $rr['gender'];
153 switch ($rr['page-flags']) {
154 case PAGE_NORMAL : $page_type = "Personal Profile"; break;
155 case PAGE_SOAPBOX : $page_type = "Fan Page" ; break;
156 case PAGE_COMMUNITY: $page_type = "Community Forum" ; break;
157 case PAGE_FREELOVE : $page_type = "Open Forum" ; break;
158 case PAGE_PRVGROUP : $page_type = "Private Group" ; break;
164 if (x($profile, 'address') == 1
165 || x($profile, 'locality') == 1
166 || x($profile, 'region') == 1
167 || x($profile, 'postal-code') == 1
168 || x($profile, 'country-name') == 1
170 $location = t('Location:');
173 $gender = x($profile, 'gender') == 1 ? t('Gender:') : false;
174 $marital = x($profile, 'marital') == 1 ? t('Status:') : false;
175 $homepage = x($profile, 'homepage') == 1 ? t('Homepage:') : false;
176 $about = x($profile, 'about') == 1 ? t('About:') : false;
178 # $tpl = file_get_contents( dirname(__file__).'/forumdirectory_item.tpl');
179 $tpl = get_markup_template('forumdirectory_item.tpl', 'addon/forumdirectory/');
181 $entry = replace_macros($tpl, [
183 '$profile_link' => $profile_link,
184 '$photo' => $rr[$photo],
185 '$alt_text' => $rr['name'],
186 '$name' => $rr['name'],
187 '$details' => $pdesc . $details,
188 '$page_type' => $page_type,
189 '$profile' => $profile,
190 '$location' => $location,
191 '$gender' => $gender,
193 '$marital' => $marital,
194 '$homepage' => $homepage,
201 $o .= "<div class=\"directory-end\" ></div>\r\n";
204 info(t("No entries \x28some entries may be hidden\x29.") . EOL);