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

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

modus version/compatibility with core 2.7

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