Пример #1
0
 /**
  * @return void
  */
 public function initializeAction()
 {
     $this->fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
     $this->contentObj = $this->configurationManager->getContentObject();
     $this->data = $this->contentObj->data;
     $this->data['image'] = $this->fileRepository->findByRelation('tt_content', 'image', $this->data['uid']);
     $this->data['imagesvg'] = $this->fileRepository->findByRelation('tt_content', 'imagesvg', $this->data['uid']);
 }
Пример #2
0
 /**
  * Find FileReference objects by relation to other records
  *
  * @param int $uid The UID of the related record (needs to be the localized uid, as translated IRRE elements relate to them)
  * @param string $as The alias to use for the found files
  * @param string $tableName Table name of the related record
  * @param string $fieldName Field name of the related record
  *
  * @return string The render template
  */
 public function render($uid, $as = 'objects', $tableName = 'tt_content', $fieldName = 'image')
 {
     $filesFromRepository = $this->fileRepository->findByRelation($tableName, $fieldName, $uid);
     $this->templateVariableContainer->add($as, $filesFromRepository);
     $content = $this->renderChildren();
     $this->templateVariableContainer->remove($as);
     return $content;
 }
 /**
  * @param array $data
  * @param string $as
  * @param string $table
  * @param string $field
  *
  * @return string
  */
 public function render($data, $as = "items", $table = "tt_content", $field = "image")
 {
     if (is_array($data) && $data['uid'] && $data[$field]) {
         $this->fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
         $items = $this->fileRepository->findByRelation($table, $field, $data['uid']);
     } else {
         $items = null;
     }
     $this->templateVariableContainer->add($as, $items);
     $content = $this->renderChildren();
     $this->templateVariableContainer->remove($as);
     return $content;
 }
 /**
  * @param int $uid
  * @param int $cField
  * @param string $as
  * @param string $table
  * @param string $field
  *
  * @return string
  */
 public function render($uid, $cField, $as = 'items', $table = 'tt_content', $field = 'image')
 {
     #\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(array("FalViewHelper"=>array( "uid"=>$uid,  "cField"=>$cField)));
     if ($uid && $cField) {
         $this->fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
         $items = $this->fileRepository->findByRelation($table, $field, $uid);
         #\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(array("FalViewHelper"=>array( "uid"=>$uid,  "cField"=>$cField, "items"=>$items)));
     } else {
         $items = NULL;
     }
     $this->templateVariableContainer->add($as, $items);
     $content = $this->renderChildren();
     $this->templateVariableContainer->remove($as);
     return $content;
 }
 /**
  * action topdownloads
  * shows a list of the top downloads
  *
  * @return void
  */
 public function topdownloadsAction()
 {
     // check if there is a file download request
     $this->checkFileDownloadRequest();
     // include default config
     $this->view->assign('config', $this->defaultTsConfig);
     // remove old and deleted files
     $this->cleanupTopDownloads();
     if (isset($this->settings['topdnum']) && (int) $this->settings['topdnum'] > 0) {
         $files = $this->downloadRepository->findTopDownloadList((int) $this->settings['topdnum']);
     } else {
         $files = $this->downloadRepository->findTopDownloadList();
     }
     $filesArray = array();
     $index = 1;
     if (is_object($files)) {
         foreach ($files as $f) {
             $file = $this->fileRepository->findByUid($f->getSysFileUid());
             if (is_object($file) && !is_null($file)) {
                 $file->getContents();
                 $filesArray[$index] = $file;
                 $index++;
             }
         }
     }
     //DebuggerUtility::var_dump($filesArray);
     $this->view->assign('files', $filesArray);
 }
