/**
  * @param array $asset
  * @return void
  */
 protected function loadByCorePageRender(array $asset)
 {
     $file = $this->resolveFileForApplicationContext($asset);
     $fileNameAndPath = GeneralUtility::getFileAbsFileName($file);
     $fileNameAndPath = PathUtility::stripPathSitePrefix($fileNameAndPath);
     if ($asset['type'] === 'js') {
         $this->getPageRenderer()->addJsFooterFile($fileNameAndPath);
     } elseif ($asset['type'] === 'css') {
         $this->getPageRenderer()->addCssFile($fileNameAndPath);
     }
 }
 /**
  * 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;
 }
 /**
  * Render the URI to the resource. The filename is used from child content.
  *
  * @param string $path The path and filename of the resource (relative to Public resource directory of the extension).
  * @param string $extensionName Target extension name. If not set, the current extension name will be used
  * @param boolean $absolute If set, an absolute URI is rendered
  * @return string The URI to the resource
  * @api
  */
 public function render($path, $extensionName = NULL, $absolute = FALSE)
 {
     if ($extensionName === NULL) {
         $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
     }
     $uri = 'EXT:' . \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
     $uri = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($uri);
     $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri);
     if (TYPO3_MODE === 'BE' && $absolute === FALSE && $uri !== FALSE) {
         $uri = '../' . $uri;
     }
     if ($absolute === TRUE) {
         $uri = $this->controllerContext->getRequest()->getBaseURI() . $uri;
     }
     return $uri;
 }
 /**
  * @param array $arguments
  * @param callable $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $path = $arguments['path'];
     $extensionName = $arguments['extensionName'];
     $absolute = $arguments['absolute'];
     if ($extensionName === NULL) {
         $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName();
     }
     $uri = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
     $uri = GeneralUtility::getFileAbsFileName($uri);
     $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri);
     if (TYPO3_MODE === 'BE' && $absolute === FALSE && $uri !== FALSE) {
         $uri = '../' . $uri;
     }
     if ($absolute === TRUE) {
         $uri = $renderingContext->getControllerContext()->getRequest()->getBaseUri() . $uri;
     }
     return $uri;
 }
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  *
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $absolutePath = $renderChildrenClosure();
     return \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($absolutePath);
 }
Beispiel #6
0
 /**
  * Setting a value for a reference for a FILE field:
  *
  * @param array $refRec sys_refindex record
  * @param array $itemArray Array of references from that field
  * @param string $newValue Value to substitute current value with (or NULL to unset it)
  * @param array $dataArray Data array in which the new value is set (passed by reference)
  * @param string $flexpointer Flexform pointer, if in a flex form field.
  * @return string Error message if any, otherwise FALSE = OK
  * @todo Define visibility
  */
 public function setReferenceValue_fileRels($refRec, $itemArray, $newValue, &$dataArray, $flexpointer = '')
 {
     $ID_absFile = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($itemArray[$refRec['sorting']]['ID_absFile']);
     if ($ID_absFile === (string) $refRec['ref_string'] && $refRec['ref_table'] === '_FILE') {
         // Setting or removing value:
         // Remove value:
         if ($newValue === NULL) {
             unset($itemArray[$refRec['sorting']]);
         } else {
             $itemArray[$refRec['sorting']]['filename'] = $newValue;
         }
         // Traverse and compile new list of records:
         $saveValue = array();
         foreach ($itemArray as $fileInfo) {
             $saveValue[] = $fileInfo['filename'];
         }
         // Set in data array:
         if ($flexpointer) {
             $flexToolObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
             $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'] = array();
             $flexToolObj->setArrayValueByPath(substr($flexpointer, 0, -1), $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'], implode(',', $saveValue));
         } else {
             $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']] = implode(',', $saveValue);
         }
     } else {
         return 'ERROR: either "' . $refRec['ref_table'] . '" was not "_FILE" or file PATH_site+"' . $refRec['ref_string'] . '" did not match that of the record ("' . $itemArray[$refRec['sorting']]['ID_absFile'] . '") in sorting index "' . $refRec['sorting'] . '"';
     }
 }
Beispiel #7
0
 /**
  * Initialize $this->curUrlArray and $this->curUrlInfo based on script parameters
  *
  * @return void
  */
 protected function initCurrentUrl()
 {
     // CurrentUrl - the current link url must be passed around if it exists
     if ($this->mode == 'wizard') {
         $currentValues = GeneralUtility::trimExplode(LF, trim($this->P['currentValue']));
         if (count($currentValues) > 0) {
             $currentValue = array_pop($currentValues);
         } else {
             $currentValue = '';
         }
         $currentLinkParts = GeneralUtility::unQuoteFilenames($currentValue, TRUE);
         $initialCurUrlArray = array('href' => $currentLinkParts[0], 'target' => $currentLinkParts[1], 'class' => $currentLinkParts[2], 'title' => $currentLinkParts[3], 'params' => $currentLinkParts[4]);
         $this->curUrlArray = is_array(GeneralUtility::_GP('curUrl')) ? array_merge($initialCurUrlArray, GeneralUtility::_GP('curUrl')) : $initialCurUrlArray;
         // Additional fields for page links
         if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'])) {
             $conf = array();
             $_params = array('conf' => &$conf, 'linkParts' => $currentLinkParts);
             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'] as $objRef) {
                 $processor =& GeneralUtility::getUserObj($objRef);
                 $processor->extendUrlArray($_params, $this);
             }
         }
         $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
         // pageid == 0 means that this is not an internal (page) link
         if ($this->curUrlInfo['pageid'] == 0 && $this->curUrlArray['href']) {
             // Check if there is the FAL API
             if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'file:')) {
                 $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
                 // Remove the "file:" prefix
                 $currentLinkParts[0] = rawurldecode(substr($this->curUrlArray['href'], 5));
             } elseif (file_exists(PATH_site . rawurldecode($this->curUrlArray['href']))) {
                 if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], PATH_site)) {
                     $currentLinkParts[0] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->curUrlArray['href']);
                 }
                 $this->curUrlInfo = $this->parseCurUrl($this->siteURL . $this->curUrlArray['href'], $this->siteURL);
             } elseif (strstr($this->curUrlArray['href'], '@')) {
                 // check for email link
                 if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'mailto:')) {
                     $currentLinkParts[0] = substr($this->curUrlArray['href'], 7);
                 }
                 $this->curUrlInfo = $this->parseCurUrl('mailto:' . $this->curUrlArray['href'], $this->siteURL);
             } else {
                 // nothing of the above. this is an external link
                 if (strpos($this->curUrlArray['href'], '://') === FALSE) {
                     $currentLinkParts[0] = 'http://' . $this->curUrlArray['href'];
                 }
                 $this->curUrlInfo = $this->parseCurUrl($currentLinkParts[0], $this->siteURL);
             }
         } elseif (!$this->curUrlArray['href']) {
             $this->curUrlInfo = array();
             $this->act = 'page';
         } else {
             $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
         }
     } else {
         $this->curUrlArray = GeneralUtility::_GP('curUrl');
         if ($this->curUrlArray['all']) {
             $this->curUrlArray = GeneralUtility::get_tag_attributes($this->curUrlArray['all']);
         }
         $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
     }
 }
 /**
  * Renders the $icon, supports a filename for skinImg or sprite-icon-name
  *
  * @param string $icon The icon passed, could be a file-reference or a sprite Icon name
  * @param string $alt Alt attribute of the icon returned
  * @param string $title Title attribute of the icon return
  * @return string A tag representing to show the asked icon
  * @internal
  */
 public static function getIconHtml($icon, $alt = '', $title = '')
 {
     $icon = (string) $icon;
     $iconFile = '';
     $iconInfo = false;
     if (StringUtility::beginsWith($icon, 'EXT:')) {
         $absoluteFilePath = GeneralUtility::getFileAbsFileName($icon);
         if (!empty($absoluteFilePath)) {
             $iconFile = '../' . PathUtility::stripPathSitePrefix($absoluteFilePath);
             $iconInfo = StringUtility::endsWith($absoluteFilePath, '.svg') ? true : getimagesize($absoluteFilePath);
         }
     } elseif (StringUtility::beginsWith($icon, '../')) {
         // @TODO: this is special modList, files from folders and selicon
         $iconFile = GeneralUtility::resolveBackPath($icon);
         if (is_file(PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3)))) {
             $iconInfo = StringUtility::endsWith($icon, '.svg') ? true : getimagesize(PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3)));
         }
     }
     if ($iconInfo !== false && is_file(GeneralUtility::resolveBackPath(PATH_typo3 . $iconFile))) {
         return '<img' . ' src="' . htmlspecialchars($iconFile) . '"' . ' alt="' . htmlspecialchars($alt) . '" ' . ($title ? 'title="' . htmlspecialchars($title) . '"' : '') . ' />';
     }
     $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
     return '<span alt="' . htmlspecialchars($alt) . '" title="' . htmlspecialchars($title) . '">' . $iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render() . '</span>';
 }
 /**
  * Returns relative path
  *
  * @param string $absolutePath
  * @return string
  */
 protected function getRelativePath($absolutePath)
 {
     return PathUtility::stripPathSitePrefix($absolutePath);
 }
 /**
  * [Describe function...]
  *
  * @param 	[type]		$imgConf: ...
  * @return 	[type]		...
  * @todo Define visibility
  */
 public function ext_getTSCE_config_image($imgConf)
 {
     if (substr($imgConf, 0, 4) == 'gfx/') {
         $iFile = $this->ext_localGfxPrefix . $imgConf;
         $tFile = $this->ext_localWebGfxPrefix . $imgConf;
     } elseif (substr($imgConf, 0, 4) == 'EXT:') {
         $iFile = GeneralUtility::getFileAbsFileName($imgConf);
         if ($iFile) {
             $f = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($iFile);
             $tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
         }
     }
     $imageInfo = @getImagesize($iFile);
     return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
 }
