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