コード例 #1
0
ファイル: ContentGalleryTags.php プロジェクト: AgentCT/tags
 /**
  * Generate the content element
  */
 public function compile()
 {
     $newMultiSRC = array();
     if (strlen(\Input::get('tag')) && !$this->tag_ignore || strlen($this->tag_filter)) {
         $tagids = array();
         $relatedlist = strlen(\Input::get('related')) ? preg_split("/,/", \Input::get('related')) : array();
         $alltags = array_merge(array(\Input::get('tag')), $relatedlist);
         $first = true;
         if (strlen($this->tag_filter)) {
             $headlinetags = preg_split("/,/", $this->tag_filter);
             $tagids = $this->getFilterTags();
             $first = false;
         } else {
             $headlinetags = array();
         }
         foreach ($alltags as $tag) {
             if (strlen(trim($tag))) {
                 if (count($tagids)) {
                     $tagids = $this->Database->prepare("SELECT tid FROM tl_tag WHERE from_table = ? AND tag = ? AND tid IN (" . join($tagids, ",") . ")")->execute('tl_files', $tag)->fetchEach('tid');
                 } else {
                     if ($first) {
                         $tagids = $this->Database->prepare("SELECT tid FROM tl_tag WHERE from_table = ? AND tag = ?")->execute('tl_files', $tag)->fetchEach('tid');
                         $first = false;
                     }
                 }
             }
         }
         while ($this->objFiles->next()) {
             if ($this->objFiles->type == 'file') {
                 if (in_array($this->objFiles->id, $tagids)) {
                     array_push($newMultiSRC, $this->objFiles->uuid);
                 }
             } else {
                 $objSubfiles = \FilesModel::findByPid($this->objFiles->uuid);
                 if ($objSubfiles === null) {
                     continue;
                 }
                 while ($objSubfiles->next()) {
                     if (in_array($objSubfiles->id, $tagids)) {
                         array_push($newMultiSRC, $objSubfiles->uuid);
                     }
                 }
             }
         }
         $this->multiSRC = $newMultiSRC;
         $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC);
         if ($this->objFiles === null) {
             return '';
         }
     }
     parent::compile();
 }
コード例 #2
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     global $objPage;
     $images = array();
     $auxDate = array();
     $objFiles = $this->objFiles;
     // 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(str_replace('_', ' ', $objFile->filename));
             }
             // 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()) {
                 // 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(str_replace('_', ' ', $objFile->filename));
                 }
                 // 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;
             }
         }
     }
     // Sort array
     switch ($this->dk_msrySortBy) {
         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->orderSRC != '') {
                 $tmp = deserialize($this->orderSRC);
                 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
     if ($this->dk_msryNumberOfItems > 0) {
         $images = array_slice($images, 0, $this->dk_msryNumberOfItems);
     }
     $intMaxWidth = TL_MODE == 'BE' ? 160 : $GLOBALS['TL_CONFIG']['maxImageWidth'];
     $strLightboxId = 'lightbox[lb' . $this->id . ']';
     $body = array();
     // create images
     for ($i = 0; $i < count($images); $i++) {
         $objCell = new \stdClass();
         // Add size
         $images[$i]['size'] = $this->dk_msryImageSize;
         $images[$i]['fullsize'] = $this->dk_msryFullsize;
         $this->addImageToTemplate($objCell, $images[$i], $intMaxWidth, $strLightboxId);
         $body[$i] = $objCell;
     }
     $objTemplate = new \FrontendTemplate($this->strTemplateGallery);
     $objTemplate->setData($this->arrData);
     $objTemplate->body = $body;
     if (TL_MODE == 'FE') {
         $this->Template->images = $objTemplate->parse();
         // --- create FE template for javascript caller
         $objTemplateJs = new \FrontendTemplate($this->strTemplateJs);
         // (unique) Element id will be used for unique HTML id element
         $objTemplateJs->id = $this->id;
         $objMasonry = new Masonry();
         $objMasonry->createTemplateData($this->Template, $objTemplateJs);
     } else {
         $this->strTemplate = 'be_masonry';
         $this->Template = new \BackendTemplate($this->strTemplate);
         $this->Template->images = $objTemplate->parse();
         // for BE styling include masonry CSS file
         $GLOBALS['TL_CSS'][] = 'system/modules/dk_masonry/assets/css/masonry.css';
     }
 }
コード例 #3
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     $images = array();
     if ($this->files) {
         $files = $this->files;
         $filesExpaned = array();
         // Get all images
         while ($files->next()) {
             if ($files->type === 'file') {
                 $filesExpaned[] = $files->current();
             } else {
                 $subFiles = \FilesModel::findByPid(version_compare(VERSION, '3.2', '<') ? $files->id : $files->uuid);
                 while ($subFiles && $subFiles->next()) {
                     if ($subFiles->type === 'file') {
                         $filesExpaned[] = $subFiles->current();
                     }
                 }
             }
         }
         foreach ($filesExpaned as $files) {
             // Continue if the files has been processed or does not exist
             if (isset($images[$files->path]) || !file_exists(TL_ROOT . '/' . $files->path)) {
                 continue;
             }
             $file = new \File($files->path, true);
             if (!$file->isGdImage && !$file->isImage) {
                 continue;
             }
             $arrMeta = $this->getMetaData($files->meta, $objPage->language);
             // Add the image
             $images[$files->path] = array('id' => $files->id, 'uuid' => isset($files->uuid) ? $files->uuid : null, 'name' => $file->basename, 'singleSRC' => $files->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
         }
         if ($this->orderSRC) {
             // Turn the order string into an array and remove all values
             if (version_compare(VERSION, '3.2', '<')) {
                 $order = explode(',', $this->orderSRC);
                 $order = array_map('intval', $order);
             } else {
                 $order = deserialize($this->orderSRC);
             }
             if (!$order || !is_array($order)) {
                 $order = array();
             }
             $order = array_flip($order);
             $order = array_map(function () {
             }, $order);
             // Move the matching elements to their position in $order
             $idKey = version_compare(VERSION, '3.2', '<') ? 'id' : 'uuid';
             foreach ($images as $k => $v) {
                 if (array_key_exists($v[$idKey], $order)) {
                     $order[$v[$idKey]] = $v;
                     unset($images[$k]);
                 }
             }
             $order = array_merge($order, array_values($images));
             // Remove empty (unreplaced) entries
             $images = array_filter($order);
             unset($order);
         }
         $images = array_values($images);
         foreach ($images as $key => $image) {
             $newImage = new \stdClass();
             $image['size'] = isset($this->imgSize) ? $this->imgSize : $this->size;
             $this->addImageToTemplate($newImage, $image);
             if ($this->rsts_navType === 'thumbs') {
                 $newImage->thumb = new \stdClass();
                 $image['size'] = $this->rsts_thumbs_imgSize;
                 $this->addImageToTemplate($newImage->thumb, $image);
             }
             $images[$key] = $newImage;
         }
     }
     // use custom skin if specified
     if (trim($this->arrData['rsts_customSkin'])) {
         $this->arrData['rsts_skin'] = trim($this->arrData['rsts_customSkin']);
     }
     $this->Template->images = $images;
     $slides = array();
     if (isset($this->newsArticles)) {
         foreach ($this->newsArticles as $newsArticle) {
             $slides[] = array('text' => $newsArticle);
         }
     } else {
         if (isset($this->eventItems)) {
             foreach ($this->eventItems as $eventItem) {
                 $slides[] = array('text' => $eventItem);
             }
         } else {
             if (isset($this->slider->id) && $this->slider->type === 'content') {
                 $slides = $this->parseSlides(SlideModel::findPublishedByPid($this->slider->id));
             }
         }
     }
     $this->Template->slides = $slides;
     $options = array();
     // strings
     foreach (array('type', 'direction', 'cssPrefix', 'skin', 'width', 'height', 'navType', 'scaleMode', 'imagePosition', 'deepLinkPrefix', 'thumbs_width', 'thumbs_height', 'thumbs_scaleMode', 'thumbs_imagePosition') as $key) {
         if (!empty($this->arrData['rsts_' . $key])) {
             $options[$key] = $this->arrData['rsts_' . $key];
         }
     }
     // strings / boolean
     foreach (array('centerContent') as $key) {
         if (!empty($this->arrData['rsts_' . $key])) {
             $options[$key] = $this->arrData['rsts_' . $key];
             if ($options[$key] === 'false') {
                 $options[$key] = false;
             }
             if ($options[$key] === 'true') {
                 $options[$key] = true;
             }
         }
     }
     // boolean
     foreach (array('random', 'loop', 'videoAutoplay', 'autoplayProgress', 'pauseAutoplayOnHover', 'keyboard', 'captions', 'controls', 'thumbControls', 'combineNavItems', 'thumbs_controls') as $key) {
         $options[$key] = (bool) $this->arrData['rsts_' . $key];
     }
     // positive numbers
     foreach (array('preloadSlides', 'duration', 'autoplay', 'autoplayRestart', 'slideMaxCount', 'slideMinSize', 'slideMaxSize', 'rowMaxCount', 'rowMinSize', 'prevNextSteps', 'visibleAreaMax', 'thumbs_duration', 'thumbs_slideMaxCount', 'thumbs_slideMinSize', 'thumbs_slideMaxSize', 'thumbs_rowMaxCount', 'thumbs_rowMinSize', 'thumbs_prevNextSteps', 'thumbs_visibleAreaMax') as $key) {
         if (!empty($this->arrData['rsts_' . $key]) && $this->arrData['rsts_' . $key] > 0) {
             $options[$key] = $this->arrData['rsts_' . $key] * 1;
         }
     }
     // percentages
     foreach (array('visibleArea', 'thumbs_visibleArea') as $key) {
         if (!empty($this->arrData['rsts_' . $key])) {
             $options[$key] = $this->arrData['rsts_' . $key] / 100;
         }
     }
     // percentages including zero
     foreach (array('visibleAreaAlign') as $key) {
         if (!empty($this->arrData['rsts_' . $key])) {
             $options[$key] = $this->arrData['rsts_' . $key] / 100;
         } else {
             $options[$key] = 0;
         }
     }
     // ratios
     foreach (array('rowSlideRatio', 'thumbs_rowSlideRatio') as $key) {
         if (!empty($this->arrData['rsts_' . $key])) {
             $ratio = explode('x', $this->arrData['rsts_' . $key], 2);
             if (empty($ratio[1])) {
                 $ratio = floatval($ratio[0]);
             } else {
                 $ratio = floatval($ratio[1]) / floatval($ratio[0]);
             }
             $options[$key] = $ratio;
         }
     }
     // gap size
     foreach (array('gapSize', 'thumbs_gapSize') as $key) {
         if (isset($this->arrData['rsts_' . $key]) && $this->arrData['rsts_' . $key] !== '') {
             if (substr($this->arrData['rsts_' . $key], -1) === '%') {
                 $options[$key] = $this->arrData['rsts_' . $key];
             } else {
                 $options[$key] = $this->arrData['rsts_' . $key] * 1;
             }
         }
     }
     foreach ($options as $key => $value) {
         if (substr($key, 0, 7) === 'thumbs_') {
             $options['thumbs'][substr($key, 7)] = $value;
             unset($options[$key]);
         }
     }
     if (empty($this->arrData['rsts_thumbs']) && isset($options['thumbs'])) {
         unset($options['thumbs']);
     }
     $this->Template->options = $options;
     $assetsDir = version_compare(VERSION, '4.0', '>=') ? 'web/bundles/rocksolidslider' : 'system/modules/rocksolid-slider/assets';
     $GLOBALS['TL_JAVASCRIPT'][] = $assetsDir . '/js/rocksolid-slider.min.js|static';
     $GLOBALS['TL_CSS'][] = $assetsDir . '/css/rocksolid-slider.min.css||static';
     $skinPath = $assetsDir . '/css/' . (empty($this->arrData['rsts_skin']) ? 'default' : $this->arrData['rsts_skin']) . '-skin.min.css';
     if (file_exists(TL_ROOT . '/' . $skinPath)) {
         $GLOBALS['TL_CSS'][] = $skinPath . '||static';
     }
 }