Beispiel #11
0
 /**
  * Determines the base URL for this driver, from the configuration or
  * the TypoScript frontend object
  *
  * @return void
  */
 protected function determineBaseUrl()
 {
     // only calculate baseURI if the storage does not enforce jumpUrl Script
     if ($this->hasCapability(ResourceStorage::CAPABILITY_PUBLIC)) {
         if (GeneralUtility::isFirstPartOfStr($this->absoluteBasePath, PATH_site)) {
             // use site-relative URLs
             $temporaryBaseUri = rtrim(PathUtility::stripPathSitePrefix($this->absoluteBasePath), '/');
             if ($temporaryBaseUri !== '') {
                 $uriParts = explode('/', $temporaryBaseUri);
                 $uriParts = array_map('rawurlencode', $uriParts);
                 $temporaryBaseUri = implode('/', $uriParts) . '/';
             }
             $this->baseUri = $temporaryBaseUri;
         } elseif (isset($this->configuration['baseUri']) && GeneralUtility::isValidUrl($this->configuration['baseUri'])) {
             $this->baseUri = rtrim($this->configuration['baseUri'], '/') . '/';
         }
     }
 }
Beispiel #12
0
 /**
  * Returns the reference used for the frontend inclusion, checks against allowed paths for inclusion.
  *
  * @param string $fileFromSetup TypoScript "resource" data type value.
  * @return string|NULL Resulting filename, is either a full absolute URL or a relative path. Returns NULL if invalid filename or a directory is given
  */
 public function getFileName($fileFromSetup)
 {
     $file = trim($fileFromSetup);
     if (!$file) {
         return NULL;
     } elseif (strpos($file, '../') !== FALSE) {
         if ($this->tt_track) {
             $this->getTimeTracker()->setTSlogMessage('File path "' . $file . '" contained illegal string "../"!', 3);
         }
         return NULL;
     }
     // Cache
     $hash = md5($file);
     if (isset($this->fileCache[$hash])) {
         return $this->fileCache[$hash];
     }
     // if this is an URL, it can be returned directly
     $urlScheme = parse_url($file, PHP_URL_SCHEME);
     if ($urlScheme === 'https' || $urlScheme === 'http' || is_file(PATH_site . $file)) {
         return $file;
     }
     // this call also resolves EXT:myext/ files
     $file = GeneralUtility::getFileAbsFileName($file);
     if (!$file) {
         if ($this->tt_track) {
             $this->getTimeTracker()->setTSlogMessage('File "' . $fileFromSetup . '" was not found!', 3);
         }
         return NULL;
     }
     $file = PathUtility::stripPathSitePrefix($file);
     // Check if the found file is in the allowed paths
     foreach ($this->allowedPaths as $val) {
         if (GeneralUtility::isFirstPartOfStr($file, $val)) {
             $this->fileCache[$hash] = $file;
             return $file;
         }
     }
     if ($this->tt_track) {
         $this->getTimeTracker()->setTSlogMessage('"' . $file . '" was not located in the allowed paths: (' . implode(',', $this->allowedPaths) . ')', 3);
     }
     return NULL;
 }
 /**
  * Logs a call to a deprecated function.
  * The log message will be taken from the annotation.
  *
  * @return void
  */
 public static function logDeprecatedFunction()
 {
     if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
         return;
     }
     // This require_once is needed for deprecation calls
     // thrown early during bootstrap, if the autoloader is
     // not instantiated yet. This can happen for example if
     // ext_localconf triggers a deprecation.
     require_once 'DebugUtility.php';
     $trail = debug_backtrace();
     if ($trail[1]['type']) {
         $function = new \ReflectionMethod($trail[1]['class'], $trail[1]['function']);
     } else {
         $function = new \ReflectionFunction($trail[1]['function']);
     }
     $msg = '';
     if (preg_match('/@deprecated\\s+(.*)/', $function->getDocComment(), $match)) {
         $msg = $match[1];
     }
     // Write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>)
     $logMsg = $trail[1]['class'] . $trail[1]['type'] . $trail[1]['function'];
     $logMsg .= '() - ' . $msg . ' - ' . \TYPO3\CMS\Core\Utility\DebugUtility::debugTrail();
     $logMsg .= ' (' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($function->getFileName()) . '#' . $function->getStartLine() . ')';
     self::deprecationLog($logMsg);
 }
