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

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

Updated version to auto

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