コード例 #4
0
ファイル: FileTree.php プロジェクト: davidmaack/dc-general
 /**
  * Render the file list.
  *
  * @param array           $values        The selected values.
  * @param array           $icons         The generated icons.
  * @param Collection|null $collection    The files collection.
  * @param bool            $followSubDirs If true subfolders get rendered.
  *
  * @return void
  */
 private function renderList(array &$values, array &$icons, Collection $collection = null, $followSubDirs = false)
 {
     if (!$collection) {
         return;
     }
     foreach ($collection as $model) {
         // File system and database seem not in sync
         if (!file_exists(TL_ROOT . '/' . $model->path)) {
             continue;
         }
         $values[$model->id] = $model->uuid;
         if ($this->isGallery && !$this->isDownloads) {
             $icons[$model->uuid] = $this->renderIcon($model);
         } elseif ($model->type === 'folder' && $followSubDirs) {
             $subCollection = \FilesModel::findByPid($model->uuid);
             $this->renderList($values, $icons, $subCollection);
         } else {
             $icon = $this->renderIcon($model, $this->isGallery, $this->isDownloads);
             if ($icon !== false) {
                 $icons[$model->uuid] = $icon;
             }
         }
     }
 }
コード例 #5
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $files = array();
     $auxDate = array();
     $objFiles = $this->objFiles;
     $allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload')));
     // Get all files
     while ($objFiles->next()) {
         // Continue if the files has been processed or does not exist
         if (isset($files[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
             continue;
         }
         // Single files
         if ($objFiles->type == 'file') {
             $objFile = new \File($objFiles->path, true);
             if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                 continue;
             }
             $arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
             if (empty($arrMeta)) {
                 if ($this->metaIgnore) {
                     continue;
                 } elseif ($objPage->rootFallbackLanguage !== null) {
                     $arrMeta = $this->getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
                 }
             }
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = specialchars($objFile->basename);
             }
             $strHref = \Environment::get('request');
             // Remove an existing file parameter (see #5683)
             if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
                 $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
             }
             $strHref .= (\Config::get('disableAlias') || strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . \System::urlEncode($objFiles->path);
             // Add the image
             $files[$objFiles->path] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'title' => specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => $this->getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
             $auxDate[] = $objFile->mtime;
         } else {
             $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
             if ($objSubfiles === null) {
                 continue;
             }
             while ($objSubfiles->next()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path, true);
                 if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                     continue;
                 }
                 $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language);
                 if (empty($arrMeta)) {
                     if ($this->metaIgnore) {
                         continue;
                     } elseif ($objPage->rootFallbackLanguage !== null) {
                         $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->rootFallbackLanguage);
                     }
                 }
                 // Use the file name as title if none is given
                 if ($arrMeta['title'] == '') {
                     $arrMeta['title'] = specialchars($objFile->basename);
                 }
                 $strHref = \Environment::get('request');
                 // Remove an existing file parameter (see #5683)
                 if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
                     $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
                 }
                 $strHref .= (\Config::get('disableAlias') || strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . \System::urlEncode($objSubfiles->path);
                 // Add the image
                 $files[$objSubfiles->path] = array('id' => $objSubfiles->id, 'uuid' => $objSubfiles->uuid, 'name' => $objFile->basename, 'title' => specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => $this->getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
                 $auxDate[] = $objFile->mtime;
             }
         }
     }
     // Sort array
     switch ($this->sortBy) {
         default:
         case 'name_asc':
             uksort($files, 'basename_natcasecmp');
             break;
         case 'name_desc':
             uksort($files, 'basename_natcasercmp');
             break;
         case 'date_asc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_ASC);
             break;
         case 'date_desc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_DESC);
             break;
         case 'meta':
             // Backwards compatibility
         // Backwards compatibility
         case 'custom':
             if ($this->orderSRC != '') {
                 $tmp = deserialize($this->orderSRC);
                 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 ($files as $k => $v) {
                         if (array_key_exists($v['uuid'], $arrOrder)) {
                             $arrOrder[$v['uuid']] = $v;
                             unset($files[$k]);
                         }
                     }
                     // Append the left-over files at the end
                     if (!empty($files)) {
                         $arrOrder = array_merge($arrOrder, array_values($files));
                     }
                     // Remove empty (unreplaced) entries
                     $files = array_values(array_filter($arrOrder));
                     unset($arrOrder);
                 }
             }
             break;
         case 'random':
             shuffle($files);
             break;
     }
     $this->Template->files = array_values($files);
 }
コード例 #6
0
ファイル: FileTree.php プロジェクト: zonky2/dc-general
 /**
  * Render the file list.
  *
  * @param array           $icons         The generated icons.
  * @param Collection|null $collection    The files collection.
  * @param bool            $followSubDirs If true subfolders get rendered.
  *
  * @return void
  */
 private function renderList(array &$icons, Collection $collection = null, $followSubDirs = false)
 {
     if (!$collection) {
         return;
     }
     foreach ($collection as $model) {
         // File system and database seem not in sync
         if (!file_exists(TL_ROOT . '/' . $model->path)) {
             continue;
         }
         if ('folder' === $model->type && $followSubDirs) {
             $this->renderList($icons, \FilesModel::findByPid($model->uuid));
             continue;
         }
         if (false !== ($icon = $this->renderIcon($model, $this->isGallery, $this->isDownloads))) {
             $icons[$model->uuid] = $icon;
         }
     }
 }
コード例 #7
0
 public function getFiles($varFolder, $loadSubdir = false)
 {
     $arrFiles = array();
     $objFiles = \FilesModel::findByPid($varFolder);
     if ($objFiles === null) {
         return false;
     }
     while ($objFiles->next()) {
         // Skip subfolders
         if ($objFiles->type == 'folder') {
             #echo $objFiles->path . "<br>";
             $varSubfiles = $this->getFiles($objFiles->uuid, $loadSubdir);
             if ($varSubfiles) {
                 $arrFiles = array_merge($arrFiles, $varSubfiles);
             }
             continue;
         }
         if ($this->extension && !in_array($objFiles->extension, $this->extension)) {
             continue;
         }
         $arrFiles[] = $objFiles;
     }
     if (is_array($arrFiles) && count($arrFiles) > 0) {
         return $arrFiles;
     } else {
         return false;
     }
 }
コード例 #8
0
 /**
  * scanDirRecursive function.
  *
  * @access protected
  * @param  string $uuid
  * @return array
  */
 protected function scanDirRecursive($uuid)
 {
     $arrUuids = array();
     $objFile = \FilesModel::findByUuid($uuid);
     switch ($objFile->type) {
         case 'folder':
             $objChildren = \FilesModel::findByPid($uuid);
             if ($objChildren !== null) {
                 while ($objChildren->next()) {
                     $arrScan = $this->scanDirRecursive($objChildren->uuid);
                     if (is_array($arrScan) && count($arrScan) > 0) {
                         $arrUuids = array_merge($arrUuids, $arrScan);
                     }
                 }
             }
             break;
         case 'file':
             // Set only the file ids with the correct extension
             if (count($this->arrExtensions) > 0) {
                 if (in_array($objFile->extension, $this->arrExtensions)) {
                     $arrUuids[] = $objFile->uuid;
                 }
             } else {
                 $arrUuids[] = $objFile->uuid;
             }
             break;
     }
     return array_unique($arrUuids);
 }
