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

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

New version

File size: 4.4 KB
Line 
1<?php
2/*
3Plugin Name: Fotorama
4Version: 2.7.k
5Description: Fotorama based full-screen slideshow
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=727
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
39  add_event_handler('loc_end_picture', 'Fotorama_end_picture');
40  add_event_handler('loc_end_page_header', 'Fotorama_end_page_header');
41}
42
43function Fotorama_end_picture()
44{
45  global $template, $conf, $user, $page;
46
47  if ($page['slideshow'] and $conf['light_slideshow'])
48  {
49    $query = '
50    SELECT *
51      FROM '.IMAGES_TABLE.'
52      WHERE id IN ('.implode(',', $page['items']).')
53      ORDER BY FIELD(id, '.implode(',', $page['items']).')
54    ;';
55
56    $result = pwg_query($query);
57
58    $current = $template->get_template_vars('current');
59    $type = $current['selected_derivative']->get_type();
60    $defined = ImageStdParams::get_defined_type_map();
61    if (!isset($defined[$type]))
62    {
63      $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
64    }
65   
66    $skip = -1;
67    $big_type = $type;
68    foreach (ImageStdParams::get_defined_type_map() as $def_type => $params)
69    {
70      if ($def_type == $type)
71        $skip = 2;
72      if ($skip >= 0)
73        $big_type = $def_type;
74      if ($skip == 0)
75        break;
76      $skip = $skip - 1;
77    }
78   
79    $picture = array();
80    while ($row = pwg_db_fetch_assoc($result))
81    {
82      $row['src_image'] = new SrcImage($row);
83//      $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
84      $row['derivative'] = DerivativeImage::get_one($type, $row['src_image']);
85      if ($row['derivative'] == null)
86      {
87        $row['derivative'] = $row['src_image'];
88      }
89      $row['derivative_big'] = DerivativeImage::get_one($big_type, $row['src_image']);
90      if ($row['derivative_big'] == null)
91      {
92        $row['derivative_big'] = $row['src_image'];
93      }
94//      $row['derivative_thumb'] = DerivativeImage::get_one(IMG_SQUARE, $row['src_image']);
95      $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']);
96      $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']);;
97      if ($row['derivative_thumb'] == null)
98      {
99        $row['derivative_thumb'] = $row['src_image'];
100      }
101
102      $row['url'] = duplicate_picture_url(
103        array(
104          'image_id' => $row['id'],
105          'image_file' => $row['file'],
106          ),
107        array(
108          'start',
109          )
110        );
111
112      $row['TITLE'] = render_element_name($row);
113      $row['TITLE_ESC'] = str_replace('"', '&quot;', $row['TITLE']);
114      $picture[] = $row;
115    }
116   
117    $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height());
118    $template->assign('items', $picture);
119    $template->assign('current_rank', $page['current_rank']);
120    $template->assign(array('Fotorama' => $conf['Fotorama']));
121    if (is_file('./themes/'.$user['theme'].'/template/fotorama.tpl'))
122    {
123      $template->set_filenames( array('slideshow' => realpath('./themes/'.$user['theme'].'/template/fotorama.tpl')));
124    }
125    else
126    {
127      $template->set_filenames( array('slideshow' => realpath(FOTORAMA_PATH.'template/slideshow.tpl')));
128    }
129  }
130}
131
132function Fotorama_end_page_header()
133{
134  global $template, $conf, $page;
135
136  if (isset($page['slideshow']) and $page['slideshow'] and $conf['light_slideshow'])
137  {
138    $template->clear_assign('page_refresh');
139    $template->clear_assign('first');
140    $template->clear_assign('previous');
141    $template->clear_assign('next');
142    $template->clear_assign('last');
143  }
144}
145
146function Fotorama_admin_menu($menu)
147{
148  $menu[] = array(
149    'NAME' => 'Fotorama',
150    'URL'  => FOTORAMA_ADMIN,
151  );
152
153  return $menu;
154}
155
156?>
Note: See TracBrowser for help on using the repository browser.