source: extensions/Fotorama/main.inc.php @ 31980

Last change on this file since 31980 was 30052, checked in by rvelices, 10 years ago

Fotorama use segmented views for large number of items
do not load plugin language and register event if not required
add event to allow video plugins to fill thumbnail.video and thumbnail.video_id (Fotorama can show youtube/vimeo videos during slideshow)

File size: 7.4 KB
Line 
1<?php
2/*
3Plugin Name: Fotorama
4Version: auto
5Description: Fotorama based full-screen slideshow
6Plugin URI: auto
7Author: JanisV
8*/
9
10global $conf;
11
12if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
13
14if (mobile_theme()) return;
15
16define('FOTORAMA_ID',       basename(dirname(__FILE__)));
17define('FOTORAMA_PATH' ,    PHPWG_PLUGINS_PATH . FOTORAMA_ID . '/');
18
19add_event_handler('init', 'Fotorama_init');
20if (defined('IN_ADMIN'))
21{
22  add_event_handler('get_admin_plugin_menu_links', 'Fotorama_admin_menu');
23}
24elseif ($conf['light_slideshow'])
25{
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');
28}
29
30function 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
37function Fotorama_init()
38{
39  global $conf, $user;
40
41  $conf['Fotorama'] = unserialize($conf['Fotorama']);
42
43  // Upgrade params from 2.7.j
44  if (!isset($conf['Fotorama']['thumbheight'])) {
45        $conf['Fotorama']['thumbheight'] = 64;
46  }
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;
51        $conf['Fotorama']['clicktransition_crossfade'] = false;
52  }
53  // Upgrade params from 2.7.m
54  if (!isset($conf['Fotorama']['close_button'])) {
55        $conf['Fotorama']['close_button'] = false;
56        $conf['Fotorama']['resize'] = false;
57  }
58  // Upgrade params from 2.7.n
59  if (!isset($conf['Fotorama']['period'])) {
60        $conf['Fotorama']['period'] = 4000;
61    $conf['Fotorama']['info_button'] = false;
62    $conf['Fotorama']['square_thumb'] = true;
63  }
64
65  if ($user['theme'] == 'modus' and Fotorama_is_replace_picture())
66  {
67    remove_event_handler('loc_begin_picture', 'modus_loc_begin_picture');
68  }
69}
70
71function Fotorama_element_content($content)
72{
73  global $page;
74
75  if (Fotorama_is_replace_picture())
76  {
77    $page['slideshow'] = true;
78  }
79  if ($page['slideshow'])
80    add_event_handler('loc_end_page_header', 'Fotorama_end_page_header');
81
82  return $content;
83}
84
85function Fotorama_end_picture()
86{
87  global $template, $conf, $user, $page;
88
89  if (Fotorama_is_replace_picture())
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  }
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)
122  {
123    $first = $split_limit * 0.2;
124    $last = $split_limit - $first;
125
126    $first = $page['current_rank'] - $first;
127    if ($first < 0)
128      $first += count($page['items']);
129
130    $last = $page['current_rank'] + $last;
131    if ($last >= count($page['items']))
132      $last -= count($page['items']);
133
134    if ($first < $last)
135    {
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);
139    }
140    else
141    {
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));
147    }
148  }
149  else
150  {
151    $selection = $page['items'];
152    $view_borders = null;
153  }
154
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'])
212    {
213      $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']);
214    }
215    else
216    {
217      $thumb_params = ImageStdParams::get_custom(9999, $conf['Fotorama']['thumbheight']);
218    }
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
229    if ($has_thumbs)
230    {
231      $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']);
232    }
233
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      );
243
244    $row['TITLE'] = render_element_name($row);
245    $picture[] = $row;
246  }
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'));
267}
268
269function Fotorama_end_page_header()
270{
271  global $template;
272
273  $template->clear_assign( array('page_refresh',
274    'first',
275    'previous',
276    'next',
277    'last',
278    ));
279}
280
281function Fotorama_admin_menu($menu)
282{
283  $menu[] = array(
284    'NAME' => 'Fotorama',
285    'URL'  => get_root_url() . 'admin.php?page=plugin-' . FOTORAMA_ID,
286  );
287
288  return $menu;
289}
290
291?>
Note: See TracBrowser for help on using the repository browser.