コード例 #9
0
ファイル: Downloads.php プロジェクト: Aziz-JH/core
 /**
  * Generate download attributes
  * @param IsotopeProduct
  * @return string
  */
 public function generate(IsotopeProduct $objProduct, array $arrOptions = array())
 {
     global $objPage;
     $arrFiles = deserialize($objProduct->{$this->field_name});
     // Return if there are no files
     if (empty($arrFiles) || !is_array($arrFiles)) {
         return '';
     }
     // Get the file entries from the database
     $objFiles = \FilesModel::findMultipleByIds($arrFiles);
     if (null === $objFiles) {
         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 ($objFiles->next()) {
             if ($file == $objFiles->path || dirname($file) == $objFiles->path) {
                 \Controller::sendFileToBrowser($file);
             }
         }
         $objFiles->reset();
     }
     $files = array();
     $auxDate = array();
     $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
     // Get all files
     while ($objFiles->next()) {
         // Continue if the files has been processed or does not exist
         if (isset($files[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
             continue;
         }
         // Single files
         if ($objFiles->type == 'file') {
             $objFile = new \File($objFiles->path, true);
             if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                 continue;
             }
             $arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->language);
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
             }
             $strHref = \Environment::get('request');
             // Remove an existing file parameter (see #5683)
             if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
                 $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
             }
             $strHref .= ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . \System::urlEncode($objFiles->path);
             // Add the image
             $files[$objFiles->path] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'title' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => \System::getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
             $auxDate[] = $objFile->mtime;
         } else {
             $objSubfiles = \FilesModel::findByPid($objFiles->id);
             if ($objSubfiles === null) {
                 continue;
             }
             while ($objSubfiles->next()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path, true);
                 if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                     continue;
                 }
                 $arrMeta = \Frontend::getMetaData($objSubfiles->meta, $objPage->language);
                 // Use the file name as title if none is given
                 if ($arrMeta['title'] == '') {
                     $arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
                 }
                 $strHref = \Environment::get('request');
                 // Remove an existing file parameter (see #5683)
                 if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
                     $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
                 }
                 $strHref .= ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . \System::urlEncode($objSubfiles->path);
                 // Add the image
                 $files[$objSubfiles->path] = array('id' => $objSubfiles->id, 'uuid' => $objSubfiles->uuid, 'name' => $objFile->basename, 'title' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => \System::getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
                 $auxDate[] = $objFile->mtime;
             }
         }
     }
     // Sort array
     $sortBy = $arrOptions['sortBy'] ?: $this->sortBy;
     switch ($sortBy) {
         default:
         case 'name_asc':
             uksort($files, 'basename_natcasecmp');
             break;
         case 'name_desc':
             uksort($files, 'basename_natcasercmp');
             break;
         case 'date_asc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_ASC);
             break;
         case 'date_desc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_DESC);
             break;
         case 'custom':
             if ($objProduct->{$this->field_name . '_order'} != '') {
                 $tmp = deserialize($objProduct->{$this->field_name . '_order'});
                 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 ($files as $k => $v) {
                         if (array_key_exists($v['uuid'], $arrOrder)) {
                             $arrOrder[$v['uuid']] = $v;
                             unset($files[$k]);
                         }
                     }
                     // Append the left-over files at the end
                     if (!empty($files)) {
                         $arrOrder = array_merge($arrOrder, array_values($files));
                     }
                     // Remove empty (unreplaced) entries
                     $files = array_values(array_filter($arrOrder));
                     unset($arrOrder);
                 }
             }
             break;
         case 'random':
             shuffle($files);
             break;
     }
     $objTemplate = new \Isotope\Template('ce_downloads');
     $objTemplate->class = $this->field_name;
     $objTemplate->files = array_values($files);
     return $objTemplate->parse();
 }
コード例 #10
0
 private function getMultiMetaData($multiSRC)
 {
     global $objPage;
     $images = array();
     $objFiles = \FilesModel::findMultipleByUuids(unserialize($multiSRC));
     if ($objFiles !== null) {
         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;
                 }
                 $images[$objFiles->path] = $this->getMetaData($objFiles->meta, $objPage->language);
             } else {
                 $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
                 if ($objSubfiles === null) {
                     continue;
                 }
                 while ($objSubfiles->next()) {
                     // Skip subfolders
                     if ($objSubfiles->type == 'folder') {
                         continue;
                     }
                     $objFile = new \File($objSubfiles->path, true);
                     if (!$objFile->isGdImage) {
                         continue;
                     }
                     $images[$objFile->path] = $this->getMetaData($objSubfiles->meta, $objPage->language);
                 }
             }
         }
     }
     // END if($objFiles !== null)
     return $images;
 }
コード例 #11
0
ファイル: FileTree.php プロジェクト: rikaix/core
   /**
    * Generate the widget and return it as string
    * @return string
    */
   public function generate()
   {
       $strValues = '';
       $arrValues = array();
       if ($this->varValue != '') {
           $strValues = implode(',', array_map('intval', (array) $this->varValue));
           $objFiles = $this->Database->execute("SELECT id, path, type FROM tl_files WHERE id IN({$strValues}) ORDER BY " . $this->Database->findInSet('id', $strValues));
           $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
           while ($objFiles->next()) {
               // File system and database seem not in sync
               if (!file_exists(TL_ROOT . '/' . $objFiles->path)) {
                   continue;
               }
               // Show files and folders
               if (!$this->blnIsGallery && !$this->blnIsDownloads) {
                   if ($objFiles->type == 'folder') {
                       $arrValues[$objFiles->id] = $this->generateImage('folderC.gif') . ' ' . $objFiles->path;
                   } else {
                       $objFile = new \File($objFiles->path);
                       $arrValues[$objFiles->id] = $this->generateImage($objFile->icon) . ' ' . $objFiles->path;
                   }
               } else {
                   if ($objFiles->type == 'folder') {
                       $objSubfiles = \FilesModel::findByPid($objFiles->id);
                       if ($objSubfiles === null) {
                           continue;
                       }
                       while ($objSubfiles->next()) {
                           // Skip subfolders
                           if ($objSubfiles->type == 'folder') {
                               continue;
                           }
                           $objFile = new \File($objSubfiles->path);
                           if ($this->blnIsGallery) {
                               // Only show images
                               if ($objFile->isGdImage) {
                                   $arrValues[$objSubfiles->id] = $this->generateImage(\Image::get($objSubfiles->path, 50, 50, 'center_center'), '', 'class="gimage"');
                               }
                           } else {
                               // Only show allowed download types
                               if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                                   $arrValues[$objSubfiles->id] = $this->generateImage($objFile->icon) . ' ' . $objSubfiles->path;
                               }
                           }
                       }
                   } else {
                       $objFile = new \File($objFiles->path);
                       if ($this->blnIsGallery) {
                           // Only show images
                           if ($objFile->isGdImage) {
                               $arrValues[$objFiles->id] = $this->generateImage(\Image::get($objFiles->path, 50, 50, 'center_center'), '', 'class="gimage"');
                           }
                       } else {
                           // Only show allowed download types
                           if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                               $arrValues[$objFiles->id] = $this->generateImage($objFile->icon) . ' ' . $objFiles->path;
                           }
                       }
                   }
               }
           }
           // Apply a custom sort order
           if ($this->strOrderField != '' && $this->orderSRC != '') {
               $arrNew = array();
               $arrOrder = array_map('intval', explode(',', $this->orderSRC));
               foreach ($arrOrder as $i) {
                   if (isset($arrValues[$i])) {
                       $arrNew[$i] = $arrValues[$i];
                       unset($arrValues[$i]);
                   }
               }
               if (!empty($arrValues)) {
                   foreach ($arrValues as $k => $v) {
                       $arrNew[$k] = $v;
                   }
               }
               $arrValues = $arrNew;
               unset($arrNew);
           }
       }
       $return = '<input type="hidden" name="' . $this->strName . '" id="ctrl_' . $this->strId . '" value="' . $strValues . '">' . ($this->strOrderField != '' ? '
 <input type="hidden" name="' . $this->strOrderName . '" id="ctrl_' . $this->strOrderId . '" value="' . $this->orderSRC . '">' : '') . '
 <div class="selector_container" id="target_' . $this->strId . '">
   <ul id="sort_' . $this->strId . '" class="' . trim(($this->strOrderField != '' ? 'sortable ' : '') . ($this->blnIsGallery ? 'sgallery' : '')) . '">';
       foreach ($arrValues as $k => $v) {
           $return .= '<li data-id="' . $k . '">' . $v . '</li>';
       }
       $return .= '</ul>
   <p><a href="contao/file.php?table=' . $this->strTable . '&amp;field=' . $this->strField . '&amp;id=' . \Input::get('id') . '&amp;value=' . $strValues . '" class="tl_submit" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':765,\'title\':\'' . $GLOBALS['TL_LANG']['MOD']['files'][0] . '\',\'url\':this.href,\'id\':\'' . $this->strId . '\'});return false">' . $GLOBALS['TL_LANG']['MSC']['changeSelection'] . '</a></p>' . ($this->strOrderField != '' ? '
   <script>Backend.makeMultiSrcSortable("sort_' . $this->strId . '", "ctrl_' . $this->strOrderId . '");</script>' : '') . '
 </div>';
       return $return;
   }
コード例 #12
0
ファイル: Slick.php プロジェクト: heimrichhannot/contao-slick
 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();
 }
コード例 #13
0
 protected function compile(\PageModel $objPage)
 {
     $images = array();
     $auxDate = array();
     $objFiles = $this->objFiles;
     $this->applySettings($objPage);
     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(str_replace('_', ' ', $objFile->filename));
             }
             // 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()) {
                 // 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(str_replace('_', ' ', $objFile->filename));
                 }
                 // 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;
             }
         }
     }
     // Sort array
     switch ($this->sortBy) {
         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->order != '') {
                 $tmp = deserialize($this->order);
                 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);
     $intMaxWidth = $GLOBALS['TL_CONFIG']['maxImageWidth'];
     $objImages = array();
     $imageIndex = 0;
     if (count($images)) {
         if ($this->mode === 'paSingleRandom') {
             mt_srand();
             $imageIndex = mt_rand(0, count($images) - 1);
         }
         foreach ($images as $image) {
             $objCell = new \stdClass();
             $this->addImageToTemplate($objCell, $image, $intMaxWidth);
             $objImages[] = $objCell;
         }
         if ($this->mode === 'paSingle' || $this->mode === 'paSingleRandom') {
             $objImages = array($objImages[$imageIndex]);
         }
         $strTemplate = 'oneup_ct_fullbgimage';
         $objTemplate = new \FrontendTemplate($strTemplate);
         $objTemplate->images = implode(',', array_map(function ($objImage) {
             return '"' . $objImage->src . '"';
         }, $objImages));
         $objTemplate->timeout = (int) $this->timeout;
         $objTemplate->speed = (int) $this->speed;
         $objTemplate->nav = $this->nav ? 'true' : 'false';
         $objTemplate->navClick = $this->navClick ? 'true' : 'false';
         $objTemplate->navPrevNext = $this->navPrevNext ? 'true' : 'false';
         $objTemplate->centeredX = $this->centeredX ? 'true' : 'false';
         $objTemplate->centeredY = $this->centeredY ? 'true' : 'false';
         // add javascript and css files
         $GLOBALS['TL_BODY'][] = $objTemplate->parse();
         $GLOBALS['TL_CSS'][] = 'system/modules/full-background-images/assets/css/style.css||static';
         $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/full-background-images/assets/js/eventListener.polyfill.js|static';
         $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/full-background-images/assets/js/jquery.backstretch.min.js|static';
         $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/full-background-images/assets/js/fullbackground.js|static';
     }
 }
