]> git.mxchange.org Git - friendica-addons.git/blob - altpager/altpager.php
PT-BR translation of appnetpost addon
[friendica-addons.git] / altpager / altpager.php
1 <?php
2 /**
3  * Name: Alternate Pagination
4  * Description: Change pagination from using explicit page numbers to simple "newer" and "older" page links. This will speed up page load times.
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  * Status: Unsupported
8  */
9
10
11 function altpager_install() {
12
13         register_hook('plugin_settings', 'addon/altpager/altpager.php', 'altpager_settings');
14         register_hook('plugin_settings_post', 'addon/altpager/altpager.php', 'altpager_settings_post');
15
16         logger("installed altpager");
17 }
18
19
20 function altpager_uninstall() {
21
22         unregister_hook('plugin_settings', 'addon/altpager/altpager.php', 'altpager_settings');
23         unregister_hook('plugin_settings_post', 'addon/altpager/altpager.php', 'altpager_settings_post');
24
25
26         logger("removed altpager");
27 }
28
29
30
31 /**
32  *
33  * Callback from the settings post function.
34  * $post contains the $_POST array.
35  * We will make sure we've got a valid user account
36  * and if so set our configuration setting for this person.
37  *
38  */
39
40 function altpager_settings_post($a,$post) {
41         if(! local_user() || (! x($_POST,'altpager-submit')))
42                 return;
43
44         set_pconfig(local_user(),'system','alt_pager',intval($_POST['altpager']));
45         info( t('Altpager settings updated.') . EOL);
46 }
47
48
49 /**
50  *
51  * Called from the Plugin Setting form. 
52  * Add our own settings info to the page.
53  *
54  */
55
56
57
58 function altpager_settings(&$a,&$s) {
59
60         if(! local_user())
61                 return;
62
63         $global = get_config("alt_pager", "global");
64         if($global == 1)
65                 return;
66
67         /* Add our stylesheet to the page so we can make our settings look nice */
68
69         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/altpager/altpager.css' . '" media="all" />' . "\r\n";
70
71         /* Get the current state of our config variable */
72
73         $altpager = get_pconfig(local_user(),'system','alt_pager');
74         if($altpager === false)
75                 $altpager = 0;
76
77         $checked = (($altpager) ? ' checked="checked" ' : '');
78         
79         /* Add some HTML to the existing form */
80
81         $s .= '<div class="settings-block">';
82         $s .= '<h3>' . t('Alternate Pagination Setting') . '</h3>';
83         $s .= '<div id="altpager-wrapper">';
84         $s .= '<label id="altpager-label" for="altpager">' . t('Use links to "newer" and "older" pages in place of page numbers?') . '</label>';
85         $s .= '<input id="altpager-input" type="checkbox" name="altpager" value="1" ' . $checked . '/>';
86         $s .= '</div><div class="clear"></div>';
87
88         /* provide a submit button */
89
90         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="altpager-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
91
92 }
93
94 function altpager_plugin_admin(&$a, &$o){
95         $t = get_markup_template( "admin.tpl", "addon/altpager/" );
96         $o = replace_macros($t, array(
97                 '$submit' => t('Save Settings'),
98                 '$global' => array('altpagerchoice', t('Global'), 1, t('Force global use of the alternate pager'),  get_config('alt_pager', 'global') == 1),
99                 '$individual' => array('altpagerchoice', t('Individual'), 2, t('Each user chooses whether to use the alternate pager'),  get_config('alt_pager', 'global') == 0)
100         ));
101 }
102
103 function altpager_plugin_admin_post(&$a){
104         $choice =       ((x($_POST,'altpagerchoice'))           ? notags(trim($_POST['altpagerchoice']))        : '');
105         set_config('alt_pager','global',($choice == 1 ? 1 : 0));
106         info( t('Settings updated.'). EOL );
107 }
108