Пример #6
0
 /**
  * Processes the actual transformation from CSV to sys_file_references
  *
  * @param array $record
  * @param string $field
  * @return void
  */
 protected function migrateRecord(array $record, $field)
 {
     if ($field === 'fal_related_files') {
         $file = $record['file'];
     } else {
         $file = $record['image'];
     }
     if (!empty($file) && file_exists(PATH_site . 'uploads/tx_news/' . $file)) {
         GeneralUtility::upload_copy_move(PATH_site . 'uploads/tx_news/' . $file, $this->targetDirectory . $file);
         $fileObject = $this->storage->getFile(self::FOLDER_ContentUploads . '/' . $file);
         $this->fileRepository->add($fileObject);
         $dataArray = ['uid_local' => $fileObject->getUid(), 'tablenames' => 'tx_news_domain_model_news', 'fieldname' => $field, 'uid_foreign' => $record['newsUid'], 'table_local' => 'sys_file', 'cruser_id' => 999, 'pid' => $record['newsPid'], 'sorting_foreign' => $record['sorting'], 'title' => $record['title'], 'hidden' => $record['hidden']];
         if ($field === 'fal_media') {
             $description = [];
             if (!empty($record['caption'])) {
                 $description[] = $record['caption'];
             }
             if (!empty($record['description'])) {
                 $description[] = $record['description'];
             }
             $additionalData = ['description' => implode(LF . LF, $description), 'alternative' => $record['alt'], 'showinpreview' => $record['showinpreview']];
         } else {
             $additionalData = ['description' => $record['description']];
         }
         $dataArray += $additionalData;
         $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_reference', $dataArray);
     }
 }
    /**
     * Processes the actual transformation from CSV to sys_file_references
     *
     * @param array $record
     * @return void
     */
    protected function migrateRecord(array $record)
    {
        $collections = array();
        if (trim($record['select_key'])) {
            $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_collection', array('pid' => $record['pid'], 'title' => $record['select_key'], 'storage' => $this->storage->getUid(), 'folder' => ltrim('fileadmin/', $record['select_key'])));
            $collections[] = $GLOBALS['TYPO3_DB']->sql_insert_id();
        }
        $files = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $record['media'], TRUE);
        $descriptions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('
', $record['imagecaption']);
        $titleText = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('
', $record['titleText']);
        $i = 0;
        foreach ($files as $file) {
            if (file_exists(PATH_site . 'uploads/media/' . $file)) {
                \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move(PATH_site . 'uploads/media/' . $file, $this->targetDirectory . $file);
                $fileObject = $this->storage->getFile(self::FOLDER_ContentUploads . '/' . $file);
                $this->fileRepository->addToIndex($fileObject);
                $dataArray = array('uid_local' => $fileObject->getUid(), 'tablenames' => 'tt_content', 'uid_foreign' => $record['uid'], 'fieldname' => 'media', 'sorting_foreign' => $i);
                if (isset($descriptions[$i])) {
                    $dataArray['description'] = $descriptions[$i];
                }
                if (isset($titleText[$i])) {
                    $dataArray['alternative'] = $titleText[$i];
                }
                $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_reference', $dataArray);
                unlink(PATH_site . 'uploads/media/' . $file);
            }
            $i++;
        }
        $this->cleanRecord($record, $i, $collections);
    }
Пример #8
0
 /**
  * Renames the fileName in this particular usage.
  *
  * @param string $newName The new name
  * @return \TYPO3\CMS\Core\Resource\FileReference
  */
 public function rename($newName)
 {
     // TODO: Implement this function. This should only rename the
     // FileReference (sys_file_reference) record, not the file itself.
     throw new \BadMethodCallException('Function not implemented FileReference::rename().', 1333754473);
     return $this->fileRepository->renameUsageRecord($this, $newName);
 }
 /**
  * Base view
  */
 public function indexAction()
 {
     if (!$this->settings['file']) {
         throw new \Exception('You have to select a valid FAL reference file', 12372183723.0);
     }
     $images = $this->fileRepository->findByRelation('tt_content', 'pdf', $this->configurationManager->getContentObject()->data['uid']);
     if (!sizeof($images)) {
         throw new \Exception('You have to select a valid FAL reference file', 12372183723.0);
     }
     /** @var FileReference $image */
     $image = current($images);
     $width = MathUtility::canBeInterpretedAsInteger($this->settings['width']) ? $this->settings['width'] . 'px' : $this->settings['width'];
     $height = MathUtility::canBeInterpretedAsInteger($this->settings['height']) ? $this->settings['height'] . 'px' : $this->settings['height'];
     $fileUrl = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . '/' . $image->getPublicUrl();
     $this->view->assignMultiple(array('fileUrl' => urlencode($fileUrl), 'language' => $GLOBALS['TSFE']->config['config']['language'], 'width' => $width, 'height' => $height));
 }
 /**
  * Migrate files to sys_file_references
  *
  * @param array $record
  * @param string $field
  * @return void
  */
 protected function migrateFiles(array $record, $field)
 {
     $filesList = $record['tx_jhopengraphprotocol_ogimage'];
     $files = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $filesList, TRUE);
     if ($files) {
         foreach ($files as $file) {
             if (file_exists(PATH_site . 'uploads/tx_jhopengraphprotocol/' . $file)) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move(PATH_site . 'uploads/tx_jhopengraphprotocol/' . $file, $this->targetDirectory . $file);
                 $fileObject = $this->storage->getFile(self::FOLDER_ContentUploads . '/' . $file);
                 $this->fileRepository->add($fileObject);
                 $dataArray = array('uid_local' => $fileObject->getUid(), 'tablenames' => 'pages', 'fieldname' => $field, 'uid_foreign' => $record['uid'], 'table_local' => 'sys_file', 'cruser_id' => self::CruserId, 'pid' => $record['pid'], 'sorting_foreign' => $record['sorting'], 'title' => $record['title']);
                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_reference', $dataArray);
             }
         }
     }
 }
