Example #1
0
 /**
  * @param array $widget
  * @param string $positionCode
  * @param array $params
  * @param XenForo_Template_Abstract $template
  * @return string
  */
 protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
 {
     if (!$this->_canViewGallery()) {
         return;
     }
     $photoModel = $this->_getPhotoModel();
     $conditions = array('content_type' => sonnb_XenGallery_Model_Photo::$contentType, 'content_state' => 'visible');
     $this->_prepareConditions($widget, $conditions, $fetchOptions);
     $photos = $photoModel->getContents($conditions, $fetchOptions);
     $photos = $photoModel->prepareContents($photos, $fetchOptions);
     $this->_prepareContents($widget, $photos, $photoModel);
     if (empty($photos)) {
         return;
     }
     $template->setParam('photos', null);
     $template->setParams(array('widget' => $widget, 'contents' => $photos));
     if (method_exists('WidgetFramework_Template_Trojan', 'WidgetFramework_setRequiredExternals')) {
         $externalRequires = array('css' => array('sonnb_xengallery_widget_photo'));
         WidgetFramework_Template_Trojan::WidgetFramework_setRequiredExternals($externalRequires);
     }
     return $template->render();
 }
Example #2
0
 /**
  * @param array $widget
  * @param string $positionCode
  * @param array $params
  * @param XenForo_Template_Abstract $template
  * @return string
  */
 protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
 {
     $core = WidgetFramework_Core::getInstance();
     /* @var $albumModel sonnb_XenGallery_Model_Album */
     $albumModel = $core->getModelFromCache('sonnb_XenGallery_Model_Album');
     /* @var $galleryModel sonnb_XenGallery_Model_Gallery */
     $galleryModel = $core->getModelFromCache('sonnb_XenGallery_Model_Gallery');
     if (!$galleryModel->canViewGallery()) {
         return;
     }
     $conditions = array('album_state' => 'visible', 'content_count' => array('>', 0), 'cover_content_id' => array('>', 0));
     $fetchOptions = array('orderDirection' => 'desc', 'limit' => $widget['options']['limit'] * 3, 'join' => sonnb_XenGallery_Model_Album::FETCH_USER | sonnb_XenGallery_Model_Album::FETCH_COVER_PHOTO, 'followingUserId' => XenForo_Visitor::getUserId());
     switch ($widget['options']['type']) {
         case 'new':
             $fetchOptions['order'] = 'album_date';
             break;
         case 'lastUpdate':
             $fetchOptions['order'] = 'album_updated_date';
             break;
         case 'mostViewed':
             $fetchOptions['order'] = 'view_count';
             break;
         case 'mostCommented':
             $fetchOptions['order'] = 'comment_count';
             break;
         case 'random':
             $fetchOptions['order'] = 'random';
             break;
         case 'recentlyLiked':
             $fetchOptions['order'] = 'recently_liked';
             break;
         case 'mostLiked':
         default:
             $fetchOptions['order'] = 'likes';
             break;
     }
     if ($widget['options']['category_id']) {
         $conditions['category_id'] = $widget['options']['category_id'];
     }
     if ($widget['options']['collection_id']) {
         $fetchOptions['fetchCollectionDate'] = true;
         $fetchOptions['order'] = 'collection_date';
         $conditions['collection_id'] = $widget['options']['collection_id'];
     }
     if ($widget['options']['likes']) {
         $conditions['likes'] = array('>', $widget['options']['likes']);
     }
     if ($widget['options']['view_count']) {
         $conditions['view_count'] = array('>', $widget['options']['view_count']);
     }
     if ($widget['options']['comment_count']) {
         $conditions['comment_count'] = array('>', $widget['options']['comment_count']);
     }
     $userIds = explode(',', $widget['options']['user_id']);
     $userIds = array_filter($userIds);
     array_walk($userIds, create_function('&$userId, $key', '$userId = trim($userId);'));
     if ($userIds) {
         $conditions['user_id'] = $userIds;
     }
     $albums = $albumModel->getAlbums($conditions, $fetchOptions);
     $albums = $albumModel->prepareAlbums($albums, $fetchOptions);
     if ($albums) {
         foreach ($albums as $albumId => $album) {
             if (!$albumModel->canViewAlbum($album)) {
                 unset($albums[$albumId]);
                 continue;
             }
         }
     }
     if (empty($albums)) {
         return;
     }
     $albums = array_slice($albums, 0, $widget['options']['limit']);
     $albums = $albumModel->attachCoversToAlbums($albums, $fetchOptions);
     if ($widget['options']['thumbnail_width'] && $widget['options']['thumbnail_height']) {
         foreach ($albums as &$album) {
             if (!empty($album['cover']['medium_height']) && !empty($album['cover']['medium_width'])) {
                 $widthRatio = $album['cover']['medium_width'] / $widget['options']['thumbnail_width'];
                 $heightRatio = $album['cover']['medium_height'] / $widget['options']['thumbnail_height'];
                 if ($widthRatio == $heightRatio) {
                     $album['cover']['medium_width'] = $widget['options']['thumbnail_width'];
                     $album['cover']['medium_height'] = $widget['options']['thumbnail_height'];
                     $album['cover']['style'] = '';
                 } elseif ($widthRatio < $heightRatio) {
                     $album['cover']['medium_height'] = $album['cover']['medium_height'] / ($album['cover']['medium_width'] / $widget['options']['thumbnail_width']);
                     $album['cover']['medium_width'] = $widget['options']['thumbnail_width'];
                     $album['cover']['style'] = 'top: -' . ($album['cover']['medium_height'] - $widget['options']['thumbnail_height']) / 2 . 'px;';
                 } else {
                     $album['cover']['medium_width'] = $album['cover']['medium_width'] / ($album['cover']['medium_height'] / $widget['options']['thumbnail_height']);
                     $album['cover']['medium_height'] = $widget['options']['thumbnail_height'];
                     $album['cover']['style'] = 'left: -' . ($album['cover']['medium_width'] - $widget['options']['thumbnail_width']) / 2 . 'px;';
                 }
             }
         }
     }
     $template->setParam('albums', null);
     $template->setParams(array('widget' => $widget, 'albums' => $albums));
     if (method_exists('WidgetFramework_Template_Trojan', 'WidgetFramework_setRequiredExternals')) {
         $externalRequires = array('css' => array('sonnb_xengallery_widget_album'));
         WidgetFramework_Template_Trojan::WidgetFramework_setRequiredExternals($externalRequires);
     }
     return $template->render();
 }