]> git.mxchange.org Git - friendica-addons.git/blob - page/page.php
Merge remote branch 'friendica/master'
[friendica-addons.git] / page / page.php
1 <?php
2 /**
3  * Name: Page
4  * Description: Shows list of subscribed community pages/forums on network sidebar
5  * Version: 1.0
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 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');
16         register_hook('profile_advanced', 'addon/page/page.php', 'page_profile_advanced');
17
18 }
19
20 function page_uninstall() {
21         unregister_hook('network_mod_init', 'addon/page/page.php', 'page_network_mod_init');
22         unregister_hook('plugin_settings', 'addon/page/page.php', 'page_plugin_settings');
23         unregister_hook('plugin_settings_post', 'addon/page/page.php', 'page_plugin_settings_post');
24         unregister_hook('profile_advanced', 'addon/page/page.php', 'page_profile_advanced');
25
26         // remove only - obsolete
27         unregister_hook('page_end', 'addon/page/page.php', 'page_page_end');
28 }
29
30
31 function page_getpage($uid,$showhidden = true,$randomise = false) {
32
33
34         $pagelist = array();
35
36         $order = (($showhidden) ? '' : " and hidden = 0 ");
37         $order .= (($randomise) ? ' order by rand() ' : ' order by name asc ');
38
39         $contacts = q("SELECT `id`, `url`, `name`, `micro` FROM `contact`
40                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
41                         $order ",
42                         intval($uid)
43         );
44
45         $page = array();
46
47         // Look if the profile is a community page
48         foreach($contacts as $contact) {
49                 $page[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
50         }
51         return($page);
52 }
53
54 function page_page_end($a,&$b) {
55         // Only move on if if it's the "network" module and there is a logged on user
56         if (($a->module != "network") OR ($a->user['uid'] == 0))
57                 return;
58
59         $page = '<div id="page-sidebar" class="widget">
60                         <div class="title tool">
61                         <h3>'.t("Forums").'</h3></div>
62                         <div id="sidebar-page-list"><ul>';
63
64
65         $contacts = page_getpage($a->user['uid']);
66
67         $total_shown = 0;
68         $more = false;
69
70         foreach($contacts as $contact) {
71                 $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 sparkle" target="external-link">'.
72                                 $contact["name"]."</a></li>";
73                 $total_shown ++;
74                 if($total_shown == 6) {
75                         $more = true;
76                         $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more') 
77                                 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
78                 } 
79         }
80         if($more)
81                 $page .= '</div>';
82         $page .= "</ul></div></div>";
83         if (sizeof($contacts) > 0)
84                 $a->page['aside'] = $page . $a->page['aside'];
85 }
86
87 function page_network_mod_init($a,$b) {
88
89         $page = '<div id="page-sidebar" class="widget">
90                         <div class="title tool">
91                         <h3>'.t("Forums").'</h3></div>
92                         <div id="sidebar-page-list"><ul>';
93
94         $show_total = intval(get_pconfig(local_user(),'page','max_pages'));
95         if($show_total === false)
96                 $show_total = 6;
97         $randomise = intval(get_pconfig(local_user(),'page','randomise'));
98
99         $contacts = page_getpage($a->user['uid'],true,$randomise);
100
101         $total_shown = 0;
102         $more = false;
103
104         foreach($contacts as $contact) {
105                 $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 sparkle" target="external-link">'.
106                                 $contact["name"]."</a></li>";
107                 $total_shown ++;
108                 if(($show_total) && ($total_shown == $show_total)) {
109                         $more = true;
110                         $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more') 
111                                 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
112                 } 
113         }
114         if($more)
115                 $page .= '</div>';
116         $page .= "</ul></div></div>";
117         if (sizeof($contacts) > 0)
118                 $a->page['aside'] = $page . $a->page['aside'];
119 }
120
121
122 function page_profile_advanced($a,&$b) {
123
124         $profile = intval(get_pconfig($a->profile['profile_uid'],'page','show_on_profile'));
125         if(! $profile)
126                 return;
127
128         $page = '<div id="page-profile">
129                         <div class="title">'.t("Forums:").'</div>
130                         <div id="profile-page-list">';
131
132         // place holder in case somebody wants configurability
133         $show_total = 9999;
134
135         $randomise = true;
136
137         $contacts = page_getpage($a->user['uid'],false,$randomise);
138
139         $total_shown = 0;
140         $more = false;
141
142         foreach($contacts as $contact) {
143                 $page .= micropro($contact,false,'page-profile-advanced');
144                 $total_shown ++;
145                 if($total_shown == $show_total)
146                         break;
147         }
148         $page .= '</div></div><div class="clear"></div>';
149
150         if(count($contacts) > 0)
151                 $b .= $page;
152
153 }
154
155
156
157 function page_plugin_settings_post($a,$post) {
158         if(! local_user() || (! x($_POST,'page-settings-submit')))
159                 return;
160
161         set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages']));
162         set_pconfig(local_user(),'page','randomise',intval($_POST['page_random']));
163         set_pconfig(local_user(),'page','show_on_profile',intval($_POST['page_profile']));
164
165         info( t('Page settings updated.') . EOL);
166 }
167
168
169 function page_plugin_settings(&$a,&$s) {
170
171         if(! local_user())
172                 return;
173
174         /* Add our stylesheet to the page so we can make our settings look nice */
175
176         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/page/page.css' . '" media="all" />' . "\r\n";
177
178         /* Get the current state of our config variable */
179
180         $max_pages = get_pconfig(local_user(),'page','max_pages');
181         if($max_pages === false)
182                 $max_pages = 6;
183
184         $randomise = intval(get_pconfig(local_user(),'page','randomise'));
185         $randomise_checked = (($randomise) ? ' checked="checked" ' : '');
186
187         $profile = intval(get_pconfig(local_user(),'page','show_on_profile'));
188         $profile_checked = (($profile) ? ' checked="checked" ' : '');
189         
190         
191         /* Add some HTML to the existing form */
192
193         $s .= '<div class="settings-block">';
194         $s .= '<h3>' . t('Page Settings') . '</h3>';
195         $s .= '<div id="page-settings-wrapper">';
196         $s .= '<label id="page-settings-label" for="page-max-pages">' . t('How many forums to display on sidebar without paging') . '</label>';
197         $s .= '<input id="page-max-pages" type="text" name="page_max_pages" value="' . intval($max_pages) . '" ' . '/>';
198         $s .= '<div class="clear"></div>';
199         $s .= '<label id="page-random-label" for="page-random">' . t('Randomise Page/Forum list') . '</label>';
200         $s .= '<input id="page-random" type="checkbox" name="page_random" value="1" ' . $randomise_checked . '/>';
201         $s .= '<div class="clear"></div>';
202         $s .= '<label id="page-profile-label" for="page-profile">' . t('Show pages/forums on profile page') . '</label>';
203         $s .= '<input id="page-profile" type="checkbox" name="page_profile" value="1" ' . $profile_checked . '/>';
204         $s .= '<div class="clear"></div>';
205
206         $s .= '</div>';
207
208         /* provide a submit button */
209
210         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="page-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
211
212 }
213
214