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

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

+1 size for inpage slideshow

File size: 5.6 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;
[29640]98    $next_type = $type;
[27034]99    foreach (ImageStdParams::get_defined_type_map() as $def_type => $params)
100    {
101      if ($def_type == $type)
102        $skip = 2;
103      if ($skip >= 0)
104        $big_type = $def_type;
[29640]105      if ($skip >= 1)
106        $next_type = $def_type;
[27034]107      if ($skip == 0)
108        break;
109      $skip = $skip - 1;
110    }
[29640]111    $type = $next_type; // +1 size for inpage slideshow
[29628]112    if ($conf['Fotorama']['only_fullscreen'])
113    {
114      $type = $big_type;
115    }
[27034]116   
117    $picture = array();
118    while ($row = pwg_db_fetch_assoc($result))
119    {
120      $row['src_image'] = new SrcImage($row);
121//      $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
122      $row['derivative'] = DerivativeImage::get_one($type, $row['src_image']);
123      if ($row['derivative'] == null)
124      {
125        $row['derivative'] = $row['src_image'];
126      }
127      $row['derivative_big'] = DerivativeImage::get_one($big_type, $row['src_image']);
128      if ($row['derivative_big'] == null)
129      {
[27155]130        $row['derivative_big'] = $row['src_image'];
[27034]131      }
[29593]132//      $row['derivative_thumb'] = DerivativeImage::get_one(IMG_SQUARE, $row['src_image']);
133      $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']);
134      $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']);;
[27155]135      if ($row['derivative_thumb'] == null)
136      {
137        $row['derivative_thumb'] = $row['src_image'];
138      }
[27039]139
[27034]140      $row['url'] = duplicate_picture_url(
141        array(
142          'image_id' => $row['id'],
143          'image_file' => $row['file'],
144          ),
145        array(
146          'start',
147          )
148        );
[27039]149
[27034]150      $row['TITLE'] = render_element_name($row);
151      $row['TITLE_ESC'] = str_replace('"', '&quot;', $row['TITLE']);
152      $picture[] = $row;
153    }
154   
155    $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height());
156    $template->assign('items', $picture);
157    $template->assign('current_rank', $page['current_rank']);
[27148]158    $template->assign(array('Fotorama' => $conf['Fotorama']));
[29381]159    if (is_file('./themes/'.$user['theme'].'/template/fotorama.tpl'))
160    {
161      $template->set_filenames( array('slideshow' => realpath('./themes/'.$user['theme'].'/template/fotorama.tpl')));
162    }
163    else
164    {
[29626]165      $template->set_filenames( array('slideshow' => realpath(FOTORAMA_PATH.'template/fotorama.tpl')));
[29381]166    }
[29626]167    $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH.'template/fotorama-content.tpl'));
[27034]168  }
169}
170
171function Fotorama_end_page_header()
172{
[27035]173  global $template, $conf, $page;
[27034]174
[29615]175  if ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()))
176  {
177    $page['slideshow'] = true;
178  }
179
[27035]180  if (isset($page['slideshow']) and $page['slideshow'] and $conf['light_slideshow'])
181  {
182    $template->clear_assign('page_refresh');
183    $template->clear_assign('first');
184    $template->clear_assign('previous');
185    $template->clear_assign('next');
186    $template->clear_assign('last');
187  }
[27034]188}
189
[27148]190function Fotorama_admin_menu($menu)
191{
192  $menu[] = array(
193    'NAME' => 'Fotorama',
194    'URL'  => FOTORAMA_ADMIN,
195  );
196
197  return $menu;
198}
199
[27034]200?>
Note: See TracBrowser for help on using the repository browser.