Beispiel #1
0
 protected function _prepareContents(array $widget, array &$contents, sonnb_XenGallery_Model_Content $contentModel)
 {
     if ($contents) {
         foreach ($contents as $contentId => $content) {
             if (!$contentModel->canViewContentAndContainer($content, $content['album'])) {
                 unset($contents[$contentId]);
                 continue;
             }
         }
     }
     $contents = array_slice($contents, 0, $widget['options']['limit']);
     if ($widget['options']['thumbnail_width'] && $widget['options']['thumbnail_height']) {
         foreach ($contents as &$content) {
             if (!empty($content['medium_height']) && !empty($content['medium_width'])) {
                 $widthRatio = $content['medium_width'] / $widget['options']['thumbnail_width'];
                 $heightRatio = $content['medium_height'] / $widget['options']['thumbnail_height'];
                 $album['cover']['style'] = '';
                 if ($widthRatio == $heightRatio) {
                     $content['medium_width'] = $widget['options']['thumbnail_width'];
                     $content['medium_height'] = $widget['options']['thumbnail_height'];
                     $content['style'] = '';
                 } elseif ($widthRatio < $heightRatio) {
                     $content['medium_height'] = $content['medium_height'] / ($content['medium_width'] / $widget['options']['thumbnail_width']);
                     $content['medium_width'] = $widget['options']['thumbnail_width'];
                     $content['style'] = 'top: -' . ($content['medium_height'] - $widget['options']['thumbnail_height']) / 2 . 'px;';
                 } else {
                     $content['medium_width'] = $content['medium_width'] / ($content['medium_height'] / $widget['options']['thumbnail_height']);
                     $content['medium_height'] = $widget['options']['thumbnail_height'];
                     $content['style'] = 'left: -' . ($content['medium_width'] - $widget['options']['thumbnail_width']) / 2 . 'px;';
                 }
             }
         }
     }
 }