1 | <?php /* |
---|
2 | Plugin Name: RV Thumb Scroller |
---|
3 | Version: 2.6.a |
---|
4 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=493 |
---|
5 | Description: Infinite scroll - loads thumbnails on index page as you scroll down the page |
---|
6 | Author: rvelices |
---|
7 | Author URI: http://www.modusoptimus.com |
---|
8 | */ |
---|
9 | define('RVTS_VERSION', '25a'); |
---|
10 | |
---|
11 | class RVTS |
---|
12 | { |
---|
13 | static 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 | |
---|
25 | static 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 | |
---|
56 | static 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('&', '&', $url_model); |
---|
69 | $ajax_url_model = str_replace('&', '&', $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 = { |
---|
97 | ajaxUrlModel: String.fromCharCode(".ord($ajax_url_model[0]).")+'".substr($ajax_url_model,1)."', |
---|
98 | start: $start, |
---|
99 | perPage: $per_page, |
---|
100 | next: ".($start+$per_page).", |
---|
101 | total: $total, |
---|
102 | moreUrlModel: String.fromCharCode(".ord($url_model[0]).")+'".substr($url_model,1)."', |
---|
103 | moreMsg: '$moreMsg', |
---|
104 | prevMsg: '".l10n("Previous")."', |
---|
105 | ajaxLoaderImage: '$ajax_loader_image' |
---|
106 | }; |
---|
107 | jQuery('.navigationBar').hide();"); |
---|
108 | return $thumbs; |
---|
109 | } |
---|
110 | |
---|
111 | static 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 | |
---|
120 | static 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 | |
---|
145 | add_event_handler('loc_end_section_init', array('RVTS','on_end_section_init')); |
---|
146 | ?> |
---|