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