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

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

compatibility with Panoramas

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