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.
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
11 function altpager_install() {
13 register_hook('plugin_settings', 'addon/altpager/altpager.php', 'altpager_settings');
14 register_hook('plugin_settings_post', 'addon/altpager/altpager.php', 'altpager_settings_post');
16 logger("installed altpager");
20 function altpager_uninstall() {
22 unregister_hook('plugin_settings', 'addon/altpager/altpager.php', 'altpager_settings');
23 unregister_hook('plugin_settings_post', 'addon/altpager/altpager.php', 'altpager_settings_post');
26 logger("removed altpager");
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.
40 function altpager_settings_post($a,$post) {
41 if(! local_user() || (! x($_POST,'altpager-submit')))
44 set_pconfig(local_user(),'system','alt_pager',intval($_POST['altpager']));
45 info( t('Altpager settings updated.') . EOL);
51 * Called from the Plugin Setting form.
52 * Add our own settings info to the page.
58 function altpager_settings(&$a,&$s) {
63 $global = get_config("alt_pager", "global");
67 /* Add our stylesheet to the page so we can make our settings look nice */
69 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/altpager/altpager.css' . '" media="all" />' . "\r\n";
71 /* Get the current state of our config variable */
73 $altpager = get_pconfig(local_user(),'system','alt_pager');
74 if($altpager === false)
77 $checked = (($altpager) ? ' checked="checked" ' : '');
79 /* Add some HTML to the existing form */
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>';
88 /* provide a submit button */
90 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="altpager-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
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)
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 );