コード例 #14
0
 /**
  * Get the file models
  *
  * @return \Model\Collection|null
  */
 public function getFileModels()
 {
     $albumFolder = $this->getAlbumFolder();
     if ($albumFolder === null) {
         return null;
     }
     return \FilesModel::findByPid($albumFolder->getModel()->uuid);
 }
 private function getElements($objParentFolder, $objPage, $level = 1)
 {
     $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
     $arrElements = array();
     $arrFolders = array();
     $arrFiles = array();
     $objElements = \FilesModel::findByPid($objParentFolder->uuid);
     if ($objElements === null) {
         return $arrElements;
     }
     while ($objElements->next()) {
         if ($objElements->type == 'folder') {
             $elements = $this->getElements($objElements, $objPage, $level + 1);
             if ($this->recursiveDownloadFolderHideEmptyFolders && !empty($elements) || !$this->recursiveDownloadFolderHideEmptyFolders) {
                 $strCssClass = 'folder';
                 if ($this->recursiveDownloadFolderShowAllLevels) {
                     $strCssClass .= ' folder-open';
                 }
                 if (empty($elements)) {
                     $strCssClass .= ' folder-empty';
                 }
                 $arrFolders[$objElements->name] = array('type' => $objElements->type, 'data' => $this->getFolderData($objElements, $objPage), 'elements' => $elements, 'elements_rendered' => $this->getElementsRendered($elements, $level + 1), 'is_empty' => empty($elements), 'css_class' => $strCssClass);
             }
         } else {
             $objFile = new \File($objElements->path, true);
             if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                 $arrFileData = $this->getFileData($objFile, $objElements, $objPage);
                 $strCssClass = 'file file-' . $arrFileData['extension'];
                 $arrFiles[$objFile->basename] = array('type' => $objElements->type, 'data' => $arrFileData, 'css_class' => $strCssClass);
             }
         }
     }
     // sort the folders and files alphabetically by their name
     ksort($arrFolders);
     ksort($arrFiles);
     // merge folders and files into one array (foders at first, files afterwards)
     $arrElements = array_values($arrFolders);
     $arrElements = array_merge($arrElements, array_values($arrFiles));
     return $arrElements;
 }
コード例 #16
0
ファイル: DC_Folder.php プロジェクト: rikaix/core
    /**
     * Synchronize the file system with the database
     * @return string
     */
    public function sync()
    {
        if (!$this->blnIsDbAssisted) {
            return '';
        }
        $this->arrMessages = array();
        // Reset the "found" flag
        $this->Database->query("UPDATE tl_files SET found=''");
        // Traverse the file system
        $this->execSync($GLOBALS['TL_CONFIG']['uploadPath']);
        // Check for left-over entries in the DB
        $objFiles = \FilesModel::findByFound('');
        if ($objFiles !== null) {
            $arrFiles = array();
            $arrFolders = array();
            while ($objFiles->next()) {
                if ($objFiles->type == 'file') {
                    $arrFiles[] = $objFiles->current();
                } else {
                    $arrFolders[] = $objFiles->current();
                }
            }
            // Check whether a folder has moved
            foreach ($arrFolders as $objFolder) {
                $objFound = \FilesModel::findBy(array('hash=?', 'found=1'), $objFolder->hash);
                if ($objFound !== null) {
                    $this->arrMessages[] = '<p class="tl_info">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncFound'], $objFolder->path, $objFound->path) . '</p>';
                    // Update the original entry
                    $objFolder->pid = $objFound->pid;
                    $objFolder->tstamp = $objFound->tstamp;
                    $objFolder->name = $objFound->name;
                    $objFolder->type = $objFound->type;
                    $objFolder->path = $objFound->path;
                    $objFolder->save();
                    // Update the PID of the child records
                    $objChildren = \FilesModel::findByPid($objFound->id);
                    if ($objChildren !== null) {
                        while ($objChildren->next()) {
                            $objChildren->pid = $objFolder->id;
                            $objChildren->save();
                        }
                    }
                    // Delete the newer (duplicate) entry
                    $objFound->delete();
                } else {
                    // Delete the entry if the folder has gone
                    $objFolder->delete();
                    $this->arrMessages[] = '<p class="tl_error">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncRemoved'], $objFolder->path) . '</p>';
                }
            }
            // Check whether a file has moved
            foreach ($arrFiles as $objFile) {
                $objFound = \FilesModel::findBy(array('hash=?', 'found=1'), $objFile->hash);
                if ($objFound !== null) {
                    $this->arrMessages[] = '<p class="tl_info">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncFound'], $objFile->path, $objFound->path) . '</p>';
                    // Update the original entry
                    $objFile->pid = $objFound->pid;
                    $objFile->tstamp = $objFound->tstamp;
                    $objFile->name = $objFound->name;
                    $objFile->type = $objFound->type;
                    $objFile->path = $objFound->path;
                    $objFile->save();
                    // Delete the newer (duplicate) entry
                    $objFound->delete();
                } else {
                    // Delete the entry if the file has gone
                    $objFile->delete();
                    $this->arrMessages[] = '<p class="tl_error">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncRemoved'], $objFile->path) . '</p>';
                }
            }
        }
        $return = '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>

<h2 class="sub_headline">' . $GLOBALS['TL_LANG']['tl_files']['sync'][1] . '</h2>
' . \Message::generate() . '
<div class="tl_message nobg" style="margin-bottom:2em">';
        // Add the messages
        foreach ($this->arrMessages as $strMessage) {
            $return .= "\n  " . $strMessage;
        }
        $return .= '
</div>

<div class="tl_submit_container">
  <a href="' . $this->getReferer(true) . '" class="tl_submit" style="display:inline-block">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>
</div>
';
        return $return;
    }
