/**
  * Return if there are no files
  *
  * @return string
  */
 public function generate()
 {
     // Use the home directory of the current user as file source
     if ($this->useHomeDir && FE_USER_LOGGED_IN) {
         $this->import('FrontendUser', 'User');
         if ($this->User->assignDir && $this->User->homeDir) {
             $this->multiSRC = array($this->User->homeDir);
         }
     } else {
         $this->multiSRC = deserialize($this->multiSRC);
     }
     // Return if there are no files
     if (!is_array($this->multiSRC) || empty($this->multiSRC)) {
         return '';
     }
     // Get the file entries from the database
     $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC);
     if ($this->objFiles === null) {
         if (!\Validator::isUuid($this->multiSRC[0])) {
             return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
         }
         return '';
     }
     $file = \Input::get('file', true);
     // Send the file to the browser and do not send a 404 header (see #4632)
     if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) {
         while ($this->objFiles->next()) {
             if ($file == $this->objFiles->path || dirname($file) == $this->objFiles->path) {
                 \Controller::sendFileToBrowser($file);
             }
         }
         $this->objFiles->reset();
     }
     return parent::generate();
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $intActive = null;
     $articles = array();
     $intCount = 1;
     while ($this->objArticles->next()) {
         /** @var \ArticleModel $objArticle */
         $objArticle = $this->objArticles->current();
         $strAlias = $objArticle->alias != '' && !\Config::get('disableAlias') ? $objArticle->alias : $objArticle->id;
         // Active article
         if (\Input::get('articles') == $strAlias) {
             $articles[] = array('isActive' => true, 'href' => $this->generateFrontendUrl($objPage->row(), '/articles/' . $strAlias), 'title' => specialchars($objArticle->title, true), 'link' => $intCount);
             $intActive = $intCount - 1;
         } else {
             $articles[] = array('isActive' => false, 'href' => $this->generateFrontendUrl($objPage->row(), '/articles/' . $strAlias), 'title' => specialchars($objArticle->title, true), 'link' => $intCount);
         }
         ++$intCount;
     }
     $this->Template->articles = $articles;
     $total = count($articles);
     // Link to first element
     if ($intActive > 1) {
         $this->Template->first = array('href' => $articles[0]['href'], 'title' => $articles[0]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['first']);
     }
     $key = $intActive - 1;
     // Link to previous element
     if ($intCount > 1 && $key >= 0) {
         $this->Template->previous = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['previous']);
     }
     $key = $intActive + 1;
     // Link to next element
     if ($intCount > 1 && $key < $total) {
         $this->Template->next = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['next']);
     }
     $key = $total - 1;
     // Link to last element
     if ($intCount > 1 && $intActive < $key - 1) {
         $this->Template->last = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['last']);
     }
 }
 public function __construct(\Model\Collection $objCss, $arrReturn = array(), $blnCache)
 {
     parent::__construct();
     $this->start = microtime(true);
     $this->cache = $blnCache;
     $this->loadDataContainer('tl_extcss');
     while ($objCss->next()) {
         $this->arrData[] = $objCss->row();
     }
     $this->variablesSrc = 'variables-' . $this->title . '.less';
     $this->mode = $this->cache ? 'none' : 'static';
     $this->arrReturn = $arrReturn;
     $this->objUserCssFile = new \File($this->getSrc($this->title . '.css'));
     // rewrite if group css is empty or created/updated recently
     if ($this->objUserCssFile->size == 0 || $this->lastUpdate > $this->objUserCssFile->mtime) {
         $this->rewrite = true;
         $this->rewriteBootstrap = true;
         $this->cache = false;
     }
     $this->uriRoot = (TL_ASSETS_URL ? TL_ASSETS_URL : \Environment::get('url')) . '/assets/css/';
     $this->arrLessOptions = array('compress' => !\Config::get('bypassCache'), 'cache_dir' => TL_ROOT . '/assets/css/lesscache');
     if (!$this->cache) {
         $this->objLess = new \Less_Parser($this->arrLessOptions);
         $this->addBootstrapVariables();
         $this->addFontAwesomeVariables();
         $this->addFontAwesomeCore();
         $this->addFontAwesomeMixins();
         $this->addFontAwesome();
         $this->addBootstrapMixins();
         $this->addBootstrapAlerts();
         $this->addBootstrap();
         $this->addBootstrapUtilities();
         $this->addBootstrapType();
         if ($this->addElegantIcons) {
             $this->addElegantIconsVariables();
             $this->addElegantIcons();
         }
         // HOOK: add custom assets
         if (isset($GLOBALS['TL_HOOKS']['addCustomAssets']) && is_array($GLOBALS['TL_HOOKS']['addCustomAssets'])) {
             foreach ($GLOBALS['TL_HOOKS']['addCustomAssets'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback}[0]->{$callback}[1]($this->objLess, $this->arrData, $this);
             }
         }
         $this->addCustomLessFiles();
         $this->addCssFiles();
     } else {
         // remove custom less files as long as we can not provide mixins and variables in cache mode
         unset($GLOBALS['TL_USER_CSS']);
         // always add bootstrap
         $this->addBootstrap();
     }
 }
 /**
  * Add a model to a collection
  *
  * @param \Model                 $objModel
  * @param \Model\Collection|null $objCollection
  *
  * @return \Model\Collection|null
  */
 public static function addModelToCollection(\Model $objModel, \Model\Collection $objCollection = null)
 {
     $arrRegistered = array();
     if ($objCollection !== null) {
         while ($objCollection->next()) {
             if ($objCollection->getTable() !== $objModel->getTable) {
                 return $objCollection;
             }
             $intId = $objCollection->{$objModel::getPk()};
             $arrRegistered[$intId] = $objCollection->current();
         }
     }
     $arrRegistered[$objModel->{$objModel::getPk()}] = $objModel;
     return static::createCollection(array_filter(array_values($arrRegistered)), $objModel->getTable());
 }
 public static function parseCredits(\Model\Collection $objModels, array $arrPids = array(), $objModule)
 {
     $arrCredits = array();
     while ($objModels->next()) {
         if (($strReturn = static::parseCredit($objModels->current(), $arrPids, $objModule)) === null) {
             continue;
         }
         $arrCredits[] = $strReturn;
     }
     $arrCredits = static::sortCredits($arrCredits, $objModule->creditsSortBy);
     $arrCredits = static::groupCredits($arrCredits, $objModule->creditsGroupBy);
     $arrCredits = array_map(function ($value) use(&$arrCredit) {
         return $value['output'];
     }, $arrCredits);
     return $arrCredits;
 }
