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

Last change on this file since 31974 was 29334, checked in by rvelices, 10 years ago

update plugin version

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