コード例 #17
0
ファイル: FileTree.php プロジェクト: rburch/core
   /**
    * Generate the widget and return it as string
    * @return string
    */
   public function generate()
   {
       $strValues = '';
       $arrValues = array();
       if (!empty($this->varValue)) {
           $strValues = implode(',', array_map('intval', (array) $this->varValue));
           $objFiles = $this->Database->execute("SELECT id, path, type FROM tl_files WHERE id IN({$strValues}) ORDER BY " . $this->Database->findInSet('id', $strValues));
           $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
           while ($objFiles->next()) {
               // File system and database seem not in sync
               if (!file_exists(TL_ROOT . '/' . $objFiles->path)) {
                   continue;
               }
               // Show files and folders
               if (!$this->blnIsGallery && !$this->blnIsDownloads) {
                   if ($objFiles->type == 'folder') {
                       $arrValues[$objFiles->id] = $this->generateImage('folderC.gif') . ' ' . $objFiles->path;
                   } else {
                       $objFile = new \File($objFiles->path);
                       $arrValues[$objFiles->id] = $this->generateImage($objFile->icon) . ' ' . $objFiles->path;
                   }
               } else {
                   if ($objFiles->type == 'folder') {
                       $objSubfiles = \FilesModel::findByPid($objFiles->id);
                       if ($objSubfiles === null) {
                           continue;
                       }
                       while ($objSubfiles->next()) {
                           // Skip subfolders
                           if ($objSubfiles->type == 'folder') {
                               continue;
                           }
                           $objFile = new \File($objSubfiles->path);
                           $strInfo = $objSubfiles->path . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isGdImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
                           if ($this->blnIsGallery) {
                               // Only show images
                               if ($objFile->isGdImage) {
                                   $arrValues[$objSubfiles->id] = $this->generateImage(\Image::get($objSubfiles->path, 80, 60, 'center_center'), '', 'class="gimage" title="' . specialchars($strInfo) . '"');
                               }
                           } else {
                               // Only show allowed download types
                               if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                                   $arrValues[$objSubfiles->id] = $this->generateImage($objFile->icon) . ' ' . $strInfo;
                               }
                           }
                       }
                   } else {
                       $objFile = new \File($objFiles->path);
                       if ($this->blnIsGallery) {
                           // Only show images
                           if ($objFile->isGdImage) {
                               $arrValues[$objFiles->id] = $this->generateImage(\Image::get($objFiles->path, 80, 60, 'center_center'), '', 'class="gimage"');
                           }
                       } else {
                           // Only show allowed download types
                           if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                               $arrValues[$objFiles->id] = $this->generateImage($objFile->icon) . ' ' . $objFiles->path;
                           }
                       }
                   }
               }
           }
           // Apply a custom sort order
           if ($this->strOrderField != '' && $this->{$this->strOrderField} != '') {
               $arrNew = array();
               $arrOrder = array_map('intval', explode(',', $this->{$this->strOrderField}));
               foreach ($arrOrder as $i) {
                   if (isset($arrValues[$i])) {
                       $arrNew[$i] = $arrValues[$i];
                       unset($arrValues[$i]);
                   }
               }
               if (!empty($arrValues)) {
                   foreach ($arrValues as $k => $v) {
                       $arrNew[$k] = $v;
                   }
               }
               $arrValues = $arrNew;
               unset($arrNew);
           }
       }
       // Load the fonts for the drag hint (see #4838)
       $GLOBALS['TL_CONFIG']['loadGoogleFonts'] = true;
       $return = '<input type="hidden" name="' . $this->strName . '" id="ctrl_' . $this->strId . '" value="' . $strValues . '">' . ($this->strOrderField != '' ? '
 <input type="hidden" name="' . $this->strOrderName . '" id="ctrl_' . $this->strOrderId . '" value="' . $this->{$this->strOrderField} . '">' : '') . '
 <div class="selector_container" id="target_' . $this->strId . '">' . ($this->strOrderField != '' && count($arrValues) ? '
   <p id="hint_' . $this->strId . '" class="sort_hint">' . $GLOBALS['TL_LANG']['MSC']['dragItemsHint'] . '</p>' : '') . '
   <ul id="sort_' . $this->strId . '" class="' . trim(($this->strOrderField != '' ? 'sortable ' : '') . ($this->blnIsGallery ? 'sgallery' : '')) . '">';
       foreach ($arrValues as $k => $v) {
           $return .= '<li data-id="' . $k . '">' . $v . '</li>';
       }
       $return .= '</ul>
   <p><a href="contao/file.php?do=' . \Input::get('do') . '&amp;table=' . $this->strTable . '&amp;field=' . $this->strField . '&amp;act=show&amp;id=' . \Input::get('id') . '&amp;value=' . $strValues . '&amp;rt=' . REQUEST_TOKEN . '" class="tl_submit" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':765,\'title\':\'' . specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MOD']['files'][0])) . '\',\'url\':this.href,\'id\':\'' . $this->strId . '\'});return false">' . $GLOBALS['TL_LANG']['MSC']['changeSelection'] . '</a></p>' . ($this->strOrderField != '' ? '
   <script>Backend.makeMultiSrcSortable("sort_' . $this->strId . '", "ctrl_' . $this->strOrderId . '");window.addEvent("sm_hide",function(){$("hint_' . $this->strId . '").destroy();$("sort_' . $this->strId . '").removeClass("sortable")})</script>' : '') . '
 </div>';
       return $return;
   }
コード例 #18
0
ファイル: ContentGallery.php プロジェクト: rikaix/core
 /**
  * Generate the content element
  */
 protected function compile()
 {
     global $objPage;
     $images = array();
     $auxDate = array();
     $auxId = array();
     $objFiles = $this->objFiles;
     // 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);
             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(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
             }
             // Add the image
             $images[$objFiles->path] = array('id' => $objFiles->id, 'name' => $objFile->basename, 'singleSRC' => $objFiles->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
             $auxDate[] = $objFile->mtime;
             $auxId[] = $objFiles->id;
         } else {
             $objSubfiles = \FilesModel::findByPid($objFiles->id);
             if ($objSubfiles === null) {
                 continue;
             }
             while ($objSubfiles->next()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path);
                 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(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
                 }
                 // Add the image
                 $images[$objSubfiles->path] = array('id' => $objSubfiles->id, 'name' => $objFile->basename, 'singleSRC' => $objSubfiles->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
                 $auxDate[] = $objFile->mtime;
                 $auxId[] = $objSubfiles->id;
             }
         }
     }
     // Sort array
     switch ($this->sortBy) {
         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->orderSRC != '') {
                 // Turn the order string into an array
                 $arrOrder = array_flip(array_map('intval', explode(',', $this->orderSRC)));
                 // Move the matching elements to their position in $arrOrder
                 foreach ($images as $k => $v) {
                     if (isset($arrOrder[$v['id']])) {
                         $arrOrder[$v['id']] = $v;
                         unset($images[$k]);
                     }
                 }
                 // Append the left-over images at the end
                 if (!empty($images)) {
                     $arrOrder = array_merge($arrOrder, $images);
                 }
                 // Remove empty or numeric (not replaced) entries
                 foreach ($arrOrder as $k => $v) {
                     if ($v == '' || is_numeric($v)) {
                         unset($arrOrder[$k]);
                     }
                 }
                 $images = $arrOrder;
                 unset($arrOrder);
             }
             break;
         case 'random':
             shuffle($images);
             break;
     }
     $images = array_values($images);
     // Limit the total number of items (see #2652)
     if ($this->numberOfItems > 0) {
         $images = array_slice($images, 0, $this->numberOfItems);
     }
     $offset = 0;
     $total = count($images);
     $limit = $total;
     // Pagination
     if ($this->perPage > 0) {
         // Get the current page
         $id = 'page_g' . $this->id;
         $page = \Input::get($id) ?: 1;
         // Do not index or cache the page if the page number is outside the range
         if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) {
             global $objPage;
             $objPage->noSearch = 1;
             $objPage->cache = 0;
             // Send a 404 header
             header('HTTP/1.1 404 Not Found');
             return;
         }
         // Set limit and offset
         $offset = ($page - 1) * $this->perPage;
         $limit = min($this->perPage + $offset, $total);
         $objPagination = new \Pagination($total, $this->perPage, 7, $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     $rowcount = 0;
     $colwidth = floor(100 / $this->perRow);
     $intMaxWidth = TL_MODE == 'BE' ? floor(640 / $this->perRow) : floor($GLOBALS['TL_CONFIG']['maxImageWidth'] / $this->perRow);
     $strLightboxId = 'lightbox[lb' . $this->id . ']';
     $body = array();
     // Rows
     for ($i = $offset; $i < $limit; $i = $i + $this->perRow) {
         $class_tr = '';
         if ($rowcount == 0) {
             $class_tr .= ' row_first';
         }
         if ($i + $this->perRow >= $limit) {
             $class_tr .= ' row_last';
         }
         $class_eo = $rowcount % 2 == 0 ? ' even' : ' odd';
         // Columns
         for ($j = 0; $j < $this->perRow; $j++) {
             $class_td = '';
             if ($j == 0) {
                 $class_td = ' col_first';
             }
             if ($j == $this->perRow - 1) {
                 $class_td = ' col_last';
             }
             $objCell = new \stdClass();
             $key = 'row_' . $rowcount . $class_tr . $class_eo;
             // Empty cell
             if (!is_array($images[$i + $j]) || $j + $i >= $limit) {
                 $objCell->class = 'col_' . $j . $class_td;
             } else {
                 // Add size and margin
                 $images[$i + $j]['size'] = $this->size;
                 $images[$i + $j]['imagemargin'] = $this->imagemargin;
                 $images[$i + $j]['fullsize'] = $this->fullsize;
                 $this->addImageToTemplate($objCell, $images[$i + $j], $intMaxWidth, $strLightboxId);
                 // Add column width and class
                 $objCell->colWidth = $colwidth . '%';
                 $objCell->class = 'col_' . $j . $class_td;
             }
             $body[$key][$j] = $objCell;
         }
         ++$rowcount;
     }
     $strTemplate = 'gallery_default';
     // Use a custom template
     if (TL_MODE == 'FE' && $this->galleryTpl != '') {
         $strTemplate = $this->galleryTpl;
     }
     $objTemplate = new \FrontendTemplate($strTemplate);
     $objTemplate->setData($this->arrData);
     $objTemplate->body = $body;
     $objTemplate->headline = $this->headline;
     // see #1603
     $this->Template->images = $objTemplate->parse();
 }
コード例 #19
0
 /**
  * Parse an item and return it as string
  * @param object
  * @param boolean
  * @param string
  * @param integer
  * @return string
  */
 protected function parseAlbumFull($objAlbum, $blnAddCategory = false, $strClass = '', $intCount = 0)
 {
     global $objPage;
     $objTemplate = new \FrontendTemplate($this->album_template);
     $objTemplate->setData($objAlbum->row());
     $objTemplate->class = ($this->item_Class != '' ? ' ' . $this->item_Class : '') . $strClass;
     $objTemplate->itemClass = $this->item_Class;
     $objTemplate->title = $objAlbum->title;
     $objTemplate->alias = $objAlbum->alias;
     $objTemplate->description = $objAlbum->description;
     $objTemplate->keywords = $objAlbum->keywords;
     $objTemplate->teaser = $objAlbum->teaser;
     $objTemplate->href = $this->generateAlbumUrl($objAlbum, $blnAddCategory);
     $objTemplate->more = $this->generateLink($GLOBALS['TL_LANG']['MSC']['moredetail'], $objAlbum, $blnAddCategory, true);
     $arrMeta = $this->getMetaFields($objAlbum);
     $objTemplate->gallery = $objAlbum->getRelated('pid');
     $objTemplate->count = $intCount;
     // see #5708
     $arrMeta = $this->getMetaFields($objAlbum);
     // Add the meta information
     $objTemplate->date = $arrMeta['date'];
     $objTemplate->hasMetaFields = !empty($arrMeta);
     $objTemplate->timestamp = $objAlbum->date;
     $objTemplate->datetime = date('Y-m-d\\TH:i:sP', $objAlbum->date);
     $objTemplate->addImage = false;
     // Add an image
     if ($objAlbum->singleSRC != '') {
         $this->addImageToTemplate($objTemplate, $this->parseImage($objAlbum, $this->imgSize));
     }
     $this->multiSRC = deserialize($objAlbum->multiSRC);
     // Get the file entries from the database
     $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC);
     $objFiles = $this->objFiles;
     // 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->isImage) {
                 continue;
             }
             $arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
             if (empty($arrMeta)) {
                 if ($this->metaIgnore) {
                     continue;
                 } elseif ($objPage->rootFallbackLanguage !== null) {
                     $arrMeta = $this->getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
                 }
             }
             // 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()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path, true);
                 if (!$objFile->isImage) {
                     continue;
                 }
                 $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language);
                 if (empty($arrMeta)) {
                     if ($this->metaIgnore) {
                         continue;
                     } elseif ($objPage->rootFallbackLanguage !== null) {
                         $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->rootFallbackLanguage);
                     }
                 }
                 // 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;
             }
         }
     }
     // Sort array
     switch ($this->sortBy) {
         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 ($objAlbum->orderSRC != '') {
                 $tmp = deserialize($objAlbum->orderSRC);
                 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);
     $arrBody = array();
     foreach ($images as $image) {
         $objCell = new \stdClass();
         // Add size and margin
         $image['size'] = $this->imgSize;
         $image['fullsize'] = $this->fullsize;
         $strLightboxId = 'lightbox[lb' . $this->id . ']';
         $this->addImageToTemplate($objCell, $image, null, $strLightboxId);
         $arrBody[] = $objCell;
     }
     $objTemplate->body = $arrBody;
     return $objTemplate->parse();
 }