Beispiel #14
0
 /**
  * If the module name ($name) is a module from an extension (has path in $this->absPathArray)
  * then that path is returned relative to PATH_site
  *
  * @param string $name Module name
  * @return string If found, the relative path from PATH_site
  */
 public function checkExtensionModule($name)
 {
     if (isset($this->absPathArray[$name])) {
         return rtrim(PathUtility::stripPathSitePrefix($this->absPathArray[$name]), '/');
     }
     return '';
 }
    /**
     * Creates a color image selector
     *
     * @return string
     */
    public function colorImage()
    {
        // Handling color-picker image if any:
        if (!$this->imageError) {
            if ($this->pickerImage) {
                if (GeneralUtility::_POST('coords_x')) {
                    /** @var $image \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
                    $image = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\GraphicalFunctions::class);
                    $this->colorValue = '#' . $this->getIndex($image->imageCreateFromFile($this->pickerImage), GeneralUtility::_POST('coords_x'), GeneralUtility::_POST('coords_y'));
                }
                $pickerFormImage = '
				<p class="c-head">' . $this->getLanguageService()->getLL('colorpicker_fromImage', true) . '</p>
				<input type="image" src="../' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->pickerImage) . '" name="coords" style="cursor:crosshair;" /><br />';
            } else {
                $pickerFormImage = '';
            }
        } else {
            $pickerFormImage = '
			<p class="c-head">' . htmlspecialchars($this->imageError) . '</p>';
        }
        return $pickerFormImage;
    }
Beispiel #16
0
 /**
  * Adds a files content to the export memory
  *
  * @param array $fI File information with three keys: "filename" = filename without path, "ID_absFile" = absolute filepath to the file (including the filename), "ID" = md5 hash of "ID_absFile". "relFileName" is optional for files attached to records, but mandatory for soft referenced files (since the relFileName determines where such a file should be stored!)
  * @param string $recordRef If the file is related to a record, this is the id on the form [table]:[id]. Information purposes only.
  * @param string $fieldname If the file is related to a record, this is the field name it was related to. Information purposes only.
  * @return void
  */
 public function export_addFile($fI, $recordRef = '', $fieldname = '')
 {
     if (!@is_file($fI['ID_absFile'])) {
         $this->error($fI['ID_absFile'] . ' was not a file! Skipping.');
         return;
     }
     if (filesize($fI['ID_absFile']) >= $this->maxFileSize) {
         $this->error($fI['ID_absFile'] . ' was larger (' . GeneralUtility::formatSize(filesize($fI['ID_absFile'])) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.');
         return;
     }
     $fileInfo = stat($fI['ID_absFile']);
     $fileRec = array();
     $fileRec['filesize'] = $fileInfo['size'];
     $fileRec['filename'] = PathUtility::basename($fI['ID_absFile']);
     $fileRec['filemtime'] = $fileInfo['mtime'];
     //for internal type file_reference
     $fileRec['relFileRef'] = PathUtility::stripPathSitePrefix($fI['ID_absFile']);
     if ($recordRef) {
         $fileRec['record_ref'] = $recordRef . '/' . $fieldname;
     }
     if ($fI['relFileName']) {
         $fileRec['relFileName'] = $fI['relFileName'];
     }
     // Setting this data in the header
     $this->dat['header']['files'][$fI['ID']] = $fileRec;
     // ... and for the recordlisting, why not let us know WHICH relations there was...
     if ($recordRef && $recordRef !== '_SOFTREF_') {
         $refParts = explode(':', $recordRef, 2);
         if (!is_array($this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'])) {
             $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'] = array();
         }
         $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'][] = $fI['ID'];
     }
     $fileMd5 = md5_file($fI['ID_absFile']);
     if (!$this->saveFilesOutsideExportFile) {
         // ... and finally add the heavy stuff:
         $fileRec['content'] = GeneralUtility::getUrl($fI['ID_absFile']);
     } else {
         GeneralUtility::upload_copy_move($fI['ID_absFile'], $this->getTemporaryFilesPathForExport() . $fileMd5);
     }
     $fileRec['content_md5'] = $fileMd5;
     $this->dat['files'][$fI['ID']] = $fileRec;
     // For soft references, do further processing:
     if ($recordRef === '_SOFTREF_') {
         // RTE files?
         if ($RTEoriginal = $this->getRTEoriginalFilename(PathUtility::basename($fI['ID_absFile']))) {
             $RTEoriginal_absPath = PathUtility::dirname($fI['ID_absFile']) . '/' . $RTEoriginal;
             if (@is_file($RTEoriginal_absPath)) {
                 $RTEoriginal_ID = md5($RTEoriginal_absPath);
                 $fileInfo = stat($RTEoriginal_absPath);
                 $fileRec = array();
                 $fileRec['filesize'] = $fileInfo['size'];
                 $fileRec['filename'] = PathUtility::basename($RTEoriginal_absPath);
                 $fileRec['filemtime'] = $fileInfo['mtime'];
                 $fileRec['record_ref'] = '_RTE_COPY_ID:' . $fI['ID'];
                 $this->dat['header']['files'][$fI['ID']]['RTE_ORIG_ID'] = $RTEoriginal_ID;
                 // Setting this data in the header
                 $this->dat['header']['files'][$RTEoriginal_ID] = $fileRec;
                 $fileMd5 = md5_file($RTEoriginal_absPath);
                 if (!$this->saveFilesOutsideExportFile) {
                     // ... and finally add the heavy stuff:
                     $fileRec['content'] = GeneralUtility::getUrl($RTEoriginal_absPath);
                 } else {
                     GeneralUtility::upload_copy_move($RTEoriginal_absPath, $this->getTemporaryFilesPathForExport() . $fileMd5);
                 }
                 $fileRec['content_md5'] = $fileMd5;
                 $this->dat['files'][$RTEoriginal_ID] = $fileRec;
             } else {
                 $this->error('RTE original file "' . PathUtility::stripPathSitePrefix($RTEoriginal_absPath) . '" was not found!');
             }
         }
         // Files with external media?
         // This is only done with files grabbed by a softreference parser since it is deemed improbable that hard-referenced files should undergo this treatment.
         $html_fI = pathinfo(PathUtility::basename($fI['ID_absFile']));
         if ($this->includeExtFileResources && GeneralUtility::inList($this->extFileResourceExtensions, strtolower($html_fI['extension']))) {
             $uniquePrefix = '###' . md5($GLOBALS['EXEC_TIME']) . '###';
             if (strtolower($html_fI['extension']) === 'css') {
                 $prefixedMedias = explode($uniquePrefix, preg_replace('/(url[[:space:]]*\\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\\))/i', '\\1' . $uniquePrefix . '\\2' . $uniquePrefix . '\\3', $fileRec['content']));
             } else {
                 // html, htm:
                 $htmlParser = GeneralUtility::makeInstance(HtmlParser::class);
                 $prefixedMedias = explode($uniquePrefix, $htmlParser->prefixResourcePath($uniquePrefix, $fileRec['content'], array(), $uniquePrefix));
             }
             $htmlResourceCaptured = false;
             foreach ($prefixedMedias as $k => $v) {
                 if ($k % 2) {
                     $EXTres_absPath = GeneralUtility::resolveBackPath(PathUtility::dirname($fI['ID_absFile']) . '/' . $v);
                     $EXTres_absPath = GeneralUtility::getFileAbsFileName($EXTres_absPath);
                     if ($EXTres_absPath && GeneralUtility::isFirstPartOfStr($EXTres_absPath, PATH_site . $this->fileadminFolderName . '/') && @is_file($EXTres_absPath)) {
                         $htmlResourceCaptured = true;
                         $EXTres_ID = md5($EXTres_absPath);
                         $this->dat['header']['files'][$fI['ID']]['EXT_RES_ID'][] = $EXTres_ID;
                         $prefixedMedias[$k] = '{EXT_RES_ID:' . $EXTres_ID . '}';
                         // Add file to memory if it is not set already:
                         if (!isset($this->dat['header']['files'][$EXTres_ID])) {
                             $fileInfo = stat($EXTres_absPath);
                             $fileRec = array();
                             $fileRec['filesize'] = $fileInfo['size'];
                             $fileRec['filename'] = PathUtility::basename($EXTres_absPath);
                             $fileRec['filemtime'] = $fileInfo['mtime'];
                             $fileRec['record_ref'] = '_EXT_PARENT_:' . $fI['ID'];
                             // Media relative to the HTML file.
                             $fileRec['parentRelFileName'] = $v;
                             // Setting this data in the header
                             $this->dat['header']['files'][$EXTres_ID] = $fileRec;
                             // ... and finally add the heavy stuff:
                             $fileRec['content'] = GeneralUtility::getUrl($EXTres_absPath);
                             $fileRec['content_md5'] = md5($fileRec['content']);
                             $this->dat['files'][$EXTres_ID] = $fileRec;
                         }
                     }
                 }
             }
             if ($htmlResourceCaptured) {
                 $this->dat['files'][$fI['ID']]['tokenizedContent'] = implode('', $prefixedMedias);
             }
         }
     }
 }
 /**
  * Return icon for file extension
  *
  * @param string File extension / item type
  * @param string Title attribute value in icon.
  * @param array TypoScript configuration specifically for search result.
  * @return string <img> tag for icon
  */
 public function makeItemTypeIcon($it, $alt = '', $specRowConf)
 {
     // Build compound key if item type is 0, iconRendering is not used
     // and specConfs.[pid].pageIcon was set in TS
     if ($it === '0' && $specRowConf['_pid'] && is_array($specRowConf['pageIcon.']) && !is_array($this->conf['iconRendering.'])) {
         $it .= ':' . $specRowConf['_pid'];
     }
     if (!isset($this->iconFileNameCache[$it])) {
         $this->iconFileNameCache[$it] = '';
         // If TypoScript is used to render the icon:
         if (is_array($this->conf['iconRendering.'])) {
             $this->cObj->setCurrentVal($it);
             $this->iconFileNameCache[$it] = $this->cObj->cObjGetSingle($this->conf['iconRendering'], $this->conf['iconRendering.']);
         } else {
             // Default creation / finding of icon:
             $icon = '';
             if ($it === '0' || substr($it, 0, 2) == '0:') {
                 if (is_array($specRowConf['pageIcon.'])) {
                     $this->iconFileNameCache[$it] = $this->cObj->cObjGetSingle('IMAGE', $specRowConf['pageIcon.']);
                 } else {
                     $icon = 'EXT:indexed_search/pi/res/pages.gif';
                 }
             } elseif ($this->external_parsers[$it]) {
                 $icon = $this->external_parsers[$it]->getIcon($it);
             }
             if ($icon) {
                 $fullPath = GeneralUtility::getFileAbsFileName($icon);
                 if ($fullPath) {
                     $info = @getimagesize($fullPath);
                     $iconPath = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($fullPath);
                     $this->iconFileNameCache[$it] = is_array($info) ? '<img src="' . $iconPath . '" ' . $info[3] . ' title="' . htmlspecialchars($alt) . '" alt="" />' : '';
                 }
             }
         }
     }
     return $this->iconFileNameCache[$it];
 }
 /**
  * Generates the name of the cached file.
  *
  * @param string $sourcePath
  * @param string $languageKey
  * @return void
  */
 protected function generateCacheFileName($sourcePath, $languageKey)
 {
     $this->hashSource = PathUtility::stripPathSitePrefix($sourcePath) . '|' . date('d-m-Y H:i:s', filemtime($sourcePath)) . '|version=2.3';
     $this->cacheFileName = PATH_site . 'typo3temp/llxml/' . substr(basename($sourcePath), 10, 15) . '_' . GeneralUtility::shortMD5($this->hashSource) . '.' . $languageKey . '.' . $this->targetCharset . '.cache';
 }
Beispiel #19
0
 /**
  * Logs a call to a deprecated function.
  * The log message will be taken from the annotation.
  *
  * @return void
  */
 public static function logDeprecatedFunction()
 {
     if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
         return;
     }
     $trail = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
     if ($trail[1]['type']) {
         $function = new \ReflectionMethod($trail[1]['class'], $trail[1]['function']);
     } else {
         $function = new \ReflectionFunction($trail[1]['function']);
     }
     $msg = '';
     if (preg_match('/@deprecated\\s+(.*)/', $function->getDocComment(), $match)) {
         $msg = $match[1];
     }
     // Write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>)
     $logMsg = $trail[1]['class'] . $trail[1]['type'] . $trail[1]['function'];
     $logMsg .= '() - ' . $msg . ' - ' . DebugUtility::debugTrail();
     $logMsg .= ' (' . PathUtility::stripPathSitePrefix($function->getFileName()) . '#' . $function->getStartLine() . ')';
     self::deprecationLog($logMsg);
 }
 /**
  * Returns the relative path to the extension as measured from the PATH_site (frontend)
  * If the extension is not loaded the function will die with an error message
  * Useful for images and links from the frontend
  *
  * @param string $key Extension key
  * @return string
  */
 public static function siteRelPath($key)
 {
     return PathUtility::stripPathSitePrefix(self::extPath($key));
 }
 /**
  * TCA config "fileFolder" evaluation. Add them to $items
  *
  * Used by TcaSelectItems and TcaSelectTreeItems data providers
  *
  * @param array $result Result array
  * @param string $fieldName Current handle field name
  * @param array $items Incoming items
  * @return array Modified item array
  */
 protected function addItemsFromFolder(array $result, $fieldName, array $items)
 {
     if (empty($result['processedTca']['columns'][$fieldName]['config']['fileFolder']) || !is_string($result['processedTca']['columns'][$fieldName]['config']['fileFolder'])) {
         return $items;
     }
     $fileFolder = $result['processedTca']['columns'][$fieldName]['config']['fileFolder'];
     $fileFolder = GeneralUtility::getFileAbsFileName($fileFolder);
     $fileFolder = rtrim($fileFolder, '/') . '/';
     if (@is_dir($fileFolder)) {
         $fileExtensionList = '';
         if (!empty($result['processedTca']['columns'][$fieldName]['config']['fileFolder_extList']) && is_string($result['processedTca']['columns'][$fieldName]['config']['fileFolder_extList'])) {
             $fileExtensionList = $result['processedTca']['columns'][$fieldName]['config']['fileFolder_extList'];
         }
         $recursionLevels = isset($fieldValue['config']['fileFolder_recursions']) ? MathUtility::forceIntegerInRange($fieldValue['config']['fileFolder_recursions'], 0, 99) : 99;
         $fileArray = GeneralUtility::getAllFilesAndFoldersInPath([], $fileFolder, $fileExtensionList, 0, $recursionLevels);
         $fileArray = GeneralUtility::removePrefixPathFromList($fileArray, $fileFolder);
         foreach ($fileArray as $fileReference) {
             $fileInformation = pathinfo($fileReference);
             $icon = GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($fileInformation['extension'])) ? '../' . PathUtility::stripPathSitePrefix($fileFolder) . $fileReference : '';
             $items[] = [$fileReference, $fileReference, $icon];
         }
     }
     return $items;
 }
 /**
  * Unpack a downloaded core
  *
  * @param string $version A version to unpack
  * @return bool TRUE on success
  */
 public function unpackVersion($version)
 {
     $messages = array();
     $success = true;
     if ($this->checkCoreFilesAvailable($version)) {
         /** @var $message StatusInterface */
         $message = $this->objectManager->get(NoticeStatus::class);
         $message->setTitle('Unpacking TYPO3 CMS core files skipped');
         $messages[] = $message;
     } else {
         $fileLocation = $this->downloadTargetPath . $version . '.tar.gz';
         if (!@is_file($fileLocation)) {
             $success = false;
             /** @var $message StatusInterface */
             $message = $this->objectManager->get(ErrorStatus::class);
             $message->setTitle('Downloaded TYPO3 CMS core not found');
             $messages[] = $message;
         } elseif (@file_exists($this->downloadTargetPath . 'typo3_src-' . $version)) {
             $success = false;
             /** @var $message StatusInterface */
             $message = $this->objectManager->get(ErrorStatus::class);
             $message->setTitle('Unpacked TYPO3 CMS core exists in download location: ' . PathUtility::stripPathSitePrefix($this->downloadTargetPath));
             $messages[] = $message;
         } else {
             $unpackCommand = 'tar xf ' . escapeshellarg($fileLocation) . ' -C ' . escapeshellarg($this->downloadTargetPath) . ' 2>&1';
             exec($unpackCommand, $output, $errorCode);
             if ($errorCode) {
                 $success = false;
                 /** @var $message StatusInterface */
                 $message = $this->objectManager->get(ErrorStatus::class);
                 $message->setTitle('Unpacking TYPO3 CMS core not successful');
                 $messages[] = $message;
             } else {
                 $removePackedFileResult = unlink($fileLocation);
                 if (!$removePackedFileResult) {
                     $success = false;
                     /** @var $message StatusInterface */
                     $message = $this->objectManager->get(ErrorStatus::class);
                     $message->setTitle('Removing packed TYPO3 CMS core not successful');
                     $messages[] = $message;
                 } else {
                     $message = $this->objectManager->get(OkStatus::class);
                     $message->setTitle('Unpacking TYPO3 CMS core successful');
                     $messages[] = $message;
                 }
             }
         }
     }
     $this->messages = $messages;
     return $success;
 }
Beispiel #23
0
 /**
  * Counting references to a record/file
  *
  * @param string $table Table name (or "_FILE" if its a file)
  * @param string $ref Reference: If table, then integer-uid, if _FILE, then file reference (relative to PATH_site)
  * @param string $msg Message with %s, eg. "There were %s records pointing to this file!
  * @param string $count Reference count
  * @return string Output string (or integer count value if no msg string specified)
  */
 public static function referenceCount($table, $ref, $msg = '', $count = NULL)
 {
     if ($count === NULL) {
         // Look up the path:
         if ($table == '_FILE') {
             if (GeneralUtility::isFirstPartOfStr($ref, PATH_site)) {
                 $ref = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($ref);
                 $condition = 'ref_string=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($ref, 'sys_refindex');
             } else {
                 return '';
             }
         } else {
             $condition = 'ref_uid=' . (int) $ref;
         }
         $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex', 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') . ' AND ' . $condition . ' AND deleted=0');
     }
     return $count ? $msg ? sprintf($msg, $count) : $count : '';
 }
 /**
  * Create array with data of all subModules of a specific main module
  *
  * @param string $moduleName Name of the main module
  * @param array $subModulesInfo Sub module information
  * @return array
  */
 protected function getSubModuleData($moduleName, array $subModulesInfo = array())
 {
     $subModulesData = array();
     foreach ($subModulesInfo as $subModuleName => $subModuleInfo) {
         $subModuleKey = $moduleName . '_' . $subModuleName . '_tab';
         $subModuleData = array();
         $subModuleData['name'] = $subModuleName;
         $subModuleData['icon'] = PathUtility::stripPathSitePrefix($this->languageService->moduleLabels['tabs_images'][$subModuleKey]);
         $subModuleData['label'] = $this->languageService->moduleLabels['tabs'][$subModuleKey];
         $subModuleData['shortDescription'] = $this->languageService->moduleLabels['labels'][$subModuleKey . 'label'];
         $subModuleData['longDescription'] = $this->languageService->moduleLabels['labels'][$subModuleKey . 'descr'];
         $subModulesData[] = $subModuleData;
     }
     return $subModulesData;
 }
 /**
  * Creates a link to the deprecation log file with the absolute path as the
  * link text.
  *
  * @return string Link to the deprecation log file
  */
 protected function getDeprecationLogFileLink()
 {
     $logFile = GeneralUtility::getDeprecationLogFileName();
     $relativePath = GeneralUtility::resolveBackPath($this->backPath . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($logFile));
     $link = '<a href="' . $relativePath . '">' . $logFile . '</a>';
     return $link;
 }
Beispiel #26
0
 /**
  * Indexing files from fileadmin
  *
  * @param array $cfgRec Indexing Configuration Record
  * @param array $session_data Session data for the indexing session spread over multiple instances of the script. Passed by reference so changes hereto will be saved for the next call!
  * @param array $params Parameters from the log queue.
  * @param object $pObj Parent object (from "crawler" extension!)
  * @return void
  */
 public function crawler_execute_type2($cfgRec, &$session_data, $params, &$pObj)
 {
     // Prepare path, making it absolute and checking:
     $readpath = $params['url'];
     if (!GeneralUtility::isAbsPath($readpath)) {
         $readpath = GeneralUtility::getFileAbsFileName($readpath);
     }
     if (GeneralUtility::isAllowedAbsPath($readpath)) {
         if (@is_file($readpath)) {
             // If file, index it!
             // Get root line (need to provide this when indexing external files)
             $rl = $this->getUidRootLineForClosestTemplate($cfgRec['pid']);
             // (Re)-Indexing file on page.
             $indexerObj = GeneralUtility::makeInstance(\TYPO3\CMS\IndexedSearch\Indexer::class);
             $indexerObj->backend_initIndexer($cfgRec['pid'], 0, 0, '', $rl);
             $indexerObj->backend_setFreeIndexUid($cfgRec['uid'], $cfgRec['set_id']);
             $indexerObj->hash['phash'] = -1;
             // EXPERIMENT - but to avoid phash_t3 being written to file sections (otherwise they are removed when page is reindexed!!!)
             // Index document:
             $indexerObj->indexRegularDocument(\TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($readpath), TRUE);
         } elseif (@is_dir($readpath)) {
             // If dir, read content and create new pending items for log:
             // Select files and directories in path:
             $extList = implode(',', GeneralUtility::trimExplode(',', $cfgRec['extensions'], TRUE));
             $fileArr = array();
             $files = GeneralUtility::getAllFilesAndFoldersInPath($fileArr, $readpath, $extList, 0, 0);
             $directoryList = GeneralUtility::get_dirs($readpath);
             if (is_array($directoryList) && $params['depth'] < $cfgRec['depth']) {
                 foreach ($directoryList as $subdir) {
                     if ((string) $subdir != '') {
                         $files[] = $readpath . $subdir . '/';
                     }
                 }
             }
             $files = GeneralUtility::removePrefixPathFromList($files, PATH_site);
             // traverse the items and create log entries:
             foreach ($files as $path) {
                 $this->instanceCounter++;
                 if ($path !== $params['url']) {
                     // Parameters:
                     $nparams = array('indexConfigUid' => $cfgRec['uid'], 'url' => $path, 'procInstructions' => array('[Index Cfg UID#' . $cfgRec['uid'] . ']'), 'depth' => $params['depth'] + 1);
                     $pObj->addQueueEntry_callBack($cfgRec['set_id'], $nparams, $this->callBack, $cfgRec['pid'], $GLOBALS['EXEC_TIME'] + $this->instanceCounter * $this->secondsPerExternalUrl);
                 }
             }
         }
     }
 }
Beispiel #27
0
 /**
  * Add file relation entries for a record's rels-array
  *
  * @param array $rels Array of file IDs
  * @param array $lines Output lines array (is passed by reference and modified)
  * @param string $preCode Pre-HTML code
  * @param string $htmlColorClass Alternative HTML color class to use.
  * @param string $tokenID Token ID if this is a softreference (in which case it only makes sense with a single element in the $rels array!)
  * @return void
  * @access private
  * @see singleRecordLines()
  */
 public function addFiles($rels, &$lines, $preCode, $htmlColorClass = '', $tokenID = '')
 {
     foreach ($rels as $ID) {
         // Process file:
         $pInfo = array();
         $fI = $this->dat['header']['files'][$ID];
         if (!is_array($fI)) {
             if (!$tokenID || $this->includeSoftref($tokenID)) {
                 $pInfo['msg'] = 'MISSING FILE: ' . $ID;
                 $this->error('MISSING FILE: ' . $ID);
             } else {
                 return;
             }
         }
         $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('status-status-reference-hard', Icon::SIZE_SMALL)->render();
         $pInfo['title'] = htmlspecialchars($fI['filename']);
         $pInfo['ref'] = 'FILE';
         $pInfo['size'] = $fI['filesize'];
         $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
         $pInfo['type'] = 'file';
         // If import mode and there is a non-RTE softreference, check the destination directory:
         if ($this->mode === 'import' && $tokenID && !$fI['RTE_ORIG_ID']) {
             if (isset($fI['parentRelFileName'])) {
                 $pInfo['msg'] = 'Seems like this file is already referenced from within an HTML/CSS file. That takes precedence. ';
             } else {
                 $testDirPrefix = PathUtility::dirname($fI['relFileName']) . '/';
                 $testDirPrefix2 = $this->verifyFolderAccess($testDirPrefix);
                 if (!$testDirPrefix2) {
                     $pInfo['msg'] = 'ERROR: There are no available filemounts to write file in! ';
                 } elseif ($testDirPrefix !== $testDirPrefix2) {
                     $pInfo['msg'] = 'File will be attempted written to "' . $testDirPrefix2 . '". ';
                 }
             }
             // Check if file exists:
             if (file_exists(PATH_site . $fI['relFileName'])) {
                 if ($this->update) {
                     $pInfo['updatePath'] .= 'File exists.';
                 } else {
                     $pInfo['msg'] .= 'File already exists! ';
                 }
             }
             // Check extension:
             $fileProcObj = $this->getFileProcObj();
             if ($fileProcObj->actionPerms['addFile']) {
                 $testFI = GeneralUtility::split_fileref(PATH_site . $fI['relFileName']);
                 if (!$this->allowPHPScripts && !$fileProcObj->checkIfAllowed($testFI['fileext'], $testFI['path'], $testFI['file'])) {
                     $pInfo['msg'] .= 'File extension was not allowed!';
                 }
             } else {
                 $pInfo['msg'] = 'You user profile does not allow you to create files on the server!';
             }
         }
         $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
         $lines[] = $pInfo;
         unset($this->remainHeader['files'][$ID]);
         // RTE originals:
         if ($fI['RTE_ORIG_ID']) {
             $ID = $fI['RTE_ORIG_ID'];
             $pInfo = array();
             $fI = $this->dat['header']['files'][$ID];
             if (!is_array($fI)) {
                 $pInfo['msg'] = 'MISSING RTE original FILE: ' . $ID;
                 $this->error('MISSING RTE original FILE: ' . $ID);
             }
             $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$ID]);
             $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('status-status-reference-hard', Icon::SIZE_SMALL)->render();
             $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Original)</em>';
             $pInfo['ref'] = 'FILE';
             $pInfo['size'] = $fI['filesize'];
             $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
             $pInfo['type'] = 'file';
             $lines[] = $pInfo;
             unset($this->remainHeader['files'][$ID]);
         }
         // External resources:
         if (is_array($fI['EXT_RES_ID'])) {
             foreach ($fI['EXT_RES_ID'] as $extID) {
                 $pInfo = array();
                 $fI = $this->dat['header']['files'][$extID];
                 if (!is_array($fI)) {
                     $pInfo['msg'] = 'MISSING External Resource FILE: ' . $extID;
                     $this->error('MISSING External Resource FILE: ' . $extID);
                 } else {
                     $pInfo['updatePath'] = $fI['parentRelFileName'];
                 }
                 $pInfo['showDiffContent'] = PathUtility::stripPathSitePrefix($this->fileIDMap[$extID]);
                 $pInfo['preCode'] = $preCode . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $this->iconFactory->getIcon('actions-insert-reference', Icon::SIZE_SMALL)->render();
                 $pInfo['title'] = htmlspecialchars($fI['filename']) . ' <em>(Resource)</em>';
                 $pInfo['ref'] = 'FILE';
                 $pInfo['size'] = $fI['filesize'];
                 $pInfo['class'] = $htmlColorClass ?: 'bgColor3';
                 $pInfo['type'] = 'file';
                 $lines[] = $pInfo;
                 unset($this->remainHeader['files'][$extID]);
             }
         }
     }
 }
 /**
  * Gets the icon for the shortcut
  *
  * @param array $row
  * @param array $shortcut
  * @return string Shortcut icon as img tag
  */
 protected function getShortcutIcon($row, $shortcut)
 {
     $databaseConnection = $this->getDatabaseConnection();
     $languageService = $this->getLanguageService();
     $titleAttribute = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.shortcut', TRUE);
     switch ($row['module_name']) {
         case 'xMOD_alt_doc.php':
             $table = $shortcut['table'];
             $recordid = $shortcut['recordid'];
             $icon = '';
             if ($shortcut['type'] == 'edit') {
                 // Creating the list of fields to include in the SQL query:
                 $selectFields = $this->fieldArray;
                 $selectFields[] = 'uid';
                 $selectFields[] = 'pid';
                 if ($table == 'pages') {
                     $selectFields[] = 'module';
                     $selectFields[] = 'extendToSubpages';
                     $selectFields[] = 'doktype';
                 }
                 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
                     $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
                 }
                 if ($GLOBALS['TCA'][$table]['ctrl']['type']) {
                     $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
                 }
                 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
                     $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
                 }
                 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
                     $selectFields[] = 't3ver_state';
                 }
                 // Unique list!
                 $selectFields = array_unique($selectFields);
                 $permissionClause = $table === 'pages' && $this->perms_clause ? ' AND ' . $this->perms_clause : '';
                 $sqlQueryParts = array('SELECT' => implode(',', $selectFields), 'FROM' => $table, 'WHERE' => 'uid IN (' . $recordid . ') ' . $permissionClause . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table));
                 $result = $databaseConnection->exec_SELECT_queryArray($sqlQueryParts);
                 $row = $databaseConnection->sql_fetch_assoc($result);
                 $icon = IconUtility::getSpriteIconForRecord($table, (array) $row, array('title' => $titleAttribute));
             } elseif ($shortcut['type'] == 'new') {
                 $icon = IconUtility::getSpriteIconForRecord($table, array(), array('title' => $titleAttribute));
             }
             break;
         case 'file_edit':
             $icon = IconUtility::getSpriteIcon('mimetypes-text-html', array('title' => $titleAttribute));
             break;
         case 'wizard_rte':
             $icon = IconUtility::getSpriteIcon('mimetypes-word', array('title' => $titleAttribute));
             break;
         default:
             if ($languageService->moduleLabels['tabs_images'][$row['module_name'] . '_tab']) {
                 $icon = $languageService->moduleLabels['tabs_images'][$row['module_name'] . '_tab'];
                 // Change icon of fileadmin references - otherwise it doesn't differ with Web->List
                 $icon = str_replace('mod/file/list/list.gif', 'mod/file/file.gif', $icon);
                 if (GeneralUtility::isAbsPath($icon)) {
                     $icon = '../' . PathUtility::stripPathSitePrefix($icon);
                 }
                 // @todo: hardcoded width as we don't have a way to address module icons with an API yet.
                 $icon = '<img src="' . htmlspecialchars($icon) . '" alt="' . $titleAttribute . '" width="16">';
             } else {
                 $icon = IconUtility::getSpriteIcon('empty-empty', array('title' => $titleAttribute));
             }
     }
     return $icon;
 }
 /**
  * Mandatory autofix function
  * Will run auto-fix on the result array. Echos status during processing.
  *
  * @param array $resultArray Result array from main() function
  * @return void
  */
 public function main_autoFix($resultArray)
 {
     foreach ($resultArray['multipleReferencesList'] as $key => $value) {
         $absFileName = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($key);
         if ($absFileName && @is_file($absFileName)) {
             echo 'Processing file: ' . $key . LF;
             $c = 0;
             foreach ($value as $hash => $recReference) {
                 if ($c == 0) {
                     echo '	Keeping ' . $key . ' for record "' . $recReference . '"' . LF;
                 } else {
                     // Create unique name for file:
                     $fileFunc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\File\BasicFileUtility::class);
                     $newName = $fileFunc->getUniqueName(basename($key), dirname($absFileName));
                     echo '	Copying ' . $key . ' to ' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($newName) . ' for record "' . $recReference . '": ';
                     if ($bypass = $this->cli_noExecutionCheck($recReference)) {
                         echo $bypass;
                     } else {
                         \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($absFileName, $newName);
                         clearstatcache();
                         if (@is_file($newName)) {
                             $sysRefObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
                             $error = $sysRefObj->setReferenceValue($hash, basename($newName));
                             if ($error) {
                                 echo '	ERROR:	TYPO3\\CMS\\Core\\Database\\ReferenceIndex::setReferenceValue(): ' . $error . LF;
                                 die;
                             } else {
                                 echo 'DONE';
                             }
                         } else {
                             echo '	ERROR: File "' . $newName . '" was not created!';
                         }
                     }
                     echo LF;
                 }
                 $c++;
             }
         } else {
             echo '	ERROR: File "' . $absFileName . '" was not found!';
         }
     }
 }
 /**
  * Returns the reference to a 'resource' in TypoScript.
  * This could be from the filesystem if '/' is found in the value $fileFromSetup, else from the resource-list
  *
  * @param string $fileFromSetup TypoScript "resource" data type value.
  * @return string Resulting filename, if any.
  * @todo Define visibility
  */
 public function getFileName($fileFromSetup)
 {
     $file = trim($fileFromSetup);
     if (!$file) {
         return;
     } elseif (strstr($file, '../')) {
         if ($this->tt_track) {
             $GLOBALS['TT']->setTSlogMessage('File path "' . $file . '" contained illegal string "../"!', 3);
         }
         return;
     }
     // Cache
     $hash = md5($file);
     if (isset($this->fileCache[$hash])) {
         return $this->fileCache[$hash];
     }
     if (substr($file, 0, 4) === 'EXT:') {
         $newFile = '';
         list($extKey, $script) = explode('/', substr($file, 4), 2);
         if ($extKey && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
             $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extKey);
             $newFile = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($extPath) . $script;
         }
         if (!@file_exists(PATH_site . $newFile)) {
             if ($this->tt_track) {
                 $GLOBALS['TT']->setTSlogMessage('Extension media file "' . $newFile . '" was not found!', 3);
             }
             return;
         } else {
             $file = $newFile;
         }
     }
     // if this is an URL, it can be returned directly
     $urlScheme = parse_url($file, PHP_URL_SCHEME);
     if ($urlScheme === 'https' || $urlScheme === 'http' || is_file(PATH_site . $file)) {
         return $file;
     }
     // Find
     if (strpos($file, '/') !== FALSE) {
         // If the file is in the media/ folder but it doesn't exist,
         // it is assumed that it's in the tslib folder
         if (GeneralUtility::isFirstPartOfStr($file, 'media/') && !file_exists($this->getFileName_backPath . $file)) {
             $file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('cms') . 'tslib/' . $file;
         }
         if (file_exists($this->getFileName_backPath . $file)) {
             $outFile = $file;
             $fileInfo = GeneralUtility::split_fileref($outFile);
             $OK = 0;
             foreach ($this->allowedPaths as $val) {
                 if (substr($fileInfo['path'], 0, strlen($val)) == $val) {
                     $OK = 1;
                     break;
                 }
             }
             if ($OK) {
                 $this->fileCache[$hash] = $outFile;
                 return $outFile;
             } elseif ($this->tt_track) {
                 $GLOBALS['TT']->setTSlogMessage('"' . $file . '" was not located in the allowed paths: (' . implode(',', $this->allowedPaths) . ')', 3);
             }
         } elseif ($this->tt_track) {
             $GLOBALS['TT']->setTSlogMessage('"' . $this->getFileName_backPath . $file . '" is not a file (non-uploads/.. resource, did not exist).', 3);
         }
     }
 }