* based on pages plugin by * Author: Michael Vogel * */ function forumlist_install() { register_hook('network_mod_init', 'addon/forumlist/forumlist.php', 'forumlist_network_mod_init'); register_hook('plugin_settings', 'addon/forumlist/forumlist.php', 'forumlist_plugin_settings'); register_hook('plugin_settings_post', 'addon/forumlist/forumlist.php', 'forumlist_plugin_settings_post'); register_hook('profile_advanced', 'addon/forumlist/forumlist.php', 'forumlist_profile_advanced'); } function forumlist_uninstall() { unregister_hook('network_mod_init', 'addon/forumlist/forumlist.php', 'forumlist_network_mod_init'); unregister_hook('plugin_settings', 'addon/forumlist/forumlist.php', 'forumlist_plugin_settings'); unregister_hook('plugin_settings_post', 'addon/forumlist/forumlist.php', 'forumlist_plugin_settings_post'); unregister_hook('profile_advanced', 'addon/forumlist/forumlist.php', 'forumlist_profile_advanced'); } function forumlist_getpage($uid,$showhidden = true,$randomise = false, $showprivate = false) { $forumlist = array(); $order = (($showhidden) ? '' : " and hidden = 0 "); $order .= (($randomise) ? ' order by rand() ' : ' order by name asc '); $select = "`forum` = 1"; if ($showprivate) { $select = "( `forum` = 1 OR `prv` = 1 )"; } $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` from contact WHERE `network`= 'dfrn' AND $select AND `uid` = %d and blocked = 0 and hidden = 0 and pending = 0 and archive = 0 $order ", intval($uid) ); // Look if the profile is a community page foreach($contacts as $contact) { $forumlist[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']); } return($forumlist); } function forumlist_network_mod_init($a,$b) { if(! intval(get_pconfig(local_user(),'forumlist','show_on_network'))) return; $a->page['htmlhead'] .= '' . "\r\n"; $forumlist = '

'.t("Forums").'

'; $forumlist .= '' . '
"; if (sizeof($contacts) > 0) $a->page['aside'] = $forumlist . $a->page['aside']; } function forumlist_profile_advanced($a,&$b) { $a->page['htmlhead'] .= '' . "\r\n"; $profile = intval(get_pconfig($a->profile['profile_uid'],'forumlist','show_on_profile')); if(! $profile) return; $forumlist = '
'.t("Forums:").'
'; // place holder in case somebody wants configurability $show_total = 9999; $randomise = true; $contacts = forumlist_getpage($a->user['uid'],false,$randomise,false); $total_shown = 0; $more = false; foreach($contacts as $contact) { $forumlist .= micropro($contact,false,'forumlist-profile-advanced'); $total_shown ++; if($total_shown == $show_total) break; } $forumlist .= '
'; if(count($contacts) > 0) $b .= $forumlist; } function forumlist_plugin_settings_post($a,$post) { logger('forum list save 1'); if(! local_user() || (! x($_POST,'forumlist-settings-submit'))) return; logger('forum list save 2'); // set_pconfig(local_user(),'forumlist','max_forumlists',intval($_POST['forumlist_max_forumlists'])); set_pconfig(local_user(),'forumlist','randomise',intval($_POST['forumlist_random'])); set_pconfig(local_user(),'forumlist','show_on_profile',intval($_POST['forumlist_profile'])); set_pconfig(local_user(),'forumlist','show_on_network',intval($_POST['forumlist_network'])); info( t('Forumlist settings updated.') . EOL); } function forumlist_plugin_settings(&$a,&$s) { if(! local_user()) return; /* Add our stylesheet to the forumlist so we can make our settings look nice */ $a->page['htmlhead'] .= '' . "\r\n"; /* Get the current state of our config variable */ $randomise = intval(get_pconfig(local_user(),'forumlist','randomise')); $randomise_checked = (($randomise) ? ' checked="checked" ' : ''); $profile = intval(get_pconfig(local_user(),'forumlist','show_on_profile')); $profile_checked = (($profile) ? ' checked="checked" ' : ''); $network = intval(get_pconfig(local_user(),'forumlist','show_on_network')); $network_checked = (($network) ? ' checked="checked" ' : ''); /* Add some HTML to the existing form */ $s .= '
'; $s .= '

' . t('Forumlist Settings') . '

'; $s .= '
'; $s .= ''; $s .= ''; $s .= '
'; $s .= ''; $s .= ''; $s .= '
'; $s .= ''; $s .= ''; $s .= '
'; $s .= '
'; /* provide a submit button */ $s .= '
'; }