public function transferAction()
 {
     $fc = FrontController::getInstance();
     $file = new FilesModel();
     $params = $fc->getParams();
     if (preg_match("/^[a-zA-Z0-9_]+(_[\\d]+s|).txt\$/", $params['filename'])) {
         $file->getDataFromFile($params['filename']);
         $file->connectToDb();
         $file->putDataToDatabase();
         $file->getStatus();
     }
 }
 /**
  * Update FileTree fields
  */
 public function updateFileTreeFields()
 {
     $objDatabase = \Database::getInstance();
     $arrFields = array('singleSRC', 'imgSRC');
     // Check the column type
     $objDesc = $objDatabase->query("DESC tl_downloadarchiveitems singleSRC");
     // Change the column type
     if ($objDesc->Type != 'binary(16)') {
         foreach ($arrFields as $field) {
             $objFiles = $objDatabase->execute("SELECT id,{$field} FROM tl_downloadarchiveitems");
             $objDatabase->query("ALTER TABLE tl_downloadarchiveitems CHANGE {$field} {$field} binary(16) NULL");
             #$objDatabase->query("UPDATE tl_downloadarchiveitems SET $field=NULL WHERE $field='' OR $field=0");
             while ($objFiles->next()) {
                 $objHelper = $this->generateHelperObject($this->changePath($objFiles->{$field}));
                 // UUID already
                 if ($objHelper->isUuid) {
                     continue;
                 }
                 // Numeric ID to UUID
                 if ($objHelper->isNumeric) {
                     $objFile = \FilesModel::findByPk($objHelper->value);
                     $objDatabase->prepare("UPDATE tl_downloadarchiveitems SET {$field}=? WHERE id=?")->execute($objFile->uuid, $objFiles->id);
                 } else {
                     $objFile = \FilesModel::findByPath($objHelper->value);
                     $objDatabase->prepare("UPDATE tl_downloadarchiveitems SET {$field}=? WHERE id=?")->execute($objFile->uuid, $objFiles->id);
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * Collect all Songs per Playlist and return them as array
  * 
  * @param object $objSongs
  * @return array
  */
 public function getFiles($objSongs)
 {
     $arrFiles = array();
     $i = 0;
     if ($objSongs === null) {
         return;
     }
     while ($objSongs->next()) {
         $arrSong = $objSongs->row();
         $arrFiles[$i]['protected'] = $arrSong['protected'];
         $arrFiles[$i]['groups'] = $arrSong['groups'];
         $arrFiles[$i]['id'] = $arrSong['id'];
         $arrFiles[$i]['interpreter'] = $arrSong['interpreter'];
         $arrFiles[$i]['title'] = $arrSong['title'];
         $arrFiles[$i]['album'] = $arrSong['album'];
         $arrFiles[$i]['track'] = $arrSong['track'];
         $arrFiles[$i]['files'] = array();
         $arrUuids = deserialize($arrSong['file']);
         $objSongFiles = \FilesModel::findMultipleByUuids($arrUuids);
         while ($objSongFiles->next()) {
             $arrSongFile = $objSongFiles->row();
             $objFile = new \Contao\File($arrSongFile['path'], true);
             $arrFiles[$i]['files'][] = array('file' => $arrSongFile['path'], 'type' => $objFile->mime);
         }
         $i++;
     }
     // sort out protected songs
     $arrFiles = $this->sortOutProtected($arrFiles);
     return $arrFiles;
 }
 /**
  * Generate sprite from given data
  */
 public function generateSprite(\DataContainer $row)
 {
     // Get the theme meta data
     $objTheme = $this->Database->prepare("SELECT * FROM tl_theme WHERE id=?")->execute($row->id);
     if ($objTheme->numRows < 1) {
         return;
     }
     if ($objTheme->spritegen_enable != false) {
         // Replace the numeric folder IDs
         $objInputFolder = FilesModel::findByPk($objTheme->spritegen_source);
         $objOutputFolder = FilesModel::findByPk($objTheme->spritegen_output_folder);
         if ($objInputFolder !== null) {
             // Provide settings for SpriteGen()
             $cssSprites = new \SpriteGen();
             $cssSprites->addImageFolder(TL_ROOT . '/' . $objInputFolder->path);
             $cssSprites->setOutputFolder(TL_ROOT . '/' . $objOutputFolder->path);
             $cssSprites->setCacheTime(0);
             $cssSprites->useDatabase($objTheme->spritegen_modify_selectors, unserialize($objTheme->spritegen_selectors));
             // Generate Sprite
             $cssSprites->generateSprite($objTheme->spritegen_output_file, $objTheme->id, true, $objTheme->spritegen_direction, $objTheme->spritegen_output_width);
             // Display success confirmation
             \Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['spritegen_successful']);
             $this->log('Generated image and style sheet for sprite ' . $objTheme->spritegen_output_file, __METHOD__, CRON);
         }
     }
 }
Example #5
0
 /**
  * Generate the widget and return it as string
  *
  * @return string
  */
 public function generate()
 {
     global $objPage;
     if ($objPage->outputFormat == 'html5') {
         $blnIsHtml5 = true;
     }
     $blnSwitchOrder = (bool) $this->efgSwitchButtonOrder;
     $strButtonBack = '';
     $strButtonSubmit = '';
     if ($this->efgAddBackButton && ($this->formTotalPages > 1 && $this->formActivePage > 1 || TL_MODE == 'BE')) {
         if ($this->efgBackImageSubmit && $this->efgBackSingleSRC != '') {
             $objFileModel = \FilesModel::findById($this->efgBackSingleSRC);
             $strButtonBack .= sprintf('<input type="image"%s src="%s" id="ctrl_%s_back" class="submit back%s" alt="%s" title="%s" value="%s"%s%s', $this->formActivePage ? ' name="FORM_BACK"' : '', $objFileModel->path, $this->strId, strlen($this->strClass) ? ' ' . $this->strClass : '', specialchars($this->efgBackSlabel), specialchars($this->efgBackSlabel), specialchars('submit_back'), $this->getAttributes(), $this->strTagEnding);
         } else {
             $strButtonBack .= sprintf('<input type="submit"%s id="ctrl_%s_back" class="submit back%s" value="%s"%s%s', $this->formActivePage ? ' name="FORM_BACK"' : '', $this->strId, strlen($this->strClass) ? ' ' . $this->strClass : '', specialchars($this->efgBackSlabel), $this->getAttributes(), $this->strTagEnding);
         }
     }
     if ($this->imageSubmit && $this->singleSRC != '') {
         $objFileModel = \FilesModel::findById($this->singleSRC);
         $strButtonSubmit .= sprintf('<input type="image"%s src="%s" id="ctrl_%s" class="submit next%s" alt="%s" title="%s" value="%s"%s%s', $this->formActivePage ? ' name="FORM_NEXT"' : '', $objFileModel->path, $this->strId, strlen($this->strClass) ? ' ' . $this->strClass : '', specialchars($this->slabel), specialchars($this->slabel), specialchars('submit_next'), $this->getAttributes(), $this->strTagEnding);
     } else {
         $strButtonSubmit .= sprintf('<input type="submit"%s id="ctrl_%s" class="submit next%s" value="%s"%s%s', $this->formActivePage ? ' name="FORM_NEXT"' : '', $this->strId, strlen($this->strClass) ? ' ' . $this->strClass : '', specialchars($this->slabel), $this->getAttributes(), $this->strTagEnding);
     }
     return $blnSwitchOrder ? $strButtonSubmit . $strButtonBack : $strButtonBack . $strButtonSubmit;
 }
 /**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Clean RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \StringUtil::toXhtml($this->text);
     } else {
         $this->text = \StringUtil::toHtml5($this->text);
     }
     $this->Template->text = \StringUtil::encodeEmail($this->text);
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($this->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($this->singleSRC)) {
                 $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             $this->singleSRC = $objModel->path;
             $this->addImageToTemplate($this->Template, $this->arrData);
         }
     }
     $classes = deserialize($this->mooClasses);
     $this->Template->toggler = $classes[0] ?: 'toggler';
     $this->Template->accordion = $classes[1] ?: 'accordion';
     $this->Template->headlineStyle = $this->mooStyle;
     $this->Template->headline = $this->mooHeadline;
 }
Example #7
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->Template->size = '';
     // Set the size
     if ($this->playerSize != '') {
         $size = deserialize($this->playerSize);
         if (is_array($size)) {
             $this->Template->size = ' width="' . $size[0] . 'px" height="' . $size[1] . 'px"';
         }
     }
     $this->Template->poster = false;
     // Optional poster
     if ($this->posterSRC != '') {
         if (($objFile = \FilesModel::findByPk($this->posterSRC)) !== null) {
             $this->Template->poster = $objFile->path;
         }
     }
     // Pre-sort the array by preference
     if (in_array($this->objFiles->extension, array('mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv'))) {
         $this->Template->isVideo = true;
         $arrFiles = array('mp4' => null, 'm4v' => null, 'mov' => null, 'wmv' => null, 'webm' => null, 'ogv' => null);
     } else {
         $this->Template->isVideo = false;
         $arrFiles = array('m4a' => null, 'mp3' => null, 'wma' => null, 'mpeg' => null, 'wav' => null);
     }
     $this->objFiles->reset();
     // Pass File objects to the template
     while ($this->objFiles->next()) {
         $objFile = new \File($this->objFiles->path);
         $arrFiles[$objFile->extension] = $objFile;
     }
     $this->Template->files = array_values(array_filter($arrFiles));
     $this->Template->autoplay = $this->autoplay;
 }
Example #8
0
 public function cb_parseTemplate(\Template &$objTemplate)
 {
     global $objPage;
     if (strpos($objTemplate->getName(), 'news_') === 0) {
         if ($objTemplate->source == 'singlefile') {
             $modelFile = \FilesModel::findByUuid($objTemplate->singlefileSRC);
             try {
                 if ($modelFile === null) {
                     throw new \Exception("no file");
                 }
                 $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
                 if (!in_array($modelFile->extension, $allowedDownload)) {
                     throw new Exception("download not allowed by extension");
                 }
                 $objFile = new \File($modelFile->path, true);
                 $strHref = \System::urlEncode($objFile->value);
             } catch (\Exception $e) {
                 $strHref = "";
             }
             $target = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"';
             $objTemplate->more = sprintf('<a %s href="%s" title="%s">%s</a>', $target, $strHref, specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['open'], $objFile->basename)), $GLOBALS['TL_LANG']['MSC']['more']);
             $objTemplate->linkHeadline = sprintf('<a %s href="%s" title="%s">%s</a>', $target, $strHref, specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['open'], $objFile->basename)), $objTemplate->headline);
         }
     }
 }
Example #9
0
 /**
  * Get the label for a form value to store in lead table.
  *
  * @param mixed $varValue
  * @param \Database\Result $objField
  *
  * @return mixed
  */
 public static function prepareLabel($varValue, $objField)
 {
     // Run for all values in an array
     if (is_array($varValue)) {
         foreach ($varValue as $k => $v) {
             $varValue[$k] = self::prepareLabel($v, $objField);
         }
         return $varValue;
     }
     // File upload
     if ($objField->type == 'upload') {
         $objFile = \FilesModel::findByUuid($varValue);
         if ($objFile !== null) {
             return $objFile->path;
         }
     }
     // Convert timestamps into date format
     if ($varValue != '' && in_array($objField->rgxp, array('date', 'time', 'datim'))) {
         $varValue = \Date::parse($GLOBALS['TL_CONFIG'][$objField->rgxp . 'Format'], $varValue);
     }
     if ($objField->options != '') {
         $arrOptions = deserialize($objField->options, true);
         foreach ($arrOptions as $arrOption) {
             if ($arrOption['value'] == $varValue && $arrOption['label'] != '') {
                 $varValue = $arrOption['label'];
             }
         }
     }
     return $varValue;
 }
 public function getPictureFromDB($strTable, $strColumn, $strWhereParam, $strObjID)
 {
     $query = "SELECT " . $strColumn . " FROM " . $strTable . "WHERE " . $strWhereParam . "=?";
     $objPicture = $this->Database->prepare($query)->execute($strObjID);
     $objFile = \FilesModel::findByUuid($objPicture->{$strColumn});
     return $objFile->path;
 }
Example #11
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->Template->size = '';
     // Set the size
     if ($this->playerSize != '') {
         $size = deserialize($this->playerSize);
         if (is_array($size)) {
             $this->Template->size = ' width="' . $size[0] . '" height="' . $size[1] . '"';
         }
     }
     $this->Template->poster = false;
     // Optional poster
     if ($this->posterSRC != '') {
         if (($objFile = \FilesModel::findByUuid($this->posterSRC)) !== null) {
             $this->Template->poster = $objFile->path;
         }
     }
     // Check for SSL (see #6900)
     $protocol = \Environment::get('ssl') ? 'https://' : 'http://';
     $objFile = new \stdClass();
     $objFile->mime = 'video/x-youtube';
     $objFile->path = $protocol . 'www.youtube.com/watch?v=' . $this->youtube;
     $this->Template->isVideo = true;
     $this->Template->files = array($objFile);
     $this->Template->autoplay = $this->autoplay;
 }
 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!');
 }
Example #13
0
 public function actionPreviewPage($id)
 {
     $file = FilesModel::getFile($id);
     if (!$file) {
         throw new BadRequestException("File not found", 404);
     }
     if (!$this->triggerEvent('allowFileDownload', $file)) {
         throw new BadRequestException("File download forbidden", 403);
     }
     $this->template->file = $file;
     $this->setLayout(false);
     //experimental for documentFile
     $xml = substr($file->info, 5);
     $sxml = simplexml_load_string($xml);
     //TODO proč nefunguje vždy?
     $pages = array();
     if ($sxml && $sxml->page) {
         foreach ($sxml->page as $p) {
             $page = array($p, array());
             foreach ($p->block as $b) {
                 foreach ($b->text as $t) {
                     $page[1][] = $t;
                 }
             }
             $pages[] = $page;
         }
     }
     $this->template->pdf2xml = $pages;
 }
Example #14
0
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new FilesModel();
     }
     return self::$instance;
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     $intList = $this->athletes_group;
     $objMembers = $this->Database->prepare("SELECT * FROM tl_athlete WHERE published=1 AND pid=? ORDER BY sorting")->execute($intList);
     //$objMembers = \MembersModel;
     // Return if no Members were found
     if (!$objMembers->numRows) {
         return;
     }
     $strLink = '';
     // Generate a jumpTo link
     if ($this->jumpTo > 0) {
         $objJump = \PageModel::findByPk($this->jumpTo);
         if ($objJump !== null) {
             $strLink = $this->generateFrontendUrl($objJump->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/items/%s');
         }
     }
     $arrMembers = array();
     // Generate Members
     while ($objMembers->next()) {
         $strPhoto = '';
         $objPhoto = \FilesModel::findByPk($objMembers->photo);
         // Add photo image
         if ($objPhoto !== null) {
             $strPhoto = \Image::getHtml(\Image::get($objPhoto->path, '140', '187', 'center_center'));
         }
         $arrMembers[] = array('name' => $objMembers->name, 'family' => $objMembers->family, 'post' => $objMembers->post, 'joined' => $objMembers->joined, 'photo' => $strPhoto, 'link' => strlen($strLink) ? sprintf($strLink, $objMembers->alias) : '');
     }
     $this->Template->members = $arrMembers;
 }
 public function storeFileMetaInformation($varValue, DataContainer $dc)
 {
     if ($dc->activeRecord->singleSRC == $varValue) {
         return $varValue;
     }
     $objFile = FilesModel::findByUuid($varValue);
     if ($objFile !== null) {
         $arrMeta = deserialize($objFile->meta);
         if (!empty($arrMeta)) {
             $objPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=(SELECT pid FROM " . ($dc->activeRecord->ptable ?: 'tl_article') . " WHERE id=?)")->execute($dc->activeRecord->pid);
             if ($objPage->numRows) {
                 $objModel = new PageModel();
                 $objModel->setRow($objPage->row());
                 $objModel->loadDetails();
                 // Convert the language to a locale (see #5678)
                 $strLanguage = str_replace('-', '_', $objModel->rootLanguage);
                 if (isset($arrMeta[$strLanguage])) {
                     Input::setPost('alt', $arrMeta[$strLanguage]['title']);
                     Input::setPost('caption', $arrMeta[$strLanguage]['caption']);
                 }
             }
         }
     }
     return $varValue;
 }
Example #17
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     global $objPage;
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \String::toXhtml($this->text);
     } else {
         $this->text = \String::toHtml5($this->text);
     }
     // Add the static files URL to images
     if (TL_FILES_URL != '') {
         $path = $GLOBALS['TL_CONFIG']['uploadPath'] . '/';
         $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text);
     }
     $this->Template->text = \String::encodeEmail($this->text);
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         if (!is_numeric($this->singleSRC)) {
             $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
         } else {
             $objModel = \FilesModel::findByPk($this->singleSRC);
             if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                 $this->singleSRC = $objModel->path;
                 $this->addImageToTemplate($this->Template, $this->arrData);
             }
         }
     }
 }
