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