]> git.mxchange.org Git - friendica-addons.git/blob - page/page.php
Facebook: Trying to optimise the handling of videos
[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
17 }
18
19 function page_uninstall() {
20         unregister_hook('network_mod_init', 'addon/page/page.php', 'page_network_mod_init');
21         unregister_hook('plugin_settings', 'addon/page/page.php', 'page_plugin_settings');
22         unregister_hook('plugin_settings_post', 'addon/page/page.php', 'page_plugin_settings_post');
23
24         // remove only - obsolete
25         unregister_hook('page_end', 'addon/page/page.php', 'page_page_end');
26 }
27
28
29 function page_getpage($uid,$randomise = false) {
30
31
32         $pagelist = array();
33
34         $order = (($randomise) ? ' order by rand() ' : ' order by name asc ');
35
36         $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
37                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
38                         $order ",
39                         intval($uid)
40         );
41
42         $page = array();
43
44         // Look if the profile is a community page
45         foreach($contacts as $contact) {
46                 $page[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
47         }
48         return($page);
49 }
50
51 function page_page_end($a,&$b) {
52         // Only move on if if it's the "network" module and there is a logged on user
53         if (($a->module != "network") OR ($a->user['uid'] == 0))
54                 return;
55
56         $page = '<div id="page-sidebar" class="widget">
57                         <div class="title tool">
58                         <h3>'.t("Forums").'</h3></div>
59                         <div id="sidebar-page-list"><ul>';
60
61
62         $contacts = page_getpage($a->user['uid']);
63
64         $total_shown = 0;
65         $more = false;
66
67         foreach($contacts as $contact) {
68                 $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">'.
69                                 $contact["name"]."</a></li>";
70                 $total_shown ++;
71                 if($total_shown == 6) {
72                         $more = true;
73                         $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more') 
74                                 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
75                 } 
76         }
77         if($more)
78                 $page .= '</div>';
79         $page .= "</ul></div></div>";
80         if (sizeof($contacts) > 0)
81                 $a->page['aside'] = $page . $a->page['aside'];
82 }
83
84 function page_network_mod_init($a,$b) {
85
86         $page = '<div id="page-sidebar" class="widget">
87                         <div class="title tool">
88                         <h3>'.t("Forums").'</h3></div>
89                         <div id="sidebar-page-list"><ul>';
90
91         $show_total = intval(get_pconfig(local_user(),'page','max_pages'));
92         if($show_total === false)
93                 $show_total = 6;
94         $randomise = intval(get_pconfig(local_user(),'page','randomise'));
95
96         $contacts = page_getpage($a->user['uid'],$randomise);
97
98         $total_shown = 0;
99         $more = false;
100
101         foreach($contacts as $contact) {
102                 $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">'.
103                                 $contact["name"]."</a></li>";
104                 $total_shown ++;
105                 if(($show_total) && ($total_shown == $show_total)) {
106                         $more = true;
107                         $page .= '</ul><div id="hide-comments-page-widget" class="fakelink" onclick="showHideComments(\'page-widget\');" >' . t('show more') 
108                                 . '</div><div id="collapsed-comments-page-widget" style="display: none;" ><ul>';
109                 } 
110         }
111         if($more)
112                 $page .= '</div>';
113         $page .= "</ul></div></div>";
114         if (sizeof($contacts) > 0)
115                 $a->page['aside'] = $page . $a->page['aside'];
116 }
117
118 function page_plugin_settings_post($a,$post) {
119         if(! local_user() || (! x($_POST,'page-settings-submit')))
120                 return;
121
122         set_pconfig(local_user(),'page','max_pages',intval($_POST['page_max_pages']));
123         set_pconfig(local_user(),'page','randomise',intval($_POST['page_random']));
124
125         info( t('Page settings updated.') . EOL);
126 }
127
128
129 function page_plugin_settings(&$a,&$s) {
130
131         if(! local_user())
132                 return;
133
134         /* Add our stylesheet to the page so we can make our settings look nice */
135
136         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/page/page.css' . '" media="all" />' . "\r\n";
137
138         /* Get the current state of our config variable */
139
140         $max_pages = get_pconfig(local_user(),'page','max_pages');
141         if($max_pages === false)
142                 $max_pages = 6;
143
144         $randomise = intval(get_pconfig(local_user(),'page','randomise'));
145         $randomise_checked = (($randomise) ? ' checked="checked" ' : '');
146
147         
148         /* Add some HTML to the existing form */
149
150         $s .= '<div class="settings-block">';
151         $s .= '<h3>' . t('Page Settings') . '</h3>';
152         $s .= '<div id="page-settings-wrapper">';
153         $s .= '<label id="page-settings-label" for="page-max-pages">' . t('How many forums to display on sidebar without paging') . '</label>';
154         $s .= '<input id="page-max-pages" type="text" name="page_max_pages" value="' . intval($max_pages) . '" ' . '/>';
155         $s .= '<div class="clear"></div>';
156         $s .= '<label id="page-random-label" for="page-random">' . t('Randomise Page/Forum list') . '</label>';
157         $s .= '<input id="page-random" type="checkbox" name="page_random" value="1" ' . $randomise_checked . '/>';
158         $s .= '<div class="clear"></div>';
159
160         $s .= '</div>';
161
162         /* provide a submit button */
163
164         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="page-settings-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
165
166 }
167
168