Пример #11
0
    /**
     * For TYPO3 Element Browser: Expand folder of files.
     *
     * @param Folder $folder The folder path to expand
     * @param array $extensionList List of fileextensions to show
     * @param bool $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
     * @return string HTML output
     */
    public function renderFilesInFolder(Folder $folder, array $extensionList = [], $noThumbs = false)
    {
        if (!$folder->checkActionPermission('read')) {
            return '';
        }
        $lang = $this->getLanguageService();
        $titleLen = (int) $this->getBackendUser()->uc['titleLen'];
        if ($this->searchWord !== '') {
            $files = $this->fileRepository->searchByName($folder, $this->searchWord);
        } else {
            $extensionList = !empty($extensionList) && $extensionList[0] === '*' ? [] : $extensionList;
            $files = $this->getFilesInFolder($folder, $extensionList);
        }
        $filesCount = count($files);
        $lines = array();
        // Create the header of current folder:
        $folderIcon = $this->iconFactory->getIconForResource($folder, Icon::SIZE_SMALL);
        $lines[] = '
			<tr>
				<th class="col-title" nowrap="nowrap">' . $folderIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</th>
				<th class="col-control" nowrap="nowrap"></th>
				<th class="col-clipboard" nowrap="nowrap">
					<a href="#" class="btn btn-default" id="t3js-importSelection" title="' . $lang->getLL('importSelection', true) . '">' . $this->iconFactory->getIcon('actions-document-import-t3d', Icon::SIZE_SMALL) . '</a>
					<a href="#" class="btn btn-default" id="t3js-toggleSelection" title="' . $lang->getLL('toggleSelection', true) . '">' . $this->iconFactory->getIcon('actions-document-select', Icon::SIZE_SMALL) . '</a>
				</th>
				<th nowrap="nowrap">&nbsp;</th>
			</tr>';
        if ($filesCount === 0) {
            $lines[] = '
				<tr>
					<td colspan="4">No files found.</td>
				</tr>';
        }
        foreach ($files as $fileObject) {
            $fileExtension = $fileObject->getExtension();
            // Thumbnail/size generation:
            $imgInfo = array();
            if (!$noThumbs && GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] . ',' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']), strtolower($fileExtension))) {
                $processedFile = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => 64, 'height' => 64));
                $imageUrl = $processedFile->getPublicUrl(true);
                $imgInfo = array($fileObject->getProperty('width'), $fileObject->getProperty('height'));
                $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
                $clickIcon = '<img src="' . $imageUrl . '"' . ' width="' . $processedFile->getProperty('width') . '"' . ' height="' . $processedFile->getProperty('height') . '"' . ' hspace="5" vspace="5" border="1" />';
            } else {
                $clickIcon = '';
                $pDim = '';
            }
            // Create file icon:
            $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
            $icon = '<span title="' . htmlspecialchars($fileObject->getName() . $size) . '">' . $this->iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL) . '</span>';
            // Create links for adding the file:
            $filesIndex = count($this->elements);
            $this->elements['file_' . $filesIndex] = array('type' => 'file', 'table' => 'sys_file', 'uid' => $fileObject->getUid(), 'fileName' => $fileObject->getName(), 'filePath' => $fileObject->getUid(), 'fileExt' => $fileExtension, 'fileIcon' => $icon);
            if ($this->fileIsSelectableInFileList($fileObject, $imgInfo)) {
                $ATag = '<a href="#" class="btn btn-default" title="' . htmlspecialchars($fileObject->getName()) . '" data-file-index="' . htmlspecialchars($filesIndex) . '" data-close="0">';
                $ATag_alt = '<a href="#" title="' . htmlspecialchars($fileObject->getName()) . '" data-file-index="' . htmlspecialchars($filesIndex) . '" data-close="1">';
                $ATag_e = '</a>';
                $bulkCheckBox = '<label class="btn btn-default btn-checkbox"><input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /><span class="t3-icon fa"></span></label>';
            } else {
                $ATag = '';
                $ATag_alt = '';
                $ATag_e = '';
                $bulkCheckBox = '';
            }
            // Create link to showing details about the file in a window:
            $Ahref = BackendUtility::getModuleUrl('show_item', array('type' => 'file', 'table' => '_FILE', 'uid' => $fileObject->getCombinedIdentifier(), 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')));
            // Combine the stuff:
            $filenameAndIcon = $ATag_alt . $icon . htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
            // Show element:
            $lines[] = '
					<tr class="file_list_normal">
						<td class="col-title" nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
						<td class="col-control">
							<div class="btn-group">' . $ATag . '<span title="' . $lang->getLL('addToList', true) . '">' . $this->iconFactory->getIcon('actions-edit-add', Icon::SIZE_SMALL)->render() . '</span>' . $ATag_e . '
							<a href="' . htmlspecialchars($Ahref) . '" class="btn btn-default" title="' . $lang->getLL('info', true) . '">' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL) . '</a>
						</td>
						<td class="col-clipboard" valign="top">' . $bulkCheckBox . '</td>
						<td nowrap="nowrap">&nbsp;' . $pDim . '</td>
					</tr>';
            if ($pDim) {
                $lines[] = '
					<tr>
						<td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
					</tr>';
            }
        }
        $out = '<h3>' . $lang->getLL('files', true) . ' ' . $filesCount . ':</h3>';
        $out .= GeneralUtility::makeInstance(FolderUtilityRenderer::class, $this)->getFileSearchField($this->searchWord);
        $out .= '<div id="filelist">';
        $out .= $this->getBulkSelector($filesCount);
        // Wrap all the rows in table tags:
        $out .= '

	<!--
		Filelisting
	-->
			<table class="table table-striped table-hover" id="typo3-filelist">
				' . implode('', $lines) . '
			</table>';
        // Return accumulated content for filelisting:
        $out .= '</div>';
        return $out;
    }
