/**
  * Initialize
  *
  * @throws InsufficientFolderAccessPermissionsException
  */
 protected function init()
 {
     // Initialize GPvars:
     $this->target = GeneralUtility::_GP('target');
     $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
     if (!$this->returnUrl) {
         $this->returnUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . BackendUtility::getModuleUrl('file_list') . '&id=' . rawurlencode($this->target);
     }
     // Create the folder object
     if ($this->target) {
         $this->folderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
     }
     if ($this->folderObject->getStorage()->getUid() === 0) {
         throw new InsufficientFolderAccessPermissionsException('You are not allowed to access folders outside your storages', 1375889834);
     }
     // Cleaning and checking target directory
     if (!$this->folderObject) {
         $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', true);
         $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', true);
         throw new \RuntimeException($title . ': ' . $message, 1294586843);
     }
     // Setting up the context sensitive menu
     $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
     // building pathInfo for metaInformation
     $pathInfo = ['combined_identifier' => $this->folderObject->getCombinedIdentifier()];
     $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
 }
 /**
  * Initialize the storage repository.
  */
 public function init()
 {
     $this->storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
     $this->storages = $this->storageRepository->findAll();
     // Add default storage for core files
     $this->storages[] = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject(0);
 }
 /**
  * Override default constructor to make it possible to instantiate this
  * class for rendering an offset table not in content object context
  *
  * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj
  */
 public function __construct(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj = NULL)
 {
     if (!is_null($cObj)) {
         $this->cObj = $cObj;
         $this->fileFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
     }
 }
 /**
  * Processing the focus point crop (fallback to LocalCropScaleMaskHelper)
  *
  * @param TaskInterface $task
  *
  * @return array|NULL
  */
 public function process(TaskInterface $task)
 {
     $configuration = $task->getConfiguration();
     $crop = $configuration['crop'] ? json_decode($configuration['crop']) : null;
     if ($crop instanceof \stdClass && isset($crop->x)) {
         // if crop is enable release the process
         return parent::process($task);
     }
     $sourceFile = $task->getSourceFile();
     try {
         if (self::$deepCheck === false) {
             self::$deepCheck = true;
             $ratio = $this->getCurrentRatioConfiguration();
             $this->dimensionService->getRatio($ratio);
             $newFile = $this->focusCropService->getCroppedImageSrcByFile($sourceFile, $ratio);
             $file = ResourceFactory::getInstance()->retrieveFileOrFolderObject($newFile);
             $targetFile = $task->getTargetFile();
             ObjectAccess::setProperty($targetFile, 'originalFile', $file, true);
             ObjectAccess::setProperty($targetFile, 'originalFileSha1', $file->getSha1(), true);
             ObjectAccess::setProperty($targetFile, 'storage', $file->getStorage(), true);
             ObjectAccess::setProperty($task, 'sourceFile', $file, true);
             ObjectAccess::setProperty($task, 'targetFile', $targetFile, true);
         }
     } catch (\Exception $ex) {
     }
     self::$deepCheck = false;
     return parent::process($task);
 }
    /**
     * Initialize script class
     *
     * @return 	void
     * @todo Define visibility
     */
    public function init()
    {
        // Setting target, which must be a file reference to a file within the mounts.
        $this->target = $this->origTarget = $fileIdentifier = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('target');
        $this->returnUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('returnUrl'));
        // create the file object
        if ($fileIdentifier) {
            $this->fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileIdentifier);
        }
        // Cleaning and checking target directory
        if (!$this->fileObject) {
            $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
            $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
            throw new \RuntimeException($title . ': ' . $message, 1294586841);
        }
        // Setting the title and the icon
        $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
        $this->title = $icon . htmlspecialchars($this->fileObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileObject->getIdentifier());
        // ***************************
        // Setting template object
        // ***************************
        $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
        $this->doc->setModuleTemplate('templates/file_edit.html');
        $this->doc->backPath = $GLOBALS['BACK_PATH'];
        $this->doc->JScode = $this->doc->wrapScriptTags('
			function backToList() {	//
				top.goToModule("file_list");
			}
		');
        $this->doc->form = '<form action="tce_file.php" method="post" name="editform">';
    }
 /**
  * @param $status
  * @param $table
  * @param $id
  * @param $fieldArray
  * @param $self
  */
 function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, &$self)
 {
     if ($table == 'tx_html5videoplayer_domain_model_video') {
         $data = $fieldArray;
         if ($status == 'update') {
             $data = array_merge($GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'tx_html5videoplayer_domain_model_video', 'uid=' . (int) $id), $data);
         }
         $vimeoUrl = $data['vimeo'];
         if (($status == 'update' || $status == 'new') && $vimeoUrl != '' && GeneralUtility::isValidUrl($vimeoUrl)) {
             if (preg_match('/https?:\\/\\/(?:www\\.)?vimeo.com\\/(?:channels\\/(?:\\w+\\/)?|groups\\/([^\\/]*)\\/videos\\/|album\\/(\\d+)\\/video\\/|)(\\d+)(?:$|\\/|\\?)/i', $vimeoUrl, $matches)) {
                 $videoId = $matches[3];
                 $videoData = unserialize(GeneralUtility::getUrl('http://vimeo.com/api/v2/video/' . $videoId . '.php'));
                 if (is_array($videoData)) {
                     // We're only interested in index zero.
                     $videoData = $videoData[0];
                     if (!isset($data['title']) || trim($data['title']) == '') {
                         $fieldArray['title'] = $videoData['title'];
                     }
                     if (!isset($data['description']) || trim($data['description']) == '') {
                         $fieldArray['description'] = $videoData['description'];
                     }
                     if (!isset($data['posterimage']) || trim($data['posterimage']) == '') {
                         $resourceFactory = ResourceFactory::getInstance();
                         $folder = $resourceFactory->retrieveFileOrFolderObject($this->getUploadFolder());
                         $thumbnailData = GeneralUtility::getUrl($videoData['thumbnail_large']);
                         $file = $folder->createFile(basename($videoData['thumbnail_large']) . '.jpg');
                         $file->setContents($thumbnailData);
                         $fieldArray['posterimage'] = 'file:' . $file->getUid();
                     }
                 }
             }
         }
     }
 }
 /**
  * Entry method for use as TCEMain "inline" field filter
  *
  * @param array $parameters
  * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain
  * @return array
  */
 public function filterInlineChildren(array $parameters, \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain)
 {
     $values = $parameters['values'];
     if ($parameters['allowedFileExtensions']) {
         $this->setAllowedFileExtensions($parameters['allowedFileExtensions']);
     }
     if ($parameters['disallowedFileExtensions']) {
         $this->setDisallowedFileExtensions($parameters['disallowedFileExtensions']);
     }
     $cleanValues = array();
     if (is_array($values)) {
         foreach ($values as $value) {
             if (empty($value)) {
                 continue;
             }
             $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::revExplode('_', $value, 2);
             $fileReferenceUid = $parts[count($parts) - 1];
             $fileReference = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($fileReferenceUid);
             $file = $fileReference->getOriginalFile();
             if ($this->isAllowed($file->getName())) {
                 $cleanValues[] = $value;
             } else {
                 // Remove the erroneously created reference record again
                 $tceMain->deleteAction('sys_file_reference', $fileReferenceUid);
             }
         }
     }
     return $cleanValues;
 }
 /**
  * Constructor for initializing the class
  *
  * @return 	void
  * @todo Define visibility
  */
 public function init()
 {
     // Initialize GPvars:
     $this->target = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('target');
     $this->returnUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('returnUrl'));
     if (!$this->returnUrl) {
         $this->returnUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('file_list') . '&id=' . rawurlencode($this->target);
     }
     // Create the folder object
     if ($this->target) {
         $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
     }
     // Cleaning and checking target directory
     if (!$this->folderObject) {
         $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
         $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
         throw new \RuntimeException($title . ': ' . $message, 1294586843);
     }
     // Setting the title and the icon
     $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
     $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
     // Setting template object
     $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
     $this->doc->setModuleTemplate('templates/file_upload.html');
     $this->doc->backPath = $GLOBALS['BACK_PATH'];
     $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
 }
 /**
  * @return \TYPO3\CMS\Core\Resource\FileReference
  */
 public function getOriginalResource()
 {
     if ($this->originalResource === null) {
         $this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($this->_localizedUid);
     }
     return $this->originalResource;
 }
