[27034] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Fotorama |
---|
[29616] | 4 | Version: auto |
---|
[27034] | 5 | Description: Fotorama based full-screen slideshow |
---|
[29616] | 6 | Plugin URI: auto |
---|
[27034] | 7 | Author: JanisV |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | global $conf; |
---|
| 11 | |
---|
| 12 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 13 | |
---|
| 14 | if (mobile_theme()) return; |
---|
| 15 | |
---|
[27148] | 16 | define('FOTORAMA_ID', basename(dirname(__FILE__))); |
---|
| 17 | define('FOTORAMA_PATH' , PHPWG_PLUGINS_PATH . FOTORAMA_ID . '/'); |
---|
[27034] | 18 | |
---|
| 19 | add_event_handler('init', 'Fotorama_init'); |
---|
[27148] | 20 | if (defined('IN_ADMIN')) |
---|
| 21 | { |
---|
| 22 | add_event_handler('get_admin_plugin_menu_links', 'Fotorama_admin_menu'); |
---|
[29917] | 23 | } |
---|
[30052] | 24 | elseif ($conf['light_slideshow']) |
---|
[29917] | 25 | { |
---|
[30052] | 26 | add_event_handler('render_element_content', 'Fotorama_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL-10); |
---|
| 27 | add_event_handler('loc_end_picture', 'Fotorama_end_picture'); |
---|
[29917] | 28 | } |
---|
[27034] | 29 | |
---|
[29946] | 30 | function Fotorama_is_replace_picture() |
---|
| 31 | { |
---|
| 32 | global $conf; |
---|
| 33 | |
---|
| 34 | return ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()) and (!isset($_GET['slidestop']))); |
---|
| 35 | } |
---|
| 36 | |
---|
[27034] | 37 | function Fotorama_init() |
---|
| 38 | { |
---|
[29946] | 39 | global $conf, $user; |
---|
| 40 | |
---|
[27148] | 41 | $conf['Fotorama'] = unserialize($conf['Fotorama']); |
---|
| 42 | |
---|
[29593] | 43 | // Upgrade params from 2.7.j |
---|
| 44 | if (!isset($conf['Fotorama']['thumbheight'])) { |
---|
| 45 | $conf['Fotorama']['thumbheight'] = 64; |
---|
| 46 | } |
---|
[29615] | 47 | // Upgrade params from 2.7.l |
---|
| 48 | if (!isset($conf['Fotorama']['replace_picture'])) { |
---|
| 49 | $conf['Fotorama']['replace_picture'] = false; |
---|
| 50 | $conf['Fotorama']['replace_picture_only_users'] = false; |
---|
[29622] | 51 | $conf['Fotorama']['clicktransition_crossfade'] = false; |
---|
[29615] | 52 | } |
---|
[29730] | 53 | // Upgrade params from 2.7.m |
---|
| 54 | if (!isset($conf['Fotorama']['close_button'])) { |
---|
| 55 | $conf['Fotorama']['close_button'] = false; |
---|
[29732] | 56 | $conf['Fotorama']['resize'] = false; |
---|
[29730] | 57 | } |
---|
[29915] | 58 | // Upgrade params from 2.7.n |
---|
| 59 | if (!isset($conf['Fotorama']['period'])) { |
---|
| 60 | $conf['Fotorama']['period'] = 4000; |
---|
[29918] | 61 | $conf['Fotorama']['info_button'] = false; |
---|
[29928] | 62 | $conf['Fotorama']['square_thumb'] = true; |
---|
[29915] | 63 | } |
---|
[27148] | 64 | |
---|
[29946] | 65 | if ($user['theme'] == 'modus' and Fotorama_is_replace_picture()) |
---|
| 66 | { |
---|
| 67 | remove_event_handler('loc_begin_picture', 'modus_loc_begin_picture'); |
---|
| 68 | } |
---|
[29945] | 69 | } |
---|
| 70 | |
---|
[30052] | 71 | function Fotorama_element_content($content) |
---|
[29945] | 72 | { |
---|
| 73 | global $page; |
---|
| 74 | |
---|
| 75 | if (Fotorama_is_replace_picture()) |
---|
| 76 | { |
---|
| 77 | $page['slideshow'] = true; |
---|
| 78 | } |
---|
[30052] | 79 | if ($page['slideshow']) |
---|
| 80 | add_event_handler('loc_end_page_header', 'Fotorama_end_page_header'); |
---|
[30029] | 81 | |
---|
| 82 | return $content; |
---|
[29945] | 83 | } |
---|
| 84 | |
---|
[27034] | 85 | function Fotorama_end_picture() |
---|
| 86 | { |
---|
[27035] | 87 | global $template, $conf, $user, $page; |
---|
[29918] | 88 | |
---|
[29945] | 89 | if (Fotorama_is_replace_picture()) |
---|
[29615] | 90 | { |
---|
| 91 | $url_up = duplicate_index_url( |
---|
| 92 | array( |
---|
| 93 | 'start' => |
---|
| 94 | floor($page['current_rank'] / $page['nb_image_page']) |
---|
| 95 | * $page['nb_image_page'] |
---|
| 96 | ), |
---|
| 97 | array( |
---|
| 98 | 'start', |
---|
| 99 | ) |
---|
| 100 | ); |
---|
| 101 | //slideshow end |
---|
| 102 | $template->assign( |
---|
| 103 | array( |
---|
| 104 | 'U_SLIDESHOW_STOP' => $url_up, |
---|
| 105 | ) |
---|
| 106 | ); |
---|
| 107 | |
---|
| 108 | $template->assign('replace_picture', true); |
---|
| 109 | } |
---|
[30052] | 110 | |
---|
| 111 | if (!$page['slideshow']) |
---|
| 112 | return; |
---|
| 113 | |
---|
| 114 | load_language('plugin.lang', FOTORAMA_PATH); |
---|
| 115 | |
---|
| 116 | $split_limit = 400; |
---|
| 117 | if ('mobile' == get_device()) |
---|
| 118 | $split_limit /= 2; |
---|
| 119 | |
---|
| 120 | $view_offset = null; |
---|
| 121 | if (count($page['items']) >= 1.2*$split_limit) |
---|
[27034] | 122 | { |
---|
[30052] | 123 | $first = $split_limit * 0.2; |
---|
| 124 | $last = $split_limit - $first; |
---|
[27034] | 125 | |
---|
[30052] | 126 | $first = $page['current_rank'] - $first; |
---|
| 127 | if ($first < 0) |
---|
| 128 | $first += count($page['items']); |
---|
[27034] | 129 | |
---|
[30052] | 130 | $last = $page['current_rank'] + $last; |
---|
| 131 | if ($last >= count($page['items'])) |
---|
| 132 | $last -= count($page['items']); |
---|
[30029] | 133 | |
---|
[30052] | 134 | if ($first < $last) |
---|
[27034] | 135 | { |
---|
[30052] | 136 | $selection = array_slice($page['items'], $first, $last-$first); |
---|
| 137 | $view_borders = array( 0, count($selection)-1); |
---|
| 138 | $view_offset = array('from'=>0, 'offset'=>$first); |
---|
[27034] | 139 | } |
---|
[30052] | 140 | else |
---|
[27034] | 141 | { |
---|
[30052] | 142 | $selection = array_slice($page['items'], 0, $last); |
---|
| 143 | $view_borders = array( count($selection), count($selection)-1); |
---|
| 144 | $view_offset = array('from'=>count($selection), 'offset'=>$first-count($selection)); |
---|
| 145 | |
---|
| 146 | $selection = array_merge($selection, array_slice($page['items'], $first)); |
---|
[27034] | 147 | } |
---|
[30052] | 148 | } |
---|
| 149 | else |
---|
| 150 | { |
---|
| 151 | $selection = $page['items']; |
---|
| 152 | $view_borders = null; |
---|
| 153 | } |
---|
[29976] | 154 | |
---|
[30052] | 155 | $query = ' |
---|
| 156 | SELECT * |
---|
| 157 | FROM '.IMAGES_TABLE.' |
---|
| 158 | WHERE id IN ('.implode(',', $selection).') |
---|
| 159 | ORDER BY FIELD(id, '.implode(',', $selection).') |
---|
| 160 | ;'; |
---|
| 161 | |
---|
| 162 | $result = pwg_query($query); |
---|
| 163 | |
---|
| 164 | $current = $template->get_template_vars('current'); |
---|
| 165 | if (isset($current['selected_derivative'])) |
---|
| 166 | { |
---|
| 167 | $type = $current['selected_derivative']->get_type(); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | $defined = ImageStdParams::get_defined_type_map(); |
---|
| 171 | if (!isset($type) or !isset($defined[$type])) |
---|
| 172 | { |
---|
| 173 | $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | $skip = -1; |
---|
| 177 | $big_type = $type; |
---|
| 178 | $next_type = $type; |
---|
| 179 | foreach (ImageStdParams::get_defined_type_map() as $def_type => $params) |
---|
| 180 | { |
---|
| 181 | if ($def_type == $type) |
---|
| 182 | $skip = 2; |
---|
| 183 | if ($skip >= 0) |
---|
| 184 | $big_type = $def_type; |
---|
| 185 | if ($skip >= 1 and $conf['Fotorama']['resize']) |
---|
| 186 | $next_type = $def_type; |
---|
| 187 | if ($skip == 0) |
---|
| 188 | break; |
---|
| 189 | $skip = $skip - 1; |
---|
| 190 | } |
---|
| 191 | $type = $next_type; // +1 size for inpage slideshow |
---|
| 192 | if ($conf['Fotorama']['only_fullscreen']) |
---|
| 193 | { |
---|
| 194 | $type = $big_type; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | $type_params = ImageStdParams::get_by_type($type); |
---|
| 198 | $big_type_params = ImageStdParams::get_by_type($big_type); |
---|
| 199 | |
---|
| 200 | if ($conf['Fotorama']['nav'] == 'thumbs' or $conf['Fotorama']['fullscreen_nav'] == 'thumbs') |
---|
| 201 | { |
---|
| 202 | $has_thumbs = true; |
---|
| 203 | } |
---|
| 204 | else |
---|
| 205 | { |
---|
| 206 | $has_thumbs = false; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | if ($has_thumbs) |
---|
| 210 | { |
---|
| 211 | if ($conf['Fotorama']['square_thumb']) |
---|
[29976] | 212 | { |
---|
[30052] | 213 | $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']); |
---|
[29976] | 214 | } |
---|
| 215 | else |
---|
| 216 | { |
---|
[30052] | 217 | $thumb_params = ImageStdParams::get_custom(9999, $conf['Fotorama']['thumbheight']); |
---|
[29976] | 218 | } |
---|
[30052] | 219 | } |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | $picture = array(); |
---|
| 223 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 224 | { |
---|
| 225 | $row['src_image'] = new SrcImage($row); |
---|
| 226 | $row['derivative'] = new DerivativeImage($type_params, $row['src_image']); |
---|
| 227 | $row['derivative_big'] = new DerivativeImage($big_type_params, $row['src_image']); |
---|
| 228 | |
---|
[29976] | 229 | if ($has_thumbs) |
---|
| 230 | { |
---|
[30052] | 231 | $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']); |
---|
[29976] | 232 | } |
---|
| 233 | |
---|
[30052] | 234 | $row['url'] = duplicate_picture_url( |
---|
| 235 | array( |
---|
| 236 | 'image_id' => $row['id'], |
---|
| 237 | 'image_file' => $row['file'], |
---|
| 238 | ), |
---|
| 239 | array( |
---|
| 240 | 'start', |
---|
| 241 | ) |
---|
| 242 | ); |
---|
[29928] | 243 | |
---|
[30052] | 244 | $row['TITLE'] = render_element_name($row); |
---|
| 245 | $picture[] = $row; |
---|
[27034] | 246 | } |
---|
[30052] | 247 | $picture = trigger_change('fotorama_items', $picture, $selection); |
---|
| 248 | $template->assign(array( |
---|
| 249 | 'TOTAL_ITEMS' => count($page['items']), |
---|
| 250 | 'view_borders' => $view_borders, |
---|
| 251 | 'view_offset' => $view_offset, |
---|
| 252 | 'current_rank' => array_search($page['image_id'],$selection), |
---|
| 253 | )); |
---|
| 254 | $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height()); |
---|
| 255 | $template->assign('items', $picture); |
---|
| 256 | $template->assign(array('Fotorama' => $conf['Fotorama'])); |
---|
| 257 | $template->assign('Fotorama_has_thumbs', $has_thumbs); |
---|
| 258 | if (is_file('./themes/'.$user['theme'].'/template/fotorama.tpl')) |
---|
| 259 | { |
---|
| 260 | $template->set_filenames( array('slideshow' => realpath('./themes/'.$user['theme'].'/template/fotorama.tpl'))); |
---|
| 261 | } |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | $template->set_filenames( array('slideshow' => realpath(FOTORAMA_PATH.'template/fotorama.tpl'))); |
---|
| 265 | } |
---|
| 266 | $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH.'template/fotorama-content.tpl')); |
---|
[27034] | 267 | } |
---|
| 268 | |
---|
| 269 | function Fotorama_end_page_header() |
---|
| 270 | { |
---|
[30052] | 271 | global $template; |
---|
[27034] | 272 | |
---|
[30052] | 273 | $template->clear_assign( array('page_refresh', |
---|
| 274 | 'first', |
---|
| 275 | 'previous', |
---|
| 276 | 'next', |
---|
| 277 | 'last', |
---|
| 278 | )); |
---|
[27034] | 279 | } |
---|
| 280 | |
---|
[27148] | 281 | function Fotorama_admin_menu($menu) |
---|
| 282 | { |
---|
| 283 | $menu[] = array( |
---|
| 284 | 'NAME' => 'Fotorama', |
---|
[30052] | 285 | 'URL' => get_root_url() . 'admin.php?page=plugin-' . FOTORAMA_ID, |
---|
[27148] | 286 | ); |
---|
| 287 | |
---|
| 288 | return $menu; |
---|
| 289 | } |
---|
| 290 | |
---|
[27034] | 291 | ?> |
---|