Пример #12
0
 /**
  * Search for files by name and pass them with a facade to fluid
  *
  * @param string $searchWord
  */
 public function searchAction($searchWord = '')
 {
     if (empty($searchWord)) {
         $this->forward('index');
     }
     $fileFacades = [];
     $files = $this->fileRepository->searchByName($this->folderObject, $searchWord);
     if (empty($files)) {
         $this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->addMessage(new FlashMessage(LocalizationUtility::translate('flashmessage.no_results', 'filelist'), '', FlashMessage::INFO));
     } else {
         foreach ($files as $file) {
             $fileFacades[] = new \TYPO3\CMS\Filelist\FileFacade($file);
         }
     }
     $pageRenderer = $this->view->getModuleTemplate()->getPageRenderer();
     $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileList');
     $this->view->assign('searchWord', $searchWord);
     $this->view->assign('files', $fileFacades);
     $this->view->assign('veriCode', $this->getBackendUser()->veriCode());
     $this->view->assign('deleteUrl', BackendUtility::getModuleUrl('tce_file'));
     $this->view->assign('settings', ['jsConfirmationDelete' => $this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)]);
     $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileDelete');
     $pageRenderer->addInlineLanguageLabelFile('EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf', 'buttons');
 }
Пример #13
0
 /**
  * Fetch a fileReference from the file repository
  *
  * @param string $table name of the table to get the file reference for
  * @param string $field name of the field referencing a file
  * @param integer $uid uid of the related record
  * @return array
  */
 protected function getFileReferences($table, $field, $uid)
 {
     $fileObjects = $this->fileRepository->findByRelation($table, $field, $uid);
     return $fileObjects;
 }