コード例 #20
0
ファイル: ModuleRandomImage.php プロジェクト: rikaix/core
 /**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     $images = array();
     $objFiles = $this->objFiles;
     // 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);
             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(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
             }
             // Add the image
             $images[$objFiles->path] = array('id' => $objFiles->id, 'name' => $objFile->basename, 'singleSRC' => $objFiles->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
         } else {
             $objSubfiles = \FilesModel::findByPid($objFiles->id);
             if ($objSubfiles === null) {
                 continue;
             }
             while ($objSubfiles->next()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path);
                 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(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
                 }
                 // Add the image
                 $images[$objSubfiles->path] = array('id' => $objSubfiles->id, 'name' => $objFile->basename, 'singleSRC' => $objSubfiles->path, 'alt' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'caption' => $arrMeta['caption']);
             }
         }
     }
     $images = array_values($images);
     if (empty($images)) {
         return;
     }
     $i = mt_rand(0, count($images) - 1);
     $arrImage = $images[$i];
     $arrImage['size'] = $this->imgSize;
     if (!$this->useCaption) {
         $arrImage['caption'] = null;
     } elseif ($arrImage['caption'] == '') {
         $arrImage['caption'] = $arrImage['title'];
     }
     $this->addImageToTemplate($this->Template, $arrImage);
 }
コード例 #21
0
 public static function findMultiplePublishedMultiSRCContentElements($arrIds, $arrExtensions, array $arrOptions = array())
 {
     if (!is_array($arrIds) || empty($arrIds) || !is_array($arrExtensions) || empty($arrExtensions)) {
         return null;
     }
     foreach ($arrExtensions as $k => $v) {
         if (!preg_match('/^[a-z0-9]{2,5}$/i', $v)) {
             unset($arrExtensions[$k]);
         }
     }
     $t = static::$strTable;
     $objDatabase = \Database::getInstance();
     // get names of parent tables (tl_news, tl_article, tl_calendar_events)
     $objTable = $objDatabase->prepare("SELECT DISTINCT ptable FROM tl_content")->execute();
     if ($objTable->numRows < 1) {
         return null;
     }
     $arrReturn = null;
     while ($objTable->next()) {
         $strQuery = "\n                    SELECT c.id AS cid, c.ptable as ptable, c.pid as parent, c.multiSRC\n                    FROM tl_content c\n                    LEFT JOIN {$objTable->ptable} p ON p.id = c.pid\n                    WHERE c.multiSRC IS NOT NULL AND c.invisible = ''";
         $objStatement = $objDatabase->prepare($strQuery);
         if (\Database::getInstance()->fieldExists('published', $objTable->ptable)) {
             $strQuery . " AND p.published = 1";
         }
         $objResult = $objStatement->execute();
         if ($objResult->numRows < 1) {
             return null;
         }
         while ($objResult->next()) {
             $arrUuids = deserialize($objResult->multiSRC, true);
             $objFiles = \FilesModel::findMultipleByUuids($arrUuids);
             if ($objFiles === null) {
                 continue;
             }
             if (!$objFiles->copyright) {
                 continue;
             }
             if ($objFiles->type == 'folder') {
                 $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
                 if ($objSubfiles === null) {
                     continue;
                 }
                 while ($objSubfiles->next()) {
                     // Skip subfolders
                     if ($objSubfiles->type == 'folder') {
                         $objFolderFiles = \FilesModel::findMultipleFilesByFolder($objSubfiles->path);
                         if ($objFolderFiles === null) {
                             continue;
                         }
                         while ($objFolderFiles->next()) {
                             if (!in_array($objFolderFiles->extension, $arrExtensions)) {
                                 continue;
                             }
                             if (!$objFolderFiles->copyright) {
                                 continue;
                             }
                             $arrReturn[] = (object) array_merge($objResult->row(), $objFolderFiles->row());
                         }
                     }
                     if (!in_array($objSubfiles->extension, $arrExtensions)) {
                         continue;
                     }
                     if (!$objSubfiles->copyright) {
                         continue;
                     }
                     $arrReturn[] = (object) array_merge($objResult->row(), $objSubfiles->row());
                 }
             } else {
                 $arrReturn[] = (object) array_merge($objResult->row(), $objFiles->row());
             }
         }
     }
     return empty($arrReturn) ? null : $arrReturn;
 }
コード例 #22
0
ファイル: FileTree.php プロジェクト: eknoes/core
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $arrSet = array();
       $arrValues = array();
       $blnHasOrder = $this->orderField != '' && is_array($this->{$this->orderField});
       if (!empty($this->varValue)) {
           $objFiles = \FilesModel::findMultipleByUuids((array) $this->varValue);
           $allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload')));
           if ($objFiles !== null) {
               while ($objFiles->next()) {
                   // File system and database seem not in sync
                   if (!file_exists(TL_ROOT . '/' . $objFiles->path)) {
                       continue;
                   }
                   $arrSet[$objFiles->id] = $objFiles->uuid;
                   // Show files and folders
                   if (!$this->isGallery && !$this->isDownloads) {
                       if ($objFiles->type == 'folder') {
                           $arrValues[$objFiles->uuid] = \Image::getHtml('folderC.gif') . ' ' . $objFiles->path;
                       } else {
                           $objFile = new \File($objFiles->path, true);
                           $strInfo = $objFiles->path . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
                           if ($objFile->isImage) {
                               $image = 'placeholder.png';
                               if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
                                   $image = \Image::get($objFiles->path, 80, 60, 'center_center');
                               }
                               $arrValues[$objFiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . specialchars($strInfo) . '"');
                           } else {
                               $arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
                           }
                       }
                   } else {
                       if ($objFiles->type == 'folder') {
                           $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
                           if ($objSubfiles === null) {
                               continue;
                           }
                           while ($objSubfiles->next()) {
                               // Skip subfolders
                               if ($objSubfiles->type == 'folder') {
                                   continue;
                               }
                               $objFile = new \File($objSubfiles->path, true);
                               $strInfo = '<span class="dirname">' . dirname($objSubfiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
                               if ($this->isGallery) {
                                   // Only show images
                                   if ($objFile->isImage) {
                                       $image = 'placeholder.png';
                                       if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
                                           $image = \Image::get($objSubfiles->path, 80, 60, 'center_center');
                                       }
                                       $arrValues[$objSubfiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . specialchars($strInfo) . '"');
                                   }
                               } else {
                                   // Only show allowed download types
                                   if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                                       $arrValues[$objSubfiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
                                   }
                               }
                           }
                       } else {
                           $objFile = new \File($objFiles->path, true);
                           $strInfo = '<span class="dirname">' . dirname($objFiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
                           if ($this->isGallery) {
                               // Only show images
                               if ($objFile->isImage) {
                                   $image = 'placeholder.png';
                                   if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
                                       $image = \Image::get($objFiles->path, 80, 60, 'center_center');
                                   }
                                   $arrValues[$objFiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . specialchars($strInfo) . '"');
                               }
                           } else {
                               // Only show allowed download types
                               if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                                   $arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
                               }
                           }
                       }
                   }
               }
           }
           // Apply a custom sort order
           if ($blnHasOrder) {
               $arrNew = array();
               foreach ((array) $this->{$this->orderField} as $i) {
                   if (isset($arrValues[$i])) {
                       $arrNew[$i] = $arrValues[$i];
                       unset($arrValues[$i]);
                   }
               }
               if (!empty($arrValues)) {
                   foreach ($arrValues as $k => $v) {
                       $arrNew[$k] = $v;
                   }
               }
               $arrValues = $arrNew;
               unset($arrNew);
           }
       }
       // Load the fonts for the drag hint (see #4838)
       \Config::set('loadGoogleFonts', true);
       // Convert the binary UUIDs
       $strSet = implode(',', array_map('StringUtil::binToUuid', $arrSet));
       $strOrder = $blnHasOrder ? implode(',', array_map('StringUtil::binToUuid', $this->{$this->orderField})) : '';
       $return = '<input type="hidden" name="' . $this->strName . '" id="ctrl_' . $this->strId . '" value="' . $strSet . '">' . ($blnHasOrder ? '
 <input type="hidden" name="' . $this->strOrderName . '" id="ctrl_' . $this->strOrderId . '" value="' . $strOrder . '">' : '') . '
 <div class="selector_container">' . ($blnHasOrder && count($arrValues) > 1 ? '
   <p class="sort_hint">' . $GLOBALS['TL_LANG']['MSC']['dragItemsHint'] . '</p>' : '') . '
   <ul id="sort_' . $this->strId . '" class="' . trim(($blnHasOrder ? 'sortable ' : '') . ($this->isGallery ? 'sgallery' : '')) . '">';
       foreach ($arrValues as $k => $v) {
           $return .= '<li data-id="' . \StringUtil::binToUuid($k) . '">' . $v . '</li>';
       }
       $return .= '</ul>
   <p><a href="contao/file.php?do=' . \Input::get('do') . '&amp;table=' . $this->strTable . '&amp;field=' . $this->strField . '&amp;act=show&amp;id=' . $this->activeRecord->id . '&amp;value=' . implode(',', array_keys($arrSet)) . '&amp;rt=' . REQUEST_TOKEN . '" class="tl_submit" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['label'][0])) . '\',\'url\':this.href,\'id\':\'' . $this->strId . '\'});return false">' . $GLOBALS['TL_LANG']['MSC']['changeSelection'] . '</a></p>' . ($blnHasOrder ? '
   <script>Backend.makeMultiSrcSortable("sort_' . $this->strId . '", "ctrl_' . $this->strOrderId . '")</script>' : '') . '
 </div>';
       if (!\Environment::get('isAjaxRequest')) {
           $return = '<div>' . $return . '</div>';
       }
       return $return;
   }
コード例 #23
0
ファイル: ContentGallery.php プロジェクト: eknoes/core
 /**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $images = array();
     $auxDate = array();
     $objFiles = $this->objFiles;
     // 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->isImage) {
                 continue;
             }
             $arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
             if (empty($arrMeta)) {
                 if ($this->metaIgnore) {
                     continue;
                 } elseif ($objPage->rootFallbackLanguage !== null) {
                     $arrMeta = $this->getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
                 }
             }
             // 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()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path, true);
                 if (!$objFile->isImage) {
                     continue;
                 }
                 $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language);
                 if (empty($arrMeta)) {
                     if ($this->metaIgnore) {
                         continue;
                     } elseif ($objPage->rootFallbackLanguage !== null) {
                         $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->rootFallbackLanguage);
                     }
                 }
                 // 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;
             }
         }
     }
     // Sort array
     switch ($this->sortBy) {
         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->orderSRC != '') {
                 $tmp = deserialize($this->orderSRC);
                 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->numberOfItems > 0) {
         $images = array_slice($images, 0, $this->numberOfItems);
     }
     $offset = 0;
     $total = count($images);
     $limit = $total;
     // Paginate the result of not randomly sorted (see #8033)
     if ($this->perPage > 0 && $this->sortBy != 'random') {
         // Get the current page
         $id = 'page_g' . $this->id;
         $page = \Input::get($id) !== null ? \Input::get($id) : 1;
         // Do not index or cache the page if the page number is outside the range
         if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) {
             /** @var \PageError404 $objHandler */
             $objHandler = new $GLOBALS['TL_PTY']['error_404']();
             $objHandler->generate($objPage->id);
         }
         // Set limit and offset
         $offset = ($page - 1) * $this->perPage;
         $limit = min($this->perPage + $offset, $total);
         $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     $rowcount = 0;
     $colwidth = floor(100 / $this->perRow);
     $intMaxWidth = TL_MODE == 'BE' ? floor(640 / $this->perRow) : floor(\Config::get('maxImageWidth') / $this->perRow);
     $strLightboxId = 'lightbox[lb' . $this->id . ']';
     $body = array();
     // Rows
     for ($i = $offset; $i < $limit; $i = $i + $this->perRow) {
         $class_tr = '';
         if ($rowcount == 0) {
             $class_tr .= ' row_first';
         }
         if ($i + $this->perRow >= $limit) {
             $class_tr .= ' row_last';
         }
         $class_eo = $rowcount % 2 == 0 ? ' even' : ' odd';
         // Columns
         for ($j = 0; $j < $this->perRow; $j++) {
             $class_td = '';
             if ($j == 0) {
                 $class_td .= ' col_first';
             }
             if ($j == $this->perRow - 1) {
                 $class_td .= ' col_last';
             }
             $objCell = new \stdClass();
             $key = 'row_' . $rowcount . $class_tr . $class_eo;
             // Empty cell
             if (!is_array($images[$i + $j]) || $j + $i >= $limit) {
                 $objCell->colWidth = $colwidth . '%';
                 $objCell->class = 'col_' . $j . $class_td;
             } else {
                 // Add size and margin
                 $images[$i + $j]['size'] = $this->size;
                 $images[$i + $j]['imagemargin'] = $this->imagemargin;
                 $images[$i + $j]['fullsize'] = $this->fullsize;
                 $this->addImageToTemplate($objCell, $images[$i + $j], $intMaxWidth, $strLightboxId);
                 // Add column width and class
                 $objCell->colWidth = $colwidth . '%';
                 $objCell->class = 'col_' . $j . $class_td;
             }
             $body[$key][$j] = $objCell;
         }
         ++$rowcount;
     }
     $strTemplate = 'gallery_default';
     // Use a custom template
     if (TL_MODE == 'FE' && $this->galleryTpl != '') {
         $strTemplate = $this->galleryTpl;
     }
     /** @var \FrontendTemplate|object $objTemplate */
     $objTemplate = new \FrontendTemplate($strTemplate);
     $objTemplate->setData($this->arrData);
     $objTemplate->body = $body;
     $objTemplate->headline = $this->headline;
     // see #1603
     $this->Template->images = $objTemplate->parse();
 }