Esempio n. 10
0
 /**
  * @return \TYPO3\CMS\Core\Resource\FileReference
  */
 public function getOriginalResource()
 {
     if ($this->originalResource === NULL) {
         $this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($this->getUid());
     }
     return $this->originalResource;
 }
 /**
  * Generate album add/edit buttons for click menu or toolbar
  *
  * @param string $combinedIdentifier
  * @return array
  */
 protected function generateButtons($combinedIdentifier)
 {
     $buttons = array();
     // In some folder copy/move actions in file list a invalid id is passed
     try {
         /** @var $file \TYPO3\CMS\Core\Resource\Folder */
         $folder = ResourceFactory::getInstance()->retrieveFileOrFolderObject($combinedIdentifier);
     } catch (ResourceDoesNotExistException $exception) {
         $folder = NULL;
     } catch (InsufficientFolderAccessPermissionsException $exception) {
         $folder = NULL;
     }
     if ($folder && $folder instanceof Folder && !$folder->getStorage()->isPublic() && in_array($folder->getRole(), array(Folder::ROLE_DEFAULT, Folder::ROLE_USERUPLOAD))) {
         /** @var \BeechIt\FalSecuredownload\Service\Utility $utility */
         $utility = GeneralUtility::makeInstance('BeechIt\\FalSecuredownload\\Service\\Utility');
         $folderRecord = $utility->getFolderRecord($folder);
         $menuItems[] = 'spacer';
         if ($folderRecord) {
             $buttons[] = $this->createLink($this->sL('clickmenu.folderpermissions'), $this->sL('clickmenu.folderpermissions'), IconUtility::getSpriteIcon('extensions-fal_securedownload-folder', array(), array('status-overlay-access-restricted' => '')), "alt_doc.php?edit[tx_falsecuredownload_folder][" . $folderRecord['uid'] . "]=edit");
         } else {
             $buttons[] = $this->createLink($this->sL('clickmenu.folderpermissions'), $this->sL('clickmenu.folderpermissions'), IconUtility::getSpriteIcon('extensions-fal_securedownload-folder', array(), array('extensions-fal_securedownload-overlay-permissions' => '')), "alt_doc.php?edit[tx_falsecuredownload_folder][0]=new&defVals[tx_falsecuredownload_folder][folder_hash]=" . $folder->getHashedIdentifier() . "&defVals[tx_falsecuredownload_folder][storage]=" . $folder->getStorage()->getUid() . "&defVals[tx_falsecuredownload_folder][folder]=" . $folder->getIdentifier());
         }
     }
     return $buttons;
 }
 /**
  * Returns a processed image to be displayed on the Frontend.
  *
  * @param string $content Content input (not used).
  * @param array $conf TypoScript configuration
  * @return string HTML output
  */
 public function renderImageAttributes($content = '', $conf)
 {
     $imageAttributes = $this->getImageAttributes();
     // It is pretty rare to be in presence of an external image as the default behaviour
     // of the RTE is to download the external image and create a local image.
     // However, it may happen if the RTE has the flag "disable"
     if (!$this->isExternalImage()) {
         $fileUid = (int) $imageAttributes['data-htmlarea-file-uid'];
         if ($fileUid) {
             try {
                 $file = Resource\ResourceFactory::getInstance()->getFileObject($fileUid);
                 if ($imageAttributes['src'] !== $file->getPublicUrl()) {
                     // Source file is a processed image
                     $imageConfiguration = array('width' => (int) $imageAttributes['width'], 'height' => (int) $imageAttributes['height']);
                     $processedFile = $this->getMagicImageService()->createMagicImage($file, $imageConfiguration);
                     $additionalAttributes = array('src' => $processedFile->getPublicUrl(), 'title' => $imageAttributes['title'] ?: $file->getProperty('title'), 'alt' => $imageAttributes['alt'] ?: $file->getProperty('alternative'), 'width' => $processedFile->getProperty('width'), 'height' => $processedFile->getProperty('height'));
                     $imageAttributes = array_merge($imageAttributes, $additionalAttributes);
                 }
             } catch (Resource\Exception\FileDoesNotExistException $fileDoesNotExistException) {
                 // Log the fact the file could not be retrieved.
                 $message = sprintf('I could not find file with uid "%s"', $fileUid);
                 $this->getLogger()->error($message);
             }
         }
     }
     return '<img ' . GeneralUtility::implodeAttributes($imageAttributes, TRUE, TRUE) . ' />';
 }
 /**
  * initializes this object
  */
 protected function init()
 {
     $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $this->database = $GLOBALS['TYPO3_DB'];
     $this->fileRepository = $this->objectManager->get('TYPO3\\CMS\\Core\\Resource\\FileRepository');
     $fileFactory = ResourceFactory::getInstance();
     $this->storageObject = $fileFactory->getStorageObject($this->storageUid);
 }
