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

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

Fixed using TITLE_ESC

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