source: extensions/modus/themeconf.inc.php @ 30053

Last change on this file since 30053 was 30053, checked in by rvelices, 10 years ago

modus improve display of image number on picture page + add fotorama template

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