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

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

Improve checking global enabling slideshow

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