Exemplo n.º 1
0
 /**
  * Return if there are no files
  * @return string
  */
 public function generate()
 {
     // show gallery instead of slickcarousel in backend mode
     if (TL_MODE == 'BE') {
         return parent::generate();
     }
     parent::generate();
     $objConfig = SlickConfigModel::findByPk($this->slickConfig);
     if ($objConfig === null) {
         return;
     }
     // Map content fields to slick fields
     $this->arrData['slickMultiSRC'] = $this->arrData['multiSRC'];
     $this->arrData['slickOrderSRC'] = $this->arrData['orderSRC'];
     $this->arrData['slickSortBy'] = $this->arrData['sortBy'];
     $this->arrData['slickUseHomeDir'] = $this->arrData['useHomeDir'];
     $this->arrData['slickSize'] = $this->arrData['size'];
     $this->arrData['slickFullsize'] = $this->arrData['fullsize'];
     $this->arrData['slickNumberOfItems'] = $this->arrData['numberOfItems'];
     $this->arrData['slickCustomTpl'] = $this->arrData['customTpl'];
     $objGallery = new Slick(Slick::createSettings($this->arrData, $objConfig));
     $this->Template->class .= ' ' . SlickConfig::getCssClassFromModel($objConfig) . ' slick';
     $this->Template->images = $objGallery->getImages();
     return $this->Template->parse();
 }
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $this->strTemplate = 'be_wildcard';
         $this->Template = new \BackendTemplate($this->strTemplate);
         $this->Template->title = $this->headline;
     }
     parent::generate();
     $objConfig = SlickConfigModel::findByPk($this->slickConfig);
     if ($objConfig === null) {
         return;
     }
     $this->Template->class .= ' ' . SlickConfig::getCssClassFromModel($objConfig) . ' slick ' . SlickConfig::getCssClassForContent($this->id);
     $this->Template->syncid = SlickConfig::getCssClassForContent($this->id);
     return $this->Template->parse();
 }
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['newslist'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
         return $objTemplate->parse();
     }
     parent::generate();
     $objConfig = SlickConfigModel::findByPk($this->slickConfig);
     if ($objConfig !== null) {
         $this->Template->class .= ' ' . SlickConfig::getCssClassFromModel($objConfig) . ' slick';
     }
     return $this->Template->parse();
 }
Exemplo n.º 4
0
 public function getImages()
 {
     global $objPage;
     $images = array();
     $auxDate = array();
     $objFiles = $this->objFiles;
     if ($objFiles === null) {
         return '';
     }
     // Get all images
     while ($objFiles->next()) {
         // Continue if the files has been processed or does not exist
         if (isset($images[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
             continue;
         }
         // Single files
         if ($objFiles->type == 'file') {
             $objFile = new \File($objFiles->path, true);
             if (!$objFile->isGdImage) {
                 continue;
             }
             $arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = specialchars($objFile->basename);
             }
             // Add the image
             $images[$objFiles->path] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'singleSRC' => $objFiles->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
             $auxDate[] = $objFile->mtime;
         } else {
             $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
             if ($objSubfiles === null) {
                 continue;
             }
             while ($objSubfiles->next()) {
                 // Continue if the files has been processed or does not exist
                 if (isset($images[$objSubfiles->path]) || !file_exists(TL_ROOT . '/' . $objSubfiles->path)) {
                     continue;
                 }
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path, true);
                 if (!$objFile->isGdImage) {
                     continue;
                 }
                 $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language);
                 // Use the file name as title if none is given
                 if ($arrMeta['title'] == '') {
                     $arrMeta['title'] = specialchars($objFile->basename);
                 }
                 // Add the image
                 $images[$objSubfiles->path] = array('id' => $objSubfiles->id, 'uuid' => $objSubfiles->uuid, 'name' => $objFile->basename, 'singleSRC' => $objSubfiles->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
                 $auxDate[] = $objFile->mtime;
             }
         }
     }
     // all files do not exist (maybe moved or deleted by FTP or else)
     if (empty($images)) {
         return '';
     }
     // Sort array
     switch ($this->slickSortBy) {
         default:
         case 'name_asc':
             uksort($images, 'basename_natcasecmp');
             break;
         case 'name_desc':
             uksort($images, 'basename_natcasercmp');
             break;
         case 'date_asc':
             array_multisort($images, SORT_NUMERIC, $auxDate, SORT_ASC);
             break;
         case 'date_desc':
             array_multisort($images, SORT_NUMERIC, $auxDate, SORT_DESC);
             break;
         case 'meta':
             // Backwards compatibility
         // Backwards compatibility
         case 'custom':
             if ($this->slickOrderSRC != '') {
                 $tmp = deserialize($this->slickOrderSRC);
                 if (!empty($tmp) && is_array($tmp)) {
                     // Remove all values
                     $arrOrder = array_map(function () {
                     }, array_flip($tmp));
                     // Move the matching elements to their position in $arrOrder
                     foreach ($images as $k => $v) {
                         if (array_key_exists($v['uuid'], $arrOrder)) {
                             $arrOrder[$v['uuid']] = $v;
                             unset($images[$k]);
                         }
                     }
                     // Append the left-over images at the end
                     if (!empty($images)) {
                         $arrOrder = array_merge($arrOrder, array_values($images));
                     }
                     // Remove empty (unreplaced) entries
                     $images = array_values(array_filter($arrOrder));
                     unset($arrOrder);
                 }
             }
             break;
         case 'random':
             shuffle($images);
             break;
     }
     $images = array_values($images);
     // Limit the total number of items (see #2652)
     if ($this->slickNumberOfItems > 0) {
         $images = array_slice($images, 0, $this->slickNumberOfItems);
     }
     $offset = 0;
     $total = count($images);
     $limit = $total;
     $intMaxWidth = TL_MODE == 'BE' ? floor(640 / $total) : floor(\Config::get('maxImageWidth') / $total);
     $strLightboxId = 'lightbox[lb' . $this->id . ']';
     $body = array();
     $strTemplate = 'slick_default';
     // Use a custom template
     if (TL_MODE == 'FE' && $this->slickgalleryTpl != '') {
         $strTemplate = $this->slickgalleryTpl;
     }
     $objTemplate = new \FrontendTemplate($strTemplate);
     $objTemplate->setData($this->arrData);
     $this->Template->setData($this->arrData);
     $this->Template->class .= ' ' . SlickConfig::getCssClassFromModel($this->objSettings) . ' slick';
     for ($i = $offset; $i < $limit; $i++) {
         $objImage = new \stdClass();
         $images[$i]['size'] = $this->slickSize;
         $images[$i]['fullsize'] = $this->slickFullsize;
         $this->addImageToTemplate($objImage, $images[$i], $intMaxWidth, $strLightboxId);
         $body[$i] = $objImage;
     }
     $objTemplate->body = $body;
     $objTemplate->headline = $this->headline;
     // see #1603
     return $objTemplate->parse();
 }