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

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

Improve support for theme

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