4 * Description: Shows lists of community pages (improved performance over 'pages')
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) {
34 $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
35 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
42 // Look if the profile is a community page
43 foreach($contacts as $contact) {
44 $page[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
49 function page_page_end($a,&$b) {
50 // Only move on if if it's the "network" module and there is a logged on user
51 if (($a->module != "network") OR ($a->user['uid'] == 0))
54 $page = '<div id="page-sidebar" class="widget">
55 <div class="title tool">
56 <h3>'.t("Forums").'</h3></div>
57 <div id="sidebar-page-list"><ul>';
60 $contacts = page_getpage($a->user['uid']);
65 foreach($contacts as $contact) {
66 $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" target="external-link">'.
67 $contact["name"]."</a></li>";
69 if($total_shown == 6) {
71 $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more')
72 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
77 $page .= "</ul></div></div>";
78 if (sizeof($contacts) > 0)
79 $a->page['aside'] = $page . $a->page['aside'];
82 function page_network_mod_init($a,$b) {
84 $page = '<div id="page-sidebar" class="widget">
85 <div class="title tool">
86 <h3>'.t("Forums").'</h3></div>
87 <div id="sidebar-page-list"><ul>';
89 $show_total = intval(get_pconfig(local_user(),'page','max_pages'));
90 if($show_total === false)
92 $contacts = page_getpage($a->user['uid']);
97 foreach($contacts as $contact) {
98 $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" target="external-link">'.
99 $contact["name"]."</a></li>";
101 if(($show_total) && ($total_shown == $show_total)) {
103 $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more')
104 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
109 $page .= "</ul></div></div>";
110 if (sizeof($contacts) > 0)
111 $a->page['aside'] = $page . $a->page['aside'];
114 function page_plugin_settings_post($a,$post) {
115 if(! local_user() || (! x($_POST,'page-settings-submit')))
118 set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages']));
119 info( t('Page settings updated.') . EOL);
123 function page_plugin_settings(&$a,&$s) {
128 /* Add our stylesheet to the page so we can make our settings look nice */
130 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/page/page.css' . '" media="all" />' . "\r\n";
132 /* Get the current state of our config variable */
134 $max_pages = get_pconfig(local_user(),'page','max_pages');
135 if($max_pages === false)
138 /* Add some HTML to the existing form */
140 $s .= '<div class="settings-block">';
141 $s .= '<h3>' . t('Page Settings') . '</h3>';
142 $s .= '<div id="page-settings-wrapper">';
143 $s .= '<label id="page-settings-label" for="page-max-pages">' . t('How many forums to display on sidebar without paging') . '</label>';
144 $s .= '<input id="page-max-pages" type="text" name="page_max_pages" value="' . intval($max_pages) . '" ' . '/>';
145 $s .= '</div><div class="clear"></div>';
147 /* provide a submit button */
149 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="page-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';