]> git.mxchange.org Git - friendica-addons.git/blob - forumlist/forumlist.php
beyond "page" and "pages"
[friendica-addons.git] / forumlist / forumlist.php
1 <?php
2 /**
3  * Name: ForumList
4  * Description: Shows list of subscribed community forums on network sidebar
5  * Version: 1.1
6  * Author: Mike Macgirvin <mike@macgirvin.com>
7  * based on pages plugin by
8  * Author: Michael Vogel <ike@piratenpartei.de>
9  *
10  */
11
12 function forumlist_install() {
13         register_hook('network_mod_init', 'addon/forumlist/forumlist.php', 'forumlist_network_mod_init');
14         register_hook('plugin_settings', 'addon/forumlist/forumlist.php', 'forumlist_plugin_settings');
15         register_hook('plugin_settings_post', 'addon/forumlist/forumlist.php', 'forumlist_plugin_settings_post');
16         register_hook('profile_advanced', 'addon/forumlist/forumlist.php', 'forumlist_profile_advanced');
17
18 }
19
20 function forumlist_uninstall() {
21         unregister_hook('network_mod_init', 'addon/forumlist/forumlist.php', 'forumlist_network_mod_init');
22         unregister_hook('plugin_settings', 'addon/forumlist/forumlist.php', 'forumlist_plugin_settings');
23         unregister_hook('plugin_settings_post', 'addon/forumlist/forumlist.php', 'forumlist_plugin_settings_post');
24         unregister_hook('profile_advanced', 'addon/forumlist/forumlist.php', 'forumlist_profile_advanced');
25
26 }
27
28
29 function forumlist_getpage($uid,$showhidden = true,$randomise = false) {
30
31
32         $forumlist = array();
33
34         $order = (($showhidden) ? '' : " and hidden = 0 ");
35         $order .= (($randomise) ? ' order by rand() ' : ' order by name asc ');
36
37         $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` from contact 
38                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
39                         $order ",
40                         intval($uid)
41         );
42
43         // Look if the profile is a community page
44         foreach($contacts as $contact) {
45                 $forumlist[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
46         }
47         return($forumlist);
48 }
49
50 function forumlist_network_mod_init($a,$b) {
51         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/forumlist/forumlist.css' . '" media="all" />' . "\r\n";
52
53         $forumlist = '<div id="forumlist-sidebar" class="widget">
54                         <div class="title tool">
55                         <h3>'.t("Forums").'</h3></div>';
56
57         $forumlist .= '<div id="hide-forum-list" class="fakelink" onclick="openClose(\'forum-list\');" >' 
58                                 . t('show/hide') . '</div>'
59                                 . '<div id="forum-list" style="display: none;">';
60
61
62         $randomise = intval(get_pconfig(local_user(),'forumlist','randomise'));
63
64         $contacts = forumlist_getpage($a->user['uid'],true,$randomise);
65
66         if(count($contacts)) {
67                 foreach($contacts as $contact) {
68                         $forumlist .= '<a href="' . $a->get_baseurl() . '/redir/' . $contact["id"] . '" title="' . $contact['url'] . '" class="label sparkle" target="external-link"><img height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /></a> <a href="' . $a->get_baseurl() . '/network?f=&cid=' . $contact['id'] . '" >' . $contact["name"]."</a><br />";
69                 }
70         }
71         else {
72                 $forumlist .= t('No forum subscriptions');
73         }
74                 
75         $forumlist .= "</div></div>";
76         if (sizeof($contacts) > 0)
77                 $a->page['aside'] = $forumlist . $a->page['aside'];
78 }
79
80
81 function forumlist_profile_advanced($a,&$b) {
82         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/forumlist/forumlist.css' . '" media="all" />' . "\r\n";
83
84         $profile = intval(get_pconfig($a->profile['profile_uid'],'forumlist','show_on_profile'));
85         if(! $profile)
86                 return;
87
88         $forumlist = '<div id="forumlist-profile">
89                         <div class="title">'.t("Forums:").'</div>
90                         <div id="profile-forumlist-list">';
91
92         // place holder in case somebody wants configurability
93         $show_total = 9999;
94
95         $randomise = true;
96
97         $contacts = forumlist_getforumlist($a->user['uid'],false,$randomise);
98
99         $total_shown = 0;
100         $more = false;
101
102         foreach($contacts as $contact) {
103                 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
104                 $total_shown ++;
105                 if($total_shown == $show_total)
106                         break;
107         }
108         $forumlist .= '</div></div><div class="clear"></div>';
109
110         if(count($contacts) > 0)
111                 $b .= $forumlist;
112
113 }
114
115
116
117 function forumlist_plugin_settings_post($a,$post) {
118         if(! local_user() || (! x($_POST,'forumlist-settings-submit')))
119                 return;
120
121 //      set_pconfig(local_user(),'forumlist','max_forumlists',intval($_POST['forumlist_max_forumlists']));
122         set_pconfig(local_user(),'forumlist','randomise',intval($_POST['forumlist_random']));
123         set_pconfig(local_user(),'forumlist','show_on_profile',intval($_POST['forumlist_profile']));
124
125         info( t('Forumlist settings updated.') . EOL);
126 }
127
128
129 function forumlist_plugin_settings(&$a,&$s) {
130
131         if(! local_user())
132                 return;
133
134         /* Add our stylesheet to the forumlist so we can make our settings look nice */
135
136         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/forumlist/forumlist.css' . '" media="all" />' . "\r\n";
137
138         /* Get the current state of our config variable */
139
140         $randomise = intval(get_pconfig(local_user(),'forumlist','randomise'));
141         $randomise_checked = (($randomise) ? ' checked="checked" ' : '');
142
143         $profile = intval(get_pconfig(local_user(),'forumlist','show_on_profile'));
144         $profile_checked = (($profile) ? ' checked="checked" ' : '');
145         
146         
147         /* Add some HTML to the existing form */
148
149         $s .= '<div class="settings-block">';
150         $s .= '<h3>' . t('Forumlist Settings') . '</h3>';
151         $s .= '<div id="forumlist-settings-wrapper">';
152         $s .= '<label id="forumlist-random-label" for="forumlist-random">' . t('Randomise forum list') . '</label>';
153         $s .= '<input id="forumlist-random" type="checkbox" name="forumlist_random" value="1" ' . $randomise_checked . '/>';
154         $s .= '<div class="clear"></div>';
155         $s .= '<label id="forumlist-profile-label" for="forumlist-profile">' . t('Show forums on profile page') . '</label>';
156         $s .= '<input id="forumlist-profile" type="checkbox" name="forumlist_profile" value="1" ' . $profile_checked . '/>';
157         $s .= '<div class="clear"></div>';
158
159         $s .= '</div>';
160
161         /* provide a submit button */
162
163         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="forumlist-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
164
165 }
166
167