source: extensions/rv_tscroller/main.inc.php @ 8900

Last change on this file since 8900 was 8900, checked in by rvelices, 13 years ago

RV Thumbnail Scroller first version

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1<?php /*
2Plugin Name: RV Thumb Scroller
3Version: 2.2.a
4Plugin URI: http://piwigo.org/ext/extension_view.php?eid=493
5Description: Loads async using ajax thumbnails on index page as you scroll down the page
6Author: rvelices
7Author URI: http://www.modusoptimus.com
8*/
9define('RVTS_VERSION', 3);
10
11class RVTS
12{
13static function on_end_section_init()
14{
15        global $page;
16        if (!@$page['start'])
17        {
18                if (script_basename()!='picture')
19                        $page['nb_image_page'] *= pwg_get_session_var('rvts_mult', 1);
20                if (count($page['items'])<$page['nb_image_page']+3)
21                        $page['nb_image_page'] = max($page['nb_image_page'], count($page['items']));
22        }
23        add_event_handler('loc_begin_index', array('RVTS','on_index_begin'));
24}
25
26static function on_index_begin()
27{
28        global $page;
29        $is_ajax = isset($_GET['rvts']);
30        if (!$is_ajax)
31        {
32                if (empty($page['items']) || @$page['start']>0)
33                        add_event_handler('loc_end_index', array('RVTS','on_end_index'));
34                else
35                        add_event_handler('loc_end_index_thumbnails', array('RVTS','on_index_thumbnails'), EVENT_HANDLER_PRIORITY_NEUTRAL, 1);
36        }
37        else
38        {
39                $adj = (int)@$_GET['adj'];
40                if ($adj)
41                {
42                        $mult = pwg_get_session_var('rvts_mult', 1);
43                        if ($adj>0 && $mult<5)
44                                pwg_set_session_var('rvts_mult', ++$mult);
45                        if ($adj<0 && $mult>1)
46                                pwg_set_session_var('rvts_mult', --$mult);
47                }
48                $page['nb_image_page']=(int)$_GET['rvts'];
49                add_event_handler('loc_end_index_thumbnails', array('RVTS','on_index_thumbnails_ajax'), EVENT_HANDLER_PRIORITY_NEUTRAL+5, 1);
50                set_make_full_url();
51                global $user, $template, $conf;
52                include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
53        }
54}
55
56static function on_index_thumbnails($thumbs)
57{
58        global $page, $template;
59        $total = count($page['items']);
60        if (count($thumbs) >= $total)
61        {
62                add_event_handler('loc_end_index', array('RVTS','on_end_index'));
63                return $thumbs;
64        }
65        $per_page = $page['nb_image_page'];
66        $url_model = str_replace('123456789', '%start%', duplicate_index_url( array('start'=>123456789) ) );
67        $ajax_url_model = add_url_params($url_model, array( 'rvts'=>'' ) );
68
69        $url_model = str_replace('&amp;', '&', $url_model);
70        $ajax_url_model = str_replace('&amp;', '&', $ajax_url_model);
71       
72        $my_base_name = basename(dirname(__FILE__));
73        $ajax_loader_image = get_root_url()."plugins/$my_base_name/ajax-loader.gif";
74        $template->func_combine_script( array(
75                        'id'=> 'jquery',
76                        'load'=> 'footer',
77                        'path'=> 'themes/default/js/jquery.min.js',
78                ), $template->smarty);
79        $template->func_combine_script( array(
80                        'id'=> $my_base_name,
81                        'load'=> 'async',
82                        'path'=> 'plugins/'.$my_base_name.'/rv_tscroller.min.js',
83                        'require' => 'jquery',
84                        'version' => RVTS_VERSION,
85                ), $template->smarty);
86        $moreMsg = 'See the remaining %d photos';
87        load_language('lang', dirname(__FILE__).'/');
88        $moreMsg = l10n($moreMsg);
89        $repeat=false;
90        $template->block_footer_script(null,
91                "var RVTS = {
92ajaxUrlModel: '$ajax_url_model'+'%per%',
93start: $per_page,
94total: $total,
95perPage: $per_page,
96urlModel: '$url_model',
97moreMsg: '$moreMsg',
98ajaxLoaderImage: '$ajax_loader_image'
99};",
100                $template->smarty, $repeat);
101        return $thumbs;
102}
103
104static function on_index_thumbnails_ajax($thumbs)
105{
106        global $template;
107        $template->assign('thumbnails', $thumbs);
108        header('Content-Type: text/html; charset='.get_pwg_charset());
109        $template->pparse('index_thumbnails');
110        exit;
111}
112
113static function on_end_index()
114{
115        global $template;
116        $req = null;
117        foreach($template->scriptLoader->get_all() as $script)
118        {
119                if($script->load_mode==2 && !$script->is_remote())
120                        $req = $script->id;
121        }
122        if($req!=null)
123        {
124                $my_base_name = basename(dirname(__FILE__));
125                $template->func_combine_script( array(
126                        'id'=> $my_base_name,
127                        'load'=> 'async',
128                        'path'=> 'plugins/'.$my_base_name.'/rv_tscroller.min.js',
129                        'require' => $req,
130                        'version' => RVTS_VERSION,
131                ), $template->smarty);
132        }
133}
134
135}
136
137add_event_handler('loc_end_section_init', array('RVTS','on_end_section_init'));
138
139?>
Note: See TracBrowser for help on using the repository browser.