]> git.mxchange.org Git - friendica-addons.git/blob - page/page.php
choose to show 'page' on profile
[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         $show_total = 6;
133         $randomise = true;
134
135         $contacts = page_getpage($a->user['uid'],false,$randomise);
136
137         $total_shown = 0;
138         $more = false;
139
140         foreach($contacts as $contact) {
141                 $page .= micropro($contact,false,'page-profile-advanced');
142                 $total_shown ++;
143                 if($total_shown == $show_total)
144                         break;
145         }
146         $page .= '</div></div><div class="clear"></div>';
147
148         if(count($contacts) > 0)
149                 $b .= $page;
150
151 }
152
153
154
155 function page_plugin_settings_post($a,$post) {
156         if(! local_user() || (! x($_POST,'page-settings-submit')))
157                 return;
158
159         set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages']));
160         set_pconfig(local_user(),'page','randomise',intval($_POST['page_random']));
161         set_pconfig(local_user(),'page','show_on_profile',intval($_POST['page_profile']));
162
163         info( t('Page settings updated.') . EOL);
164 }
165
166
167 function page_plugin_settings(&$a,&$s) {
168
169         if(! local_user())
170                 return;
171
172         /* Add our stylesheet to the page so we can make our settings look nice */
173
174         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/page/page.css' . '" media="all" />' . "\r\n";
175
176         /* Get the current state of our config variable */
177
178         $max_pages = get_pconfig(local_user(),'page','max_pages');
179         if($max_pages === false)
180                 $max_pages = 6;
181
182         $randomise = intval(get_pconfig(local_user(),'page','randomise'));
183         $randomise_checked = (($randomise) ? ' checked="checked" ' : '');
184
185         $profile = intval(get_pconfig(local_user(),'page','show_on_profile'));
186         $profile_checked = (($profile) ? ' checked="checked" ' : '');
187         
188         
189         /* Add some HTML to the existing form */
190
191         $s .= '<div class="settings-block">';
192         $s .= '<h3>' . t('Page Settings') . '</h3>';
193         $s .= '<div id="page-settings-wrapper">';
194         $s .= '<label id="page-settings-label" for="page-max-pages">' . t('How many forums to display on sidebar without paging') . '</label>';
195         $s .= '<input id="page-max-pages" type="text" name="page_max_pages" value="' . intval($max_pages) . '" ' . '/>';
196         $s .= '<div class="clear"></div>';
197         $s .= '<label id="page-random-label" for="page-random">' . t('Randomise Page/Forum list') . '</label>';
198         $s .= '<input id="page-random" type="checkbox" name="page_random" value="1" ' . $randomise_checked . '/>';
199         $s .= '<div class="clear"></div>';
200         $s .= '<label id="page-profile-label" for="page-profile">' . t('Show pages/forums on profile page') . '</label>';
201         $s .= '<input id="page-profile" type="checkbox" name="page_profile" value="1" ' . $profile_checked . '/>';
202         $s .= '<div class="clear"></div>';
203
204         $s .= '</div>';
205
206         /* provide a submit button */
207
208         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="page-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
209
210 }
211
212