1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Fotorama |
---|
4 | Version: auto |
---|
5 | Description: Fotorama based full-screen slideshow |
---|
6 | Plugin URI: auto |
---|
7 | Author: JanisV |
---|
8 | */ |
---|
9 | |
---|
10 | global $conf; |
---|
11 | |
---|
12 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
13 | |
---|
14 | if (mobile_theme()) return; |
---|
15 | |
---|
16 | define('FOTORAMA_ID', basename(dirname(__FILE__))); |
---|
17 | define('FOTORAMA_PATH' , PHPWG_PLUGINS_PATH . FOTORAMA_ID . '/'); |
---|
18 | define('FOTORAMA_ADMIN', get_root_url() . 'admin.php?page=plugin-' . FOTORAMA_ID); |
---|
19 | |
---|
20 | add_event_handler('init', 'Fotorama_init'); |
---|
21 | if (defined('IN_ADMIN')) |
---|
22 | { |
---|
23 | add_event_handler('get_admin_plugin_menu_links', 'Fotorama_admin_menu'); |
---|
24 | } |
---|
25 | else |
---|
26 | { |
---|
27 | if ($conf['light_slideshow']) |
---|
28 | { |
---|
29 | add_event_handler('render_element_content', 'Fotorama_element_content'); |
---|
30 | add_event_handler('loc_end_picture', 'Fotorama_end_picture'); |
---|
31 | add_event_handler('loc_end_page_header', 'Fotorama_end_page_header'); |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | function Fotorama_is_replace_picture() |
---|
36 | { |
---|
37 | global $conf; |
---|
38 | |
---|
39 | return ($conf['Fotorama']['replace_picture'] and (!$conf['Fotorama']['replace_picture_only_users'] or !is_admin()) and (!isset($_GET['slidestop']))); |
---|
40 | } |
---|
41 | |
---|
42 | function Fotorama_init() |
---|
43 | { |
---|
44 | global $conf, $user; |
---|
45 | |
---|
46 | load_language('plugin.lang', FOTORAMA_PATH); |
---|
47 | |
---|
48 | $conf['Fotorama'] = unserialize($conf['Fotorama']); |
---|
49 | |
---|
50 | // Upgrade params from 2.7.j |
---|
51 | if (!isset($conf['Fotorama']['thumbheight'])) { |
---|
52 | $conf['Fotorama']['thumbheight'] = 64; |
---|
53 | } |
---|
54 | // Upgrade params from 2.7.l |
---|
55 | if (!isset($conf['Fotorama']['replace_picture'])) { |
---|
56 | $conf['Fotorama']['replace_picture'] = false; |
---|
57 | $conf['Fotorama']['replace_picture_only_users'] = false; |
---|
58 | $conf['Fotorama']['clicktransition_crossfade'] = false; |
---|
59 | } |
---|
60 | // Upgrade params from 2.7.m |
---|
61 | if (!isset($conf['Fotorama']['close_button'])) { |
---|
62 | $conf['Fotorama']['close_button'] = false; |
---|
63 | $conf['Fotorama']['resize'] = false; |
---|
64 | } |
---|
65 | // Upgrade params from 2.7.n |
---|
66 | if (!isset($conf['Fotorama']['period'])) { |
---|
67 | $conf['Fotorama']['period'] = 4000; |
---|
68 | $conf['Fotorama']['info_button'] = false; |
---|
69 | $conf['Fotorama']['square_thumb'] = true; |
---|
70 | } |
---|
71 | |
---|
72 | if ($user['theme'] == 'modus' and Fotorama_is_replace_picture()) |
---|
73 | { |
---|
74 | remove_event_handler('loc_begin_picture', 'modus_loc_begin_picture'); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | function Fotorama_element_content() |
---|
79 | { |
---|
80 | global $page; |
---|
81 | |
---|
82 | if (Fotorama_is_replace_picture()) |
---|
83 | { |
---|
84 | $page['slideshow'] = true; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | function Fotorama_end_picture() |
---|
89 | { |
---|
90 | global $template, $conf, $user, $page; |
---|
91 | |
---|
92 | if (Fotorama_is_replace_picture()) |
---|
93 | { |
---|
94 | $url_up = duplicate_index_url( |
---|
95 | array( |
---|
96 | 'start' => |
---|
97 | floor($page['current_rank'] / $page['nb_image_page']) |
---|
98 | * $page['nb_image_page'] |
---|
99 | ), |
---|
100 | array( |
---|
101 | 'start', |
---|
102 | ) |
---|
103 | ); |
---|
104 | //slideshow end |
---|
105 | $template->assign( |
---|
106 | array( |
---|
107 | 'U_SLIDESHOW_STOP' => $url_up, |
---|
108 | ) |
---|
109 | ); |
---|
110 | |
---|
111 | $template->assign('replace_picture', true); |
---|
112 | } |
---|
113 | |
---|
114 | if ($page['slideshow']) |
---|
115 | { |
---|
116 | $query = ' |
---|
117 | SELECT * |
---|
118 | FROM '.IMAGES_TABLE.' |
---|
119 | WHERE id IN ('.implode(',', $page['items']).') |
---|
120 | ORDER BY FIELD(id, '.implode(',', $page['items']).') |
---|
121 | ;'; |
---|
122 | |
---|
123 | $result = pwg_query($query); |
---|
124 | |
---|
125 | $current = $template->get_template_vars('current'); |
---|
126 | $type = $current['selected_derivative']->get_type(); |
---|
127 | $defined = ImageStdParams::get_defined_type_map(); |
---|
128 | if (!isset($defined[$type])) |
---|
129 | { |
---|
130 | $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']); |
---|
131 | } |
---|
132 | |
---|
133 | $skip = -1; |
---|
134 | $big_type = $type; |
---|
135 | $next_type = $type; |
---|
136 | foreach (ImageStdParams::get_defined_type_map() as $def_type => $params) |
---|
137 | { |
---|
138 | if ($def_type == $type) |
---|
139 | $skip = 2; |
---|
140 | if ($skip >= 0) |
---|
141 | $big_type = $def_type; |
---|
142 | if ($skip >= 1 and $conf['Fotorama']['resize']) |
---|
143 | $next_type = $def_type; |
---|
144 | if ($skip == 0) |
---|
145 | break; |
---|
146 | $skip = $skip - 1; |
---|
147 | } |
---|
148 | $type = $next_type; // +1 size for inpage slideshow |
---|
149 | if ($conf['Fotorama']['only_fullscreen']) |
---|
150 | { |
---|
151 | $type = $big_type; |
---|
152 | } |
---|
153 | $type_params = ImageStdParams::get_by_type($type); |
---|
154 | $big_type_params = ImageStdParams::get_by_type($big_type); |
---|
155 | |
---|
156 | if ($conf['Fotorama']['nav'] == 'thumbs' or $conf['Fotorama']['fullscreen_nav'] == 'thumbs') |
---|
157 | { |
---|
158 | $has_thumbs = true; |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | $has_thumbs = false; |
---|
163 | } |
---|
164 | |
---|
165 | if ($has_thumbs) |
---|
166 | { |
---|
167 | if ($conf['Fotorama']['square_thumb']) |
---|
168 | { |
---|
169 | $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']); |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | $thumb_params = ImageStdParams::get_custom(9999, $conf['Fotorama']['thumbheight']); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | $picture = array(); |
---|
178 | while ($row = pwg_db_fetch_assoc($result)) |
---|
179 | { |
---|
180 | $row['src_image'] = new SrcImage($row); |
---|
181 | $row['derivative'] = new DerivativeImage($type_params, $row['src_image']); |
---|
182 | $row['derivative_big'] = new DerivativeImage($big_type_params, $row['src_image']); |
---|
183 | |
---|
184 | if ($has_thumbs) |
---|
185 | { |
---|
186 | $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']); |
---|
187 | } |
---|
188 | |
---|
189 | $row['url'] = duplicate_picture_url( |
---|
190 | array( |
---|
191 | 'image_id' => $row['id'], |
---|
192 | 'image_file' => $row['file'], |
---|
193 | ), |
---|
194 | array( |
---|
195 | 'start', |
---|
196 | ) |
---|
197 | ); |
---|
198 | |
---|
199 | $row['TITLE'] = render_element_name($row); |
---|
200 | $picture[] = $row; |
---|
201 | } |
---|
202 | |
---|
203 | $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height()); |
---|
204 | $template->assign('items', $picture); |
---|
205 | $template->assign('current_rank', $page['current_rank']); |
---|
206 | $template->assign(array('Fotorama' => $conf['Fotorama'])); |
---|
207 | $template->assign('Fotorama_has_thumbs', $has_thumbs); |
---|
208 | if (is_file('./themes/'.$user['theme'].'/template/fotorama.tpl')) |
---|
209 | { |
---|
210 | $template->set_filenames( array('slideshow' => realpath('./themes/'.$user['theme'].'/template/fotorama.tpl'))); |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | $template->set_filenames( array('slideshow' => realpath(FOTORAMA_PATH.'template/fotorama.tpl'))); |
---|
215 | } |
---|
216 | $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH.'template/fotorama-content.tpl')); |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | function Fotorama_end_page_header() |
---|
221 | { |
---|
222 | global $template, $page; |
---|
223 | |
---|
224 | if (isset($page['slideshow']) and $page['slideshow']) |
---|
225 | { |
---|
226 | $template->clear_assign('page_refresh'); |
---|
227 | $template->clear_assign('first'); |
---|
228 | $template->clear_assign('previous'); |
---|
229 | $template->clear_assign('next'); |
---|
230 | $template->clear_assign('last'); |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | function Fotorama_admin_menu($menu) |
---|
235 | { |
---|
236 | $menu[] = array( |
---|
237 | 'NAME' => 'Fotorama', |
---|
238 | 'URL' => FOTORAMA_ADMIN, |
---|
239 | ); |
---|
240 | |
---|
241 | return $menu; |
---|
242 | } |
---|
243 | |
---|
244 | ?> |
---|