[8900] | 1 | <?php /* |
---|
| 2 | Plugin Name: RV Thumb Scroller |
---|
[13194] | 3 | Version: 2.4.a |
---|
[8900] | 4 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=493 |
---|
| 5 | Description: Loads async using ajax thumbnails on index page as you scroll down the page |
---|
| 6 | Author: rvelices |
---|
| 7 | Author URI: http://www.modusoptimus.com |
---|
| 8 | */ |
---|
[13194] | 9 | define('RVTS_VERSION', '24a'); |
---|
[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); |
---|
[8900] | 50 | global $user, $template, $conf; |
---|
| 51 | include(PHPWG_ROOT_PATH.'include/category_default.inc.php'); |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | static function on_index_thumbnails($thumbs) |
---|
| 56 | { |
---|
| 57 | global $page, $template; |
---|
| 58 | $total = count($page['items']); |
---|
| 59 | if (count($thumbs) >= $total) |
---|
| 60 | { |
---|
| 61 | add_event_handler('loc_end_index', array('RVTS','on_end_index')); |
---|
| 62 | return $thumbs; |
---|
| 63 | } |
---|
| 64 | $url_model = str_replace('123456789', '%start%', duplicate_index_url( array('start'=>123456789) ) ); |
---|
[9813] | 65 | $ajax_url_model = add_url_params($url_model, array( 'rvts'=>'%per%' ) ); |
---|
[8900] | 66 | |
---|
| 67 | $url_model = str_replace('&', '&', $url_model); |
---|
| 68 | $ajax_url_model = str_replace('&', '&', $ajax_url_model); |
---|
| 69 | |
---|
| 70 | $my_base_name = basename(dirname(__FILE__)); |
---|
| 71 | $ajax_loader_image = get_root_url()."plugins/$my_base_name/ajax-loader.gif"; |
---|
| 72 | $template->func_combine_script( array( |
---|
| 73 | 'id'=> 'jquery', |
---|
| 74 | 'load'=> 'footer', |
---|
| 75 | 'path'=> 'themes/default/js/jquery.min.js', |
---|
| 76 | ), $template->smarty); |
---|
| 77 | $template->func_combine_script( array( |
---|
| 78 | 'id'=> $my_base_name, |
---|
| 79 | 'load'=> 'async', |
---|
| 80 | 'path'=> 'plugins/'.$my_base_name.'/rv_tscroller.min.js', |
---|
| 81 | 'require' => 'jquery', |
---|
| 82 | 'version' => RVTS_VERSION, |
---|
| 83 | ), $template->smarty); |
---|
[13194] | 84 | $start = (int)$page['start']; |
---|
| 85 | $per_page = $page['nb_image_page']; |
---|
[8900] | 86 | $moreMsg = 'See the remaining %d photos'; |
---|
[8935] | 87 | if ('en' != $GLOBALS['lang_info']['code']) |
---|
| 88 | { |
---|
| 89 | load_language('lang', dirname(__FILE__).'/'); |
---|
| 90 | $moreMsg = l10n($moreMsg); |
---|
| 91 | } |
---|
[8900] | 92 | $repeat=false; |
---|
[9813] | 93 | // the String.fromCharCode comes from google bot which somehow manage to get these urls |
---|
[8900] | 94 | $template->block_footer_script(null, |
---|
| 95 | "var RVTS = { |
---|
[9813] | 96 | ajaxUrlModel: String.fromCharCode(".ord($ajax_url_model[0]).")+'".substr($ajax_url_model,1)."', |
---|
[13194] | 97 | start: $start, |
---|
| 98 | perPage: $per_page, |
---|
| 99 | next: ".($start+$per_page).", |
---|
[8900] | 100 | total: $total, |
---|
[9813] | 101 | moreUrlModel: String.fromCharCode(".ord($url_model[0]).")+'".substr($url_model,1)."', |
---|
[8900] | 102 | moreMsg: '$moreMsg', |
---|
[13194] | 103 | prevMsg: '".l10n("Previous")."', |
---|
[8900] | 104 | ajaxLoaderImage: '$ajax_loader_image' |
---|
| 105 | };", |
---|
| 106 | $template->smarty, $repeat); |
---|
| 107 | return $thumbs; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | static function on_index_thumbnails_ajax($thumbs) |
---|
| 111 | { |
---|
| 112 | global $template; |
---|
| 113 | $template->assign('thumbnails', $thumbs); |
---|
| 114 | header('Content-Type: text/html; charset='.get_pwg_charset()); |
---|
| 115 | $template->pparse('index_thumbnails'); |
---|
| 116 | exit; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | static function on_end_index() |
---|
| 120 | { |
---|
| 121 | global $template; |
---|
| 122 | $req = null; |
---|
| 123 | foreach($template->scriptLoader->get_all() as $script) |
---|
| 124 | { |
---|
| 125 | if($script->load_mode==2 && !$script->is_remote()) |
---|
| 126 | $req = $script->id; |
---|
| 127 | } |
---|
| 128 | if($req!=null) |
---|
| 129 | { |
---|
| 130 | $my_base_name = basename(dirname(__FILE__)); |
---|
| 131 | $template->func_combine_script( array( |
---|
| 132 | 'id'=> $my_base_name, |
---|
| 133 | 'load'=> 'async', |
---|
| 134 | 'path'=> 'plugins/'.$my_base_name.'/rv_tscroller.min.js', |
---|
| 135 | 'require' => $req, |
---|
| 136 | 'version' => RVTS_VERSION, |
---|
| 137 | ), $template->smarty); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | add_event_handler('loc_end_section_init', array('RVTS','on_end_section_init')); |
---|
| 144 | ?> |
---|