Пример #14
0
 /**
  * Test action
  *
  * @plugin Test
  */
 public function testAction()
 {
     $contentElement = $this->configurationManager->getContentObject()->data;
     $fileReferences = $this->fileRepository->findByRelation('tt_content', 'image', $contentElement['uid']);
     $this->view->assignMultiple(array('fileReferences' => $fileReferences, 'customRatio' => $contentElement['image_ratio']));
 }
Пример #15
0
 /**
  * @param \TYPO3\CMS\Core\Resource\FileRepository $fileRepository
  * @param int $pageId
  * @return array
  * @deprecated will be removed if no occurences from nkwsubmenu are found
  */
 protected function getFilesFromNkwMenu($fileRepository, $pageId)
 {
     \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
     return $fileRepository->findByRelation('pages', 'tx_nkwsubmenu_picture', $pageId);
 }
Пример #16
0
 /**
  * Search for files by name and pass them with a facade to fluid
  *
  * @param string $searchWord
  */
 public function searchAction($searchWord = '')
 {
     if (empty($searchWord)) {
         $this->forward('index');
     }
     $fileFacades = [];
     $files = $this->fileRepository->searchByName($this->folderObject, $searchWord);
     if (empty($files)) {
         $this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->addMessage(new FlashMessage(LocalizationUtility::translate('flashmessage.no_results', 'filelist'), '', FlashMessage::INFO));
     } else {
         foreach ($files as $file) {
             $fileFacades[] = new \TYPO3\CMS\Filelist\FileFacade($file);
         }
     }
     $this->view->assign('searchWord', $searchWord);
     $this->view->assign('files', $fileFacades);
     $this->view->assign('settings', ['jsConfirmationDelete' => $this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)]);
 }
Пример #17
0
 /**
  * For TYPO3 Element Browser: Expand folder of files.
  *
  * @param Folder $folder The folder path to expand
  * @param string $extensionList List of fileextensions to show
  * @param bool $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
  * @return string HTML output
  */
 public function TBE_expandFolder(Folder $folder, $extensionList = '', $noThumbs = false)
 {
     if (!$folder->checkActionPermission('read')) {
         return '';
     }
     $extensionList = $extensionList == '*' ? '' : $extensionList;
     if ($this->searchWord !== '') {
         $files = $this->fileRepository->searchByName($folder, $this->searchWord);
     } else {
         $files = $this->getFilesInFolder($folder, $extensionList);
     }
     return $this->fileList($files, $folder, $noThumbs);
 }