Esempio n. 14
0
 /**
  * User function for sys_file_meta (element)
  *
  * @param array $propertyArray the array with additional configuration options.
  * @param \TYPO3\CMS\Backend\Form\FormEngine $tceformsObj the TCEforms parent object
  * @return string The HTML code for the TCEform field
  */
 public function renderFileMetadataInfo(array $propertyArray, \TYPO3\CMS\Backend\Form\FormEngine $tceformsObj)
 {
     $fileMetadataRecord = $propertyArray['row'];
     $fileObject = NULL;
     if ($fileMetadataRecord['file'] > 0) {
         $fileObject = ResourceFactory::getInstance()->getFileObject((int) $fileMetadataRecord['file']);
     }
     return $this->renderFileInformationContent($fileObject);
 }
Esempio n. 15
0
 /**
  * Render a file upload field.
  *
  * @throws \Fab\Media\Exception\EmptyPropertyException
  * @return string
  */
 public function render()
 {
     // Instantiate the file object for the whole class if possible.
     if ($this->getValue()) {
         $this->file = ResourceFactory::getInstance()->getFileObject($this->getValue());
     }
     $result = sprintf($this->template, $this->getInlineStyle(), $this->getThumbnail(), $this->getFileInfo(), $this->elementId, $this->getJavaScriptTemplate(), $this->getJavaScript());
     return $result;
 }
