X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=page%2Fpage.php;h=21a83e16d48126d96e061d40136b0c55f3e357c1;hb=d235df3f482c201d6920a9fe6df7fa58a6221547;hp=54d3d97c649b29a7fffe69fbc8e59daf93a0d441;hpb=28c5e4615ecfa069cc579bd86d4d26453a835914;p=friendica-addons.git diff --git a/page/page.php b/page/page.php index 54d3d97c..21a83e16 100755 --- a/page/page.php +++ b/page/page.php @@ -1,7 +1,7 @@ * based on pages plugin by @@ -10,22 +10,36 @@ */ function page_install() { - register_hook('page_end', 'addon/page/page.php', 'page_page_end'); + register_hook('network_mod_init', 'addon/page/page.php', 'page_network_mod_init'); + register_hook('plugin_settings', 'addon/page/page.php', 'page_plugin_settings'); + register_hook('plugin_settings_post', 'addon/page/page.php', 'page_plugin_settings_post'); + register_hook('profile_advanced', 'addon/page/page.php', 'page_profile_advanced'); + } function page_uninstall() { + unregister_hook('network_mod_init', 'addon/page/page.php', 'page_network_mod_init'); + unregister_hook('plugin_settings', 'addon/page/page.php', 'page_plugin_settings'); + unregister_hook('plugin_settings_post', 'addon/page/page.php', 'page_plugin_settings_post'); + unregister_hook('profile_advanced', 'addon/page/page.php', 'page_profile_advanced'); + + // remove only - obsolete unregister_hook('page_end', 'addon/page/page.php', 'page_page_end'); } -function page_getpage($uid) { +function page_getpage($uid,$showhidden = true,$randomise = false) { $pagelist = array(); - $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact` + $order = (($showhidden) ? '' : " and hidden = 0 "); + $order .= (($randomise) ? ' order by rand() ' : ' order by name asc '); + + $contacts = q("SELECT `id`, `url`, `name`, `micro` FROM `contact` WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d - order by name asc ", + and blocked = 0 and hidden = 0 and pending = 0 and archive = 0 + $order ", intval($uid) ); @@ -48,16 +62,154 @@ function page_page_end($a,&$b) {

'.t("Forums").'

"; + if (sizeof($contacts) > 0) + $a->page['aside'] = $page . $a->page['aside']; +} + +function page_network_mod_init($a,$b) { + + $page = '
+
+

'.t("Forums").'

+
"; if (sizeof($contacts) > 0) $a->page['aside'] = $page . $a->page['aside']; } +function page_profile_advanced($a,&$b) { + + $profile = intval(get_pconfig($a->profile['profile_uid'],'page','show_on_profile')); + if(! $profile) + return; + + $page = '
+
'.t("Forums:").'
+
'; + + // place holder in case somebody wants configurability + $show_total = 9999; + + $randomise = true; + + $contacts = page_getpage($a->user['uid'],false,$randomise); + + $total_shown = 0; + $more = false; + + foreach($contacts as $contact) { + $page .= micropro($contact,false,'page-profile-advanced'); + $total_shown ++; + if($total_shown == $show_total) + break; + } + $page .= '
'; + + if(count($contacts) > 0) + $b .= $page; + +} + + + +function page_plugin_settings_post($a,$post) { + if(! local_user() || (! x($_POST,'page-settings-submit'))) + return; + + set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages'])); + set_pconfig(local_user(),'page','randomise',intval($_POST['page_random'])); + set_pconfig(local_user(),'page','show_on_profile',intval($_POST['page_profile'])); + + info( t('Page settings updated.') . EOL); +} + + +function page_plugin_settings(&$a,&$s) { + + if(! local_user()) + return; + + /* Add our stylesheet to the page so we can make our settings look nice */ + + $a->page['htmlhead'] .= '' . "\r\n"; + + /* Get the current state of our config variable */ + + $max_pages = get_pconfig(local_user(),'page','max_pages'); + if($max_pages === false) + $max_pages = 6; + + $randomise = intval(get_pconfig(local_user(),'page','randomise')); + $randomise_checked = (($randomise) ? ' checked="checked" ' : ''); + + $profile = intval(get_pconfig(local_user(),'page','show_on_profile')); + $profile_checked = (($profile) ? ' checked="checked" ' : ''); + + + /* Add some HTML to the existing form */ + + $s .= '
'; + $s .= '

' . t('Page Settings') . '

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