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