Esempio n. 16
0
 /**
  * User function for sys_file_meta (element)
  *
  * @param array $propertyArray the array with additional configuration options.
  * @return string The HTML code for the TCEform field
  */
 public function renderFileMetadataInfo(array $propertyArray)
 {
     $fileMetadataRecord = $propertyArray['row'];
     $fileObject = null;
     if (!empty($fileMetadataRecord['file']) && $fileMetadataRecord['file'][0] > 0) {
         $fileObject = ResourceFactory::getInstance()->getFileObject((int) $fileMetadataRecord['file'][0]);
     }
     return $this->renderFileInformationContent($fileObject);
 }
 /**
  * Render file tree
  */
 public function treeAction()
 {
     $resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
     try {
         $folder = $resourceFactory->getFolderObjectFromCombinedIdentifier($this->settings['storage'] . ':' . $this->settings['folder']);
     } catch (\TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException $exception) {
         // folder not found
     }
     $this->view->assign('folder', $folder);
 }
 /**
  * Validate additional fields
  *
  * @param array $submittedData Reference to the array containing the data submitted by the user
  * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
  * @return bool True if validation was ok (or selected class is not relevant), false otherwise
  */
 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
 {
     $value = $submittedData['scheduler_fileStorageIndexing_storage'];
     if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($value)) {
         return false;
     } elseif (\TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) !== null) {
         return true;
     }
     return false;
 }
Esempio n. 19
0
	/**
	 * Function execute from the Scheduler
	 *
	 * @return bool TRUE on successful execution, FALSE on error
	 */
	public function execute() {
		if ((int)$this->storageUid > 0) {
			$storage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($this->storageUid);
			$storage->setEvaluatePermissions(FALSE);
			$indexer = $this->getIndexer($storage);
			$indexer->processChangesInStorages();
			$storage->setEvaluatePermissions(TRUE);
		}
		return TRUE;
	}