Example #18
0
 /**
  * Return if the file does not exist
  * @return string
  */
 public function generate()
 {
     // Return if there is no file
     if ($this->singleSRC == '') {
         return '';
     }
     // Check for version 3 format
     if (!is_numeric($this->singleSRC)) {
         return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
     }
     $objFile = \FilesModel::findByPk($this->singleSRC);
     if ($objFile === null) {
         return '';
     }
     $allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
     // Return if the file type is not allowed
     if (!in_array($objFile->extension, $allowedDownload)) {
         return '';
     }
     $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) {
         $this->sendFileToBrowser($file);
     }
     $this->singleSRC = $objFile->path;
     return parent::generate();
 }
Example #19
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     // Clean the RTE output
     if ($objPage->outputFormat == 'xhtml') {
         $this->text = \StringUtil::toXhtml($this->text);
     } else {
         $this->text = \StringUtil::toHtml5($this->text);
     }
     // Add the static files URL to images
     if (TL_FILES_URL != '') {
         $path = \Config::get('uploadPath') . '/';
         $this->text = str_replace(' src="' . $path, ' src="' . TL_FILES_URL . $path, $this->text);
     }
     $this->Template->text = \StringUtil::encodeEmail($this->text);
     $this->Template->addImage = false;
     // Add an image
     if ($this->addImage && $this->singleSRC != '') {
         $objModel = \FilesModel::findByUuid($this->singleSRC);
         if ($objModel === null) {
             if (!\Validator::isUuid($this->singleSRC)) {
                 $this->Template->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             }
         } elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
             $this->singleSRC = $objModel->path;
             $this->addImageToTemplate($this->Template, $this->arrData);
         }
     }
 }
 protected function updateFileField($table)
 {
     $database = \Database::getInstance();
     if (!$database->tableExists($table)) {
         return;
     }
     if ($database->fieldExists('file', $table)) {
         // get the field description
         $desc = $database->query('DESC ' . $table . ' file');
         // convert the field into a blob
         if ($desc->Type != 'blob') {
             $database->query('ALTER TABLE `' . $table . '` CHANGE `file` `file` blob NULL');
             $database->query('UPDATE `' . $table . '` SET `file`=NULL WHERE `file`=\'\' OR `file`=0');
         }
         // select fields with numeric values
         $resultSet = $database->query('SELECT id, file FROM ' . $table . ' WHERE file REGEXP \'^[0-9]+$\'');
         while ($resultSet->next()) {
             // Numeric ID to UUID
             $file = \FilesModel::findByPk($resultSet->file);
             if ($file) {
                 $database->prepare('UPDATE `' . $table . '` SET file=? WHERE id=?')->execute($file->uuid, $resultSet->id);
             }
         }
     }
 }
 /**
  * Parse the icon and prepare it for the Template
  * @param array
  * @return array
  */
 protected function parseIcon($icon)
 {
     $arrIcon = array();
     //Check for image
     if ($icon['iconfile'] != '') {
         $objFile = \FilesModel::findByUuid($icon['iconfile']);
         if ($objFile != null) {
             if (is_file(TL_ROOT . '/' . $objFile->path)) {
                 $arrIcon['hasImage'] = true;
                 $arrIcon['img'] = $objFile->path;
             }
         }
     }
     //Add Foundation icon class
     if (!$arrIcon['hasImage'] && $icon['iconclass'] != '') {
         $arrIcon['iconclass'] = 'fi-' . $icon['iconclass'];
     }
     if ($icon['iconclass_custom'] != '') {
         $arrIcon['class'] .= ' ' . $icon['iconclass_custom'];
     }
     if ($icon['icon_label'] != '') {
         $arrIcon['label'] .= $icon['icon_label'];
     }
     $arrIcon['href'] = $icon['icon_href'];
     return $arrIcon;
 }
