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

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

Improve image loading in only fullscreen mode

File size: 5.5 KB
RevLine 
[27034]1<?php
2/*
3Plugin Name: Fotorama
[29616]4Version: auto
[27034]5Description: Fotorama based full-screen slideshow
[29616]6Plugin URI: auto
[27034]7Author: JanisV
8*/
9
10global $conf;
11
12if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
13
14if (mobile_theme()) return;
15
[27148]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);
[27034]19
20add_event_handler('init', 'Fotorama_init');
[27148]21if (defined('IN_ADMIN'))
22{
23  add_event_handler('get_admin_plugin_menu_links', 'Fotorama_admin_menu');
24} 
[27034]25
26function Fotorama_init()
27{
[27148]28  global $conf;
[27034]29 
[27148]30  load_language('plugin.lang', FOTORAMA_PATH);
31
32  $conf['Fotorama'] = unserialize($conf['Fotorama']);
33
[29593]34  // Upgrade params from 2.7.j
35  if (!isset($conf['Fotorama']['thumbheight'])) {
36        $conf['Fotorama']['thumbheight'] = 64;
37  }
[29615]38  // Upgrade params from 2.7.l
39  if (!isset($conf['Fotorama']['replace_picture'])) {
40        $conf['Fotorama']['replace_picture'] = false;
41        $conf['Fotorama']['replace_picture_only_users'] = false;
[29622]42        $conf['Fotorama']['clicktransition_crossfade'] = false;
[29615]43  }
[29593]44
[27034]45  add_event_handler('loc_end_picture', 'Fotorama_end_picture');
46  add_event_handler('loc_end_page_header', 'Fotorama_end_page_header');
47}
[27148]48
[27034]49function Fotorama_end_picture()
50{
[27035]51  global $template, $conf, $user, $page;
[29615]52 
53  if ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()))
54  {
55    $page['slideshow'] = true;
[27034]56
[29615]57    $url_up = duplicate_index_url(
58      array(
59        'start' =>
60          floor($page['current_rank'] / $page['nb_image_page'])
61          * $page['nb_image_page']
62        ),
63      array(
64        'start',
65        )
66      );
67    //slideshow end
68    $template->assign(
69      array(
70        'U_SLIDESHOW_STOP' => $url_up,
71        )
72      );
73
74    $template->assign('replace_picture', true);
75  }
76
[27034]77  if ($page['slideshow'] and $conf['light_slideshow'])
78  {
79    $query = '
80    SELECT *
81      FROM '.IMAGES_TABLE.'
82      WHERE id IN ('.implode(',', $page['items']).')
83      ORDER BY FIELD(id, '.implode(',', $page['items']).')
84    ;';
85
86    $result = pwg_query($query);
87
88    $current = $template->get_template_vars('current');
89    $type = $current['selected_derivative']->get_type();
90    $defined = ImageStdParams::get_defined_type_map();
91    if (!isset($defined[$type]))
92    {
93      $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
94    }
95   
96    $skip = -1;
97    $big_type = $type;
98    foreach (ImageStdParams::get_defined_type_map() as $def_type => $params)
99    {
100      if ($def_type == $type)
101        $skip = 2;
102      if ($skip >= 0)
103        $big_type = $def_type;
104      if ($skip == 0)
105        break;
106      $skip = $skip - 1;
107    }
[29628]108    if ($conf['Fotorama']['only_fullscreen'])
109    {
110      $type = $big_type;
111    }
[27034]112   
113    $picture = array();
114    while ($row = pwg_db_fetch_assoc($result))
115    {
116      $row['src_image'] = new SrcImage($row);
117//      $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
118      $row['derivative'] = DerivativeImage::get_one($type, $row['src_image']);
119      if ($row['derivative'] == null)
120      {
121        $row['derivative'] = $row['src_image'];
122      }
123      $row['derivative_big'] = DerivativeImage::get_one($big_type, $row['src_image']);
124      if ($row['derivative_big'] == null)
125      {
[27155]126        $row['derivative_big'] = $row['src_image'];
[27034]127      }
[29593]128//      $row['derivative_thumb'] = DerivativeImage::get_one(IMG_SQUARE, $row['src_image']);
129      $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']);
130      $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']);;
[27155]131      if ($row['derivative_thumb'] == null)
132      {
133        $row['derivative_thumb'] = $row['src_image'];
134      }
[27039]135
[27034]136      $row['url'] = duplicate_picture_url(
137        array(
138          'image_id' => $row['id'],
139          'image_file' => $row['file'],
140          ),
141        array(
142          'start',
143          )
144        );
[27039]145
[27034]146      $row['TITLE'] = render_element_name($row);
147      $row['TITLE_ESC'] = str_replace('"', '&quot;', $row['TITLE']);
148      $picture[] = $row;
149    }
150   
151    $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height());
152    $template->assign('items', $picture);
153    $template->assign('current_rank', $page['current_rank']);
[27148]154    $template->assign(array('Fotorama' => $conf['Fotorama']));
[29381]155    if (is_file('./themes/'.$user['theme'].'/template/fotorama.tpl'))
156    {
157      $template->set_filenames( array('slideshow' => realpath('./themes/'.$user['theme'].'/template/fotorama.tpl')));
158    }
159    else
160    {
[29626]161      $template->set_filenames( array('slideshow' => realpath(FOTORAMA_PATH.'template/fotorama.tpl')));
[29381]162    }
[29626]163    $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH.'template/fotorama-content.tpl'));
[27034]164  }
165}
166
167function Fotorama_end_page_header()
168{
[27035]169  global $template, $conf, $page;
[27034]170
[29615]171  if ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()))
172  {
173    $page['slideshow'] = true;
174  }
175
[27035]176  if (isset($page['slideshow']) and $page['slideshow'] and $conf['light_slideshow'])
177  {
178    $template->clear_assign('page_refresh');
179    $template->clear_assign('first');
180    $template->clear_assign('previous');
181    $template->clear_assign('next');
182    $template->clear_assign('last');
183  }
[27034]184}
185
[27148]186function Fotorama_admin_menu($menu)
187{
188  $menu[] = array(
189    'NAME' => 'Fotorama',
190    'URL'  => FOTORAMA_ADMIN,
191  );
192
193  return $menu;
194}
195
[27034]196?>
Note: See TracBrowser for help on using the repository browser.