Esempio n. 20
0
 /**
  * Checks if this is the handler for the given link
  *
  * The handler may store this information locally for later usage.
  *
  * @param array $linkParts Link parts as returned from TypoLinkCodecService
  *
  * @return bool
  */
 public function canHandleLink(array $linkParts)
 {
     if (!empty($linkParts['currentImage'])) {
         try {
             $this->currentFile = ResourceFactory::getInstance()->getFileObject($linkParts['currentImage']);
             return true;
         } catch (FileDoesNotExistException $e) {
         }
     }
     return false;
 }
 /**
  * Populates the content-entries of the collection
  *
  * @return void
  */
 public function loadContents()
 {
     $resource = $this->getDatabaseConnection()->exec_SELECT_mm_query('sys_file_metadata.file', 'sys_category', 'sys_category_record_mm', 'sys_file_metadata', 'AND sys_category.uid=' . (int) $this->getItemsCriteria() . ' AND sys_category_record_mm.tablenames = \'sys_file_metadata\'');
     $resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
     if ($resource) {
         while (($record = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) !== FALSE) {
             $this->add($resourceFactory->getFileObject((int) $record['file']));
         }
         $this->getDatabaseConnection()->sql_free_result($resource);
     }
 }
Esempio n. 22
0
 /**
  * Set the point (between -100 and 100)
  *
  * @param int $x
  * @param int $y
  * @return void
  */
 public function setCurrentPoint($x, $y)
 {
     $values = ['focus_point_x' => MathUtility::forceIntegerInRange($x, -100, 100, 0), 'focus_point_y' => MathUtility::forceIntegerInRange($y, -100, 100, 0)];
     GlobalUtility::getDatabaseConnection()->exec_UPDATEquery('sys_file_reference', 'uid=' . $this->getReferenceUid(), $values);
     // save also to the file
     $reference = ResourceFactory::getInstance()->getFileReferenceObject($this->getReferenceUid());
     $fileUid = $reference->getOriginalFile()->getUid();
     $row = GlobalUtility::getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'sys_file_metadata', 'file=' . $fileUid);
     if ($row) {
         GlobalUtility::getDatabaseConnection()->exec_UPDATEquery('sys_file_metadata', 'uid=' . $row['uid'], $values);
     }
 }
Esempio n. 23
0
 /**
  * Check if $storageIdentifier is allowed. If it is not valid, throw an exception.
  *
  * @param int $combinedIdentifier
  * @return void
  */
 public function isValid($combinedIdentifier)
 {
     $allowedStorageIdentifiers = array();
     foreach ($this->getMediaModule()->getAllowedStorages() as $allowedStorage) {
         $allowedStorageIdentifiers[] = $allowedStorage->getUid();
     }
     $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
     if (!in_array($storage->getUid(), $allowedStorageIdentifiers)) {
         $message = sprintf('Storage identifier "%s" is not allowed or is currently off-line.', $combinedIdentifier);
         $this->addError($message, 1380813503);
     }
 }
 /**
  * Rendering the "data-htmlarea-clickenlarge" custom attribute, called from TypoScript
  *
  * @param 	string		Content input. Not used, ignore.
  * @param 	array		TypoScript configuration
  * @return 	string		HTML output.
  * @access private
  * @todo Define visibility
  */
 public function render_clickenlarge($content, $conf)
 {
     $clickenlarge = isset($this->cObj->parameters['data-htmlarea-clickenlarge']) ? $this->cObj->parameters['data-htmlarea-clickenlarge'] : 0;
     if (!$clickenlarge) {
         // Backward compatibility
         $clickenlarge = isset($this->cObj->parameters['clickenlarge']) ? $this->cObj->parameters['clickenlarge'] : 0;
     }
     $fileFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
     $fileTable = $this->cObj->parameters['data-htmlarea-file-table'];
     $fileUid = $this->cObj->parameters['data-htmlarea-file-uid'];
     if ($fileUid) {
         $fileObject = $fileFactory->getFileObject($fileUid);
         $filePath = $fileObject->getForLocalProcessing(FALSE);
         $file = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($filePath);
     } else {
         // Pre-FAL backward compatibility
         $path = $this->cObj->parameters['src'];
         $magicFolder = $fileFactory->getFolderObjectFromCombinedIdentifier($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']);
         if ($magicFolder instanceof \TYPO3\CMS\Core\Resource\Folder) {
             $magicFolderPath = $magicFolder->getPublicUrl();
             $pathPre = $magicFolderPath . 'RTEmagicC_';
             if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($path, $pathPre)) {
                 // Find original file:
                 $pI = pathinfo(substr($path, strlen($pathPre)));
                 $filename = substr($pI['basename'], 0, -strlen('.' . $pI['extension']));
                 $file = $magicFolderPath . 'RTEmagicP_' . $filename;
             } else {
                 $file = $this->cObj->parameters['src'];
             }
         }
     }
     // Unset clickenlarge custom attribute
     unset($this->cObj->parameters['data-htmlarea-clickenlarge']);
     // Backward compatibility
     unset($this->cObj->parameters['clickenlarge']);
     unset($this->cObj->parameters['allParams']);
     $content = '<img ' . \TYPO3\CMS\Core\Utility\GeneralUtility::implodeAttributes($this->cObj->parameters, TRUE, TRUE) . ' />';
     if ($clickenlarge && is_array($conf['imageLinkWrap.'])) {
         $theImage = $file ? $GLOBALS['TSFE']->tmpl->getFileName($file) : '';
         if ($theImage) {
             $this->cObj->parameters['origFile'] = $theImage;
             if ($this->cObj->parameters['title']) {
                 $conf['imageLinkWrap.']['title'] = $this->cObj->parameters['title'];
             }
             if ($this->cObj->parameters['alt']) {
                 $conf['imageLinkWrap.']['alt'] = $this->cObj->parameters['alt'];
             }
             $content = $this->cObj->imageLinkWrap($content, $theImage, $conf['imageLinkWrap.']);
             $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
         }
     }
     return $content;
 }
