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

Last change on this file since 11298 was 6718, checked in by patdenice, 14 years ago

Compatible with 2.1.x
Move icons to title

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1<?php /*
2Plugin Name: RV Thumbs
3Version: 2.1.a
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                                if (count($page['items']) > $page['nb_image_page'] * $multiplier)
25                                {
26                                        $multiplier = ($multiplier==1) ? 4 : $multiplier*2;
27                                        $multiplier = min($multiplier, ceil(RV_THUMBS_MAX/$page['nb_image_page']));
28                                }
29                                break;
30                        case 'less':
31                                $multiplier = ($multiplier==4) ? 1 : (int)$multiplier/2;
32                                $multiplier = max(1, $multiplier);
33                                break;
34                }
35                if ($multiplier>1)
36                        pwg_set_session_var('idx_thumbs_muliplier', $multiplier);
37                else
38                        pwg_unset_session_var('idx_thumbs_muliplier');
39        }
40        $page['nb_image_page'] *= $multiplier;
41        if ( count($page['items']) )
42                add_event_handler('loc_end_index', 'rv_thumbs_end_index' );
43}
44
45function rv_thumbs_end_index()
46{
47        global $user, $template, $page;
48        $multiplier = pwg_get_session_var('idx_thumbs_muliplier', 1);
49        $title = & $template->get_template_vars('TITLE');
50        $ini_per_page = $user['nb_image_page'];
51        $has_less = $multiplier>1 && count($page['items'])>$ini_per_page;
52        $has_more = !empty($page['navigation_bar']) && $multiplier < ceil(RV_THUMBS_MAX/$ini_per_page );
53        if ($has_less || $has_more)
54        {
55                global $lang_info, $conf; if ($lang_info['code']!='en' or $conf['debug_l10n']) load_language( 'lang', dirname(__FILE__).'/' );
56                $css = 'background:url('.get_root_url().'plugins/rv_thumbs/sprite.gif) no-repeat top left; height:15px; width:17px; padding:0 5px 1px 0; display:inline-block; background-position:center ';
57                $fmt_link = '<a href="%s" rel="nofollow" style="border:none; margin:0;"><div style="'.$css.'%spx;" title="%s">&nbsp;</div></a>';
58                $fmt = '<div style="'.$css.'%spx; cursor:default" title="%s">&nbsp;</div>';
59                $bar = '<span style="margin-left:10px;vertical-align:middle;">';
60                if ($has_less)
61                        $bar .= sprintf( $fmt_link, add_url_params(duplicate_index_url(), array('thumbs'=>'less')), -39, l10n('Show less thumbnails') );
62                else
63                        $bar .= sprintf( $fmt, -57, l10n('Show less thumbnails') );
64                if ($has_more)
65                        $bar .= sprintf( $fmt_link, add_url_params(duplicate_index_url(array('start'=>0)), array('thumbs'=>'more')), -3, l10n('Show more thumbnails') );
66                else
67                        $bar .= sprintf( $fmt, -21, l10n('Show more thumbnails') );
68                $bar .= '</span>';
69                $title .= $bar;
70        }
71}
72?>
Note: See TracBrowser for help on using the repository browser.