[8900] | 1 | <?php /* |
---|
| 2 | Plugin Name: RV Thumb Scroller |
---|
[18955] | 3 | Version: 2.5.a |
---|
[8900] | 4 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=493 |
---|
[18904] | 5 | Description: Infinite scroll - loads thumbnails on index page as you scroll down the page |
---|
[8900] | 6 | Author: rvelices |
---|
| 7 | Author URI: http://www.modusoptimus.com |
---|
| 8 | */ |
---|
[18955] | 9 | define('RVTS_VERSION', '25a'); |
---|
[8900] | 10 | |
---|
| 11 | class RVTS |
---|
| 12 | { |
---|
| 13 | static 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 | |
---|
| 25 | static 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 | |
---|
| 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) ) ); |
---|
[9813] | 66 | $ajax_url_model = add_url_params($url_model, array( 'rvts'=>'%per%' ) ); |
---|
[8900] | 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', |
---|
[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] | 97 | ajaxUrlModel: String.fromCharCode(".ord($ajax_url_model[0]).")+'".substr($ajax_url_model,1)."', |
---|
[13194] | 98 | start: $start, |
---|
| 99 | perPage: $per_page, |
---|
| 100 | next: ".($start+$per_page).", |
---|
[8900] | 101 | total: $total, |
---|
[9813] | 102 | moreUrlModel: String.fromCharCode(".ord($url_model[0]).")+'".substr($url_model,1)."', |
---|
[8900] | 103 | moreMsg: '$moreMsg', |
---|
[13194] | 104 | prevMsg: '".l10n("Previous")."', |
---|
[8900] | 105 | ajaxLoaderImage: '$ajax_loader_image' |
---|
[18904] | 106 | }; |
---|
| 107 | jQuery('.navigationBar').hide();"); |
---|
[8900] | 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 | { |
---|
[24746] | 126 | if($script->load_mode==2 && !$script->is_remote() && count($script->precedents)==0) |
---|
[8900] | 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 | } |
---|
[24746] | 140 | //var_export($template->scriptLoader); |
---|
[8900] | 141 | } |
---|
| 142 | |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | add_event_handler('loc_end_section_init', array('RVTS','on_end_section_init')); |
---|
| 146 | ?> |
---|