Esempio n. 25
0
 /**
  * Actually convert from $source to $targetType
  *
  * @param string $source
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param PropertyMappingConfigurationInterface $configuration
  * @return File
  * @api
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = NULL)
 {
     /** @var $file File */
     $file = ResourceFactory::getInstance()->getFileObject((int) $source);
     if (!$file) {
         $message = sprintf('File with identifier "%s" could not be found.', $file);
         throw new \Exception($message, 1433529796);
     }
     $file->getType();
     // force to internally know its mime-type.
     return $file;
 }
Esempio n. 26
0
 /**
  * get the image
  *
  * @param $src
  * @param $treatIdAsReference
  *
  * @return \TYPO3\CMS\Core\Resource\File|FileInterface|\TYPO3\CMS\Core\Resource\FileReference|\TYPO3\CMS\Core\Resource\Folder
  * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
  * @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
  */
 protected function getImage($src, $treatIdAsReference)
 {
     $resourceFactory = ResourceFactory::getInstance();
     if (!MathUtility::canBeInterpretedAsInteger($src)) {
         return $resourceFactory->retrieveFileOrFolderObject($src);
     }
     if (!$treatIdAsReference) {
         return $resourceFactory->getFileObject($src);
     }
     $image = $resourceFactory->getFileReferenceObject($src);
     return $image->getOriginalFile();
 }
