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
47 // Look if the profile is a community page
48 foreach($contacts as $contact) {
49 $page[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
54 function page_page_end($a,&$b) {
55 // Only move on if if it's the "network" module and there is a logged on user
56 if (($a->module != "network") OR ($a->user['uid'] == 0))
59 $page = '<div id="page-sidebar" class="widget">
60 <div class="title tool">
61 <h3>'.t("Forums").'</h3></div>
62 <div id="sidebar-page-list"><ul>';
65 $contacts = page_getpage($a->user['uid']);
70 foreach($contacts as $contact) {
71 $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">'.
72 $contact["name"]."</a></li>";
74 if($total_shown == 6) {
76 $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more')
77 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
82 $page .= "</ul></div></div>";
83 if (sizeof($contacts) > 0)
84 $a->page['aside'] = $page . $a->page['aside'];
87 function page_network_mod_init($a,$b) {
89 $page = '<div id="page-sidebar" class="widget">
90 <div class="title tool">
91 <h3>'.t("Forums").'</h3></div>
92 <div id="sidebar-page-list"><ul>';
94 $show_total = intval(get_pconfig(local_user(),'page','max_pages'));
95 if($show_total === false)
97 $randomise = intval(get_pconfig(local_user(),'page','randomise'));
99 $contacts = page_getpage($a->user['uid'],true,$randomise);
104 foreach($contacts as $contact) {
105 $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">'.
106 $contact["name"]."</a></li>";
108 if(($show_total) && ($total_shown == $show_total)) {
110 $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more')
111 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
116 $page .= "</ul></div></div>";
117 if (sizeof($contacts) > 0)
118 $a->page['aside'] = $page . $a->page['aside'];
122 function page_profile_advanced($a,&$b) {
124 $profile = intval(get_pconfig($a->profile['profile_uid'],'page','show_on_profile'));
128 $page = '<div id="page-profile">
129 <div class="title">'.t("Forums:").'</div>
130 <div id="profile-page-list">';
132 // place holder in case somebody wants configurability
137 $contacts = page_getpage($a->user['uid'],false,$randomise);
142 foreach($contacts as $contact) {
143 $page .= micropro($contact,false,'page-profile-advanced');
145 if($total_shown == $show_total)
148 $page .= '</div></div><div class="clear"></div>';
150 if(count($contacts) > 0)
157 function page_plugin_settings_post($a,$post) {
158 if(! local_user() || (! x($_POST,'page-settings-submit')))
161 set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages']));
162 set_pconfig(local_user(),'page','randomise',intval($_POST['page_random']));
163 set_pconfig(local_user(),'page','show_on_profile',intval($_POST['page_profile']));
165 info( t('Page settings updated.') . EOL);
169 function page_plugin_settings(&$a,&$s) {
174 /* Add our stylesheet to the page so we can make our settings look nice */
176 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/page/page.css' . '" media="all" />' . "\r\n";
178 /* Get the current state of our config variable */
180 $max_pages = get_pconfig(local_user(),'page','max_pages');
181 if($max_pages === false)
184 $randomise = intval(get_pconfig(local_user(),'page','randomise'));
185 $randomise_checked = (($randomise) ? ' checked="checked" ' : '');
187 $profile = intval(get_pconfig(local_user(),'page','show_on_profile'));
188 $profile_checked = (($profile) ? ' checked="checked" ' : '');
191 /* Add some HTML to the existing form */
193 $s .= '<div class="settings-block">';
194 $s .= '<h3>' . t('Page Settings') . '</h3>';
195 $s .= '<div id="page-settings-wrapper">';
196 $s .= '<label id="page-settings-label" for="page-max-pages">' . t('How many forums to display on sidebar without paging') . '</label>';
197 $s .= '<input id="page-max-pages" type="text" name="page_max_pages" value="' . intval($max_pages) . '" ' . '/>';
198 $s .= '<div class="clear"></div>';
199 $s .= '<label id="page-random-label" for="page-random">' . t('Randomise Page/Forum list') . '</label>';
200 $s .= '<input id="page-random" type="checkbox" name="page_random" value="1" ' . $randomise_checked . '/>';
201 $s .= '<div class="clear"></div>';
202 $s .= '<label id="page-profile-label" for="page-profile">' . t('Show pages/forums on profile page') . '</label>';
203 $s .= '<input id="page-profile" type="checkbox" name="page_profile" value="1" ' . $profile_checked . '/>';
204 $s .= '<div class="clear"></div>';
208 /* provide a submit button */
210 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="page-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';