Example #22
0
 /**
  * Return if the file does not exist
  *
  * @return string
  */
 public function generate()
 {
     // Return if there is no file
     if ($this->singleSRC == '') {
         return '';
     }
     $objFile = \FilesModel::findByUuid($this->singleSRC);
     if ($objFile === null) {
         if (!\Validator::isUuid($this->singleSRC)) {
             return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
         }
         return '';
     }
     $allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload')));
     // Return if the file type is not allowed
     if (!in_array($objFile->extension, $allowedDownload)) {
         return '';
     }
     $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->singleSRC = $objFile->path;
     return parent::generate();
 }
Example #23
0
 /**
  * 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();
 }
Example #24
0
 /**
  * @deprecated
  */
 public static function loadStoreDetails(array $arrStore, $jumpTo = null)
 {
     //load country names
     //@todo load only once. not every time.
     $arrCountryNames = \System::getCountries();
     //full localized country name
     //@todo rename country to countrycode in database
     $arrStore['countrycode'] = $arrStore['country'];
     $arrStore['country'] = $arrCountryNames[$arrStore['countrycode']];
     // generate jump to
     if ($jumpTo) {
         if (($objLocation = \PageModel::findByPk($jumpTo)) !== null) {
             //@todo language parameter
             $strStoreKey = !$GLOBALS['TL_CONFIG']['useAutoItem'] ? '/store/' : '/';
             $strStoreValue = $arrStore['alias'];
             $arrStore['href'] = \Controller::generateFrontendUrl($objLocation->row(), $strStoreKey . $strStoreValue);
         }
     }
     // opening times
     $arrStore['opening_times'] = deserialize($arrStore['opening_times']);
     // store logo
     //@todo change size and properties in module
     if ($arrStore['logo']) {
         if (($objLogo = \FilesModel::findByUuid($arrStore['logo'])) !== null) {
             $arrLogo = $objLogo->row();
             $arrMeta = deserialize($arrLogo['meta']);
             $arrLogo['meta'] = $arrMeta[$GLOBALS['TL_LANGUAGE']];
             $arrStore['logo'] = $arrLogo;
         } else {
             $arrStore['logo'] = null;
         }
     }
     return $arrStore;
 }
 /**
  * @return string
  */
 public function generate()
 {
     if (TL_MODE === 'BE') {
         $template = new \BackendTemplate('be_wildcard');
         $template->wildcard = '### ANTRAGO Event-Details ###';
         $template->title = 'Event Details';
         //"Kategorien: " . implode(', ',deserialize($this->arrData['ac_categories']));
         return $template->parse();
     }
     // hole event details;
     $url = $_SERVER["REQUEST_URI"];
     $id = explode("veranstaltung=", $url)[1];
     $this->configuration = AntragoConnector::getAntragoConfiguration($this->arrData['ac_event_details_config']);
     $db = \Database::getInstance();
     $this->product = $db->prepare("SELECT * FROM tl_antrago_products WHERE productId=?")->execute($id)->fetchAssoc();
     $this->formConfig = array('showRegisterForm' => $this->arrData['ac_event_details_show_register'], 'showApplicationForm' => $this->arrData['ac_event_details_show_applicationform']);
     // contact
     $this->contact = $db->prepare("SELECT * FROM tl_antrago_contacts WHERE id =?")->execute($this->product['productContact'])->fetchAssoc();
     $oContactImage = \FilesModel::findByPk($this->contact['image']);
     // Add cover image
     if ($oContactImage !== null) {
         $sImage = \Image::get($oContactImage->path, '80', '100', 'center_center');
     }
     $this->contact['image'] = $sImage;
     return parent::generate();
 }