Example #6
0
 protected function buildOptions(\Model\Collection $collection)
 {
     while ($collection->next()) {
         $theme = \ThemeModel::findByPk($collection->pid);
         switch ($collection->type) {
             case 'code':
                 $label = $collection->code_snippet_title;
                 break;
             case 'url':
                 $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $collection->url);
                 break;
             case 'file':
                 if ($collection->filesource == $GLOBALS['TL_CONFIG']['uploadPath'] && version_compare(VERSION, '3', '>=')) {
                     $file = version_compare(VERSION, '3.2', '>=') ? \FilesModel::findByUuid($collection->file) : \FilesModel::findByPk($collection->file);
                     if ($file) {
                         $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $file->path);
                         break;
                     }
                 } else {
                     $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $collection->file);
                     break;
                 }
                 // no break
             // no break
             default:
                 $label = '?';
         }
         if (strlen($collection->cc)) {
             $label .= ' <span style="padding-left: 3px; color: #B3B3B3;">[' . $collection->cc . ']</span>';
         }
         $filterRules = File::renderFilterRules($collection->row());
         if ($filterRules) {
             $label .= ' <span style="padding-left: 3px; color: #B3B3B3;">' . $filterRules . '</span>';
         }
         $image = 'assets/theme-plus/images/' . $collection->type . '.png';
         $options[$theme->name][$collection->id] = ($image ? $this->generateImage($image, $label, 'style="vertical-align:-3px"') . ' ' : '') . $label;
     }
     return $options;
 }
Example #7
0
 /**
  * Parse one or more items and return them as array
  *
  * @param \Model\Collection $objArticles
  * @param boolean           $blnAddArchive
  *
  * @return array
  */
 protected function parseArticles($objArticles, $blnAddArchive = false)
 {
     $limit = $objArticles->count();
     if ($limit < 1) {
         return array();
     }
     $count = 0;
     $arrArticles = array();
     while ($objArticles->next()) {
         /** @var \NewsModel $objArticle */
         $objArticle = $objArticles->current();
         $arrArticles[] = $this->parseArticle($objArticle, $blnAddArchive, (++$count == 1 ? ' first' : '') . ($count == $limit ? ' last' : '') . ($count % 2 == 0 ? ' odd' : ' even'), $count);
     }
     return $arrArticles;
 }
 protected static function indexFiles(\Model\Collection $objFiles)
 {
     $blnCheck = true;
     while ($objFiles->next()) {
         $return = static::indexFile($objFiles->current());
         $blnCheck = !$blnCheck ?: $return;
     }
     return $blnCheck;
 }