コード例 #24
0
 /**
  * Collect the images from content element
  * @param object
  * @param string
  */
 public function collectContentElementImages($objModel, $strBuffer)
 {
     if (!is_array($GLOBALS['SOCIAL_IMAGES']) || !in_array($objModel->type, $GLOBALS['SOCIAL_IMAGES_CE'])) {
         return $strBuffer;
     }
     switch ($objModel->type) {
         case 'text':
             if ($objModel->addImage) {
                 $objFile = \FilesModel::findByPk($objModel->singleSRC);
                 if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) {
                     $GLOBALS['SOCIAL_IMAGES'][] = $objFile->path;
                 }
             }
             break;
         case 'image':
             $objFile = \FilesModel::findByPk($objModel->singleSRC);
             if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) {
                 $GLOBALS['SOCIAL_IMAGES'][] = $objFile->path;
             }
             break;
         case 'gallery':
             $objFiles = \FilesModel::findMultipleByUuids(deserialize($objModel->multiSRC));
             if ($objFiles !== null) {
                 $images = array();
                 $auxDate = array();
                 // 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;
                         }
                         $images[$objFiles->path] = array('path' => $objFiles->path, 'uuid' => $objFiles->uuid);
                         $auxDate[] = $objFile->mtime;
                     } else {
                         $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
                         if ($objSubfiles === null) {
                             continue;
                         }
                         while ($objSubfiles->next()) {
                             // Skip subfolders
                             if ($objSubfiles->type == 'folder') {
                                 continue;
                             }
                             $objFile = new \File($objSubfiles->path, true);
                             if (!$objFile->isGdImage) {
                                 continue;
                             }
                             $images[$objSubfiles->path] = array('path' => $objSubfiles->path, 'uuid' => $objSubfiles->uuid);
                             $auxDate[] = $objFile->mtime;
                         }
                     }
                 }
                 // Sort array
                 switch ($objModel->sortBy) {
                     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 ($objModel->orderSRC != '') {
                             $tmp = deserialize($objModel->orderSRC);
                             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 ($objModel->numberOfItems > 0) {
                     $images = array_slice($images, 0, $objModel->numberOfItems);
                 }
                 $offset = 0;
                 $total = count($images);
                 $limit = $total;
                 // Pagination
                 if ($objModel->perPage > 0) {
                     // Get the current page
                     $id = 'page_g' . $objModel->id;
                     $page = \Input::get($id) ?: 1;
                     // Do not index or cache the page if the page number is outside the range
                     if ($page < 1 || $page > max(ceil($total / $objModel->perPage), 1)) {
                         global $objPage;
                         $objPage->noSearch = 1;
                         $objPage->cache = 0;
                         // Send a 404 header
                         header('HTTP/1.1 404 Not Found');
                         return $strBuffer;
                     }
                     // Set limit and offset
                     $offset = ($page - 1) * $objModel->perPage;
                     $limit = min($this->perPage + $offset, $total);
                 }
                 // Limit the images
                 if ($offset > 0) {
                     $images = array_slice($images, $offset, $limit);
                 }
                 foreach ($images as $image) {
                     $GLOBALS['SOCIAL_IMAGES'][] = $image['path'];
                 }
             }
             break;
         case 'player':
         case 'youtube':
             $objFile = \FilesModel::findByPk($objModel->posterSRC);
             if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) {
                 $GLOBALS['SOCIAL_IMAGES'][] = $objFile->path;
             }
             break;
     }
     return $strBuffer;
 }
コード例 #25
0
ファイル: ContentDownloads.php プロジェクト: rikaix/core
 /**
  * Generate the content element
  */
 protected function compile()
 {
     global $objPage;
     $files = array();
     $auxDate = array();
     $auxId = array();
     $objFiles = $this->objFiles;
     $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
     // Get all files
     while ($objFiles->next()) {
         // Continue if the files has been processed or does not exist
         if (isset($files[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
             continue;
         }
         // Single files
         if ($objFiles->type == 'file') {
             $objFile = new \File($objFiles->path);
             if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                 continue;
             }
             $arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
             }
             // Add the image
             $files[$objFiles->path] = array('id' => $objFiles->id, 'name' => $objFile->basename, 'title' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&amp;' : '?') . 'file=' . $this->urlEncode($objFiles->path), 'filesize' => $this->getReadableSize($objFile->filesize, 1), 'icon' => TL_FILES_URL . 'system/themes/' . $this->getTheme() . '/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
             $auxDate[] = $objFile->mtime;
             $auxId[] = $objFiles->id;
         } else {
             $objSubfiles = \FilesModel::findByPid($objFiles->id);
             if ($objSubfiles === null) {
                 continue;
             }
             while ($objSubfiles->next()) {
                 // Skip subfolders
                 if ($objSubfiles->type == 'folder') {
                     continue;
                 }
                 $objFile = new \File($objSubfiles->path);
                 if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
                     continue;
                 }
                 $arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language);
                 // Use the file name as title if none is given
                 if ($arrMeta['title'] == '') {
                     $arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
                 }
                 // Add the image
                 $files[$objSubfiles->path] = array('id' => $objSubfiles->id, 'name' => $objFile->basename, 'title' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&amp;' : '?') . 'file=' . $this->urlEncode($objSubfiles->path), 'filesize' => $this->getReadableSize($objFile->filesize, 1), 'icon' => 'system/themes/' . $this->getTheme() . '/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
                 $auxDate[] = $objFile->mtime;
                 $auxId[] = $objSubfiles->id;
             }
         }
     }
     // Sort array
     switch ($this->sortBy) {
         default:
         case 'name_asc':
             uksort($files, 'basename_natcasecmp');
             break;
         case 'name_desc':
             uksort($files, 'basename_natcasercmp');
             break;
         case 'date_asc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_ASC);
             break;
         case 'date_desc':
             array_multisort($files, SORT_NUMERIC, $auxDate, SORT_DESC);
             break;
         case 'meta':
             // Backwards compatibility
         // Backwards compatibility
         case 'custom':
             if ($this->orderSRC != '') {
                 // Turn the order string into an array
                 $arrOrder = array_flip(array_map('intval', explode(',', $this->orderSRC)));
                 // Move the matching elements to their position in $arrOrder
                 foreach ($files as $k => $v) {
                     if (isset($arrOrder[$v['id']])) {
                         $arrOrder[$v['id']] = $v;
                         unset($files[$k]);
                     }
                 }
                 // Append the left-over images at the end
                 if (!empty($files)) {
                     $arrOrder = array_merge($arrOrder, $files);
                 }
                 // Remove empty or numeric (not replaced) entries
                 foreach ($arrOrder as $k => $v) {
                     if ($v == '' || is_numeric($v)) {
                         unset($arrOrder[$k]);
                     }
                 }
                 $files = $arrOrder;
                 unset($arrOrder);
             }
             break;
         case 'random':
             shuffle($files);
             break;
     }
     $this->Template->files = array_values($files);
 }
