Пример #1
0
function modus_thumbs($x, $smarty)
{
    global $template, $page, $conf;
    $default_params = $smarty->getTemplateVars('derivative_params');
    $row_height = $default_params->max_height();
    $device = get_device();
    $container_margin = 5;
    if ('mobile' == $device) {
        $horizontal_margin = floor(0.01 * $row_height);
        $container_margin = 0;
    } elseif ('tablet' == $device) {
        $horizontal_margin = floor(0.015 * $row_height);
    } else {
        $horizontal_margin = floor(0.02 * $row_height);
    }
    $vertical_margin = $horizontal_margin + 1;
    $candidates = array($default_params);
    foreach (ImageStdParams::get_defined_type_map() as $params) {
        if ($params->max_height() > $row_height && $params->sizing->max_crop == $default_params->sizing->max_crop) {
            $candidates[] = $params;
            if (count($candidates) == 3) {
                break;
            }
        }
    }
    $do_over = 'desktop' == $device;
    $new_icon = " <span class=albSymbol title=\"" . l10n('posted on %s') . "\">" . MODUS_STR_RECENT . '</span>';
    foreach ($smarty->getTemplateVars('thumbnails') as $item) {
        $src_image = $item['src_image'];
        $new = !empty($item['icon_ts']) ? sprintf($new_icon, format_date($item['date_available'])) : '';
        $idx = 0;
        do {
            $cparams = $candidates[$idx];
            $c = new DerivativeImage($cparams, $src_image);
            $csize = $c->get_size();
            $idx++;
        } while ($csize[1] < $row_height - 2 && $idx < count($candidates));
        $a_style = '';
        if ($csize[1] < $row_height) {
            $a_style = ' style="top:' . floor(($row_height - $csize[1]) / 2) . 'px"';
        } elseif ($csize[1] > $row_height) {
            $csize = $c->get_scaled_size(9999, $row_height);
        }
        if ($do_over) {
            ?>
<li style=width:<?php 
            echo $csize[0];
            ?>
px;height:<?php 
            echo $row_height;
            ?>
px><a href="<?php 
            echo $item['URL'];
            ?>
"<?php 
            echo $a_style;
            ?>
><img src="<?php 
            echo $c->get_url();
            ?>
" width=<?php 
            echo $csize[0];
            ?>
 height=<?php 
            echo $csize[1];
            ?>
 alt="<?php 
            echo $item['TN_ALT'];
            ?>
"></a><div class=overDesc><?php 
            echo $item['NAME'];
            echo $new;
            ?>
</div></li>
<?php 
        } else {
            ?>
<li style=width:<?php 
            echo $csize[0];
            ?>
px;height:<?php 
            echo $row_height;
            ?>
px><a href="<?php 
            echo $item['URL'];
            ?>
"<?php 
            echo $a_style;
            ?>
><img src="<?php 
            echo $c->get_url();
            ?>
" width=<?php 
            echo $csize[0];
            ?>
 height=<?php 
            echo $csize[1];
            ?>
 alt="<?php 
            echo $item['TN_ALT'];
            ?>
"></a></li>
<?php 
        }
    }
    $template->block_html_style(null, '#thumbnails{text-align:justify;overflow:hidden;margin-left:' . ($container_margin - $horizontal_margin) . 'px;margin-right:' . $container_margin . 'px}
#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}');
    $template->block_footer_script(null, 'rvgtProcessor=new RVGThumbs({hMargin:' . $horizontal_margin . ',rowHeight:' . $row_height . '});');
    $my_base_name = basename(dirname(__FILE__));
    // not async to avoid visible flickering reflow
    $template->scriptLoader->add('modus.arange', 1, array('jquery'), 'themes/' . $my_base_name . "/js/thumb.arrange.min.js", 0);
}