/** * Generate media attribute * * @param \Isotope\Interfaces\IsotopeProduct $objProduct * @param array $arrOptions * @return string */ public function generate(IsotopeProduct $objProduct, array $arrOptions = array()) { $strPoster = null; $arrFiles = deserialize($objProduct->{$this->field_name}, true); // 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 ''; } // Find poster while ($objFiles->next()) { if (in_array($objFiles->extension, trimsplit(',', $GLOBALS['TL_CONFIG']['validImageTypes']))) { $strPoster = $objFiles->uuid; $arrFiles = array_diff($arrFiles, array($objFiles->uuid)); } } $objContentModel = new \ContentModel(); $objContentModel->type = 'media'; $objContentModel->cssID = serialize(array('', $this->field_name)); $objContentModel->playerSRC = serialize($arrFiles); $objContentModel->posterSRC = $strPoster; if ($arrOptions['autoplay']) { $objContentModel->autoplay = '1'; } if ($arrOptions['width'] || $arrOptions['height']) { $objContentModel->playerSize = serialize(array($arrOptions['width'], $arrOptions['height'])); } $objElement = new \ContentMedia($objContentModel); return $objElement->generate(); }
/** * Return if there are no files * @return string */ public function generate() { // Use the home directory of the current user as file source if ($this->useHomeDir && FE_USER_LOGGED_IN) { $this->import('FrontendUser', 'User'); if ($this->User->assignDir && is_dir(TL_ROOT . '/' . $this->User->homeDir)) { $this->multiSRC = array($this->User->homeDir); } } else { $this->multiSRC = deserialize($this->multiSRC); } // Return if there are no files if (!is_array($this->multiSRC) || empty($this->multiSRC)) { return ''; } // Check for version 3 format if (!is_numeric($this->multiSRC[0])) { return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } // Get the file entries from the database $this->objFiles = \FilesModel::findMultipleByIds($this->multiSRC); if ($this->objFiles === null) { return ''; } return parent::generate(); }
/** * Return if there are no files * @return string */ public function generate() { // Use the home directory of the current user as file source if ($this->useHomeDir && FE_USER_LOGGED_IN) { $this->import('FrontendUser', 'User'); if ($this->User->assignDir && is_dir(TL_ROOT . '/' . $this->User->homeDir)) { $this->multiSRC = array($this->User->homeDir); } } else { $this->multiSRC = deserialize($this->multiSRC); } // Return if there are no files if (!is_array($this->multiSRC) || empty($this->multiSRC)) { return ''; } // Check for version 3 format if (!is_numeric($this->multiSRC[0])) { return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } // Get the file entries from the database $this->objFiles = \FilesModel::findMultipleByIds($this->multiSRC); if ($this->objFiles === null) { return ''; } $file = \Input::get('file', true); // Send the file to the browser and do not send a 404 header (see #4632) if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) { while ($this->objFiles->next()) { if ($file == $this->objFiles->path || dirname($file) == $this->objFiles->path) { $this->sendFileToBrowser($file); } } } return parent::generate(); }
public function generate(IsotopeProduct $objProduct, array $arrOptions = array()) { $varValue = $objProduct->{$this->field_name}; if ($this->fieldType == 'checkbox') { $varValue = deserialize($varValue, true); } $objFiles = \FilesModel::findMultipleByIds((array) $varValue); if (null !== $objFiles) { return $this->generateList($objFiles->fetchEach('path')); } return ''; }
/** * Check the source folder * @return string */ public function generate() { $this->multiSRC = deserialize($this->multiSRC); if (!is_array($this->multiSRC) || empty($this->multiSRC)) { return ''; } // Check for version 3 format if (!is_numeric($this->multiSRC[0])) { return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } // Get the file entries from the database $this->objFiles = \FilesModel::findMultipleByIds($this->multiSRC); if ($this->objFiles === null) { return ''; } return parent::generate(); }
/** * Add enclosures to a template * * @param object $objTemplate The template object to add the enclosures to * @param array $arrItem The element or module as array */ public static function addEnclosuresToTemplate($objTemplate, $arrItem) { $arrEnclosures = deserialize($arrItem['enclosure']); if (!is_array($arrEnclosures) || empty($arrEnclosures)) { return; } // Check for version 3 format if (!is_numeric($arrEnclosures[0])) { foreach (array('details', 'answer', 'text') as $key) { if (isset($objTemplate->{$key})) { $objTemplate->{$key} = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } return; } $objFiles = \FilesModel::findMultipleByIds($arrEnclosures); if ($objFiles === null) { return; } $file = \Input::get('file', true); // Send the file to the browser if ($file != '') { while ($objFiles->next()) { if ($file == $objFiles->path) { static::sendFileToBrowser($file); } } // Do not index or cache the page global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); foreach (array('details', 'answer', 'text') as $key) { if (isset($objTemplate->{$key})) { $objTemplate->{$key} = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['ERR']['download'], $file) . '</p>'; } } } $arrEnclosures = array(); $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload'])); // Add download links while ($objFiles->next()) { if ($objFiles->type == 'file') { if (!in_array($objFiles->extension, $allowedDownload)) { continue; } $objFile = new \File($objFiles->path); $arrEnclosures[] = array('link' => $objFiles->name, 'filesize' => static::getReadableSize($objFile->filesize), 'title' => ucfirst(str_replace('_', ' ', $objFile->filename)), 'href' => \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'file=' . static::urlEncode($objFiles->path), 'enclosure' => $objFiles->path, 'icon' => TL_FILES_URL . 'system/themes/' . static::getTheme() . '/images/' . $objFile->icon, 'mime' => $objFile->mime); } } $objTemplate->enclosure = $arrEnclosures; }
/** * Translate the file IDs to file paths */ protected function convertValuesToPaths() { if (empty($this->varValue)) { return; } if (!is_array($this->varValue)) { $this->varValue = array($this->varValue); } elseif (empty($this->varValue[0])) { $this->varValue = array(); } $objFiles = \FilesModel::findMultipleByIds($this->varValue); if ($objFiles !== null) { $this->varValue = array_values($objFiles->fetchEach('path')); } }
/** * Parse the given page and return the image information * @param \PageModel * @return array */ protected static function parsePage(\PageModel $objPage) { if ($objPage->pageImage == '') { return array(); } $arrImages = array(); $objImages = \FilesModel::findMultipleByIds(deserialize($objPage->pageImage, true)); if (null !== $objImages) { while ($objImages->next()) { $objFile = new \File($objImages->path, true); if (!$objFile->isGdImage) { continue; } $arrImage = $objImages->row(); $arrMeta = static::getMetaData($objImages->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))); } $arrImage['alt'] = $objPage->pageImageAlt; $arrImage['imageUrl'] = $arrMeta['link']; $arrImage['caption'] = $arrMeta['caption']; if (null !== $objPage->getRelated('pageImageJumpTo')) { $arrImage['hasLink'] = true; $arrImage['title'] = $objPage->pageImageTitle ?: ($arrMeta['title'] ?: ($objJumpTo->pageTitle ?: $objJumpTo->title)); $arrImage['href'] = \Controller::generateFrontendUrl($objPage->getRelated('pageImageJumpTo')->row()); } $arrImages[] = $arrImage; } $arrOrder = deserialize($objPage->pageImageOrder); if (!empty($arrOrder) && is_array($arrOrder)) { // Remove all values $arrOrder = array_map(function () { }, array_flip($arrOrder)); // Move the matching elements to their position in $arrOrder foreach ($arrImages as $k => $v) { if (array_key_exists($v['uuid'], $arrOrder)) { $arrOrder[$v['uuid']] = $v; unset($arrImages[$k]); } } // Append the left-over images at the end if (!empty($arrImages)) { $arrOrder = array_merge($arrOrder, array_values($arrImages)); } // Remove empty (unreplaced) entries $arrImages = array_values(array_filter($arrOrder)); unset($arrOrder); } } return $arrImages; }
/** * Parse slides * * @param \Model\Collection $objSlides slides retrieved from the database * @return array parsed slides */ protected function parseSlides($objSlides) { global $objPage; $slides = array(); $pids = array(); $idIndexes = array(); if (!$objSlides) { return $slides; } while ($objSlides->next()) { $slide = $objSlides->row(); $slide['text'] = ''; $pids[] = $slide['id']; $idIndexes[(int) $slide['id']] = count($slides); if (trim($slide['singleSRC']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['singleSRC']) : \FilesModel::findByUuid($slide['singleSRC'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) { $meta = $this->getMetaData($file->meta, $objPage->language); $slide['image'] = new \stdClass(); $this->addImageToTemplate($slide['image'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'alt' => $meta['title'], 'imageUrl' => $meta['link'], 'caption' => $meta['caption'], 'size' => isset($this->imgSize) ? $this->imgSize : $this->size)); } if ($slide['videoURL'] && empty($slide['image'])) { $slide['image'] = new \stdClass(); if (preg_match('(^ https?:// # http or https (?: www\\.youtube\\.com/(?:watch\\?v=|v/|embed/) # Different URL formats | youtu\\.be/ # Short YouTube domain ) ([0-9a-z_\\-]{11}) # YouTube ID (?:$|&|/) # End or separator )ix', html_entity_decode($slide['videoURL']), $matches)) { $video = $matches[1]; $slide['image']->src = '//img.youtube.com/vi/' . $video . '/0.jpg'; } else { // Grey dummy image $slide['image']->src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAJCAMAAAAM9FwAAAAAA1BMVEXGxsbd/8BlAAAAFUlEQVR42s3BAQEAAACAkP6vdiO6AgCZAAG/wrlvAAAAAElFTkSuQmCC'; } $slide['image']->imgSize = ''; $slide['image']->alt = ''; if (version_compare(VERSION, '3.4', '>=')) { $slide['image']->picture = array('img' => array('src' => $slide['image']->src, 'srcset' => $slide['image']->src), 'sources' => array()); } } if ($slide['videos']) { $videoFiles = deserialize($slide['videos'], true); if (version_compare(VERSION, '3.2', '<')) { $videoFiles = \FilesModel::findMultipleByIds($videoFiles); } else { $videoFiles = \FilesModel::findMultipleByUuids($videoFiles); } $videos = array(); foreach ($videoFiles as $file) { $videos[] = $file; } $slide['videos'] = $videos; } if (trim($slide['backgroundImage']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['backgroundImage']) : \FilesModel::findByUuid($slide['backgroundImage'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) { $meta = $this->getMetaData($file->meta, $objPage->language); $slide['backgroundImage'] = new \stdClass(); $this->addImageToTemplate($slide['backgroundImage'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'alt' => $meta['title'], 'imageUrl' => $meta['link'], 'caption' => $meta['caption'], 'size' => $slide['backgroundImageSize'])); } else { $slide['backgroundImage'] = null; } if ($slide['backgroundVideos']) { $videoFiles = deserialize($slide['backgroundVideos'], true); if (version_compare(VERSION, '3.2', '<')) { $videoFiles = \FilesModel::findMultipleByIds($videoFiles); } else { $videoFiles = \FilesModel::findMultipleByUuids($videoFiles); } $videos = array(); foreach ($videoFiles as $file) { $videos[] = $file; } $slide['backgroundVideos'] = $videos; } if ($this->rsts_navType === 'thumbs') { $slide['thumb'] = new \stdClass(); if (trim($slide['thumbImage']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['thumbImage']) : \FilesModel::findByUuid($slide['thumbImage'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) { $this->addImageToTemplate($slide['thumb'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'size' => $this->rsts_thumbs_imgSize)); } elseif (trim($slide['singleSRC']) && ($file = version_compare(VERSION, '3.2', '<') ? \FilesModel::findByPk($slide['singleSRC']) : \FilesModel::findByUuid($slide['singleSRC'])) && ($fileObject = new \File($file->path, true)) && ($fileObject->isGdImage || $fileObject->isImage)) { $this->addImageToTemplate($slide['thumb'], array('id' => $file->id, 'name' => $fileObject->basename, 'singleSRC' => $file->path, 'size' => $this->rsts_thumbs_imgSize)); } elseif (!empty($slide['image']->src)) { $slide['thumb'] = clone $slide['image']; } elseif (!empty($slide['backgroundImage']->src)) { $slide['thumb'] = clone $slide['backgroundImage']; } } $slides[] = $slide; } $slideContents = ContentModel::findPublishedByPidsAndTable($pids, SlideModel::getTable()); if ($slideContents) { while ($slideContents->next()) { $slides[$idIndexes[(int) $slideContents->pid]]['text'] .= $this->getContentElement($slideContents->current()); } } return $slides; }
/** * Export a theme * @param \DataContainer */ public function exportTheme(\DataContainer $dc) { // Get the theme meta data $objTheme = $this->Database->prepare("SELECT * FROM tl_theme WHERE id=?")->limit(1)->execute($dc->id); if ($objTheme->numRows < 1) { return; } // Romanize the name $strName = utf8_romanize($objTheme->name); $strName = strtolower(str_replace(' ', '_', $strName)); $strName = preg_replace('/[^A-Za-z0-9\\._-]/', '', $strName); $strName = basename($strName); // Replace the numeric folder IDs $arrFolders = deserialize($objTheme->folders); if (is_array($arrFolders) && !empty($arrFolders)) { $objFolders = \FilesModel::findMultipleByIds($arrFolders); if ($objFolders !== null) { $objTheme->folders = serialize($objFolders->fetchEach('path')); } } // Replace the numeric screenshot ID if ($objTheme->screenshot != '') { $objFile = \FilesModel::findByPk($objTheme->screenshot); if ($objFile !== null) { $objTheme->screenshot = $objFile->path; } } // Create a new XML document $xml = new \DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; // Root element $tables = $xml->createElement('tables'); $tables = $xml->appendChild($tables); // Add the tables $this->addTableTlTheme($xml, $tables, $objTheme); $this->addTableTlStyleSheet($xml, $tables, $objTheme); $this->addTableTlModule($xml, $tables, $objTheme); $this->addTableTlLayout($xml, $tables, $objTheme); // Generate the archive $strTmp = md5(uniqid(mt_rand(), true)); $objArchive = new \ZipWriter('system/tmp/' . $strTmp); // Add the XML document $objArchive->addString($xml->saveXML(), 'theme.xml'); // Add the folders $arrFolders = deserialize($objTheme->folders); if (is_array($arrFolders) && !empty($arrFolders)) { foreach ($this->eliminateNestedPaths($arrFolders) as $strFolder) { $this->addFolderToArchive($objArchive, $strFolder); } } // Add the template files $this->addTemplatesToArchive($objArchive, $objTheme->templates); // Close the archive $objArchive->close(); // Open the "save as …" dialogue $objFile = new \File('system/tmp/' . $strTmp); header('Content-Type: application/octet-stream'); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . $strName . '.cto"'); header('Content-Length: ' . $objFile->filesize); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Expires: 0'); $resFile = fopen(TL_ROOT . '/system/tmp/' . $strTmp, 'rb'); fpassthru($resFile); fclose($resFile); exit; }
/** * Add an event to the array of active events * @param object * @param integer * @param integer * @param string * @param string */ protected function addEvent($objEvent, $intStart, $intEnd, $strUrl, $strBase) { if ($intEnd < time()) { return; } global $objPage; // Called in the back end (see #4026) if ($objPage === null) { $objPage = new \stdClass(); $objPage->dateFormat = $GLOBALS['TL_CONFIG']['dateFormat']; $objPage->datimFormat = $GLOBALS['TL_CONFIG']['datimFormat']; $objPage->timeFormat = $GLOBALS['TL_CONFIG']['timeFormat']; } $intKey = date('Ymd', $intStart); $span = self::calculateSpan($intStart, $intEnd); $format = $objEvent->addTime ? 'datimFormat' : 'dateFormat'; // Add date if ($span > 0) { $title = $this->parseDate($objPage->{$format}, $intStart) . ' - ' . $this->parseDate($objPage->{$format}, $intEnd); } else { $title = $this->parseDate($objPage->dateFormat, $intStart) . ($objEvent->addTime ? ' (' . $this->parseDate($objPage->timeFormat, $intStart) . ($intStart < $intEnd ? ' - ' . $this->parseDate($objPage->timeFormat, $intEnd) : '') . ')' : ''); } // Add title and link $title .= ' ' . $objEvent->title; $link = ''; switch ($objEvent->source) { case 'external': $link = $objEvent->url; break; case 'internal': if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) { $link = $strBase . $this->generateFrontendUrl($objTarget->row()); } break; case 'article': if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null) { $link = $strBase . ampersand($this->generateFrontendUrl($objArticle->getRelated('pid')->row(), '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id))); } break; } // Link to the default page if ($link == '') { $link = $strBase . sprintf($strUrl, $objEvent->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objEvent->alias : $objEvent->id); } // Clean the RTE output if ($objPage->outputFormat == 'xhtml') { $objEvent->teaser = \String::toXhtml($objEvent->teaser); } else { $objEvent->teaser = \String::toHtml5($objEvent->teaser); } $arrEvent = array('title' => $title, 'description' => $objEvent->details, 'teaser' => $objEvent->teaser, 'link' => $link, 'published' => $objEvent->tstamp, 'authorName' => $objEvent->authorName); // Add the article image as enclosure if ($objEvent->addImage) { $objFile = \FilesModel::findByPk($objEvent->singleSRC); if ($objFile !== null) { $arrEvent['enclosure'][] = $objFile->path; } } // Enclosures if ($objEvent->addEnclosure) { $arrEnclosure = deserialize($objEvent->enclosure, true); if (is_array($arrEnclosure)) { $objFile = \FilesModel::findMultipleByIds($arrEnclosure); while ($objFile->next()) { $arrEvent['enclosure'][] = $objFile->path; } } } $this->arrEvents[$intKey][$intStart][] = $arrEvent; }
/** * DCA Header callback * * Adds selected images to the header or redirects to the parent slider if * no slides are found * * @param array $headerFields label value pairs of header fields * @param \DataContainer $dc data container * @return array */ public function headerCallback($headerFields, $dc) { $sliderData = $this->Database->prepare('SELECT * FROM ' . $GLOBALS['TL_DCA'][$dc->table]['config']['ptable'] . ' WHERE id = ?')->limit(1)->execute(CURRENT_ID); if ($sliderData->numRows < 1) { return $headerFields; } $files = deserialize($sliderData->multiSRC); if (is_array($files) && count($files)) { $slidesCount = $this->Database->prepare('SELECT count(*) as count FROM ' . $dc->table . ' WHERE pid = ?')->execute(CURRENT_ID); if (!$slidesCount->count) { $this->redirect('contao/main.php?do=rocksolid_slider&act=edit&id=' . CURRENT_ID . '&ref=' . \Input::get('ref') . '&rt=' . REQUEST_TOKEN); } $headerFields[$GLOBALS['TL_LANG']['tl_rocksolid_slide']['headerImagesSelected'][0]] = $GLOBALS['TL_LANG']['tl_rocksolid_slide']['headerImagesSelected'][1]; $images = array(); if (version_compare(VERSION, '3.2', '<')) { $files = \FilesModel::findMultipleByIds($files); } else { $files = \FilesModel::findMultipleByUuids($files); } while ($files->next()) { // 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) { continue; } // Add the image $images[$files->path] = array('id' => $files->id, 'uuid' => isset($files->uuid) ? $files->uuid : null, 'name' => $file->basename, 'path' => $files->path); } if ($sliderData->orderSRC) { // Turn the order string into an array and remove all values if (version_compare(VERSION, '3.2', '<')) { $order = explode(',', $sliderData->orderSRC); $order = array_map('intval', $order); } else { $order = deserialize($sliderData->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); $imagesHtml = ''; foreach ($images as $image) { $imagesHtml .= ' ' . $this->generateImage(\Image::get($image['path'], 60, 45, 'center_center'), '', 'class="gimage"'); } $headerFields[$GLOBALS['TL_LANG']['tl_rocksolid_slide']['headerImages']] = '<div style="margin-top: 12px; margin-right: -40px;">' . $imagesHtml . '</div>'; } return $headerFields; }
/** * Generate an XML files and save them to the root directory * @param array */ protected function generateFiles($arrFeed) { $arrArchives = deserialize($arrFeed['archives']); if (!is_array($arrArchives) || empty($arrArchives)) { return; } $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss'; $strLink = $arrFeed['feedBase'] ?: \Environment::get('base'); $strFile = $arrFeed['feedName']; $objFeed = new \Feed($strFile); $objFeed->link = $strLink; $objFeed->title = $arrFeed['title']; $objFeed->description = $arrFeed['description']; $objFeed->language = $arrFeed['language']; $objFeed->published = $arrFeed['tstamp']; // Get the items if ($arrFeed['maxItems'] > 0) { $objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']); } else { $objArticle = \NewsModel::findPublishedByPids($arrArchives); } // Parse the items if ($objArticle !== null) { $arrUrls = array(); while ($objArticle->next()) { $jumpTo = $objArticle->getRelated('pid')->jumpTo; // No jumpTo page set (see #4784) if (!$jumpTo) { continue; } // Get the jumpTo URL if (!isset($arrUrls[$jumpTo])) { $objParent = $this->getPageDetails($jumpTo); $arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/items/%s', $objParent->language); } $strUrl = $arrUrls[$jumpTo]; $objItem = new \FeedItem(); $objItem->title = $objArticle->headline; $objItem->link = $this->getLink($objArticle, $strUrl, $strLink); $objItem->published = $objArticle->date; $objItem->author = $objArticle->authorName; // Prepare the description if ($arrFeed['source'] == 'source_text') { $strDescription = ''; $objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news'); if ($objElement !== null) { while ($objElement->next()) { $strDescription .= $this->getContentElement($objElement->id); } } } else { $strDescription = $objArticle->teaser; } $strDescription = $this->replaceInsertTags($strDescription); $objItem->description = $this->convertRelativeUrls($strDescription, $strLink); // Add the article image as enclosure if ($objArticle->addImage) { $objFile = \FilesModel::findByPk($objArticle->singleSRC); if ($objFile !== null) { $objItem->addEnclosure($objFile->path); } } // Enclosures if ($objArticle->addEnclosure) { $arrEnclosure = deserialize($objArticle->enclosure, true); if (is_array($arrEnclosure)) { $objFile = \FilesModel::findMultipleByIds($arrEnclosure); while ($objFile->next()) { $objItem->addEnclosure($objFile->path); } } } $objFeed->addItem($objItem); } } // Create the file $objRss = new \File('share/' . $strFile . '.xml'); $objRss->write($this->replaceInsertTags($objFeed->{$strType}())); $objRss->close(); }
/** * Create all header scripts * @param object * @param object * @throws \Exception */ protected function createHeaderScripts($objPage, $objLayout) { $strStyleSheets = ''; $strCcStyleSheets = ''; $arrStyleSheets = deserialize($objLayout->stylesheet); $blnXhtml = $objPage->outputFormat == 'xhtml'; $strTagEnding = $blnXhtml ? ' />' : '>'; $arrFramework = deserialize($objLayout->framework); // Google web fonts if ($objLayout->webfonts != '') { $protocol = \Environment::get('ssl') ? 'https://' : 'http://'; $strStyleSheets .= '<link' . ($blnXhtml ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $protocol . 'fonts.googleapis.com/css?family=' . $objLayout->webfonts . '"' . $strTagEnding . "\n"; } // Add the Contao CSS framework style sheets if (is_array($arrFramework)) { foreach ($arrFramework as $strFile) { if ($strFile != 'tinymce.css') { $GLOBALS['TL_FRAMEWORK_CSS'][] = 'assets/contao/css/' . $strFile; } } } // Add the TinyMCE style sheet if (is_array($arrFramework) && in_array('tinymce.css', $arrFramework) && file_exists(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css')) { $GLOBALS['TL_FRAMEWORK_CSS'][] = $GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css'; } // User style sheets if (is_array($arrStyleSheets) && strlen($arrStyleSheets[0])) { $objStylesheets = \StyleSheetModel::findByIds($arrStyleSheets); if ($objStylesheets !== null) { while ($objStylesheets->next()) { $media = implode(',', deserialize($objStylesheets->media)); // Overwrite the media type with a custom media query if ($objStylesheets->mediaQuery != '') { $media = $objStylesheets->mediaQuery; } // Aggregate regular style sheets if (!$objStylesheets->cc && !$objStylesheets->hasFontFace) { $GLOBALS['TL_USER_CSS'][] = 'assets/css/' . $objStylesheets->name . '.css|' . $media . '|static|' . max($objStylesheets->tstamp, $objStylesheets->tstamp2, $objStylesheets->tstamp3); } else { $strStyleSheet = '<link' . ($blnXhtml ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . TL_ASSETS_URL . 'assets/css/' . $objStylesheets->name . '.css"' . ($media != '' && $media != 'all' ? ' media="' . $media . '"' : '') . $strTagEnding; if ($objStylesheets->cc) { $strStyleSheet = '<!--[' . $objStylesheets->cc . ']>' . $strStyleSheet . '<![endif]-->'; } $strCcStyleSheets .= $strStyleSheet . "\n"; } } } } $arrExternal = deserialize($objLayout->external); // External style sheets if (is_array($arrExternal) && !empty($arrExternal)) { // Get the file entries from the database $objFiles = \FilesModel::findMultipleByIds($arrExternal); if ($objFiles !== null) { while ($objFiles->next()) { if (file_exists(TL_ROOT . '/' . $objFiles->path)) { $GLOBALS['TL_USER_CSS'][] = $objFiles->path . '||static'; } } } } // Add a placeholder for dynamic style sheets (see #4203) $strStyleSheets .= '[[TL_CSS]]'; // Add the debug style sheet if ($GLOBALS['TL_CONFIG']['debugMode']) { $strStyleSheets .= '<link rel="stylesheet" href="' . $this->addStaticUrlTo('assets/contao/css/debug.css') . '"' . $strTagEnding . "\n"; } // Always add conditional style sheets at the end $strStyleSheets .= $strCcStyleSheets; $newsfeeds = deserialize($objLayout->newsfeeds); $calendarfeeds = deserialize($objLayout->calendarfeeds); // Add newsfeeds if (is_array($newsfeeds) && !empty($newsfeeds)) { $objFeeds = \NewsFeedModel::findByIds($newsfeeds); if ($objFeeds !== null) { while ($objFeeds->next()) { $base = $objFeeds->feedBase ?: \Environment::get('base'); $strStyleSheets .= '<link rel="alternate" href="' . $base . 'share/' . $objFeeds->alias . '.xml" type="application/' . $objFeeds->format . '+xml" title="' . $objFeeds->title . '"' . $strTagEnding . "\n"; } } } // Add calendarfeeds if (is_array($calendarfeeds) && !empty($calendarfeeds)) { $objFeeds = \CalendarFeedModel::findByIds($calendarfeeds); if ($objFeeds !== null) { while ($objFeeds->next()) { $base = $objFeeds->feedBase ?: \Environment::get('base'); $strStyleSheets .= '<link rel="alternate" href="' . $base . 'share/' . $objFeeds->alias . '.xml" type="application/' . $objFeeds->format . '+xml" title="' . $objFeeds->title . '"' . $strTagEnding . "\n"; } } } // Add a placeholder for dynamic <head> tags (see #4203) $strHeadTags = '[[TL_HEAD]]'; // Add the user <head> tags if (($strHead = trim($objLayout->head)) != false) { $strHeadTags .= $strHead . "\n"; } $this->Template->stylesheets = $strStyleSheets; $this->Template->head = $strHeadTags; }
public function showAll() { $return = ''; $query = 'SELECT * FROM tl_theme ORDER BY name '; $objRowStmt = $this->Database->prepare($query); $objRow = $objRowStmt->execute(); $themeList = array(); $result = $objRow->fetchAllAssoc(); $this->import('FilesModel'); foreach ($result as $row) { $files = array(); if (version_compare(VERSION, '3.2', '<')) { $folders = \FilesModel::findMultipleByIds(deserialize($row['folders'])); } else { $folders = \FilesModel::findMultipleByUuids(deserialize($row['folders'])); } if ($folders !== null) { foreach ($folders->fetchEach('path') as $folder) { $filesResult = \FilesModel::findBy(array($this->FilesModel->getTable() . '.path LIKE ? AND extension = \'base\''), $folder . '/%'); if ($filesResult === null) { continue; } foreach ($filesResult->fetchEach('path') as $file) { if (!file_exists(TL_ROOT . '/' . substr($file, 0, -5))) { continue; } $extension = explode('.', $file); $extension = $extension[count($extension) - 2]; $files[] = array('id' => $file, 'type' => $extension === 'html5' ? 'html' : $extension, 'name' => substr($file, strlen($folder) + 1, -5)); } } } $templateFiles = scandir(TL_ROOT . '/' . $row['templates']); foreach ($templateFiles as $file) { if (substr($file, -5) === '.base' && file_exists(TL_ROOT . '/' . $row['templates'] . '/' . substr($file, 0, -5))) { $extension = explode('.', $file); $extension = $extension[count($extension) - 2]; $files[] = array('id' => $row['templates'] . '/' . $file, 'type' => $extension === 'html5' ? 'html' : $extension, 'name' => substr($file, 0, -5)); } } if (version_compare(VERSION, '3.2', '<')) { $screenshot = \FilesModel::findByPk($row['screenshot']); } else { $screenshot = \FilesModel::findByUuid($row['screenshot']); } if ($screenshot) { $screenshot = TL_FILES_URL . \Image::get($screenshot->path, 40, 30, 'center_top'); } if (count($files)) { $themeList[] = array('name' => $row['name'], 'files' => $files, 'screenshot' => $screenshot); } } if (!count($themeList)) { return '<p class="tl_empty">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>'; } $return .= '<div id="tl_buttons">' . $this->generateGlobalButtons() . '</div>' . \Message::generate(true); $return .= '<div class="tl_listing_container list_view">'; $return .= '<table class="tl_listing' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] ? ' showColumns' : '') . '">'; foreach ($themeList as $key => $theme) { if ($key) { $return .= '<tr style="height: 30px;"><td colspan="2"> </td></tr>'; } $return .= '<tr><td colspan="2" class="tl_folder_tlist">'; if ($theme['screenshot']) { $return .= '<img src="' . $theme['screenshot'] . '" alt="" class="theme_preview"> '; } $return .= $theme['name'] . '</td></tr>'; $eoCount = -1; foreach ($theme['files'] as $file) { $return .= '<tr class="' . (++$eoCount % 2 == 0 ? 'even' : 'odd') . '" onmouseover="Theme.hoverRow(this,1)" onmouseout="Theme.hoverRow(this,0)">'; $return .= '<td class="tl_file_list">' . $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['file_types'][$file['type']] . ' (' . $file['name'] . ')</td>'; $return .= '<td class="tl_file_list tl_right_nowrap">' . $this->generateButtons($file, $this->strTable) . '</td>'; $return .= '</tr>'; } } $return .= '</table>'; $return .= '</div>'; return $return; }
/** * 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 ? '&' : '?') . '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 ? '&' : '?') . '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(); }
/** * Set all user properties from a database record */ protected function setUserFromDb() { $this->intId = $this->id; // Unserialize values foreach ($this->arrData as $k => $v) { if (!is_numeric($v)) { $this->{$k} = deserialize($v); } } $GLOBALS['TL_LANGUAGE'] = $this->language; $GLOBALS['TL_USERNAME'] = $this->username; $GLOBALS['TL_CONFIG']['showHelp'] = $this->showHelp; $GLOBALS['TL_CONFIG']['useRTE'] = $this->useRTE; $GLOBALS['TL_CONFIG']['useCE'] = $this->useCE; $GLOBALS['TL_CONFIG']['thumbnails'] = $this->thumbnails; $GLOBALS['TL_CONFIG']['backendTheme'] = $this->backendTheme; // Inherit permissions $always = array('alexf'); $depends = array('modules', 'themes', 'pagemounts', 'alpty', 'filemounts', 'fop', 'forms', 'formp'); // HOOK: Take custom permissions if (is_array($GLOBALS['TL_PERMISSIONS']) && !empty($GLOBALS['TL_PERMISSIONS'])) { $depends = array_merge($depends, $GLOBALS['TL_PERMISSIONS']); } // Overwrite user permissions if only group permissions shall be inherited if ($this->inherit == 'group') { foreach ($depends as $field) { $this->{$field} = array(); } } // Merge permissions $inherit = in_array($this->inherit, array('group', 'extend')) ? array_merge($always, $depends) : $always; $time = time(); foreach ((array) $this->groups as $id) { $objGroup = $this->Database->prepare("SELECT * FROM tl_user_group WHERE id=? AND disable!=1 AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time})")->limit(1)->execute($id); if ($objGroup->numRows > 0) { foreach ($inherit as $field) { $value = deserialize($objGroup->{$field}); if (is_array($value)) { $this->{$field} = array_merge(is_array($this->{$field}) ? $this->{$field} : ($this->{$field} != '' ? array($this->{$field}) : array()), $value); $this->{$field} = array_unique($this->{$field}); } } } } // Restore session if (is_array($this->session)) { $this->Session->setData($this->session); } else { $this->session = array(); } // Make sure pagemounts and filemounts are set! if (!is_array($this->pagemounts)) { $this->pagemounts = array(); } else { $this->filemounts = array_filter($this->filemounts); } if (!is_array($this->filemounts)) { $this->filemounts = array(); } else { $this->filemounts = array_filter($this->filemounts); } // Convert the numeric file mounts into paths if (!$this->isAdmin && !empty($this->filemounts)) { $objFiles = \FilesModel::findMultipleByIds($this->filemounts); if ($objFiles !== null) { $this->filemounts = $objFiles->fetchEach('path'); } } }
/** * Translate the file IDs to file paths */ protected function convertValuesToPaths() { if (empty($this->varValue)) { return; } if (!is_array($this->varValue)) { $this->varValue = array($this->varValue); } elseif (empty($this->varValue[0])) { $this->varValue = array(); } if (empty($this->varValue)) { return; } // TinyMCE will pass the path instead of the ID if (strncmp($this->varValue[0], \Config::get('uploadPath') . '/', strlen(\Config::get('uploadPath')) + 1) === 0) { return; } // Ignore the numeric IDs when in switch mode (TinyMCE) if (\Input::get('switch')) { return; } $objFiles = \FilesModel::findMultipleByIds($this->varValue); if ($objFiles !== null) { $this->varValue = array_values($objFiles->fetchEach('path')); } }
/** * Add a data row to the XML document * @param \DOMDocument * @param \DOMElement * @param \Database\Result */ protected function addDataRow(\DOMDocument $xml, \DOMElement $table, \Database\Result $objData) { $row = $xml->createElement('row'); $row = $table->appendChild($row); foreach ($objData->row() as $k => $v) { $field = $xml->createElement('field'); $field->setAttribute('name', $k); $field = $row->appendChild($field); if ($v === null) { $v = 'NULL'; } elseif ($table->getAttribute('name') == 'tl_theme' && $k == 'screenshot' || $table->getAttribute('name') == 'tl_module' && $k == 'singleSRC' || $table->getAttribute('name') == 'tl_module' && $k == 'reg_homeDir') { $objFile = \FilesModel::findByPk($v); if ($objFile !== null) { // Standardize the upload path if it is not "files" if ($GLOBALS['TL_CONFIG']['uploadPath'] != 'files') { $v = 'files/' . preg_replace('@^' . preg_quote($GLOBALS['TL_CONFIG']['uploadPath'], '@') . '/@', '', $objFile->path); } else { $v = $objFile->path; } } } elseif ($table->getAttribute('name') == 'tl_theme' && $k == 'folders' || $table->getAttribute('name') == 'tl_module' && $k == 'multiSRC' || $table->getAttribute('name') == 'tl_layout' && $k == 'external') { $arrFiles = deserialize($v); if (is_array($arrFiles) && !empty($arrFiles)) { $objFiles = \FilesModel::findMultipleByIds($arrFiles); if ($objFiles !== null) { // Standardize the upload path if it is not "files" if ($GLOBALS['TL_CONFIG']['uploadPath'] != 'files') { $arrTmp = array(); while ($objFiles->next()) { $arrTmp[] = 'files/' . preg_replace('@^' . preg_quote($GLOBALS['TL_CONFIG']['uploadPath'], '@') . '/@', '', $objFiles->path); } $v = serialize($arrTmp); } else { $v = serialize($objFiles->fetchEach('path')); } } } } $value = $xml->createTextNode($v); $field->appendChild($value); } }