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