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
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} 
25
26function Fotorama_init()
27{
28  global $conf;
29 
30  load_language('plugin.lang', FOTORAMA_PATH);
31
32  $conf['Fotorama'] = unserialize($conf['Fotorama']);
33
34  // Upgrade params from 2.7.j
35  if (!isset($conf['Fotorama']['thumbheight'])) {
36        $conf['Fotorama']['thumbheight'] = 64;
37  }
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;
42        $conf['Fotorama']['clicktransition_crossfade'] = false;
43  }
44
45  add_event_handler('loc_end_picture', 'Fotorama_end_picture');
46  add_event_handler('loc_end_page_header', 'Fotorama_end_page_header');
47}
48
49function Fotorama_end_picture()
50{
51  global $template, $conf, $user, $page;
52 
53  if ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()))
54  {
55    $page['slideshow'] = true;
56
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
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    $next_type = $type;
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;
105      if ($skip >= 1)
106        $next_type = $def_type;
107      if ($skip == 0)
108        break;
109      $skip = $skip - 1;
110    }
111    $type = $next_type; // +1 size for inpage slideshow
112    if ($conf['Fotorama']['only_fullscreen'])
113    {
114      $type = $big_type;
115    }
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      {
130        $row['derivative_big'] = $row['src_image'];
131      }
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']);;
135      if ($row['derivative_thumb'] == null)
136      {
137        $row['derivative_thumb'] = $row['src_image'];
138      }
139
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        );
149
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']);
158    $template->assign(array('Fotorama' => $conf['Fotorama']));
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    {
165      $template->set_filenames( array('slideshow' => realpath(FOTORAMA_PATH.'template/fotorama.tpl')));
166    }
167    $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH.'template/fotorama-content.tpl'));
168  }
169}
170
171function Fotorama_end_page_header()
172{
173  global $template, $conf, $page;
174
175  if ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()))
176  {
177    $page['slideshow'] = true;
178  }
179
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  }
188}
189
190function Fotorama_admin_menu($menu)
191{
192  $menu[] = array(
193    'NAME' => 'Fotorama',
194    'URL'  => FOTORAMA_ADMIN,
195  );
196
197  return $menu;
198}
199
200?>
Note: See TracBrowser for help on using the repository browser.