コード例 #26
0
ファイル: Dbafs.php プロジェクト: iCodr8/core
 /**
  * Synchronize the file system with the database
  *
  * @return string The path to the synchronization log file
  *
  * @throws \Exception If a parent ID entry is missing
  */
 public static function syncFiles()
 {
     // Try to raise the limits (see #7035)
     @ini_set('memory_limit', -1);
     @ini_set('max_execution_time', 0);
     $objDatabase = \Database::getInstance();
     // Lock the files table
     $objDatabase->lockTables(array('tl_files'));
     // Reset the "found" flag
     $objDatabase->query("UPDATE tl_files SET found=''");
     // Get a filtered list of all files
     $objFiles = new \RecursiveIteratorIterator(new \Dbafs\Filter(new \RecursiveDirectoryIterator(TL_ROOT . '/' . \Config::get('uploadPath'), \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS)), \RecursiveIteratorIterator::SELF_FIRST);
     $strLog = 'system/tmp/' . md5(uniqid(mt_rand(), true));
     // Open the log file
     $objLog = new \File($strLog, true);
     $objLog->truncate();
     $arrModels = array();
     // Create or update the database entries
     foreach ($objFiles as $objFile) {
         $strRelpath = str_replace(TL_ROOT . '/', '', $objFile->getPathname());
         // Get all subfiles in a single query
         if ($objFile->isDir()) {
             $objSubfiles = \FilesModel::findMultipleFilesByFolder($strRelpath);
             if ($objSubfiles !== null) {
                 while ($objSubfiles->next()) {
                     $arrModels[$objSubfiles->path] = $objSubfiles->current();
                 }
             }
         }
         // Get the model
         if (isset($arrModels[$strRelpath])) {
             $objModel = $arrModels[$strRelpath];
         } else {
             $objModel = \FilesModel::findByPath($strRelpath);
         }
         if ($objModel === null) {
             // Add a log entry
             $objLog->append("[Added] {$strRelpath}");
             // Get the parent folder
             $strParent = dirname($strRelpath);
             // Get the parent ID
             if ($strParent == \Config::get('uploadPath')) {
                 $strPid = null;
             } else {
                 $objParent = \FilesModel::findByPath($strParent);
                 if ($objParent === null) {
                     throw new \Exception("No parent entry for {$strParent}");
                 }
                 $strPid = $objParent->uuid;
             }
             // Create the file or folder
             if (is_file(TL_ROOT . '/' . $strRelpath)) {
                 $objFile = new \File($strRelpath, true);
                 $objModel = new \FilesModel();
                 $objModel->pid = $strPid;
                 $objModel->tstamp = time();
                 $objModel->name = $objFile->name;
                 $objModel->type = 'file';
                 $objModel->path = $objFile->path;
                 $objModel->extension = $objFile->extension;
                 $objModel->found = 2;
                 $objModel->hash = $objFile->hash;
                 $objModel->uuid = $objDatabase->getUuid();
                 $objModel->save();
             } else {
                 $objFolder = new \Folder($strRelpath);
                 $objModel = new \FilesModel();
                 $objModel->pid = $strPid;
                 $objModel->tstamp = time();
                 $objModel->name = $objFolder->name;
                 $objModel->type = 'folder';
                 $objModel->path = $objFolder->path;
                 $objModel->extension = '';
                 $objModel->found = 2;
                 $objModel->hash = $objFolder->hash;
                 $objModel->uuid = $objDatabase->getUuid();
                 $objModel->save();
             }
         } else {
             // Check whether the MD5 hash has changed
             $objResource = $objFile->isDir() ? new \Folder($strRelpath) : new \File($strRelpath);
             $strType = $objModel->hash != $objResource->hash ? 'Changed' : 'Unchanged';
             // Add a log entry
             $objLog->append("[{$strType}] {$strRelpath}");
             // Update the record
             $objModel->found = 1;
             $objModel->hash = $objResource->hash;
             $objModel->save();
         }
     }
     // Check for left-over entries in the DB
     $objFiles = \FilesModel::findByFound('');
     if ($objFiles !== null) {
         $arrMapped = array();
         $arrPidUpdate = array();
         while ($objFiles->next()) {
             $objFound = \FilesModel::findBy(array('hash=?', 'found=2'), $objFiles->hash);
             if ($objFound !== null) {
                 // Check for matching file names if the result is ambiguous (see #5644)
                 if ($objFound->count() > 1) {
                     while ($objFound->next()) {
                         if ($objFound->name == $objFiles->name) {
                             $objFound = $objFound->current();
                             break;
                         }
                     }
                 }
                 // If another file has been mapped already, delete the entry (see #6008)
                 if (in_array($objFound->path, $arrMapped)) {
                     $objLog->append("[Deleted] {$objFiles->path}");
                     $objFiles->delete();
                     continue;
                 }
                 $arrMapped[] = $objFound->path;
                 // Store the PID change
                 if ($objFiles->type == 'folder') {
                     $arrPidUpdate[$objFound->uuid] = $objFiles->uuid;
                 }
                 // Add a log entry BEFORE changing the object
                 $objLog->append("[Moved] {$objFiles->path} to {$objFound->path}");
                 // Update the original entry
                 $objFiles->pid = $objFound->pid;
                 $objFiles->tstamp = $objFound->tstamp;
                 $objFiles->name = $objFound->name;
                 $objFiles->type = $objFound->type;
                 $objFiles->path = $objFound->path;
                 $objFiles->found = 1;
                 // Delete the newer (duplicate) entry
                 $objFound->delete();
                 // Then save the modified original entry (prevents duplicate key errors)
                 $objFiles->save();
             } else {
                 // Add a log entry BEFORE changing the object
                 $objLog->append("[Deleted] {$objFiles->path}");
                 // Delete the entry if the resource has gone
                 $objFiles->delete();
             }
         }
         // Update the PID of the child records
         if (!empty($arrPidUpdate)) {
             foreach ($arrPidUpdate as $from => $to) {
                 $objChildren = \FilesModel::findByPid($from);
                 if ($objChildren !== null) {
                     while ($objChildren->next()) {
                         $objChildren->pid = $to;
                         $objChildren->save();
                     }
                 }
             }
         }
     }
     // Close the log file
     $objLog->close();
     // Reset the found flag
     $objDatabase->query("UPDATE tl_files SET found=1 WHERE found=2");
     // Unlock the tables
     $objDatabase->unlockTables();
     // Return the path to the log file
     return $strLog;
 }
コード例 #27
0
ファイル: Galleria.php プロジェクト: katgirl/galerie
 /**
  * Get gallery images
  *
  * @access public
  * @return null
  */
 public function getPictures($database, $galerie, $template, $imagesFolder, $sortBy, $size, $orderSRC)
 {
     // Adds a group of images from a folder
     $imagesFolder = deserialize($imagesFolder);
     $objFiles = \FilesModel::findMultipleByUuids($imagesFolder);
     $size = deserialize($size);
     global $objPage;
     $images = array();
     $auxDate = array();
     if ($objFiles !== null) {
         // 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(str_replace('_', ' ', $objFile->filename));
                 }
                 // Add the image
                 $images[$objFiles->path] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'imageSRC' => $size[0] == null && $size[1] == null ? $objFiles->path : \Image::get($this->urlEncode($objFiles->path), $size[0], $size[1], $size[2]), 'thumbnailSRC' => \Image::get($this->urlEncode($objFiles->path), '100px', null, 'center_center'), 'title' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'alt' => $arrMeta['caption']);
                 $auxDate[] = $objFile->mtime;
             } else {
                 $objSubfiles = \FilesModel::findByPid($objFiles->uuid);
                 if ($objSubfiles === null) {
                     continue;
                 }
                 while ($objSubfiles->next()) {
                     // 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(str_replace('_', ' ', $objFile->filename));
                     }
                     // Add the image
                     $images[$objSubfiles->path] = array('id' => $objSubfiles->id, 'uuid' => $objSubfiles->uuid, 'name' => $objFile->basename, 'imageSRC' => $size[0] == null && $size[1] == null ? $objSubfiles->path : \Image::get($this->urlEncode($objSubfiles->path), $size[0], $size[1], $size[2]), 'thumbnailSRC' => \Image::get($this->urlEncode($objSubfiles->path), '100px', null, 'center_center'), 'title' => $arrMeta['title'], 'imageUrl' => $arrMeta['link'], 'alt' => $arrMeta['caption']);
                     $auxDate[] = $objFile->mtime;
                 }
             }
         }
         // Sort array
         switch ($sortBy) {
             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 ($orderSRC != '') {
                     $tmp = deserialize($orderSRC);
                     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);
         $total = count($images);
     } else {
         $total = 0;
     }
     // Retrieve the current gallery images
     $objPictures = $database->prepare("SELECT * FROM tl_galerie_pictures WHERE pid=? AND published=1 ORDER BY sorting")->execute($galerie);
     if ($objPictures->numRows > 0) {
         while ($objPictures->next()) {
             // Standard image
             $imgSize = deserialize($objPictures->size);
             $objImg = \FilesModel::findByUuid($objPictures->singleSRC);
             $imageSRC = \Image::get($this->urlEncode($objImg->path), $imgSize[0], $imgSize[1], $imgSize[2]);
             // Fullscreen image
             $objFullscreenImgSRC = \FilesModel::findByUuid($objPictures->fullscreenSingleSRC);
             // Thumbnails are created separately.
             $thumbSize = deserialize($objPictures->thumbSize);
             $objThumb = \FilesModel::findByUuid($objPictures->thumbSRC);
             $objThumb ? $thumbnail = $objThumb->path : ($thumbnail = $objImg->path);
             if ($thumbSize[0] == null && $thumbSize[1] == null) {
                 $thumbnailSRC = \Image::get($this->urlEncode($thumbnail), '100px', null, 'center_center');
             } else {
                 $thumbnailSRC = \Image::get($this->urlEncode($thumbnail), $thumbSize[0], $thumbSize[1], $thumbSize[2]);
             }
             $arrPictures[$objPictures->id] = array('alt' => $objPictures->alt, 'title' => $objPictures->title, 'imageUrl' => $objPictures->imageUrl, 'imageSRC' => $imageSRC, 'thumbnailSRC' => $thumbnailSRC, 'imageFullscreenSRC' => $this->urlEncode($objFullscreenImgSRC->path), 'video' => self::urlVerification($objPictures->video), 'iframe' => $objPictures->iframe, 'iframeThumb' => $objPictures->iframeThumb, 'layer' => htmlentities($objPictures->layerHTML, ENT_COMPAT, 'UTF-8'), 'dataConfig' => $objPictures->dataConfigHTML);
         }
         $pictures = array_values($arrPictures);
         // Add a group of images
         if ($total > 0) {
             $pictures = array_merge($pictures, $images);
         }
         $template->pictures = $pictures;
     } elseif ($total > 0) {
         $template->pictures = $images;
     } else {
         $template->pictures = array();
         $template->noImages = $GLOBALS['TL_LANG']['MSC']['noImages'];
     }
 }