]> git.mxchange.org Git - friendica-addons.git/blob - page/page.php
add page to advanced 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         $page = '<div id="page-profile">
125                         <div class="title">'.t("Forums:").'</div>
126                         <div id="profile-page-list">';
127
128         $show_total = 6;
129         $randomise = true;
130
131         $contacts = page_getpage($a->user['uid'],false,$randomise);
132
133         $total_shown = 0;
134         $more = false;
135
136         foreach($contacts as $contact) {
137                 $page .= micropro($contact,false,'page-profile-advanced');
138                 $total_shown ++;
139                 if(($show_total) && ($total_shown == $show_total)) {
140                         $more = true;
141                         $page .= '<div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more') 
142                                 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
143                 } 
144         }
145         if($more)
146                 $page .= '</div>';
147         $page .= '</div></div><div class="clear"></div>';
148
149         if(count($contacts) > 0)
150                 $b .= $page;
151
152 }
153
154
155
156 function page_plugin_settings_post($a,$post) {
157         if(! local_user() || (! x($_POST,'page-settings-submit')))
158                 return;
159
160         set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages']));
161         set_pconfig(local_user(),'page','randomise',intval($_POST['page_random']));
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         
186         /* Add some HTML to the existing form */
187
188         $s .= '<div class="settings-block">';
189         $s .= '<h3>' . t('Page Settings') . '</h3>';
190         $s .= '<div id="page-settings-wrapper">';
191         $s .= '<label id="page-settings-label" for="page-max-pages">' . t('How many forums to display on sidebar without paging') . '</label>';
192         $s .= '<input id="page-max-pages" type="text" name="page_max_pages" value="' . intval($max_pages) . '" ' . '/>';
193         $s .= '<div class="clear"></div>';
194         $s .= '<label id="page-random-label" for="page-random">' . t('Randomise Page/Forum list') . '</label>';
195         $s .= '<input id="page-random" type="checkbox" name="page_random" value="1" ' . $randomise_checked . '/>';
196         $s .= '<div class="clear"></div>';
197
198         $s .= '</div>';
199
200         /* provide a submit button */
201
202         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="page-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
203
204 }
205
206