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

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

Added option for resizing

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