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

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

Added close button

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