Example #26
0
 /**
  * Run the controller
  */
 public function run()
 {
     $strFile = \Input::get('file', true);
     if ($strFile != '') {
         // Make sure there are no attempts to hack the file system
         if (preg_match('@^\\.+@i', $strFile) || preg_match('@\\.+/@i', $strFile) || preg_match('@(://)+@i', $strFile)) {
             header('HTTP/1.1 404 Not Found');
             die('Invalid file name');
         }
         // Limit downloads to the files directory
         if (!preg_match('@^' . preg_quote(\Config::get('uploadPath'), '@') . '@i', $strFile)) {
             header('HTTP/1.1 404 Not Found');
             die('Invalid path');
         }
         // Check whether the file exists
         if (!is_file(TL_ROOT . '/' . $strFile)) {
             header('HTTP/1.1 404 Not Found');
             die('File not found');
         }
         // find the path in the database
         if (($objFile = \FilesModel::findOneByPath($strFile)) !== null) {
             // authenticate the frontend user
             \FrontendUser::getInstance()->authenticate();
             // check if file is protected
             if (!\Controller::isVisibleElement($objFile)) {
                 $objHandler = new $GLOBALS['TL_PTY']['error_403']();
                 $objHandler->generate($strFile);
             } elseif ($objFile->pid) {
                 // check if parent folders are proteced
                 do {
                     $objFile = \FilesModel::findById($objFile->pid);
                     if (!\Controller::isVisibleElement($objFile)) {
                         $objHandler = new $GLOBALS['TL_PTY']['error_403']();
                         $objHandler->generate($strFile);
                     }
                 } while ($objFile->pid);
             }
         }
         // get the file
         $objFile = new \File($strFile);
         // Make sure no output buffer is active
         // @see http://ch2.php.net/manual/en/function.fpassthru.php#74080
         while (@ob_end_clean()) {
         }
         // Prevent session locking (see #2804)
         session_write_close();
         // Disable zlib.output_compression (see #6717)
         @ini_set('zlib.output_compression', 'Off');
         // Set headers
         header('Content-Type: ' . $objFile->mime);
         header('Content-Length: ' . $objFile->filesize);
         // Disable maximum execution time
         @ini_set('max_execution_time', 0);
         // Output the file
         readfile(TL_ROOT . '/' . $objFile->path);
     }
     // Stop the script (see #4565)
     exit;
 }
