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

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

Added period parameter for autoplay

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