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

Last change on this file since 18955 was 18955, checked in by rvelices, 11 years ago

rv_db_integrity, menutree and tscroller versions for piwigo 2.5

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
RevLine 
[8900]1<?php /*
2Plugin Name: RV Thumb Scroller
[18955]3Version: 2.5.a
[8900]4Plugin URI: http://piwigo.org/ext/extension_view.php?eid=493
[18904]5Description: Infinite scroll - loads thumbnails on index page as you scroll down the page
[8900]6Author: rvelices
7Author URI: http://www.modusoptimus.com
8*/
[18955]9define('RVTS_VERSION', '25a');
[8900]10
11class RVTS
12{
13static function on_end_section_init()
14{
15        global $page;
[13194]16        $page['nb_image_page'] *= pwg_get_session_var('rvts_mult', 1);
17        if (count($page['items'])<$page['nb_image_page']+3)
[8900]18        {
[13194]19                if (!@$page['start'] || script_basename()=='picture')
[8900]20                        $page['nb_image_page'] = max($page['nb_image_page'], count($page['items']));
21        }
[12713]22        add_event_handler('loc_begin_index', array('RVTS','on_index_begin'), EVENT_HANDLER_PRIORITY_NEUTRAL+10);
[8900]23}
24
25static function on_index_begin()
26{
27        global $page;
28        $is_ajax = isset($_GET['rvts']);
29        if (!$is_ajax)
30        {
[13194]31                if (empty($page['items']))
[8900]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);
[8935]49                $page['root_path'] = get_absolute_root_url(false);
[18955]50                $page['body_id'] = 'scroll';
[8900]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) ) );
[9813]66        $ajax_url_model = add_url_params($url_model, array( 'rvts'=>'%per%' ) );
[8900]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',
[17505]77                ));
[8900]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,
[17505]84                ));
[18955]85        $start = (int)$page['start'];
[13194]86        $per_page = $page['nb_image_page'];
[8900]87        $moreMsg = 'See the remaining %d photos';
[8935]88        if ('en' != $GLOBALS['lang_info']['code'])
89        {
90                load_language('lang', dirname(__FILE__).'/');
91                $moreMsg = l10n($moreMsg);
92        }
[17505]93
[9813]94        // the String.fromCharCode comes from google bot which somehow manage to get these urls
[8900]95        $template->block_footer_script(null,
96                "var RVTS = {
[9813]97ajaxUrlModel: String.fromCharCode(".ord($ajax_url_model[0]).")+'".substr($ajax_url_model,1)."',
[13194]98start: $start,
99perPage: $per_page,
100next: ".($start+$per_page).",
[8900]101total: $total,
[9813]102moreUrlModel: String.fromCharCode(".ord($url_model[0]).")+'".substr($url_model,1)."',
[8900]103moreMsg: '$moreMsg',
[13194]104prevMsg: '".l10n("Previous")."',
[8900]105ajaxLoaderImage: '$ajax_loader_image'
[18904]106};
107jQuery('.navigationBar').hide();");
[8900]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())
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}
141
142}
143
144add_event_handler('loc_end_section_init', array('RVTS','on_end_section_init'));
145?>
Note: See TracBrowser for help on using the repository browser.