Example #9
0
    /**
     * Parse slides
     *
     * @param  \Model\Collection $objSlides slides retrieved from the database
     * @return array                        parsed slides
     */
    protected function parseSlides($objSlides)
    {
        global $objPage;
        $slides = array();
        $pids = array();
        $idIndexes = array();
        if (!$objSlides) {
            return $slides;
        }
        while ($objSlides->next()) {
            $slide = $objSlides->row();
            $slide['text'] = '';
            $pids[] = $slide['id'];
            $idIndexes[(int) $slide['id']] = count($slides);
            if (trim($slide['singleSRC']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['singleSRC']) : \FilesModel::findByUuid($slide['singleSRC'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) {
                $meta = $this->getMetaData($file->meta, $objPage->language);
                $slide['image'] = new \stdClass();
                $this->addImageToTemplate($slide['image'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'alt' => $meta['title'], 'imageUrl' => $meta['link'], 'caption' => $meta['caption'], 'size' => isset($this->imgSize) ? $this->imgSize : $this->size));
            }
            if ($slide['videoURL'] && empty($slide['image'])) {
                $slide['image'] = new \stdClass();
                if (preg_match('(^
						https?://  # http or https
						(?:
							www\\.youtube\\.com/(?:watch\\?v=|v/|embed/)  # Different URL formats
							| youtu\\.be/  # Short YouTube domain
						)
						([0-9a-z_\\-]{11})  # YouTube ID
						(?:$|&|/)  # End or separator
					)ix', html_entity_decode($slide['videoURL']), $matches)) {
                    $video = $matches[1];
                    $slide['image']->src = '//img.youtube.com/vi/' . $video . '/0.jpg';
                } else {
                    // Grey dummy image
                    $slide['image']->src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAJCAMAAAAM9FwAAAAAA1BMVEXGxsbd/8BlAAAAFUlEQVR42s3BAQEAAACAkP6vdiO6AgCZAAG/wrlvAAAAAElFTkSuQmCC';
                }
                $slide['image']->imgSize = '';
                $slide['image']->alt = '';
                if (version_compare(VERSION, '3.4', '>=')) {
                    $slide['image']->picture = array('img' => array('src' => $slide['image']->src, 'srcset' => $slide['image']->src), 'sources' => array());
                }
            }
            if ($slide['videos']) {
                $videoFiles = deserialize($slide['videos'], true);
                if (version_compare(VERSION, '3.2', '<')) {
                    $videoFiles = \FilesModel::findMultipleByIds($videoFiles);
                } else {
                    $videoFiles = \FilesModel::findMultipleByUuids($videoFiles);
                }
                $videos = array();
                foreach ($videoFiles as $file) {
                    $videos[] = $file;
                }
                $slide['videos'] = $videos;
            }
            if (trim($slide['backgroundImage']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['backgroundImage']) : \FilesModel::findByUuid($slide['backgroundImage'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) {
                $meta = $this->getMetaData($file->meta, $objPage->language);
                $slide['backgroundImage'] = new \stdClass();
                $this->addImageToTemplate($slide['backgroundImage'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'alt' => $meta['title'], 'imageUrl' => $meta['link'], 'caption' => $meta['caption'], 'size' => $slide['backgroundImageSize']));
            } else {
                $slide['backgroundImage'] = null;
            }
            if ($slide['backgroundVideos']) {
                $videoFiles = deserialize($slide['backgroundVideos'], true);
                if (version_compare(VERSION, '3.2', '<')) {
                    $videoFiles = \FilesModel::findMultipleByIds($videoFiles);
                } else {
                    $videoFiles = \FilesModel::findMultipleByUuids($videoFiles);
                }
                $videos = array();
                foreach ($videoFiles as $file) {
                    $videos[] = $file;
                }
                $slide['backgroundVideos'] = $videos;
            }
            if ($this->rsts_navType === 'thumbs') {
                $slide['thumb'] = new \stdClass();
                if (trim($slide['thumbImage']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['thumbImage']) : \FilesModel::findByUuid($slide['thumbImage'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) {
                    $this->addImageToTemplate($slide['thumb'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'size' => $this->rsts_thumbs_imgSize));
                } elseif (trim($slide['singleSRC']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['singleSRC']) : \FilesModel::findByUuid($slide['singleSRC'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) {
                    $this->addImageToTemplate($slide['thumb'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'size' => $this->rsts_thumbs_imgSize));
                } elseif (!empty($slide['image']->src)) {
                    $slide['thumb'] = clone $slide['image'];
                } elseif (!empty($slide['backgroundImage']->src)) {
                    $slide['thumb'] = clone $slide['backgroundImage'];
                }
            }
            $slides[] = $slide;
        }
        $slideContents = ContentModel::findPublishedByPidsAndTable($pids, SlideModel::getTable());
        if ($slideContents) {
            while ($slideContents->next()) {
                $slides[$idIndexes[(int) $slideContents->pid]]['text'] .= $this->getContentElement($slideContents->current());
            }
        }
        return $slides;
    }