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

Last change on this file since 30029 was 30029, checked in by JanisV, 10 years ago

Compatibility with VideoJS

File size: 6.5 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 . '/');
18define('FOTORAMA_ADMIN',    get_root_url() . 'admin.php?page=plugin-' . FOTORAMA_ID);
19
20add_event_handler('init', 'Fotorama_init');
21if (defined('IN_ADMIN'))
22{
23  add_event_handler('get_admin_plugin_menu_links', 'Fotorama_admin_menu');
24}
25else
26{
27  if ($conf['light_slideshow'])
28  {
29    add_event_handler('render_element_content', 'Fotorama_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL-10);
30    add_event_handler('loc_end_picture', 'Fotorama_end_picture');
31    add_event_handler('loc_end_page_header', 'Fotorama_end_page_header');
32  }
33}
34
35function Fotorama_is_replace_picture()
36{
37  global $conf;
38
39  return ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()) and (!isset($_GET['slidestop'])));
40}
41
42function Fotorama_init()
43{
44  global $conf, $user;
45
46  load_language('plugin.lang', FOTORAMA_PATH);
47
48  $conf['Fotorama'] = unserialize($conf['Fotorama']);
49
50  // Upgrade params from 2.7.j
51  if (!isset($conf['Fotorama']['thumbheight'])) {
52        $conf['Fotorama']['thumbheight'] = 64;
53  }
54  // Upgrade params from 2.7.l
55  if (!isset($conf['Fotorama']['replace_picture'])) {
56        $conf['Fotorama']['replace_picture'] = false;
57        $conf['Fotorama']['replace_picture_only_users'] = false;
58        $conf['Fotorama']['clicktransition_crossfade'] = false;
59  }
60  // Upgrade params from 2.7.m
61  if (!isset($conf['Fotorama']['close_button'])) {
62        $conf['Fotorama']['close_button'] = false;
63        $conf['Fotorama']['resize'] = false;
64  }
65  // Upgrade params from 2.7.n
66  if (!isset($conf['Fotorama']['period'])) {
67        $conf['Fotorama']['period'] = 4000;
68    $conf['Fotorama']['info_button'] = false;
69    $conf['Fotorama']['square_thumb'] = true;
70  }
71
72  if ($user['theme'] == 'modus' and Fotorama_is_replace_picture())
73  {
74    remove_event_handler('loc_begin_picture', 'modus_loc_begin_picture');
75  }
76}
77
78function Fotorama_element_content($content, $picture)
79{
80  global $page;
81
82  if (Fotorama_is_replace_picture())
83  {
84    $page['slideshow'] = true;
85  }
86
87  return $content;
88}
89
90function Fotorama_end_picture()
91{
92  global $template, $conf, $user, $page;
93
94  if (Fotorama_is_replace_picture())
95  {
96    $url_up = duplicate_index_url(
97      array(
98        'start' =>
99          floor($page['current_rank'] / $page['nb_image_page'])
100          * $page['nb_image_page']
101        ),
102      array(
103        'start',
104        )
105      );
106    //slideshow end
107    $template->assign(
108      array(
109        'U_SLIDESHOW_STOP' => $url_up,
110        )
111      );
112
113    $template->assign('replace_picture', true);
114  }
115 
116  if ($page['slideshow'])
117  {
118    $query = '
119    SELECT *
120      FROM '.IMAGES_TABLE.'
121      WHERE id IN ('.implode(',', $page['items']).')
122      ORDER BY FIELD(id, '.implode(',', $page['items']).')
123    ;';
124
125    $result = pwg_query($query);
126
127    $current = $template->get_template_vars('current');
128    if (isset($current['selected_derivative']))
129    {
130      $type = $current['selected_derivative']->get_type();
131    }
132
133    $defined = ImageStdParams::get_defined_type_map();
134    if (!isset($type) or !isset($defined[$type]))
135    {
136      $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
137    }
138   
139    $skip = -1;
140    $big_type = $type;
141    $next_type = $type;
142    foreach (ImageStdParams::get_defined_type_map() as $def_type => $params)
143    {
144      if ($def_type == $type)
145        $skip = 2;
146      if ($skip >= 0)
147        $big_type = $def_type;
148      if ($skip >= 1 and $conf['Fotorama']['resize'])
149        $next_type = $def_type;
150      if ($skip == 0)
151        break;
152      $skip = $skip - 1;
153    }
154    $type = $next_type; // +1 size for inpage slideshow
155    if ($conf['Fotorama']['only_fullscreen'])
156    {
157      $type = $big_type;
158    }
159    $type_params = ImageStdParams::get_by_type($type);
160    $big_type_params = ImageStdParams::get_by_type($big_type);
161
162    if ($conf['Fotorama']['nav'] == 'thumbs' or $conf['Fotorama']['fullscreen_nav'] == 'thumbs')
163    {
164      $has_thumbs = true;
165    }
166    else
167    {
168      $has_thumbs = false;
169    }
170   
171    if ($has_thumbs)
172    {
173      if ($conf['Fotorama']['square_thumb'])
174      {
175        $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']);
176      }
177      else
178      {
179        $thumb_params = ImageStdParams::get_custom(9999, $conf['Fotorama']['thumbheight']);
180      }
181    }
182
183    $picture = array();
184    while ($row = pwg_db_fetch_assoc($result))
185    {
186      $row['src_image'] = new SrcImage($row);
187      $row['derivative'] = new DerivativeImage($type_params, $row['src_image']);
188      $row['derivative_big'] = new DerivativeImage($big_type_params, $row['src_image']);
189
190      if ($has_thumbs)
191      {
192        $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']);
193      }
194
195      $row['url'] = duplicate_picture_url(
196        array(
197          'image_id' => $row['id'],
198          'image_file' => $row['file'],
199          ),
200        array(
201          'start',
202          )
203        );
204
205      $row['TITLE'] = render_element_name($row);
206      $picture[] = $row;
207    }
208   
209    $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height());
210    $template->assign('items', $picture);
211    $template->assign('current_rank', $page['current_rank']);
212    $template->assign(array('Fotorama' => $conf['Fotorama']));
213    $template->assign('Fotorama_has_thumbs', $has_thumbs);
214    if (is_file('./themes/'.$user['theme'].'/template/fotorama.tpl'))
215    {
216      $template->set_filenames( array('slideshow' => realpath('./themes/'.$user['theme'].'/template/fotorama.tpl')));
217    }
218    else
219    {
220      $template->set_filenames( array('slideshow' => realpath(FOTORAMA_PATH.'template/fotorama.tpl')));
221    }
222    $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH.'template/fotorama-content.tpl'));
223  }
224}
225
226function Fotorama_end_page_header()
227{
228  global $template, $page;
229
230  if (isset($page['slideshow']) and $page['slideshow'])
231  {
232    $template->clear_assign('page_refresh');
233    $template->clear_assign('first');
234    $template->clear_assign('previous');
235    $template->clear_assign('next');
236    $template->clear_assign('last');
237  }
238}
239
240function Fotorama_admin_menu($menu)
241{
242  $menu[] = array(
243    'NAME' => 'Fotorama',
244    'URL'  => FOTORAMA_ADMIN,
245  );
246
247  return $menu;
248}
249
250?>
Note: See TracBrowser for help on using the repository browser.