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