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

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

Remove debug output

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    $type = $current['selected_derivative']->get_type();
106    $defined = ImageStdParams::get_defined_type_map();
107    if (!isset($defined[$type]))
108    {
109      $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
110    }
111   
112    $skip = -1;
113    $big_type = $type;
114    $next_type = $type;
115    foreach (ImageStdParams::get_defined_type_map() as $def_type => $params)
116    {
117      if ($def_type == $type)
118        $skip = 2;
119      if ($skip >= 0)
120        $big_type = $def_type;
121      if ($skip >= 1 and $conf['Fotorama']['resize'])
122        $next_type = $def_type;
123      if ($skip == 0)
124        break;
125      $skip = $skip - 1;
126    }
127    $type = $next_type; // +1 size for inpage slideshow
128    if ($conf['Fotorama']['only_fullscreen'])
129    {
130      $type = $big_type;
131    }
132   
133    $picture = array();
134    while ($row = pwg_db_fetch_assoc($result))
135    {
136      $row['src_image'] = new SrcImage($row);
137//      $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
138      $row['derivative'] = DerivativeImage::get_one($type, $row['src_image']);
139      if ($row['derivative'] == null)
140      {
141        $row['derivative'] = $row['src_image'];
142      }
143      $row['derivative_big'] = DerivativeImage::get_one($big_type, $row['src_image']);
144      if ($row['derivative_big'] == null)
145      {
146        $row['derivative_big'] = $row['src_image'];
147      }
148
149      if ($conf['Fotorama']['square_thumb'])
150      {
151        $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']);
152      }
153      else
154      {
155        $thumb_params = ImageStdParams::get_custom(9999, $conf['Fotorama']['thumbheight']);
156      }
157      $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']);;
158      if ($row['derivative_thumb'] == null)
159      {
160        $row['derivative_thumb'] = $row['src_image'];
161      }
162
163      $row['url'] = duplicate_picture_url(
164        array(
165          'image_id' => $row['id'],
166          'image_file' => $row['file'],
167          ),
168        array(
169          'start',
170          )
171        );
172
173      $row['TITLE'] = render_element_name($row);
174      $row['TITLE_ESC'] = str_replace('"', '&quot;', $row['TITLE']);
175      $picture[] = $row;
176    }
177   
178    $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height());
179    $template->assign('items', $picture);
180    $template->assign('current_rank', $page['current_rank']);
181    $template->assign(array('Fotorama' => $conf['Fotorama']));
182    if (is_file('./themes/'.$user['theme'].'/template/fotorama.tpl'))
183    {
184      $template->set_filenames( array('slideshow' => realpath('./themes/'.$user['theme'].'/template/fotorama.tpl')));
185    }
186    else
187    {
188      $template->set_filenames( array('slideshow' => realpath(FOTORAMA_PATH.'template/fotorama.tpl')));
189    }
190    $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH.'template/fotorama-content.tpl'));
191  }
192}
193
194function Fotorama_end_page_header()
195{
196  global $template, $conf, $page;
197
198  if ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()) and (!isset($_GET['slidestop'])))
199  {
200    $page['slideshow'] = true;
201  }
202
203  if (isset($page['slideshow']) and $page['slideshow'])
204  {
205    $template->clear_assign('page_refresh');
206    $template->clear_assign('first');
207    $template->clear_assign('previous');
208    $template->clear_assign('next');
209    $template->clear_assign('last');
210  }
211}
212
213function Fotorama_admin_menu($menu)
214{
215  $menu[] = array(
216    'NAME' => 'Fotorama',
217    'URL'  => FOTORAMA_ADMIN,
218  );
219
220  return $menu;
221}
222
223?>
Note: See TracBrowser for help on using the repository browser.