1 | <?php |
---|
2 | /* |
---|
3 | Theme Name: modus |
---|
4 | Version: 2.7.a |
---|
5 | Description: Responsive, horizontal menu, retina aware, no lost space. |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=728 |
---|
7 | Author: rvelices |
---|
8 | Author URI: http://www.modusoptimus.com |
---|
9 | */ |
---|
10 | $themeconf = array( |
---|
11 | 'name' => 'modus', |
---|
12 | 'parent' => 'default', |
---|
13 | ); |
---|
14 | |
---|
15 | define('MODUS_POP',0); |
---|
16 | define('MODUS_STR_RECENT', "\xe2\x9c\xbd"); //HEAVY TEARDROP-SPOKED ASTERISK |
---|
17 | define('MODUS_STR_RECENT_CHILD', "\xe2\x9c\xbb"); //TEARDROP-SPOKED ASTERISK |
---|
18 | |
---|
19 | if (isset($conf['modus_theme']) && !is_array($conf['modus_theme'])) |
---|
20 | { |
---|
21 | $conf['modus_theme'] = unserialize($conf['modus_theme']); |
---|
22 | } |
---|
23 | |
---|
24 | if (!empty($_GET['skin']) && !preg_match('/[^a-zA-Z0-9_-]/', $_GET['skin'])) |
---|
25 | $conf['modus_theme']['skin'] = $_GET['skin']; |
---|
26 | |
---|
27 | $this->assign('MODUS_CSS_VERSION', crc32(implode(',', array( |
---|
28 | 'a'.@$conf['modus_theme']['skin'], |
---|
29 | @$conf['modus_theme']['album_thumb_size'], |
---|
30 | ImageStdParams::get_by_type(IMG_SQUARE)->max_width(), |
---|
31 | MODUS_POP |
---|
32 | )))); |
---|
33 | |
---|
34 | if (isset($_COOKIE['caps'])) |
---|
35 | { |
---|
36 | setcookie('caps',false,0,cookie_path()); |
---|
37 | pwg_set_session_var('caps', explode('x', $_COOKIE['caps']) ); |
---|
38 | /*file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'tmp/modus.log', implode("\t", array( |
---|
39 | date("Y-m-d H:i:s"), $_COOKIE['caps'], $_SERVER['HTTP_USER_AGENT'] |
---|
40 | ))."\n", FILE_APPEND);*/ |
---|
41 | } |
---|
42 | |
---|
43 | if ('mobile'==get_device()) |
---|
44 | $conf['tag_letters_column_number'] = 1; |
---|
45 | elseif ('tablet'==get_device()) |
---|
46 | $conf['tag_letters_column_number'] = min($conf['tag_letters_column_number'],3); |
---|
47 | |
---|
48 | $this->smarty->registerFilter('pre', 'rv_menubar'); |
---|
49 | function rv_menubar($source) |
---|
50 | { |
---|
51 | global $lang, $conf; |
---|
52 | |
---|
53 | $source = str_replace('<div id="imageHeaderBar">', '<div class=titrePage id=imageHeaderBar>', $source ); |
---|
54 | $source = str_replace('<div id=imageHeaderBar>', '<div class=titrePage id=imageHeaderBar>', $source ); |
---|
55 | |
---|
56 | if (!isset($lang['modus_theme'])) |
---|
57 | load_language('theme.lang', dirname(__FILE__).'/'); |
---|
58 | |
---|
59 | // picture page actionButtons wrap for mobile |
---|
60 | if (strpos($source, '<div id="imageToolBar">')!==false || strpos($source, '<div id=imageToolBar>')!==false){ |
---|
61 | if ( !($pos=strpos($source,'<div class="actionButtons">') ) ) |
---|
62 | $pos = strpos($source,'<div class=actionButtons>'); |
---|
63 | if ($pos !== false) |
---|
64 | { |
---|
65 | $source = substr_replace($source, '<div class=actionButtonsWrapper><a id=imageActionsSwitch class=pwg-button><span class="pwg-icon pwg-icon-ellipsis"></span></a>{combine_script version=1 id=\'modus.async\' path="themes/`$themeconf.id`/js/modus.async.js" load=\'async\'}', $pos, 0); |
---|
66 | $pos = strpos($source,'caddie', $pos+1); |
---|
67 | $pos = strpos($source,'</div>', $pos+1); |
---|
68 | $source = substr_replace($source, '</div>', $pos, 0); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | if ( ($pos=strpos($source, '<ul class="categoryActions">'))!==false || ($pos=strpos($source, '<ul class=categoryActions>'))!==false){ |
---|
73 | if ( ($pos2=strpos($source, '</ul>', $pos))!==false |
---|
74 | && (substr_count($source, '<li>', $pos, $pos2-$pos) > 2) ) |
---|
75 | $source = substr_replace($source, '<a id=albumActionsSwitcher class=pwg-button><span class="pwg-icon pwg-icon-ellipsis"></span></a>{combine_script version=1 id=\'modus.async\' path="themes/`$themeconf.id`/js/modus.async.js" load=\'async\'}', $pos, 0); |
---|
76 | } |
---|
77 | |
---|
78 | $re = preg_quote('<img title="{$cat.icon_ts.TITLE}" src="', '/') |
---|
79 | .'[^>]+' |
---|
80 | .preg_quote('/recent{if $cat.icon_ts.IS_CHILD_DATE}_by_child{/if}.png"', '/') |
---|
81 | .'[^>]+' |
---|
82 | .preg_quote('alt="(!)">', '/'); |
---|
83 | $source = preg_replace('/'.$re.'/', |
---|
84 | '<span class=albSymbol title="{$cat.icon_ts.TITLE}">{if $cat.icon_ts.IS_CHILD_DATE}'.MODUS_STR_RECENT_CHILD.'{else}'.MODUS_STR_RECENT.'{/if}</span>', |
---|
85 | $source); |
---|
86 | |
---|
87 | $re = preg_quote('<img title="{$thumbnail.icon_ts.TITLE}" src="', '/') |
---|
88 | .'[^>]+' |
---|
89 | .preg_quote('/recent.png" alt="(!)">', '/'); |
---|
90 | $source = preg_replace('/'.$re.'/', |
---|
91 | '<span class=albSymbol title="{$thumbnail.icon_ts.TITLE}">'.MODUS_STR_RECENT.'</span>', |
---|
92 | $source); |
---|
93 | |
---|
94 | return $source; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | if (!defined('IN_ADMIN') && defined('RVCDN') ) |
---|
99 | { |
---|
100 | $this->smarty->registerFilter('pre', 'rv_cdn_prefilter' ); |
---|
101 | add_event_handler('combined_script', 'rv_cdn_combined_script', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
102 | } |
---|
103 | |
---|
104 | function rv_cdn_prefilter($source, &$smarty) |
---|
105 | { |
---|
106 | $source = str_replace('src="{$ROOT_URL}{$themeconf.icon_dir}/', 'src="'.RVCDN_ROOT_URL.'{$themeconf.icon_dir}/', $source); |
---|
107 | $source = str_replace('url({$'.'ROOT_URL}', 'url('.RVCDN_ROOT_URL, $source); |
---|
108 | return $source; |
---|
109 | } |
---|
110 | function rv_cdn_combined_script($url, $script) |
---|
111 | { |
---|
112 | if (!$script->is_remote()) |
---|
113 | $url = RVCDN_ROOT_URL.$script->path; |
---|
114 | return $url; |
---|
115 | } |
---|
116 | |
---|
117 | if (defined('RVPT_JQUERY_SRC')) |
---|
118 | add_event_handler('loc_begin_page_header', 'modus_loc_begin_page_header'); |
---|
119 | function modus_loc_begin_page_header() |
---|
120 | { |
---|
121 | global $template; |
---|
122 | $all = $template->scriptLoader->get_all(); |
---|
123 | if ( ($jq = @$all['jquery']) ) |
---|
124 | $jq->set_path(RVPT_JQUERY_SRC); |
---|
125 | } |
---|
126 | |
---|
127 | add_event_handler('combinable_preparse', 'modus_combinable_preparse'); |
---|
128 | function modus_combinable_preparse($template) |
---|
129 | { |
---|
130 | global $conf; |
---|
131 | if (!is_callable('modus_css_gradient')) { |
---|
132 | include_once(dirname(__FILE__).'/functions.inc.php'); |
---|
133 | $template->smarty->registerPlugin('modifier', 'cssGradient', 'modus_css_gradient'); |
---|
134 | } |
---|
135 | |
---|
136 | include( dirname(__FILE__).'/skins/'.$conf['modus_theme']['skin'].'.inc.php' ); |
---|
137 | |
---|
138 | $template->assign( array( |
---|
139 | 'skin' => $skin, |
---|
140 | 'MODUS_ALBUM_THUMB_SIZE' => intval(@$conf['modus_theme']['album_thumb_size']), |
---|
141 | 'SQUARE_WIDTH' => ImageStdParams::get_by_type(IMG_SQUARE)->max_width(), |
---|
142 | 'loaded_plugins' => $GLOBALS['pwg_loaded_plugins'] |
---|
143 | )); |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | $this->smarty->registerPlugin('function', 'cssResolution', 'modus_css_resolution'); |
---|
148 | function modus_css_resolution($params) |
---|
149 | { |
---|
150 | $base = @$params['base']; |
---|
151 | $min = @$params['min']; |
---|
152 | $max = @$params['max']; |
---|
153 | |
---|
154 | $rules = array(); |
---|
155 | if (!empty($base)) |
---|
156 | $rules[] = $base; |
---|
157 | foreach(array('min','max') as $type) |
---|
158 | { |
---|
159 | if (!empty($$type)) |
---|
160 | $rules[] = '(-webkit-'.$type.'-device-pixel-ratio:'.$$type.')'; |
---|
161 | } |
---|
162 | $res = implode(' and ', $rules); |
---|
163 | |
---|
164 | $rules = array(); |
---|
165 | if (!empty($base)) |
---|
166 | $rules[] = $base; |
---|
167 | foreach(array('min','max') as $type) |
---|
168 | { |
---|
169 | if (!empty($$type)) |
---|
170 | $rules[] = '('.$type.'-resolution:'.round(96*$$type,1).'dpi)'; |
---|
171 | } |
---|
172 | $res .= ','.implode(' and ', $rules); |
---|
173 | |
---|
174 | return $res; |
---|
175 | } |
---|
176 | |
---|
177 | $this->smarty->registerPlugin('function', 'modus_thumbs', 'modus_thumbs'); |
---|
178 | function modus_thumbs($x, $smarty) |
---|
179 | { |
---|
180 | global $template, $page, $conf; |
---|
181 | if (!isset($_GET['rvts'])) echo '<div id=pop style=display:none;z-index:2;border:0;position:absolute></div> |
---|
182 | '; |
---|
183 | |
---|
184 | $default_params = $smarty->getTemplateVars('derivative_params'); |
---|
185 | $row_height = $default_params->max_height(); |
---|
186 | $device = get_device(); |
---|
187 | $container_margin = 5; |
---|
188 | |
---|
189 | if ('mobile'==$device) |
---|
190 | { |
---|
191 | $horizontal_margin = floor(0.01*$row_height); |
---|
192 | $container_margin = 0; |
---|
193 | } |
---|
194 | elseif ('tablet'==$device) |
---|
195 | $horizontal_margin = floor(0.015*$row_height); |
---|
196 | else |
---|
197 | $horizontal_margin = floor(0.02*$row_height); |
---|
198 | $vertical_margin = $horizontal_margin+1; |
---|
199 | |
---|
200 | $candidates = array($default_params); |
---|
201 | foreach( ImageStdParams::get_defined_type_map() as $params) |
---|
202 | { |
---|
203 | if ($params->max_height() > $row_height && $params->sizing->max_crop == $default_params->sizing->max_crop ) |
---|
204 | { |
---|
205 | $candidates[] = $params; |
---|
206 | if (count($candidates)==3) |
---|
207 | break; |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | $do_pop = MODUS_POP && 'desktop' == $device; |
---|
212 | $do_over = !MODUS_POP && 'desktop' == $device; |
---|
213 | |
---|
214 | $new_icon = " <span class=albSymbol title=\"".l10n('posted on %s')."\">".MODUS_STR_RECENT.'</span>'; |
---|
215 | |
---|
216 | foreach($smarty->getTemplateVars('thumbnails') as $item) |
---|
217 | { |
---|
218 | $src_image = $item['src_image']; |
---|
219 | $new = !empty($item['icon_ts']) ? sprintf($new_icon, format_date($item['date_available'])) : ''; |
---|
220 | |
---|
221 | $idx=0; |
---|
222 | do { |
---|
223 | $cparams = $candidates[$idx]; |
---|
224 | $c = new DerivativeImage($cparams, $src_image); |
---|
225 | $csize = $c->get_size(); |
---|
226 | $idx++; |
---|
227 | } |
---|
228 | while($csize[1]<$row_height-2 && $idx<count($candidates)); |
---|
229 | |
---|
230 | if ($do_pop && $idx<count($candidates)) |
---|
231 | { |
---|
232 | $pop = new DerivativeImage($candidates[$idx], $src_image); |
---|
233 | $popsize = $pop->get_size(); |
---|
234 | } |
---|
235 | else |
---|
236 | { |
---|
237 | $pop = $c; |
---|
238 | $popsize = $csize; |
---|
239 | } |
---|
240 | |
---|
241 | $a_style = ''; |
---|
242 | if ($csize[1] < $row_height) |
---|
243 | $a_style=' style="top:'.floor(($row_height-$csize[1])/2).'px"'; |
---|
244 | elseif ($csize[1] > $row_height) |
---|
245 | $csize = $c->get_scaled_size(9999, $row_height); |
---|
246 | if ($do_pop) {?> |
---|
247 | <li style=width:<?=$csize[0]?>px;height:<?=$row_height?>px><a href="<?=$item['URL']?>"<?=$a_style?>><img src="<?=$c->get_url()?>" width=<?=$csize[0]?> height=<?=$csize[1]?> alt="<?=$item['TN_ALT']?>" data-pop='{"w":<?=$popsize[0]?>,"h":<?=$popsize[1]?>,"url":"<?=$pop->get_url()?>"}'></a><b class=popDesc><b><?=$item['NAME']?></b><?=$new?><br><?=$item['DESCRIPTION']?></b></li> |
---|
248 | <?php |
---|
249 | } elseif ($do_over) {?> |
---|
250 | <li style=width:<?=$csize[0]?>px;height:<?=$row_height?>px><a href="<?=$item['URL']?>"<?=$a_style?>><img src="<?=$c->get_url()?>" width=<?=$csize[0]?> height=<?=$csize[1]?> alt="<?=$item['TN_ALT']?>"></a><div class=overDesc><?=$item['NAME']?><?=$new?></div></li> |
---|
251 | <?php |
---|
252 | } else {?> |
---|
253 | <li style=width:<?=$csize[0]?>px;height:<?=$row_height?>px><a href="<?=$item['URL']?>"<?=$a_style?>><img src="<?=$c->get_url()?>" width=<?=$csize[0]?> height=<?=$csize[1]?> alt="<?=$item['TN_ALT']?>"></a></li> |
---|
254 | <?php |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | $template->block_html_style(null, |
---|
259 | '#thumbnails{text-align:justify;overflow:hidden;margin-left:'.($container_margin-$horizontal_margin).'px;margin-right:'.$container_margin.'px} |
---|
260 | #thumbnails>li{float:left;overflow:hidden;position:relative;margin-bottom:'.$vertical_margin.'px;margin-left:'.$horizontal_margin.'px}#thumbnails>li>a{position:absolute;border:0}'); |
---|
261 | $template->block_footer_script(null, 'rvgtProcessor=new RVGThumbs({hMargin:'.$horizontal_margin.',rowHeight:'.$row_height.'});'); |
---|
262 | |
---|
263 | $my_base_name = basename(dirname(__FILE__)); |
---|
264 | // not async to avoid visible flickering reflow |
---|
265 | $template->scriptLoader->add('modus.arange', 1, array('jquery'), 'themes/'.$my_base_name."/js/thumb.arrange.min.js", 0); |
---|
266 | if ($do_pop) |
---|
267 | $template->scriptLoader->add('modus.pop', 2, array('jquery'), 'themes/'.$my_base_name."/js/thumb.pop.js", 0); |
---|
268 | } |
---|
269 | |
---|
270 | add_event_handler('loc_end_index', 'modus_on_end_index'); |
---|
271 | function modus_on_end_index() |
---|
272 | { |
---|
273 | global $template; |
---|
274 | if (!pwg_get_session_var('caps')) |
---|
275 | $template->block_footer_script(null, 'try{document.cookie="caps="+(window.devicePixelRatio?window.devicePixelRatio:1)+"x"+document.documentElement.clientWidth+"x"+document.documentElement.clientHeight+";path='.cookie_path().'"}catch(er){document.cookie="caps=1x1x1x"+err.message;}'); |
---|
276 | |
---|
277 | $req = null; |
---|
278 | $all = $template->scriptLoader->get_all(); |
---|
279 | if (isset($all['modus.thumb.pop']) || !MODUS_POP || 'desktop' != get_device()) |
---|
280 | return; |
---|
281 | foreach($all as $script) |
---|
282 | { |
---|
283 | if($script->load_mode==2 && !$script->is_remote() && count($script->precedents)==0) |
---|
284 | { |
---|
285 | $req = $script->id; |
---|
286 | break; |
---|
287 | } |
---|
288 | } |
---|
289 | if($req!=null) |
---|
290 | $template->scriptLoader->add('modus.pop', 2, array($req), 'themes/'.basename(dirname(__FILE__))."/js/thumb.pop.js", 0); |
---|
291 | } |
---|
292 | |
---|
293 | add_event_handler('get_index_derivative_params', 'modus_get_index_photo_derivative_params', EVENT_HANDLER_PRIORITY_NEUTRAL+1 ); |
---|
294 | function modus_get_index_photo_derivative_params($default) |
---|
295 | { |
---|
296 | global $conf; |
---|
297 | if (isset($conf['modus_theme']) && pwg_get_session_var('index_deriv')===null) |
---|
298 | { |
---|
299 | $type = $conf['modus_theme']['index_photo_deriv']; |
---|
300 | if ( $caps=pwg_get_session_var('caps') ) |
---|
301 | { |
---|
302 | if ( ($caps[0]>=2 && $caps[1]>=768) /*Ipad3 always has clientWidth 768 independently of orientation*/ |
---|
303 | || $caps[0]>=3 |
---|
304 | ) |
---|
305 | $type = $conf['modus_theme']['index_photo_deriv_hdpi']; |
---|
306 | } |
---|
307 | $new = @ImageStdParams::get_by_type($type); |
---|
308 | if ($new) return $new; |
---|
309 | } |
---|
310 | return $default; |
---|
311 | } |
---|
312 | |
---|
313 | add_event_handler('loc_end_index_category_thumbnails', 'modus_index_category_thumbnails' ); |
---|
314 | function modus_index_category_thumbnails($items) |
---|
315 | { |
---|
316 | global $page, $template, $conf; |
---|
317 | |
---|
318 | if ('categories'!=$page['section'] || !($wh=@$conf['modus_theme']['album_thumb_size']) ) |
---|
319 | return $items;; |
---|
320 | |
---|
321 | $template->assign('album_thumb_size', $wh); |
---|
322 | |
---|
323 | $def_params = ImageStdParams::get_custom($wh, $wh, 1, $wh, $wh); |
---|
324 | foreach( ImageStdParams::get_defined_type_map() as $params) |
---|
325 | { |
---|
326 | if ($params->max_height() == $wh) |
---|
327 | $alt_params = $params; |
---|
328 | } |
---|
329 | |
---|
330 | foreach($items as &$item) |
---|
331 | { |
---|
332 | $src_image = $item['representative']['src_image']; |
---|
333 | $src_size = $src_image->get_size(); |
---|
334 | |
---|
335 | $deriv = null; |
---|
336 | if (isset($alt_params) && $src_size[0]>=$src_size[1]) |
---|
337 | { |
---|
338 | $dsize = $alt_params->compute_final_size($src_size); |
---|
339 | if ($dsize[0]>=$wh && $dsize[1]>=$wh) |
---|
340 | { |
---|
341 | $deriv = new DerivativeImage($alt_params, $src_image); |
---|
342 | $rect = new ImageRect($dsize); |
---|
343 | $rect->crop_h( $dsize[0]-$wh, $item['representative']['coi'] ); |
---|
344 | $rect->crop_v( $dsize[1]-$wh, $item['representative']['coi'] ); |
---|
345 | $l = - $rect->l; |
---|
346 | $t = - $rect->t; |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | if (!isset($deriv)) |
---|
351 | { |
---|
352 | $deriv = new DerivativeImage($def_params, $src_image); |
---|
353 | $dsize = $deriv->get_size(); |
---|
354 | $l = intval($wh-$dsize[0])/2; |
---|
355 | $t = intval($wh-$dsize[1])/2; |
---|
356 | } |
---|
357 | $item['modus_deriv'] = $deriv; |
---|
358 | |
---|
359 | if (!empty($item['icon_ts'])) |
---|
360 | $item['icon_ts']['TITLE'] = time_since($item['max_date_last'], 'month'); |
---|
361 | |
---|
362 | $styles = array(); |
---|
363 | if ($l<-1 || $l>1) |
---|
364 | $styles[] = 'left:'.(100*$l/$wh).'%'; |
---|
365 | |
---|
366 | if ($t<-1 || $t>1) |
---|
367 | $styles[] = 'top:'.$t.'px'; |
---|
368 | if (count($styles)) |
---|
369 | $styles = ' style='.implode(';', $styles); |
---|
370 | else |
---|
371 | $styles=''; |
---|
372 | $item['MODUS_STYLE'] = $styles; |
---|
373 | } |
---|
374 | |
---|
375 | return $items; |
---|
376 | } |
---|
377 | |
---|
378 | add_event_handler('loc_begin_picture', 'modus_loc_begin_picture'); |
---|
379 | function modus_loc_begin_picture() |
---|
380 | { |
---|
381 | global $conf, $template; |
---|
382 | if ( isset($_GET['slideshow']) ) |
---|
383 | { |
---|
384 | $conf['picture_menu'] = false; |
---|
385 | return; |
---|
386 | } |
---|
387 | |
---|
388 | if ( isset($_GET['map']) ) |
---|
389 | return; |
---|
390 | $template->append('head_elements', '<script>if(document.documentElement.offsetWidth>1270)document.documentElement.className=\'wide\'</script>'); |
---|
391 | } |
---|
392 | |
---|
393 | add_event_handler('render_element_content', 'modus_picture_content', EVENT_HANDLER_PRIORITY_NEUTRAL-1, 2 ); |
---|
394 | function modus_picture_content($content, $element_info) |
---|
395 | { |
---|
396 | global $conf, $picture, $template; |
---|
397 | |
---|
398 | if ( !empty($content) ) // someone hooked us - so we skip; |
---|
399 | return $content; |
---|
400 | |
---|
401 | $unique_derivatives = array(); |
---|
402 | $show_original = isset($element_info['element_url']); |
---|
403 | $added = array(); |
---|
404 | foreach($element_info['derivatives'] as $type => $derivative) |
---|
405 | { |
---|
406 | if ($type==IMG_SQUARE || $type==IMG_THUMB) |
---|
407 | continue; |
---|
408 | if (!array_key_exists($type, ImageStdParams::get_defined_type_map())) |
---|
409 | continue; |
---|
410 | $url = $derivative->get_url(); |
---|
411 | if (isset($added[$url])) |
---|
412 | continue; |
---|
413 | $added[$url] = 1; |
---|
414 | $show_original &= !($derivative->same_as_source()); |
---|
415 | $unique_derivatives[$type]= $derivative; |
---|
416 | } |
---|
417 | |
---|
418 | if (isset($_COOKIE['picture_deriv'])) // ignore persistence |
---|
419 | setcookie('picture_deriv', false, 0, cookie_path() ); |
---|
420 | |
---|
421 | $selected_derivative = null; |
---|
422 | if (isset($_COOKIE['phavsz'])) |
---|
423 | $available_size = explode('x', $_COOKIE['phavsz']); |
---|
424 | elseif ( ($caps=pwg_get_session_var('caps')) && $caps[0]>1 ) |
---|
425 | $available_size = array($caps[0]*$caps[1], $caps[0]*($caps[2]-100), $caps[0]); |
---|
426 | |
---|
427 | if (isset($available_size)) |
---|
428 | { |
---|
429 | foreach($unique_derivatives as $derivative) |
---|
430 | { |
---|
431 | $size = $derivative->get_size(); |
---|
432 | if (!$size) |
---|
433 | break; |
---|
434 | |
---|
435 | if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1]) |
---|
436 | $selected_derivative = $derivative; |
---|
437 | else |
---|
438 | { |
---|
439 | if ($available_size[2]>1 || !$selected_derivative) |
---|
440 | $selected_derivative = $derivative; |
---|
441 | break; |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | if ($available_size[2]>1 && $selected_derivative) |
---|
446 | { |
---|
447 | $ratio_w = $size[0] / $available_size[0]; |
---|
448 | $ratio_h = $size[1] / $available_size[1]; |
---|
449 | if ($ratio_w>1 || $ratio_h>1) |
---|
450 | { |
---|
451 | if ($ratio_w > $ratio_h) |
---|
452 | $display_size = array( $available_size[0]/$available_size[2], floor($size[1] / $ratio_w / $available_size[2]) ); |
---|
453 | else |
---|
454 | $display_size = array( floor($size[0] / $ratio_h / $available_size[2]), $available_size[1]/$available_size[2] ); |
---|
455 | } |
---|
456 | else |
---|
457 | $display_size = array( round($size[0]/$available_size[2]), round($size[1]/$available_size[2]) ); |
---|
458 | $template->assign( array( |
---|
459 | 'rvas_display_size' => $display_size, |
---|
460 | 'rvas_natural_size' => $size, |
---|
461 | )); |
---|
462 | } |
---|
463 | |
---|
464 | if (isset($picture['next']) |
---|
465 | and $picture['next']['src_image']->is_original()) |
---|
466 | { |
---|
467 | $next_best = null; |
---|
468 | foreach( $picture['next']['derivatives'] as $derivative) |
---|
469 | { |
---|
470 | $size = $derivative->get_size(); |
---|
471 | if (!$size) |
---|
472 | break; |
---|
473 | if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1]) |
---|
474 | $next_best = $derivative; |
---|
475 | else |
---|
476 | { |
---|
477 | if ($available_size[2]>1 || !$next_best) |
---|
478 | $next_best = $derivative; |
---|
479 | break; |
---|
480 | } |
---|
481 | } |
---|
482 | |
---|
483 | if (isset($next_best)) |
---|
484 | $template->assign('U_PREFETCH', $derivative->get_url() ); |
---|
485 | } |
---|
486 | } |
---|
487 | |
---|
488 | $as_pending = false; |
---|
489 | if (!$selected_derivative) |
---|
490 | { |
---|
491 | $as_pending = true; |
---|
492 | $selected_derivative = $element_info['derivatives'][ pwg_get_session_var('picture_deriv',$conf['derivative_default_size']) ]; |
---|
493 | } |
---|
494 | |
---|
495 | |
---|
496 | if ($show_original) |
---|
497 | $template->assign( 'U_ORIGINAL', $element_info['element_url'] ); |
---|
498 | |
---|
499 | $template->append('current', array( |
---|
500 | 'selected_derivative' => $selected_derivative, |
---|
501 | 'unique_derivatives' => $unique_derivatives, |
---|
502 | ), true); |
---|
503 | |
---|
504 | |
---|
505 | $template->set_filenames( |
---|
506 | array('default_content'=>'picture_content_asize.tpl') |
---|
507 | ); |
---|
508 | |
---|
509 | $template->assign( array( |
---|
510 | 'ALT_IMG' => $element_info['file'], |
---|
511 | 'COOKIE_PATH' => cookie_path(), |
---|
512 | 'RVAS_PENDING' => $as_pending, |
---|
513 | ) |
---|
514 | ); |
---|
515 | return $template->parse( 'default_content', true); |
---|
516 | } |
---|
517 | |
---|
518 | ?> |
---|