4 * Description: Shows list of subscribed community pages/forums on network sidebar
6 * Author: Mike Macgirvin <mike@macgirvin.com>
7 * based on pages plugin by
8 * Author: Michael Vogel <ike@piratenpartei.de>
12 function page_install() {
13 register_hook('network_mod_init', 'addon/page/page.php', 'page_network_mod_init');
14 register_hook('plugin_settings', 'addon/page/page.php', 'page_plugin_settings');
15 register_hook('plugin_settings_post', 'addon/page/page.php', 'page_plugin_settings_post');
19 function page_uninstall() {
20 unregister_hook('network_mod_init', 'addon/page/page.php', 'page_network_mod_init');
21 unregister_hook('plugin_settings', 'addon/page/page.php', 'page_plugin_settings');
22 unregister_hook('plugin_settings_post', 'addon/page/page.php', 'page_plugin_settings_post');
24 // remove only - obsolete
25 unregister_hook('page_end', 'addon/page/page.php', 'page_page_end');
29 function page_getpage($uid,$randomise = false) {
34 $order = (($randomise) ? ' order by rand() ' : ' order by name asc ');
36 $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
37 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
44 // Look if the profile is a community page
45 foreach($contacts as $contact) {
46 $page[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
51 function page_page_end($a,&$b) {
52 // Only move on if if it's the "network" module and there is a logged on user
53 if (($a->module != "network") OR ($a->user['uid'] == 0))
56 $page = '<div id="page-sidebar" class="widget">
57 <div class="title tool">
58 <h3>'.t("Forums").'</h3></div>
59 <div id="sidebar-page-list"><ul>';
62 $contacts = page_getpage($a->user['uid']);
67 foreach($contacts as $contact) {
68 $page .= '<li style="list-style-type: none;" class="tool"><img height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /> <a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" title="' . $contact['url'] . '" class="label sparkle" target="external-link">'.
69 $contact["name"]."</a></li>";
71 if($total_shown == 6) {
73 $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more')
74 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
79 $page .= "</ul></div></div>";
80 if (sizeof($contacts) > 0)
81 $a->page['aside'] = $page . $a->page['aside'];
84 function page_network_mod_init($a,$b) {
86 $page = '<div id="page-sidebar" class="widget">
87 <div class="title tool">
88 <h3>'.t("Forums").'</h3></div>
89 <div id="sidebar-page-list"><ul>';
91 $show_total = intval(get_pconfig(local_user(),'page','max_pages'));
92 if($show_total === false)
94 $randomise = intval(get_pconfig(local_user(),'page','randomise'));
96 $contacts = page_getpage($a->user['uid'],$randomise);
101 foreach($contacts as $contact) {
102 $page .= '<li style="list-style-type: none;" class="tool"><img height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /> <a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" title="' . $contact['url'] . '" class="label sparkle" target="external-link">'.
103 $contact["name"]."</a></li>";
105 if(($show_total) && ($total_shown == $show_total)) {
107 $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more')
108 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
113 $page .= "</ul></div></div>";
114 if (sizeof($contacts) > 0)
115 $a->page['aside'] = $page . $a->page['aside'];
118 function page_plugin_settings_post($a,$post) {
119 if(! local_user() || (! x($_POST,'page-settings-submit')))
122 set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages']));
123 set_pconfig(local_user(),'page','randomise',intval($_POST['page_random']));
125 info( t('Page settings updated.') . EOL);
129 function page_plugin_settings(&$a,&$s) {
134 /* Add our stylesheet to the page so we can make our settings look nice */
136 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/page/page.css' . '" media="all" />' . "\r\n";
138 /* Get the current state of our config variable */
140 $max_pages = get_pconfig(local_user(),'page','max_pages');
141 if($max_pages === false)
144 $randomise = intval(get_pconfig(local_user(),'page','randomise'));
145 $randomise_checked = (($randomise) ? ' checked="checked" ' : '');
148 /* Add some HTML to the existing form */
150 $s .= '<div class="settings-block">';
151 $s .= '<h3>' . t('Page Settings') . '</h3>';
152 $s .= '<div id="page-settings-wrapper">';
153 $s .= '<label id="page-settings-label" for="page-max-pages">' . t('How many forums to display on sidebar without paging') . '</label>';
154 $s .= '<input id="page-max-pages" type="text" name="page_max_pages" value="' . intval($max_pages) . '" ' . '/>';
155 $s .= '<div class="clear"></div>';
156 $s .= '<label id="page-random-label" for="page-random">' . t('Randomise Page/Forum list') . '</label>';
157 $s .= '<input id="page-random" type="checkbox" name="page_random" value="1" ' . $randomise_checked . '/>';
158 $s .= '<div class="clear"></div>';
162 /* provide a submit button */
164 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="page-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';