public static function checkPermissionForProtectedHomeDirs($strFile) { $strUuid = \Config::get('protectedHomeDirRoot'); if (!$strFile) { return; } if ($strUuid && ($strProtectedHomeDirRootPath = \HeimrichHannot\HastePlus\Files::getPathFromUuid($strUuid)) !== null) { // check only if path inside the protected root dir if (StringUtil::startsWith($strFile, $strProtectedHomeDirRootPath)) { if (FE_USER_LOGGED_IN) { if (($objFrontendUser = \FrontendUser::getInstance()) !== null) { if (\Config::get('allowAccessByMemberId') && $objFrontendUser->assignProtectedDir && $objFrontendUser->protectedHomeDir) { $strProtectedHomeDirMemberRootPath = Files::getPathFromUuid($objFrontendUser->protectedHomeDir); // fe user id = dir owner member id if (StringUtil::startsWith($strFile, $strProtectedHomeDirMemberRootPath)) { return; } } if (\Config::get('allowAccessByMemberGroups')) { $arrAllowedGroups = deserialize(\Config::get('allowedMemberGroups'), true); if (array_intersect(deserialize($objFrontendUser->groups, true), $arrAllowedGroups)) { return; } } } } $intNoAccessPage = \Config::get('jumpToNoAccess'); if ($intNoAccessPage && ($objPageJumpTo = \PageModel::findByPk($intNoAccessPage)) !== null) { \Controller::redirect(\Controller::generateFrontendUrl($objPageJumpTo->row())); } else { die($GLOBALS['TL_LANG']['MSC']['noAccessDownload']); } } } }
public static function generate() { if (($objConfig = ConfigModel::findByPk(\Input::get('id'))) !== null && ($intCount = \Input::get('count'))) { $arrAlphabets = deserialize($objConfig->alphabets, true); $arrRules = deserialize($objConfig->rules, true); $arrCodes = array(); for ($i = 0; $i < $intCount; $i++) { $strCode = CodeGenerator::generate($objConfig->length, $objConfig->preventAmbiguous, $arrAlphabets, $arrRules, $objConfig->allowedSpecialChars); if ($objConfig->preventDoubleCodes) { $blnFound = false; if ($objConfig->doubleCodeTable && $objConfig->doubleCodeTableField) { $blnFound = static::findCodeInTable($strCode, $objConfig->doubleCodeTable, $objConfig->doubleCodeTableField); } while (in_array($strCode, $arrCodes) || $blnFound) { $strCode = CodeGenerator::generate($objConfig->length, $objConfig->preventAmbiguous, $arrAlphabets, $arrRules, $objConfig->allowedSpecialChars); $blnFound = false; if ($objConfig->doubleCodeTable && $objConfig->doubleCodeTableField) { $blnFound = static::findCodeInTable($strCode, $objConfig->doubleCodeTable, $objConfig->doubleCodeTableField); } } } $arrCodes[] = $strCode; } Files::sendTextAsFileToBrowser(implode("\n", $arrCodes), 'codes_' . date('Y-m-d-H-i') . '.txt'); } }
protected function buildFileDir($objEntity = null) { if ($this->fileDir && ($objFolder = \FilesModel::findByUuid($this->fileDir))) { $objMember = \FrontendUser::getInstance(); $strDir = $objFolder->path; if ($this->useHomeDir && FE_USER_LOGGED_IN && $objMember->assignDir && $objMember->homeDir) { $strDir = Files::getPathFromUuid($objMember->homeDir); } if (in_array('protected_homedirs', \ModuleLoader::getActive())) { if ($this->useProtectedHomeDir && $objMember->assignProtectedDir && $objMember->protectedHomeDir) { $strDir = Files::getPathFromUuid($objMember->protectedHomeDir); } } if ($this->fileSubDirName) { $strDir .= '/' . $this->fileSubDirName; } if (isset($GLOBALS['TL_HOOKS']['exporter_modifyFileDir']) && is_array($GLOBALS['TL_HOOKS']['exporter_modifyFileDir'])) { foreach ($GLOBALS['TL_HOOKS']['exporter_modifyFileDir'] as $callback) { $objCallback = \System::importStatic($callback[0]); $strFixedDir = $objCallback->{$callback}[1]($strDir, $this); $strDir = $strFixedDir ?: $strDir; } } return $strDir; } throw new \Exception('No exporter fileDir defined!'); }
public static function getStylesheetPaths(Message $objMessage, $strMode) { $arrStylesheets = deserialize($strMode == static::CSS_MODE_INLINE ? $objMessage->inlineStylesheets : $objMessage->headerStylesheets, true); if (!empty($arrStylesheets)) { $arrStylesheetPaths = array_map(function ($strUuid) { $strPath = TL_ROOT . '/' . Files::getPathFromUuid($strUuid); return file_exists($strPath) ? $strPath : ''; }, $arrStylesheets); // remove non-found stylesheets return array_filter($arrStylesheetPaths); } return array(); }
protected function collectItems() { if ($strSourceFile = Files::getPathFromUuid($this->sourceFile)) { $objCsv = new CsvReader($strSourceFile); $objCsv->setDelimiter($this->delimiter); $objCsv->setEnclosure($this->enclosure); $objCsv->rewind(); $objCsv->next(); while ($arrCurrent = $objCsv->current()) { $this->arrItems[] = $arrCurrent; $objCsv->next(); } } }
protected function runBeforeTemplateParsing($objTemplate, $arrItem) { if (!$this->useDummyImage) { return; } if ($arrItem['fields']['addImage'] && $arrItem['fields']['singleSRC'] != '') { $this->addImage($arrItem['raw'], 'singleSRC', $arrItem); if (is_file(TL_ROOT . '/' . $arrItem['fields']['singleSRC'])) { $this->addImageToTemplate($objTemplate, $arrItem['fields']); } } elseif ($this->useDummyImage && $this->dummyImage) { $arrItem['fields']['addImage'] = true; $arrItem['fields']['singleSRC'] = Files::getPathFromUuid($this->dummyImage); $this->addImage($arrItem['raw'], 'singleSRC', $arrItem); if (is_file(TL_ROOT . '/' . $arrItem['fields']['singleSRC'])) { $this->addImageToTemplate($objTemplate, $arrItem['fields']); } } }
protected function runBeforeTemplateParsing($objTemplate, $arrItem) { if ($arrItem['fields']['addImage'] && $arrItem['fields']['singleSRC'] != '') { if (is_file(TL_ROOT . '/' . $arrItem['fields']['singleSRC'])) { $this->addImageToTemplate($objTemplate, $arrItem['fields']); } } elseif ($this->useDummyImage && $this->dummyImage) { $arrItem['fields']['addImage'] = true; $arrItem['fields']['singleSRC'] = Files::getPathFromUuid($this->dummyImage); if (is_file(TL_ROOT . '/' . $arrItem['fields']['singleSRC'])) { $this->addImageToTemplate($objTemplate, $arrItem['fields']); } } if ($arrItem['fields']['addEnclosure']) { if (!is_array($arrItem['fields']['enclosure'])) { $arrItem['fields']['enclosure'] = array($arrItem['fields']['enclosure']); } $this->addEnclosuresToTemplate($objTemplate, $arrItem['fields']); } }
protected function parseItem($objItem, $strClass = '', $intCount = 0) { if (in_array('member_content_archives', \ModuleLoader::getActive())) { $arrFilterTags = deserialize($this->memberContentArchiveTags, true); $objItem->memberContent = ''; if (($objMemberContentArchives = \HeimrichHannot\MemberContentArchives\MemberContentArchiveModel::findBy('mid', $objItem->memberId ?: $objItem->id)) !== null) { while ($objMemberContentArchives->next()) { if (in_array($objMemberContentArchives->tag, $arrFilterTags)) { $objItem->memberContentId = $objMemberContentArchives->id; $objElement = \ContentModel::findPublishedByPidAndTable($objMemberContentArchives->id, 'tl_member_content_archive'); if ($objElement !== null) { while ($objElement->next()) { $objItem->memberContent .= \Controller::getContentElement($objElement->current()); } } } } if ($objMemberContentArchives->tag == $this->memberContentArchiveTeaserTag) { $objItem->memberContentTitle = $objMemberContentArchives->title; $objItem->memberContentTeaser = $objMemberContentArchives->teaser; } // override member fields $arrOverridableMemberFields = deserialize(\Config::get('overridableMemberFields')); if (!empty($arrOverridableMemberFields)) { foreach ($arrOverridableMemberFields as $strField) { $strFieldOverride = 'member' . ucfirst($strField); if ($objMemberContentArchives->{$strFieldOverride}) { if (\Validator::isUuid($objMemberContentArchives->{$strFieldOverride})) { $objMemberContentArchives->{$strFieldOverride} = Files::getPathFromUuid($objMemberContentArchives->{$strFieldOverride}); } $objItem->{$strField} = $objMemberContentArchives->{$strFieldOverride}; } } } } } return parent::parseItem($objItem, $strClass, $intCount); }
public static function prepareSpecialValueForPrint($varValue, $arrData, $strTable, $objDc, $objItem = null) { $varValue = deserialize($varValue); $arrOpts = $arrData['options']; $arrReference = $arrData['reference']; $strRegExp = $arrData['eval']['rgxp']; // get options if ((is_array($arrData['options_callback']) || is_callable($arrData['options_callback'])) && !$arrData['reference']) { if (is_array($arrData['options_callback'])) { $strClass = $arrData['options_callback'][0]; $strMethod = $arrData['options_callback'][1]; $objInstance = \Controller::importStatic($strClass); $arrOptionsCallback = @$objInstance->{$strMethod}($objDc); } elseif (is_callable($arrData['options_callback'])) { $arrOptionsCallback = @$arrData['options_callback']($objDc); } $arrOptions = !is_array($varValue) ? array($varValue) : $varValue; if ($varValue !== null && is_array($arrOptionsCallback)) { $varValue = array_intersect_key($arrOptionsCallback, array_flip($arrOptions)); } } if ($arrData['inputType'] == 'explanation') { $varValue = $arrData['eval']['text']; } elseif ($strRegExp == 'date') { $varValue = \Date::parse(\Config::get('dateFormat'), $varValue); } elseif ($strRegExp == 'time') { $varValue = \Date::parse(\Config::get('timeFormat'), $varValue); } elseif ($strRegExp == 'datim') { $varValue = \Date::parse(\Config::get('datimFormat'), $varValue); } elseif ($arrData['inputType'] == 'tag' && in_array('tags_plus', \ModuleLoader::getActive())) { if (($arrTags = \HeimrichHannot\TagsPlus\TagsPlus::loadTags($strTable, $objItem->id)) !== null) { $varValue = $arrTags; } } elseif (!is_array($varValue) && \Validator::isBinaryUuid($varValue)) { $strPath = Files::getPathFromUuid($varValue); $varValue = $strPath ? \Environment::get('url') . '/' . $strPath : \StringUtil::binToUuid($varValue); } elseif (is_array($varValue)) { $varValue = Arrays::flattenArray($varValue); $varValue = array_filter($varValue); // remove empty elements // transform binary uuids to paths $varValue = array_map(function ($varValue) { if (\Validator::isBinaryUuid($varValue)) { $strPath = Files::getPathFromUuid($varValue); if ($strPath) { return \Environment::get('url') . '/' . $strPath; } return \StringUtil::binToUuid($varValue); } return $varValue; }, $varValue); if (!$arrReference) { $varValue = array_map(function ($varValue) use($arrOpts) { return isset($arrOpts[$varValue]) ? $arrOpts[$varValue] : $varValue; }, $varValue); } $varValue = array_map(function ($varValue) use($arrReference) { if (is_array($arrReference)) { return isset($arrReference[$varValue]) ? is_array($arrReference[$varValue]) ? $arrReference[$varValue][0] : $arrReference[$varValue] : $varValue; } else { return $varValue; } }, $varValue); } else { if ($arrData['eval']['isBoolean'] || $arrData['inputType'] == 'checkbox' && !$arrData['eval']['multiple']) { $varValue = $varValue != '' ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no']; } elseif (is_array($arrOpts) && array_is_assoc($arrOpts)) { $varValue = isset($arrOpts[$varValue]) ? $arrOpts[$varValue] : $varValue; } elseif (is_array($arrReference)) { $varValue = isset($arrReference[$varValue]) ? is_array($arrReference[$varValue]) ? $arrReference[$varValue][0] : $arrReference[$varValue] : $varValue; } } if (is_array($varValue)) { $varValue = implode(', ', $varValue); } // Convert special characters (see #1890) return specialchars($varValue); }
protected static function parseTemplate($strTemplate, $objEntityTemplate, $strTargetFile, array $arrData = array()) { if (!$strTemplate) { return; } $objTemplate = new \BackendTemplate($strTemplate); $objTemplate->setData($arrData + $objEntityTemplate->row()); $strResult = $objTemplate->parse(); if ($strResult) { new \Folder(Files::getPathWithoutFilename($strTargetFile)); if (file_put_contents(TL_ROOT . '/' . $strTargetFile, '<?php' . "\n\n" . $strResult) !== false) { \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['MSC']['entity_generator']['fileSuccessfullyGenerated'], $strTargetFile)); } } }
/** * Handle downloads * @return bool return true, or false if the file does not exist */ protected function handleDownload() { $objFile = \HeimrichHannot\Haste\Util\Files::getFileFromUuid($this->fileSRC); if ($objFile === null) { return false; } $allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload'))); // Return if the file type is not allowed if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) { return false; } $arrMeta = $this->getMetaFromFile($objFile); $file = \Input::get('file', true); // Send the file to the browser and do not send a 404 header (see #4632) if ($file != '' && $file == $objFile->path) { \Controller::sendFileToBrowser($file); } $this->setHref(\Environment::get('request')); // Remove an existing file parameter (see #5683) if (preg_match('/(&(amp;)?|\\?)file=/', $this->getHref())) { $this->setHref(preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $this->getHref())); } $this->setHref($this->getHref() . (\Config::get('disableAlias') || strpos($this->getHref(), '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFile->path)); $this->setTitle(sprintf($GLOBALS['TL_LANG']['MSC']['linkteaser']['downloadTitle'], $arrMeta['title'])); $this->setLink(sprintf($this->getLink(), $arrMeta['title'])); return true; }
public function moveAttachments(\DataContainer $objDc) { if (($objSubmission = \HeimrichHannot\Submissions\SubmissionModel::findByPk($objDc->id)) === null) { return false; } if (($objSubmissionArchive = $objSubmission->getRelated('pid')) === null) { return false; } if (!$objSubmission->attachments) { return false; } $strSubFolder = Tokens::replace($objSubmissionArchive->attachmentSubFolderPattern, $objSubmission); $objFileModels = \FilesModel::findMultipleByUuids(deserialize($objSubmission->attachments, true)); if ($objFileModels === null || $strSubFolder == '') { return false; } $strFolder = $objSubmissionArchive->attachmentUploadFolder; if (\Validator::isUuid($objSubmissionArchive->attachmentUploadFolder)) { if (($strFolder = Files::getPathFromUuid($objSubmissionArchive->attachmentUploadFolder)) === null) { return false; } } $strTarget = rtrim($strFolder, '/') . '/' . ltrim($strSubFolder, '/'); while ($objFileModels->next()) { if (!file_exists(TL_ROOT . '/' . $objFileModels->path)) { continue; } $objFile = new \File($objFileModels->path, true); $objFile->renameTo($strTarget . '/' . basename($objFile->value)); } }
protected function doExport($objEntity = null, array $arrFields = array()) { switch ($this->type) { case Exporter::TYPE_ITEM: $arrMargins = deserialize($this->pdfMargins, true); if (count($arrMargins) > 0) { $objPdf = new PdfTemplate('A4', PdfTemplate::ORIENTATION_PORTRAIT, $arrMargins['left'], $arrMargins['right'], $arrMargins['top'], $arrMargins['bottom']); } else { $objPdf = new PdfTemplate(); } // template if ($this->pdfBackground) { $objPdf->addTemplatePdf(Files::getPathFromUuid($this->objConfig->pdfBackground)); } // fonts if (($objPdfFonts = FieldPaletteModel::findByPidAndTableAndField($this->objConfig->id, 'tl_exporter', 'pdfFonts')) !== null) { while ($objPdfFonts->next()) { switch ($objPdfFonts->exporter_pdfFonts_fontWeight) { case 'B': $strMethod = 'addBoldFont'; break; case 'I': $strMethod = 'addItalicFont'; break; case 'BI': $strMethod = 'addBoldItalicFont'; break; default: $strMethod = 'addRegularFont'; } $objPdf->{$strMethod}($objPdfFonts->exporter_pdfFonts_fontName, Files::getPathFromUuid($objPdfFonts->exporter_pdfFonts_file)); } } $objTemplate = new \FrontendTemplate($this->pdfTemplate ?: 'exporter_pdf_item_default'); $objTemplate->raw = $objEntity->row(); foreach ($objEntity->row() as $strName => $arrValue) { $objTemplate->{$strName} = $arrValue; } // skip fields $arrSkipFields = array_map(function ($val) { list($strTable, $strField) = explode('.', $val); return $strField; }, deserialize($this->skipFields, true)); foreach ($arrSkipFields as $strName) { unset($arrFields[$strName]); } // skip labels $arrSkipLabels = array_map(function ($val) { list($strTable, $strField) = explode('.', $val); return $strField; }, deserialize($this->skipLabels, true)); foreach ($arrSkipLabels as $strName) { unset($arrFields[$strName]['label']); } $objTemplate->fields = $arrFields; // css $arrCss = deserialize($this->pdfCss, true); $strCss = ''; if (!empty($arrCss)) { $strCss = implode('', array_map(function ($val) { return file_get_contents(Files::getPathFromUuid($val)); }, $arrCss)); } $objPdf->writeHtml($objTemplate->parse(), $strCss); return $objPdf; break; case Exporter::TYPE_LIST: break; } }
public function prepareFile($varUuid) { if (($objFile = Files::getFileFromUuid($varUuid, true)) !== null && $objFile->exists()) { static::addAllowedDownload($objFile->value); $arrReturn = array('name' => StringUtil::preg_replace_last('@_[a-f0-9]{13}@', $objFile->name), 'uuid' => \StringUtil::binToUuid($objFile->getModel()->uuid), 'size' => $objFile->filesize); if (($strImage = $this->getPreviewImage($objFile)) !== null) { $arrReturn['url'] = $strImage; } if (($strInfoUrl = $this->getInfoAction($objFile)) !== null) { $arrReturn['info'] = $strInfoUrl; } return $arrReturn; } return false; }
/** * Returns a member home dir and creates one, if desired. * * @param $varMember object|int The member as object or member id * @param $strBooleanPropertyName string The name of the boolean member property (e.g. "assignDir") * @param $strPropertyName string The name of the member property (e.g. "homeDir") * @param $varRootFolder string|object The base folder as instance of \FilesModel, path string or uuid * @param bool|false $blnOverwrite bool Determines if an existing folder can be overridden * * @return bool|string Returns the home dir or false if an error occurred. */ public static function getHomeDir($varMember, $strBooleanPropertyName = 'assignDir', $strPropertyName = 'homeDir', $varRootFolder = 'files/members', $blnOverwrite = false) { if (($objMember = is_numeric($varMember) ? \MemberModel::findByPk($varMember) : $varMember) === null) { return false; } $varResult = static::addHomeDir($objMember, $strBooleanPropertyName, $strPropertyName, $varRootFolder, $blnOverwrite); if ($varResult === false) { return false; } else { return Files::getPathFromUuid($objMember->{$strPropertyName}); } }
public function deleteScheduledFiles($arrScheduledFiles) { $arrFiles = array(); if (empty($arrScheduledFiles)) { return $arrFiles; } foreach ($arrScheduledFiles as $strUuid) { if (($objFile = Files::getFileFromUuid($strUuid, true)) !== null && $objFile->exists()) { if ($objFile->delete() === true) { $arrFiles[] = $strUuid; } } } }