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

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

Added info button

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