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

Last change on this file since 26010 was 25794, checked in by rvelices, 10 years ago
File size: 16.5 KB
Line 
1<?php
2/*
3Theme Name: modus
4Version: 201312
5Description: Dark background, grayscale.
6*/
7$themeconf = array(
8        'name'  => 'modus',
9        'parent' => 'default',
10);
11
12define('MODUS_STR_RECENT', "\xe2\x9c\xbd"); //HEAVY TEARDROP-SPOKED ASTERISK
13define('MODUS_STR_RECENT_CHILD', "\xe2\x9c\xbb"); //TEARDROP-SPOKED ASTERISK
14
15if (isset($conf['modus_theme']) && !is_array($conf['modus_theme']))
16{
17        $conf['modus_theme'] = unserialize($conf['modus_theme']);
18}
19
20if (!empty($_GET['skin']) && !preg_match('/[^a-zA-Z0-9_-]/', $_GET['skin']))
21        $conf['modus_theme']['skin'] = $_GET['skin'];
22
23$this->assign('MODUS_CSS_VERSION', crc32(implode(',', array(
24                'a'.@$conf['modus_theme']['skin'],
25                @$conf['modus_theme']['album_thumb_size'],
26                ImageStdParams::get_by_type(IMG_SQUARE)->max_width(),
27        ))));
28
29if (isset($_COOKIE['caps']))
30{
31        setcookie('caps',false,0,cookie_path());
32        pwg_set_session_var('caps', explode('x', $_COOKIE['caps']) );
33        /*file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'tmp/modus.log', implode("\t", array(
34                date("Y-m-d H:i:s"), $_COOKIE['caps'], $_SERVER['HTTP_USER_AGENT']
35                ))."\n", FILE_APPEND);*/
36}
37
38if ('mobile'==get_device())
39        $conf['tag_letters_column_number'] = 1;
40elseif ('tablet'==get_device())
41        $conf['tag_letters_column_number'] = min($conf['tag_letters_column_number'],3);
42
43$this->smarty->registerFilter('pre', 'rv_menubar');
44function rv_menubar($source)
45{
46        global $lang, $conf;
47
48  //$source = str_replace('{if isset($MENUBAR)} contentWithMenu{/if}', '', $source );
49        //$source = str_replace('{if isset($MENUBAR)} class="contentWithMenu"{/if}', '', $source );
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        //add_event_handler('combined_css_postfilter', 'rv_cdn_combined_css_postfilter');
101}
102
103function rv_cdn_prefilter($source, &$smarty)
104{
105        $source = str_replace('src="{$ROOT_URL}{$themeconf.icon_dir}/', 'src="'.RVCDN_ROOT_URL.'{$themeconf.icon_dir}/', $source);
106        $source = str_replace('url({$'.'ROOT_URL}', 'url('.RVCDN_ROOT_URL, $source);
107        return $source;
108}
109function rv_cdn_combined_script($url, $script)
110{
111        if (!$script->is_remote() /*&& strpos($script->path,'thumb.arrange')===false*/)
112                $url = RVCDN_ROOT_URL.$script->path;
113        return $url;
114}
115function rv_cdn_combined_css_postfilter($css)
116{
117        return str_replace('url(/', 'url('.RVCDN.'/', $css);
118}
119
120if (defined('RVPT_JQUERY_SRC'))
121add_event_handler('loc_begin_page_header', 'modus_loc_begin_page_header');
122function modus_loc_begin_page_header()
123{
124        global $template;
125        $all = $template->scriptLoader->get_all();
126        if ( ($jq = @$all['jquery']) )
127        {
128                $jq->set_path(RVPT_JQUERY_SRC);
129        }
130}
131
132add_event_handler('combinable_preparse', 'modus_combinable_preparse');
133function modus_combinable_preparse($template)
134{
135        global $conf;
136        include_once(dirname(__FILE__).'/functions.inc.php');
137  $template->smarty->unregisterPlugin('modifier', 'cssGradient');
138        $template->smarty->registerPlugin('modifier', 'cssGradient', 'modus_css_gradient');
139
140        include( dirname(__FILE__).'/skins/'.$conf['modus_theme']['skin'].'.inc.php' );
141
142        $template->assign( array(
143                'skin' => $skin,
144                'MODUS_ALBUM_THUMB_SIZE' => intval(@$conf['modus_theme']['album_thumb_size']),
145                'SQUARE_WIDTH' => ImageStdParams::get_by_type(IMG_SQUARE)->max_width(),
146                ));
147}
148
149
150$this->smarty->registerPlugin('function', 'cssResolution', 'modus_css_resolution');
151function modus_css_resolution($params)
152{
153  $base = @$params['base'];
154  $min = @$params['min'];
155  $max = @$params['max'];
156 
157  $rules = array();
158  if (!empty($base))
159    $rules[] = $base;
160  foreach(array('min','max') as $type)
161  {
162    if (!empty($$type))
163      $rules[] = '(-webkit-'.$type.'-device-pixel-ratio:'.$$type.')';
164  }
165  $res = implode(' and ', $rules);
166
167  $rules = array();
168  if (!empty($base))
169    $rules[] = $base;
170  foreach(array('min','max') as $type)
171  {
172    if (!empty($$type))
173      $rules[] = '('.$type.'-resolution:'.round(96*$$type,1).'dpi)';
174  }
175  $res .= ','.implode(' and ', $rules);
176
177  return $res;
178}
179
180$this->smarty->registerPlugin('function', 'modus_thumbs', 'modus_thumbs');
181function modus_thumbs()
182{
183        global $template, $page, $conf;
184        if (!isset($_GET['rvts'])) echo '<div id=pop style=display:none;z-index:2;border:0;position:absolute></div>
185';
186
187        $default_params = $template->get_template_vars('derivative_params');
188        $row_height = $default_params->max_height();
189        $device = get_device();
190        $container_margin = 5;
191       
192        if ('mobile'==$device)
193        {
194                $horizontal_margin = floor(0.01*$row_height);
195                $container_margin = 0;
196        }
197        elseif ('tablet'==$device)
198                $horizontal_margin = floor(0.015*$row_height);
199        else
200                $horizontal_margin = floor(0.02*$row_height);
201        $vertical_margin = $horizontal_margin+1;
202
203        $candidates = array($default_params);
204        foreach( ImageStdParams::get_defined_type_map() as $params)
205        {
206                if ($params->max_height() > $row_height && $params->sizing->max_crop == $default_params->sizing->max_crop )
207                {
208                        $candidates[] = $params;
209                        if (count($candidates)==3)
210                                break;
211                }
212        }
213
214        $do_pop = 'desktop' == $device;
215
216        $new_icon = " <span class=albSymbol title=\"".l10n('posted on %s')."\">".MODUS_STR_RECENT.'</span>';
217
218        foreach($template->get_template_vars('thumbnails') as $item)
219        {
220                $src_image = $item['src_image'];
221                $new = !empty($item['icon_ts']) ? sprintf($new_icon, format_date($item['date_available'])) : '';
222
223                $idx=0;
224                do {
225                        $cparams = $candidates[$idx];
226                        $c = new DerivativeImage($cparams, $src_image);
227                        $csize = $c->get_size();
228                        $idx++;
229                }
230                while($csize[1]<$row_height-2 && $idx<count($candidates));
231               
232                if ($do_pop && $idx<count($candidates))
233                {
234                        $pop = new DerivativeImage($candidates[$idx], $src_image);
235                        $popsize = $pop->get_size();
236                }
237                else
238                {
239                        $pop = $c;
240                        $popsize = $csize;
241                }
242
243                $a_style = '';
244                if ($csize[1] < $row_height)
245                        $a_style=' style="top:'.floor(($row_height-$csize[1])/2).'px"';
246                elseif ($csize[1] > $row_height)
247                {
248                        $csize = $c->get_scaled_size(9999, $row_height);
249                }
250?>
251<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>
252<?php
253        }
254
255        $template->block_html_style(null,
256'#thumbnails{text-align:justify;overflow:hidden;margin-left:'.($container_margin-$horizontal_margin).'px;margin-right:'.$container_margin.'px}
257#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}');
258        $template->block_footer_script(null, 'rvgtProcessor=new RVGThumbs({hMargin:'.$horizontal_margin.',rowHeight:'.$row_height.',resizeThreshold:'.$conf['modus_theme']['resize_threshold'].',resizeFactor:'.$conf['modus_theme']['resize_factor'].'});');
259
260        $my_base_name = basename(dirname(__FILE__));
261  // not async to avoid visible flickering reflow
262  $template->scriptLoader->add('modus.arange', 1, array('jquery'), 'themes/'.$my_base_name."/js/thumb.arrange.min.js", 0);
263        if ($do_pop)
264                $template->scriptLoader->add('modus.pop', 2, array('jquery'), 'themes/'.$my_base_name."/js/thumb.pop.js", 0);
265}
266
267add_event_handler('loc_end_index', 'modus_on_end_index');
268function modus_on_end_index()
269{
270        global $template;
271        if (!pwg_get_session_var('caps'))
272                $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;}');
273
274        $req = null;
275        $all = $template->scriptLoader->get_all();
276        if (isset($all['modus.thumb.pop']) || 'desktop' != get_device())
277                return;
278        foreach($all as $script)
279        {
280                if($script->load_mode==2 && !$script->is_remote() && count($script->precedents)==0)
281                {
282                        $req = $script->id;
283                        break;
284                }
285        }
286        if($req!=null)
287        {
288                $my_base_name = basename(dirname(__FILE__));
289    $template->scriptLoader->add('modus.pop', 2, array($req), 'themes/'.$my_base_name."/js/thumb.pop.js", 0);
290        }
291}
292
293add_event_handler('get_index_derivative_params', 'modus_get_index_photo_derivative_params', EVENT_HANDLER_PRIORITY_NEUTRAL+1 );
294function 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
313add_event_handler('loc_end_index_category_thumbnails', 'modus_index_category_thumbnails' );
314function 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                {
365                        //$styles[] = 'left:'.$l.'px';
366                        $styles[] = 'left:'.(100*$l/$wh).'%';
367                }
368                if ($t<-1 || $t>1)
369                        $styles[] = 'top:'.$t.'px';
370                if (count($styles))
371                        $styles = ' style='.implode(';', $styles);
372                else
373                        $styles='';
374                $item['MODUS_STYLE'] = $styles;
375        }
376
377        return $items;
378}
379
380add_event_handler('loc_begin_picture', 'modus_loc_begin_picture');
381function modus_loc_begin_picture()
382{
383        global $conf, $template;
384        if ( isset($_GET['slideshow']) )
385        {
386                $conf['picture_menu'] = false;
387                return;
388        }
389
390        if ( isset($_GET['map']) )
391                return;
392        $template->append('head_elements', '<script>if(document.documentElement.offsetWidth>1270)document.documentElement.className=\'wide\'</script>');
393}
394
395add_event_handler('loc_end_picture', 'modus_loc_end_picture');
396function modus_loc_end_picture()
397{
398        global $template, $picture;
399}
400
401add_event_handler('render_element_content', 'modus_picture_content', EVENT_HANDLER_PRIORITY_NEUTRAL-1, 2 );
402function modus_picture_content($content, $element_info)
403{
404        global $conf, $picture, $template;
405
406        if ( !empty($content) )
407        {// someone hooked us - so we skip;
408                return $content;
409        }
410
411        $unique_derivatives = array();
412        $show_original = isset($element_info['element_url']);
413        $added = array();
414        foreach($element_info['derivatives'] as $type => $derivative)
415        {
416                if ($type==IMG_SQUARE || $type==IMG_THUMB)
417                        continue;
418                if (!array_key_exists($type, ImageStdParams::get_defined_type_map()))
419                        continue;
420                $url = $derivative->get_url();
421                if (isset($added[$url]))
422                        continue;
423                $added[$url] = 1;
424                $show_original &= !($derivative->same_as_source());
425                $unique_derivatives[$type]= $derivative;
426        }
427
428        if (isset($_COOKIE['picture_deriv'])) // ignore persistence
429                setcookie('picture_deriv', false, 0, cookie_path() );
430
431        $selected_derivative = null;
432        if (isset($_COOKIE['phavsz']))
433        {
434                $available_size = explode('x', $_COOKIE['phavsz']);
435                if (empty($available_size[2]))
436                        $available_size[2] = 1;
437
438                foreach($unique_derivatives as $derivative)
439                {
440                        $size = $derivative->get_size();
441                        if (!$size)
442                                break;
443
444                        if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1])
445                        {
446                                $selected_derivative = $derivative;
447                        }
448                        else
449                        {
450                                if ($available_size[2]>1 || !$selected_derivative)
451                                        $selected_derivative = $derivative;
452                                break;
453                        }
454                }
455
456                if ($available_size[2]>1 && $selected_derivative)
457                {
458                        $ratio_w = $size[0] / $available_size[0];
459                        $ratio_h = $size[1] / $available_size[1];
460                        if ($ratio_w>1 || $ratio_h>1)
461                        {
462                                if ($ratio_w > $ratio_h)
463                                        $display_size = array( $available_size[0]/$available_size[2], floor($size[1] / $ratio_w / $available_size[2]) );
464                                else
465                                        $display_size = array( floor($size[0] / $ratio_h / $available_size[2]), $available_size[1]/$available_size[2] );
466                        }
467                        else
468                                $display_size = array( round($size[0]/$available_size[2]), round($size[1]/$available_size[2]) );
469                        $template->assign( array(
470                                        'rvas_display_size' => $display_size,
471                                        'rvas_natural_size' => $size,
472                                ));
473                }
474
475                if (isset($picture['next'])
476                        and $picture['next']['src_image']->is_original())
477                {
478                        $next_best = null;
479                        foreach( $picture['next']['derivatives'] as $derivative)
480                        {
481                                $size = $derivative->get_size();
482                                if (!$size)
483                                        break;
484                                if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1])
485                                        $next_best = $derivative;
486                                else
487                                {
488                                        if ($available_size[2]>1 || !$next_best)
489                                                 $next_best = $derivative;
490                                        break;
491                                }
492                        }
493
494                        if (isset($next_best))
495                                $template->assign('U_PREFETCH', $derivative->get_url() );
496                }
497
498        }
499
500        $as_pending = false;
501        if (!$selected_derivative)
502        {
503                $as_pending = true;
504                $selected_derivative = $element_info['derivatives'][ pwg_get_session_var('picture_deriv',$conf['derivative_default_size']) ];
505        }
506
507
508
509        if ($show_original)
510        {
511                $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
512        }
513
514        $template->append('current', array(
515                        'selected_derivative' => $selected_derivative,
516                        'unique_derivatives' => $unique_derivatives,
517                ), true);
518
519
520        $template->set_filenames(
521                array('default_content'=>'picture_content_asize.tpl')
522                );
523
524        $template->assign( array(
525                        'ALT_IMG' => $element_info['file'],
526                        'COOKIE_PATH' => cookie_path(),
527                        'RVAS_PENDING' => $as_pending,
528                        )
529                );
530        return $template->parse( 'default_content', true);
531}
532
533?>
Note: See TracBrowser for help on using the repository browser.