Example #27
0
 public function generateActRow($arrRow)
 {
     $objImage = \FilesModel::findByPk($arrRow['singleSRC']);
     if ($objImage !== null) {
         $strImage = \Image::getHtml(\Image::get($objImage->path, '25', '33', 'center_center'));
     }
     return '<div><div style="float:left; margin-right:10px;">' . $strImage . '</div>' . $arrRow['title'] . ' <br /><span style="padding-left:3px;color:#b3b3b3;">[' . $arrRow['post'] . ']</span></div>';
 }
 /**
  * Transforms a value from the transformed representation to its original
  * representation.
  * An example might be transforming a human readable date format to a unix timestamp.
  *
  * @param mixed $value The value in the transformed representation
  *
  * @return mixed The value in the original representation
  *
  * @throws TransformationFailedException When the transformation fails.
  */
 public function reverseTransform($value)
 {
     $filesModel = \FilesModel::findByPath($value);
     if (null === $filesModel) {
         return $value;
     }
     return $filesModel->uuid;
 }
 /**
  * Generate a song row and return it as HTML string
  * @param array
  * @return string
  */
 public function generateItemRow($arrRow)
 {
     $objImage = \FilesModel::findByPk($arrRow['singleSRC']);
     if ($objImage !== null) {
         $strImage = \Image::getHtml(\Image::get($objImage->path, '30', '30', 'center_center'));
     }
     return '<div><div style="float:left; margin-right:10px;">' . $strImage . '</div>' . $arrRow['title'] . '</div>';
 }
