[8900] | 1 | <?php /* |
---|
| 2 | Plugin Name: RV Thumb Scroller |
---|
| 3 | Version: 2.2.a |
---|
| 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 | */ |
---|
[8935] | 9 | define('RVTS_VERSION', '2.2.a'); |
---|
[8900] | 10 | |
---|
| 11 | class RVTS |
---|
| 12 | { |
---|
| 13 | static function on_end_section_init() |
---|
| 14 | { |
---|
| 15 | global $page; |
---|
| 16 | if (!@$page['start']) |
---|
| 17 | { |
---|
| 18 | if (script_basename()!='picture') |
---|
| 19 | $page['nb_image_page'] *= pwg_get_session_var('rvts_mult', 1); |
---|
| 20 | if (count($page['items'])<$page['nb_image_page']+3) |
---|
| 21 | $page['nb_image_page'] = max($page['nb_image_page'], count($page['items'])); |
---|
| 22 | } |
---|
| 23 | add_event_handler('loc_begin_index', array('RVTS','on_index_begin')); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | static function on_index_begin() |
---|
| 27 | { |
---|
| 28 | global $page; |
---|
| 29 | $is_ajax = isset($_GET['rvts']); |
---|
| 30 | if (!$is_ajax) |
---|
| 31 | { |
---|
| 32 | if (empty($page['items']) || @$page['start']>0) |
---|
| 33 | add_event_handler('loc_end_index', array('RVTS','on_end_index')); |
---|
| 34 | else |
---|
| 35 | add_event_handler('loc_end_index_thumbnails', array('RVTS','on_index_thumbnails'), EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
| 36 | } |
---|
| 37 | else |
---|
| 38 | { |
---|
| 39 | $adj = (int)@$_GET['adj']; |
---|
| 40 | if ($adj) |
---|
| 41 | { |
---|
| 42 | $mult = pwg_get_session_var('rvts_mult', 1); |
---|
| 43 | if ($adj>0 && $mult<5) |
---|
| 44 | pwg_set_session_var('rvts_mult', ++$mult); |
---|
| 45 | if ($adj<0 && $mult>1) |
---|
| 46 | pwg_set_session_var('rvts_mult', --$mult); |
---|
| 47 | } |
---|
| 48 | $page['nb_image_page']=(int)$_GET['rvts']; |
---|
| 49 | add_event_handler('loc_end_index_thumbnails', array('RVTS','on_index_thumbnails_ajax'), EVENT_HANDLER_PRIORITY_NEUTRAL+5, 1); |
---|
[8935] | 50 | $page['root_path'] = get_absolute_root_url(false); |
---|
[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 | $per_page = $page['nb_image_page']; |
---|
| 66 | $url_model = str_replace('123456789', '%start%', duplicate_index_url( array('start'=>123456789) ) ); |
---|
| 67 | $ajax_url_model = add_url_params($url_model, array( 'rvts'=>'' ) ); |
---|
| 68 | |
---|
| 69 | $url_model = str_replace('&', '&', $url_model); |
---|
| 70 | $ajax_url_model = str_replace('&', '&', $ajax_url_model); |
---|
| 71 | |
---|
| 72 | $my_base_name = basename(dirname(__FILE__)); |
---|
| 73 | $ajax_loader_image = get_root_url()."plugins/$my_base_name/ajax-loader.gif"; |
---|
| 74 | $template->func_combine_script( array( |
---|
| 75 | 'id'=> 'jquery', |
---|
| 76 | 'load'=> 'footer', |
---|
| 77 | 'path'=> 'themes/default/js/jquery.min.js', |
---|
| 78 | ), $template->smarty); |
---|
| 79 | $template->func_combine_script( array( |
---|
| 80 | 'id'=> $my_base_name, |
---|
| 81 | 'load'=> 'async', |
---|
| 82 | 'path'=> 'plugins/'.$my_base_name.'/rv_tscroller.min.js', |
---|
| 83 | 'require' => 'jquery', |
---|
| 84 | 'version' => RVTS_VERSION, |
---|
| 85 | ), $template->smarty); |
---|
| 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; |
---|
| 93 | $template->block_footer_script(null, |
---|
| 94 | "var RVTS = { |
---|
| 95 | ajaxUrlModel: '$ajax_url_model'+'%per%', |
---|
| 96 | start: $per_page, |
---|
| 97 | total: $total, |
---|
| 98 | perPage: $per_page, |
---|
| 99 | urlModel: '$url_model', |
---|
| 100 | moreMsg: '$moreMsg', |
---|
| 101 | ajaxLoaderImage: '$ajax_loader_image' |
---|
| 102 | };", |
---|
| 103 | $template->smarty, $repeat); |
---|
| 104 | return $thumbs; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | static function on_index_thumbnails_ajax($thumbs) |
---|
| 108 | { |
---|
| 109 | global $template; |
---|
| 110 | $template->assign('thumbnails', $thumbs); |
---|
| 111 | header('Content-Type: text/html; charset='.get_pwg_charset()); |
---|
| 112 | $template->pparse('index_thumbnails'); |
---|
| 113 | exit; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | static function on_end_index() |
---|
| 117 | { |
---|
| 118 | global $template; |
---|
| 119 | $req = null; |
---|
| 120 | foreach($template->scriptLoader->get_all() as $script) |
---|
| 121 | { |
---|
| 122 | if($script->load_mode==2 && !$script->is_remote()) |
---|
| 123 | $req = $script->id; |
---|
| 124 | } |
---|
| 125 | if($req!=null) |
---|
| 126 | { |
---|
| 127 | $my_base_name = basename(dirname(__FILE__)); |
---|
| 128 | $template->func_combine_script( array( |
---|
| 129 | 'id'=> $my_base_name, |
---|
| 130 | 'load'=> 'async', |
---|
| 131 | 'path'=> 'plugins/'.$my_base_name.'/rv_tscroller.min.js', |
---|
| 132 | 'require' => $req, |
---|
| 133 | 'version' => RVTS_VERSION, |
---|
| 134 | ), $template->smarty); |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | add_event_handler('loc_end_section_init', array('RVTS','on_end_section_init')); |
---|
| 141 | |
---|
| 142 | ?> |
---|