source: extensions/rv_thumbs/trunk/main.inc.php @ 4211

Last change on this file since 4211 was 4207, checked in by rvelices, 15 years ago

added rv_thumbs extension

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1<?php /*
2Plugin Name: RV Thumbs
3Version: 2.0.c
4Description: Let users see a variable number of thumbnails on index page
5Plugin URI: http://piwigo.org/ext/extension_view.php?eid=261
6Author: rvelices
7Author URI: http://www.modusoptimus.com/
8*/
9
10define('RV_THUMBS_MAX', 384);
11
12add_event_handler('loc_begin_index', 'rv_thumbs_begin_index' );
13
14function rv_thumbs_begin_index()
15{
16        global $page;
17        $multiplier = pwg_get_session_var('idx_thumbs_muliplier', 1);
18        if (isset($_GET['thumbs']))
19        {
20                $page['meta_robots']['noindex']=1;
21                switch ($_GET['thumbs'])
22                {
23                        case 'more':
24                                $multiplier = ($multiplier==1) ? 4 : $multiplier*2;
25                                $multiplier = min($multiplier, ceil(RV_THUMBS_MAX/$page['nb_image_page']));
26                                break;
27                        case 'less':
28                                $multiplier = ($multiplier==4) ? 1 : (int)$multiplier/2;
29                                $multiplier = max(1, $multiplier);
30                                break;
31                }
32                if ($multiplier>1)
33                        pwg_set_session_var('idx_thumbs_muliplier', $multiplier);
34                else
35                        pwg_unset_session_var('idx_thumbs_muliplier');
36        }
37        $page['nb_image_page'] *= $multiplier;
38        if ( count($page['items']) )
39                add_event_handler('loc_end_index', 'rv_thumbs_end_index' );
40}
41
42function rv_thumbs_end_index()
43{
44        global $user, $template, $page;
45        $multiplier = pwg_get_session_var('idx_thumbs_muliplier', 1);
46        $nav_bar = & $template->get_template_vars('NAV_BAR');
47        $ini_per_page = $user['nb_image_page'];
48        $has_less = $multiplier>1 && count($page['items'])>$ini_per_page;
49        $has_more = !empty($nav_bar) && $multiplier < ceil(RV_THUMBS_MAX/$ini_per_page );
50        if ($has_less || $has_more)
51        {
52                global $lang_info, $conf; if ($lang_info['code']!='en' or $conf['debug_l10n']) load_language( 'lang', dirname(__FILE__).'/' );
53                $css = 'background:url('.get_root_url().'plugins/rv_thumbs/sprite.gif) no-repeat top left; height:15px; width:17px; padding:0 15px 1px 0; display:inline; background-position:center ';
54                $fmt_link = '<a href="%s" rel="nofollow" style="border:none"><div style="'.$css.'%spx;" title="%s">&nbsp;</div></a>';
55                $fmt = '<div style="'.$css.'%spx; cursor:default" title="%s">&nbsp;</div>';
56                $bar = '<span style="margin-left:10px;">';
57                if ($has_less)
58                        $bar .= sprintf( $fmt_link, add_url_params(duplicate_index_url(), array('thumbs'=>'less')), -39, l10n('Show less thumbnails') );
59                else
60                        $bar .= sprintf( $fmt, -57, l10n('Show less thumbnails') );
61                if ($has_more)
62                        $bar .= sprintf( $fmt_link, add_url_params(duplicate_index_url(array('start'=>0)), array('thumbs'=>'more')), -3, l10n('Show more thumbnails') );
63                else
64                        $bar .= sprintf( $fmt, -21, l10n('Show more thumbnails') );
65                $bar .= '</span>';
66                $nav_bar .= ( !empty($nav_bar) ? ' &nbsp; ' : '' ) . $bar;
67        }
68}
69?>
Note: See TracBrowser for help on using the repository browser.