Esempio n. 27
0
 /**
  * Internal function to retrieve the target magic image folder
  *
  * @param string $targetFolderCombinedIdentifier
  * @return \TYPO3\CMS\Core\Resource\Folder
  */
 protected function getMagicFolder($targetFolderCombinedIdentifier)
 {
     $fileFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
     // @todo Proper exception handling is missing here
     if ($targetFolderCombinedIdentifier) {
         $magicFolder = $fileFactory->getFolderObjectFromCombinedIdentifier($targetFolderCombinedIdentifier);
     }
     if (empty($magicFolder) || !$magicFolder instanceof \TYPO3\CMS\Core\Resource\Folder) {
         $magicFolder = $fileFactory->getFolderObjectFromCombinedIdentifier($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']);
     }
     return $magicFolder;
 }
 /**
  * goes through all DAM files and checks if they have a counterpart in the sys_file
  * table. If not, fetch the file (via the storage, which indexes the file directly)
  * and update the DAM DB table
  * Please note that this does not migrate the metadata
  * this command can be run multiple times
  *
  * @param int|string $storageUid the UID of the storage (usually 1, don't modify if you are unsure)
  */
 public function connectDamRecordsWithSysFileCommand($storageUid = 1)
 {
     $this->headerMessage(LocalizationUtility::translate('connectDamRecordsWithSysFileCommand', 'dam_falmigration'));
     $fileFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
     // create the storage object
     $storageObject = $fileFactory->getStorageObject($storageUid);
     $migratedFiles = 0;
     // get all DAM records that have not been migrated yet
     $damRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_dam', 'deleted=0 AND uid NOT IN (SELECT _migrateddamuid FROM sys_file WHERE _migrateddamuid > 0)');
     $this->infoMessage('Found ' . count($damRecords) . ' DAM records with no connected sys_file entry');
     foreach ($damRecords as $damRecord) {
         $damUid = $damRecord['uid'];
         $fileIdentifier = $damRecord['file_path'] . $damRecord['file_name'];
         // right now, only files in fileadmin/ are supported
         if (GeneralUtility::isFirstPartOfStr($fileIdentifier, 'fileadmin/') === FALSE) {
             continue;
         }
         // strip away the "fileadmin/" prefix
         $fullFileName = substr($fileIdentifier, 10);
         // check if the DAM record is already indexed for FAL (based on the filename)
         $fileObject = NULL;
         try {
             $fileObject = $storageObject->getFile($fullFileName);
         } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
             // file not found jump to next file
             continue;
         } catch (\Exception $e) {
             $this->errorMessage('File not found: "' . $fullFileName . '"');
             continue;
         }
         // add the migrated uid of the DAM record to the FAL record
         if ($fileObject instanceof \TYPO3\CMS\Core\Resource\File) {
             if ($fileObject->isMissing()) {
                 $this->warningMessage('FAL did not find any file resource for DAM record. DAM uid: ' . $damUid . ': "' . $fullFileName . '"');
                 continue;
             }
             $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_file', 'uid=' . $fileObject->getUid(), array('_migrateddamuid' => $damUid));
             $migratedFiles++;
             $this->successMessage('DAM File is now indexed for FAL. FAL uid: ' . $fileObject->getUid() . ', DAM uid: ' . $damUid . ': "' . $fullFileName . '"');
         } else {
             $this->warningMessage('FAL did not find any file resource for DAM record. DAM uid: ' . $damUid . ': "' . $fullFileName . '"');
         }
     }
     // print a message
     if ($migratedFiles > 0) {
         $this->successMessage(LocalizationUtility::translate('migrationSuccessful', 'dam_falmigration'));
         $this->successMessage(LocalizationUtility::translate('migratedFiles', 'dam_falmigration', array(0 => $migratedFiles)));
     } else {
         $this->infoMessage(LocalizationUtility::translate('migrationNotNecessary', 'dam_falmigration'));
         $this->infoMessage(LocalizationUtility::translate('allFilesMigrated', 'dam_falmigration'));
     }
 }
Esempio n. 29
0
 /**
  * Handle file upload.
  *
  * @param int $storageIdentifier
  * @return string
  */
 public function uploadAction($storageIdentifier)
 {
     $storage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier);
     /** @var $uploadManager \TYPO3\CMS\Media\FileUpload\UploadManager */
     $uploadManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Media\\FileUpload\\UploadManager', $storage);
     try {
         $uploadedFile = $uploadManager->handleUpload();
         $result = array('success' => TRUE, 'viewUrl' => $uploadedFile->getPublicUrl());
     } catch (\Exception $e) {
         $result = array('error' => $e->getMessage());
     }
     return json_encode($result);
 }
Esempio n. 30
0
 /**
  * Fetch the files given an object assuming
  *
  * @param $propertyName
  * @param Content $object
  * @return File[]
  */
 protected function findByFileReference($propertyName, Content $object)
 {
     $fileField = 'uid_local';
     $tableName = 'sys_file_reference';
     $clause = sprintf('tablenames = "%s" %s AND fieldname = "%s" AND uid_foreign = %s', $object->getDataType(), $this->getWhereClauseForEnabledFields($tableName), GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName), $object->getUid());
     $rows = $this->getDatabaseConnection()->exec_SELECTgetRows($fileField, $tableName, $clause);
     // Build array of Files
     $files = array();
     foreach ($rows as $row) {
         $files[] = ResourceFactory::getInstance()->getFileObject($row[$fileField]);
     }
     return $files;
 }