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');
16 register_hook('profile_advanced', 'addon/page/page.php', 'page_profile_advanced');
20 function page_uninstall() {
21 unregister_hook('network_mod_init', 'addon/page/page.php', 'page_network_mod_init');
22 unregister_hook('plugin_settings', 'addon/page/page.php', 'page_plugin_settings');
23 unregister_hook('plugin_settings_post', 'addon/page/page.php', 'page_plugin_settings_post');
24 unregister_hook('profile_advanced', 'addon/page/page.php', 'page_profile_advanced');
26 // remove only - obsolete
27 unregister_hook('page_end', 'addon/page/page.php', 'page_page_end');
31 function page_getpage($uid,$showhidden = true,$randomise = false) {
36 $order = (($showhidden) ? '' : " and hidden = 0 ");
37 $order .= (($randomise) ? ' order by rand() ' : ' order by name asc ');
39 $contacts = q("SELECT `id`, `url`, `name`, `micro` FROM `contact`
40 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
41 and blocked = 0 and hidden = 0 and pending = 0 and archive = 0
48 // Look if the profile is a community page
49 foreach($contacts as $contact) {
50 $page[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
55 function page_page_end($a,&$b) {
56 // Only move on if if it's the "network" module and there is a logged on user
57 if (($a->module != "network") OR ($a->user['uid'] == 0))
60 $page = '<div id="page-sidebar" class="widget">
61 <div class="title tool">
62 <h3>'.t("Forums").'</h3></div>
63 <div id="sidebar-page-list"><ul>';
66 $contacts = page_getpage($a->user['uid']);
71 foreach($contacts as $contact) {
72 $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">'.
73 $contact["name"]."</a></li>";
75 if($total_shown == 6) {
77 $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more')
78 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
83 $page .= "</ul></div></div>";
84 if (sizeof($contacts) > 0)
85 $a->page['aside'] = $page . $a->page['aside'];
88 function page_network_mod_init($a,$b) {
90 $page = '<div id="page-sidebar" class="widget">
91 <div class="title tool">
92 <h3>'.t("Forums").'</h3></div>
93 <div id="sidebar-page-list"><ul>';
95 $show_total = intval(get_pconfig(local_user(),'page','max_pages'));
96 if($show_total === false)
98 $randomise = intval(get_pconfig(local_user(),'page','randomise'));
100 $contacts = page_getpage($a->user['uid'],true,$randomise);
105 foreach($contacts as $contact) {
106 $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">'.
107 $contact["name"]."</a></li>";
109 if(($show_total) && ($total_shown == $show_total)) {
111 $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more')
112 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
117 $page .= "</ul></div></div>";
118 if (sizeof($contacts) > 0)
119 $a->page['aside'] = $page . $a->page['aside'];
123 function page_profile_advanced($a,&$b) {
125 $profile = intval(get_pconfig($a->profile['profile_uid'],'page','show_on_profile'));
129 $page = '<div id="page-profile">
130 <div class="title">'.t("Forums:").'</div>
131 <div id="profile-page-list">';
133 // place holder in case somebody wants configurability
138 $contacts = page_getpage($a->user['uid'],false,$randomise);
143 foreach($contacts as $contact) {
144 $page .= micropro($contact,false,'page-profile-advanced');
146 if($total_shown == $show_total)
149 $page .= '</div></div><div class="clear"></div>';
151 if(count($contacts) > 0)
158 function page_plugin_settings_post($a,$post) {
159 if(! local_user() || (! x($_POST,'page-settings-submit')))
162 set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages']));
163 set_pconfig(local_user(),'page','randomise',intval($_POST['page_random']));
164 set_pconfig(local_user(),'page','show_on_profile',intval($_POST['page_profile']));
166 info( t('Page settings updated.') . EOL);
170 function page_plugin_settings(&$a,&$s) {
175 /* Add our stylesheet to the page so we can make our settings look nice */
177 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/page/page.css' . '" media="all" />' . "\r\n";
179 /* Get the current state of our config variable */
181 $max_pages = get_pconfig(local_user(),'page','max_pages');
182 if($max_pages === false)
185 $randomise = intval(get_pconfig(local_user(),'page','randomise'));
186 $randomise_checked = (($randomise) ? ' checked="checked" ' : '');
188 $profile = intval(get_pconfig(local_user(),'page','show_on_profile'));
189 $profile_checked = (($profile) ? ' checked="checked" ' : '');
192 /* Add some HTML to the existing form */
194 $s .= '<div class="settings-block">';
195 $s .= '<h3>' . t('Page Settings') . '</h3>';
196 $s .= '<div id="page-settings-wrapper">';
197 $s .= '<label id="page-settings-label" for="page-max-pages">' . t('How many forums to display on sidebar without paging') . '</label>';
198 $s .= '<input id="page-max-pages" type="text" name="page_max_pages" value="' . intval($max_pages) . '" ' . '/>';
199 $s .= '<div class="clear"></div>';
200 $s .= '<label id="page-random-label" for="page-random">' . t('Randomise Page/Forum list') . '</label>';
201 $s .= '<input id="page-random" type="checkbox" name="page_random" value="1" ' . $randomise_checked . '/>';
202 $s .= '<div class="clear"></div>';
203 $s .= '<label id="page-profile-label" for="page-profile">' . t('Show pages/forums on profile page') . '</label>';
204 $s .= '<input id="page-profile" type="checkbox" name="page_profile" value="1" ' . $profile_checked . '/>';
205 $s .= '<div class="clear"></div>';
209 /* provide a submit button */
211 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="page-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';