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