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

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

Native proportions for thumbnails can be enabled

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