Example #30
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $objFaq = \FaqModel::findPublishedByPids($this->faq_categories);
     if ($objFaq === null) {
         $this->Template->faq = array();
         return;
     }
     global $objPage;
     $arrFaq = array_fill_keys($this->faq_categories, array());
     // Add FAQs
     while ($objFaq->next()) {
         $objTemp = (object) $objFaq->row();
         // Clean RTE output
         if ($objPage->outputFormat == 'xhtml') {
             $objFaq->answer = \String::toXhtml($objFaq->answer);
         } else {
             $objFaq->answer = \String::toHtml5($objFaq->answer);
         }
         $objTemp->answer = \String::encodeEmail($objFaq->answer);
         $objTemp->addImage = false;
         // Add an image
         if ($objFaq->addImage && $objFaq->singleSRC != '') {
             if (!is_numeric($objFaq->singleSRC)) {
                 $objTemp->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
             } else {
                 $objModel = \FilesModel::findByPk($objFaq->singleSRC);
                 if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                     $objFaq->singleSRC = $objModel->path;
                     $this->addImageToTemplate($objTemp, $objFaq->row());
                 }
             }
         }
         $objTemp->enclosure = array();
         // Add enclosure
         if ($objFaq->addEnclosure) {
             $this->addEnclosuresToTemplate($objTemp, $objFaq->row());
         }
         $objTemp->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], $this->parseDate($objPage->dateFormat, $objFaq->tstamp), $objFaq->getRelated('author')->name);
         // Order by PID
         $arrFaq[$objFaq->pid]['items'][] = $objTemp;
         $arrFaq[$objFaq->pid]['headline'] = $objFaq->category;
     }
     $arrFaq = array_values(array_filter($arrFaq));
     $limit_i = count($arrFaq) - 1;
     // Add classes first, last, even and odd
     for ($i = 0; $i <= $limit_i; $i++) {
         $class = ($i == 0 ? 'first ' : '') . ($i == $limit_i ? 'last ' : '') . ($i % 2 == 0 ? 'even' : 'odd');
         $arrFaq[$i]['class'] = trim($class);
         $limit_j = count($arrFaq[$i]['items']) - 1;
         for ($j = 0; $j <= $limit_j; $j++) {
             $class = ($j == 0 ? 'first ' : '') . ($j == $limit_j ? 'last ' : '') . ($j % 2 == 0 ? 'even' : 'odd');
             $arrFaq[$i]['items'][$j]->class = trim($class);
         }
     }
     $this->Template->faq = $arrFaq;
     $this->Template->request = $this->getIndexFreeRequest(true);
     $this->Template->topLink = $GLOBALS['TL_LANG']['MSC']['backToTop'];
 }