/**
  * Loads "columns" of a $TCA table definition if extracted
  * to a "dynamicConfigFile". This method is called after each
  * single ext_tables.php files was included to immediately have
  * the full $TCA ready for the next extension.
  *
  * $TCA[$tableName]['ctrl']['dynamicConfigFile'] must be the
  * absolute path to a file.
  *
  * Be aware that 'dynamicConfigFile' is obsolete, and all TCA
  * table definitions should be moved to Configuration/TCA/tablename.php
  * to be fully loaded automatically.
  *
  * Example:
  * dynamicConfigFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'SysNote.php',
  *
  * @return void
  * @throws \RuntimeException
  * @internal Internal use ONLY. It is called by cache files and can not be protected. Do not call yourself!
  * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8. Table definition should be moved to <your_extension>/Configuration/TCA/<table_name>
  */
 public static function loadNewTcaColumnsConfigFiles()
 {
     global $TCA;
     foreach ($TCA as $tableName => $_) {
         if (!isset($TCA[$tableName]['columns'])) {
             $columnsConfigFile = $TCA[$tableName]['ctrl']['dynamicConfigFile'];
             if ($columnsConfigFile) {
                 GeneralUtility::logDeprecatedFunction();
                 if (GeneralUtility::isAbsPath($columnsConfigFile)) {
                     include $columnsConfigFile;
                 } else {
                     throw new \RuntimeException('Columns configuration file not found', 1341151261);
                 }
             }
         }
     }
 }
Exemple #2
1
 /**
  * Sets the path to the log file.
  *
  * Log file can be outside of given PATH_site directory
  *
  * @param  string  $logFile  Path to the log file, relative to PATH_site
  * @return  \TYPO3\CMS\Core\Log\Writer\WriterInterface
  */
 public function setLogFile($logFile)
 {
     if (strpos($logFile, '://') === false) {
         if (!GeneralUtility::isAbsPath($logFile)) {
             $logFile = PATH_site . $logFile;
         }
     }
     $this->logFile = $logFile;
     $this->openLogFile();
     return $this;
 }
 /**
  * Checks RSA configuration and creates warnings if necessary.
  *
  * @param array $warnings Warnings
  * @return void
  * @see 	t3lib_BEfunc::displayWarningMessages()
  */
 public function displayWarningMessages_postProcess(array &$warnings)
 {
     $backend = \TYPO3\CMS\Rsaauth\Backend\BackendFactory::getBackend();
     if ($backend instanceof \TYPO3\CMS\Rsaauth\Backend\CommandLineBackend) {
         // Not using the PHP extension!
         $warnings['rsaauth_cmdline'] = $GLOBALS['LANG']->sL('LLL:EXT:rsaauth/hooks/locallang.xml:hook_using_cmdline');
         // Check the path
         $extconf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['rsaauth']);
         $path = trim($extconf['temporaryDirectory']);
         if ($path == '') {
             // Path is empty
             $warnings['rsaauth'] = $GLOBALS['LANG']->sL('LLL:EXT:rsaauth/hooks/locallang.xml:hook_empty_directory');
         } elseif (!\TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath($path)) {
             // Path is not absolute
             $warnings['rsaauth'] = $GLOBALS['LANG']->sL('LLL:EXT:rsaauth/hooks/locallang.xml:hook_directory_not_absolute');
         } elseif (!@is_dir($path)) {
             // Path does not represent a directory
             $warnings['rsaauth'] = $GLOBALS['LANG']->sL('LLL:EXT:rsaauth/hooks/locallang.xml:hook_directory_not_exist');
         } elseif (!@is_writable($path)) {
             // Directory is not writable
             $warnings['rsaauth'] = $GLOBALS['LANG']->sL('LLL:EXT:rsaauth/hooks/locallang.xml:hook_directory_not_writable');
         } elseif (substr($path, 0, strlen(PATH_site)) == PATH_site) {
             // Directory is inside the site root
             $warnings['rsaauth'] = $GLOBALS['LANG']->sL('LLL:EXT:rsaauth/hooks/locallang.xml:hook_directory_inside_siteroot');
         }
     }
 }
 /**
  * Changes directory to the given path.
  *
  * @param string $path Path to change to
  * @return boolean
  */
 public function changeDirectory($path)
 {
     if (GeneralUtility::isAbsPath($path)) {
         $fullPath = $path;
     } else {
         $fullPath = $this->currentDirectory . $path;
     }
     // Make sure the path has a trailing slash
     if (strrpos($fullPath, '/') !== strlen($fullPath) - 1) {
         $fullPath .= '/';
     }
     $this->currentDirectory = $fullPath;
 }
 /**
  * Replace the EXT:extkey prefix with the appropriate path.
  *
  * @param string $encodedTemplateRootPath
  * @return string
  */
 public static function substituteExtensionPath($encodedTemplateRootPath)
 {
     $result = '';
     if (GeneralUtility::isFirstPartOfStr($encodedTemplateRootPath, 'EXT:')) {
         list($extKey, $script) = explode('/', substr($encodedTemplateRootPath, 4), 2);
         if ($extKey && ExtensionManagementUtility::isLoaded($extKey)) {
             $result = ExtensionManagementUtility::extPath($extKey) . $script;
         }
     } elseif (GeneralUtility::isAbsPath($encodedTemplateRootPath)) {
         $result = $encodedTemplateRootPath;
     } else {
         $result = PATH_site . $encodedTemplateRootPath;
     }
     return $result;
 }
 /**
  * Returns relative path to the icon filename for use in img-tags
  *
  * @param string $iconFilename Icon filename
  * @return string Icon filename with relative path
  * @see getModuleIconAbsolute()
  */
 protected function getModuleIconRelative($iconFilename)
 {
     if (GeneralUtility::isAbsPath($iconFilename)) {
         $iconFilename = '../' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($iconFilename);
     }
     return $iconFilename;
 }
 /**
  * For testing we must allow vfs:// as first part of file path
  *
  * @param string $path File path to evaluate
  * @return bool
  */
 public static function isAbsPath($path)
 {
     return self::isFirstPartOfStr($path, 'vfs://') || parent::isAbsPath($path);
 }
 /**
  * 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;
 }
Exemple #9
0
 /**
  * Indexing a regular document given as $file (relative to PATH_site, local file)
  *
  * @param string $file Relative Filename, relative to PATH_site. It can also be an absolute path as long as it is inside the lockRootPath (validated with \TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath()). Finally, if $contentTmpFile is set, this value can be anything, most likely a URL
  * @param bool $force If set, indexing is forced (despite content hashes, mtime etc).
  * @param string $contentTmpFile Temporary file with the content to read it from (instead of $file). Used when the $file is a URL.
  * @param string $altExtension File extension for temporary file.
  * @return void
  */
 public function indexRegularDocument($file, $force = false, $contentTmpFile = '', $altExtension = '')
 {
     // Init
     $fI = pathinfo($file);
     $ext = $altExtension ?: strtolower($fI['extension']);
     // Create abs-path:
     if (!$contentTmpFile) {
         if (!GeneralUtility::isAbsPath($file)) {
             // Relative, prepend PATH_site:
             $absFile = GeneralUtility::getFileAbsFileName(PATH_site . $file);
         } else {
             // Absolute, pass-through:
             $absFile = $file;
         }
         $absFile = GeneralUtility::isAllowedAbsPath($absFile) ? $absFile : '';
     } else {
         $absFile = $contentTmpFile;
     }
     // Indexing the document:
     if ($absFile && @is_file($absFile)) {
         if ($this->external_parsers[$ext]) {
             $fileInfo = stat($absFile);
             $cParts = $this->fileContentParts($ext, $absFile);
             foreach ($cParts as $cPKey) {
                 $this->internal_log = array();
                 $this->log_push('Index: ' . str_replace('.', '_', basename($file)) . ($cPKey ? '#' . $cPKey : ''), '');
                 $Pstart = GeneralUtility::milliseconds();
                 $subinfo = array('key' => $cPKey);
                 // Setting page range. This is "0" (zero) when no division is made, otherwise a range like "1-3"
                 $phash_arr = $this->file_phash_arr = $this->setExtHashes($file, $subinfo);
                 $check = $this->checkMtimeTstamp($fileInfo['mtime'], $phash_arr['phash']);
                 if ($check > 0 || $force) {
                     if ($check > 0) {
                         $this->log_setTSlogMessage('Indexing needed, reason: ' . $this->reasons[$check], 1);
                     } else {
                         $this->log_setTSlogMessage('Indexing forced by flag', 1);
                     }
                     // Check external file counter:
                     if ($this->externalFileCounter < $this->maxExternalFiles || $force) {
                         // Divide into title,keywords,description and body:
                         $this->log_push('Split content', '');
                         $contentParts = $this->readFileContent($ext, $absFile, $cPKey);
                         $this->log_pull();
                         if (is_array($contentParts)) {
                             // Calculating a hash over what is to be the actual content. (see indexTypo3PageContent())
                             $content_md5h = IndexedSearchUtility::md5inthash(implode($contentParts, ''));
                             if ($this->checkExternalDocContentHash($phash_arr['phash_grouping'], $content_md5h) || $force) {
                                 // Increment counter:
                                 $this->externalFileCounter++;
                                 // Splitting words
                                 $this->log_push('Extract words from content', '');
                                 $splitInWords = $this->processWordsInArrays($contentParts);
                                 $this->log_pull();
                                 // Analyse the indexed words.
                                 $this->log_push('Analyse the extracted words', '');
                                 $indexArr = $this->indexAnalyze($splitInWords);
                                 $this->log_pull();
                                 // Submitting page (phash) record
                                 $this->log_push('Submitting page', '');
                                 // Unfortunately I cannot determine WHEN a file is originally made - so I must return the modification time...
                                 $this->submitFilePage($phash_arr, $file, $subinfo, $ext, $fileInfo['mtime'], $fileInfo['ctime'], $fileInfo['size'], $content_md5h, $contentParts);
                                 $this->log_pull();
                                 // Check words and submit to word list if not there
                                 $this->log_push('Check word list and submit words', '');
                                 if (IndexedSearchUtility::isTableUsed('index_words')) {
                                     $this->checkWordList($indexArr);
                                     $this->submitWords($indexArr, $phash_arr['phash']);
                                 }
                                 $this->log_pull();
                                 // Set parsetime
                                 $this->updateParsetime($phash_arr['phash'], GeneralUtility::milliseconds() - $Pstart);
                             } else {
                                 // Update the timestamp
                                 $this->updateTstamp($phash_arr['phash'], $fileInfo['mtime']);
                                 $this->log_setTSlogMessage('Indexing not needed, the contentHash, ' . $content_md5h . ', has not changed. Timestamp updated.');
                             }
                         } else {
                             $this->log_setTSlogMessage('Could not index file! Unsupported extension.');
                         }
                     } else {
                         $this->log_setTSlogMessage('The limit of ' . $this->maxExternalFiles . ' has already been exceeded, so no indexing will take place this time.');
                     }
                 } else {
                     $this->log_setTSlogMessage('Indexing not needed, reason: ' . $this->reasons[$check]);
                 }
                 // Checking and setting sections:
                 $this->submitFile_section($phash_arr['phash']);
                 // Setting a section-record for the file. This is done also if the file is not indexed. Notice that section records are deleted when the page is indexed.
                 $this->log_pull();
             }
         } else {
             $this->log_setTSlogMessage('Indexing not possible; The extension "' . $ext . '" was not supported.');
         }
     } else {
         $this->log_setTSlogMessage('Indexing not possible; File "' . $absFile . '" not found or valid.');
     }
 }
Exemple #10
0
 /**
  * Function to load a HTML template file with markers.
  * When calling from own extension, use  syntax getHtmlTemplate('EXT:extkey/template.html')
  *
  * @param string $filename tmpl name, usually in the typo3/template/ directory
  * @return string HTML of template
  */
 public function getHtmlTemplate($filename)
 {
     // setting the name of the original HTML template
     $this->moduleTemplateFilename = $filename;
     if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
         $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
     }
     if (GeneralUtility::isFirstPartOfStr($filename, 'EXT:')) {
         $filename = GeneralUtility::getFileAbsFileName($filename, true, true);
     } elseif (!GeneralUtility::isAbsPath($filename)) {
         $filename = GeneralUtility::resolveBackPath($filename);
     } elseif (!GeneralUtility::isAllowedAbsPath($filename)) {
         $filename = '';
     }
     $htmlTemplate = '';
     if ($filename !== '') {
         $htmlTemplate = GeneralUtility::getUrl($filename);
     }
     return $htmlTemplate;
 }
 /**
  * Gets the icon for the shortcut
  *
  * @param array $row
  * @param array $shortcut
  * @return string Shortcut icon as img tag
  */
 protected function getShortcutIcon($row, $shortcut)
 {
     switch ($row['module_name']) {
         case 'xMOD_alt_doc.php':
             $table = $shortcut['table'];
             $recordid = $shortcut['recordid'];
             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') {
                     if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('cms')) {
                         $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 . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table) . \TYPO3\CMS\Backend\Utility\BackendUtility::versioningPlaceholderClause($table));
                 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($sqlQueryParts);
                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
                 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getIcon($table, $row, $this->backPath);
             } elseif ($shortcut['type'] == 'new') {
                 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getIcon($table, '', $this->backPath);
             }
             $icon = \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, $icon, '', 1);
             break;
         case 'xMOD_file_edit.php':
             $icon = 'gfx/edit_file.gif';
             break;
         case 'xMOD_wizard_rte.php':
             $icon = 'gfx/edit_rtewiz.gif';
             break;
         default:
             if ($GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'] . '_tab']) {
                 $icon = $GLOBALS['LANG']->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 (\TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath($icon)) {
                     $icon = '../' . substr($icon, strlen(PATH_site));
                 }
             } else {
                 $icon = 'gfx/dummy_module.gif';
             }
     }
     return '<img src="' . $icon . '" alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.shortcut', TRUE) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.shortcut', TRUE) . '" />';
 }
Exemple #12
0
 /**
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\Extension $extension
  * @param string $backupDir
  *
  * @return void
  */
 static function backupExtension(Model\Extension $extension, $backupDir)
 {
     if (empty($backupDir)) {
         throw new \Exception('Please define a backup directory in extension configuration!');
     } elseif (!GeneralUtility::validPathStr($backupDir)) {
         throw new \Exception('Backup directory is not a valid path: ' . $backupDir);
     } elseif (GeneralUtility::isAbsPath($backupDir)) {
         if (!GeneralUtility::isAllowedAbsPath($backupDir)) {
             throw new \Exception('Backup directory is not an allowed absolute path: ' . $backupDir);
         }
     } else {
         $backupDir = PATH_site . $backupDir;
     }
     if (strrpos($backupDir, '/') < strlen($backupDir) - 1) {
         $backupDir .= '/';
     }
     if (!is_dir($backupDir)) {
         throw new \Exception('Backup directory does not exist: ' . $backupDir);
     } elseif (!is_writable($backupDir)) {
         throw new \Exception('Backup directory is not writable: ' . $backupDir);
     }
     $backupDir .= $extension->getExtensionKey();
     // create a subdirectory for this extension
     if (!is_dir($backupDir)) {
         GeneralUtility::mkdir($backupDir);
     }
     if (strrpos($backupDir, '/') < strlen($backupDir) - 1) {
         $backupDir .= '/';
     }
     $backupDir .= date('Y-m-d-') . time();
     if (!is_dir($backupDir)) {
         GeneralUtility::mkdir($backupDir);
     }
     $extensionDir = substr($extension->getExtensionDir(), 0, strlen($extension->getExtensionDir()) - 1);
     try {
         self::recurse_copy($extensionDir, $backupDir);
     } catch (\Exception $e) {
         throw new \Exception('Code generation aborted:' . $e->getMessage());
     }
     self::log('Backup created in ' . $backupDir);
 }
 /**
  * Read image information from a associated text file.
  * The text file should have the same name as the image but
  * should end with '.txt'. Format
  * <pre>
  * {{title}}
  * {{description}}
  * {{author}}
  * </pre>
  *
  * @param	string		$image: path to the image
  * @return	array		title, description and author
  */
 public function readTextComment($image)
 {
     if (!\TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath($image)) {
         $image = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($image);
     }
     $data = array('title' => '', 'description' => '', 'author' => '');
     $textfile = substr($image, 0, strrpos($image, '.')) . '.txt';
     if (file_exists($textfile)) {
         $lines = file($textfile);
         if (count($lines)) {
             $data['title'] = $lines[0];
             $data['description'] = $lines[1];
             $data['author'] = $lines[2];
         }
     }
     return $data;
 }
 /**
  * Insert javascript-tags for google-analytics
  *
  * @param array $params
  * @param \TYPO3\CMS\Core\Page\PageRenderer $pObj
  * @return void
  */
 public function renderPreProcess($params, $pObj)
 {
     if (TYPO3_MODE === 'FE') {
         // Get plugin-configuration
         $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_libjsanalytics.']['settings.'];
         // Exclude the analytics-snippet on some pages
         $pageExclude = GeneralUtility::trimExplode(',', $conf['pageExclude'], true);
         // Generate script-tag for google-analytics if enabled
         if ((int) $conf['enable'] && !in_array($GLOBALS['TSFE']->id, $pageExclude)) {
             $analyticsPreScript = '';
             $analyticsPostScript = '';
             // Instruct analytics.js to use the name defined in typoscript
             if (!empty($conf['gaObjectName']) && $conf['gaObjectName'] !== 'ga') {
                 $gaObjectName = $conf['gaObjectName'];
             } else {
                 $gaObjectName = 'ga';
             }
             // Get filePath to analytics.js
             $analyticsJavascriptFile = Tools::getConfParam('localFile');
             if ($conf['forceCdn'] || !file_exists(PATH_site . $analyticsJavascriptFile)) {
                 $analyticsJavascriptFile = Tools::getConfParam('sourceFile');
             } else {
                 // If local file is not available, fall back to CDN
                 if (empty($analyticsJavascriptFile)) {
                     $analyticsJavascriptFile = Tools::getConfParam('sourceFile');
                 } else {
                     // Prefix file with absRefPrefix if path is relative
                     if (!GeneralUtility::isAbsPath($analyticsJavascriptFile)) {
                         $analyticsJavascriptFile = $GLOBALS['TSFE']->absRefPrefix . $analyticsJavascriptFile;
                     }
                     // Append filename with version numbers
                     $analyticsJavascriptFile = GeneralUtility::createVersionNumberedFilename($analyticsJavascriptFile);
                 }
             }
             // Insert different codeblocks for different integration (old/new)
             if ((int) $conf['alternative']) {
                 if ($conf['gaObjectName'] !== 'ga') {
                     $scriptTag .= LF . 'window.GoogleAnalyticsObject = \'' . $gaObjectName . '\';';
                 }
                 // Create an initial analytics() function
                 // The queued commands will be executed once analytics.js loads
                 $scriptTag .= LF . 'window.' . $gaObjectName . ' = window.' . $gaObjectName . ' || function() {' . '(' . $gaObjectName . '.q = ' . $gaObjectName . '.q || []).push(arguments)};';
                 // Set the time (as an integer) this tag was executed (Used for timing hits)
                 $scriptTag .= LF . $gaObjectName . '.l =+ new Date;';
                 // Compile final script-tag for analytics.js
                 $analyticsPostScript = LF . '<script src="' . $analyticsJavascriptFile . '" type="text/javascript" async="async"></script>';
             } else {
                 // Compile final script-tag for analytics.js
                 $analyticsPreScript = LF . '(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){' . LF . '(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),' . LF . 'm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)' . LF . '})(window,document,\'script\',\'' . $analyticsJavascriptFile . '\',\'' . $gaObjectName . '\');';
             }
             // Create the tracker
             foreach ($conf['gaObject.'] as $gaName => $gaTracker) {
                 // Set the name of the tracker if defined in typoscript
                 $trackerName = '';
                 if ($gaName !== 'default.') {
                     $trackerName = $gaName;
                 }
                 // Check if analytics objects are defined
                 if (is_array($gaTracker)) {
                     $scriptTag .= $this->iterateTrackerMethods($gaObjectName, $trackerName, $gaTracker);
                 }
             }
             // TEST/TODO
             // Add additional javascript to a single page if defined in PageTSConfig
             //debug($GLOBALS['TSFE']->page['TSconfig']);
             /*
              $pageTS = BackendUtility::getPagesTSconfig($GLOBALS['TSFE']->id, [$GLOBALS['TSFE']->id]);
              if (isset($pageTS['tx_libjsanalytics.'])) {
              $analyticsPageTS = $pageTS['tx_libjsanalytics.'];
              if (is_array($analyticsPageTS['additionalScript.'])) {
              $scriptTag .= LF . $this->getCobject($analyticsPageTS['additionalScript'], $analyticsPageTS['additionalScript.']);
              }
              }
             */
             // Compile final codeblock
             $scriptTag = '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . $analyticsPreScript . $scriptTag . LF . '/*]]>*/' . LF . '</script>' . $analyticsPostScript;
             // Add final code to HTML
             $pObj->addHeaderData($scriptTag);
         }
     }
 }
 /**
  * Validates index file path.
  *
  * @param array $submittedData
  * @param array $errors
  * @return void
  */
 protected function validateIndexFilePath(array &$submittedData, array &$errors)
 {
     if (GeneralUtility::isAbsPath($submittedData['indexFilePath'])) {
         $errors[] = 'scheduler.error.badIndexFilePath';
     } else {
         $testPath = GeneralUtility::getFileAbsFileName($submittedData['indexFilePath'], TRUE);
         if (!file_exists($testPath)) {
             if (!@touch($testPath)) {
                 $errors[] = 'scheduler.error.badIndexFilePath';
             } else {
                 unlink($testPath);
             }
         }
     }
 }
 /**
  * Returns relative path to the icon filename for use in img-tags
  *
  * @param string $iconFilename Icon filename
  * @return string Icon filename with relative path
  * @see getModuleIconAbsolute()
  */
 protected function getModuleIconRelative($iconFilename)
 {
     if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath($iconFilename)) {
         $iconFilename = '../' . substr($iconFilename, strlen(PATH_site));
     }
     return $this->backPath . $iconFilename;
 }
 /**
  * Returns relative filename for icon.
  *
  * @param string $Ifilename Absolute filename of the icon
  * @param string $backPath Backpath string to prepend the icon after made relative
  * @return void
  * @todo Define visibility
  */
 public function mIconFilename($Ifilename, $backPath)
 {
     // Change icon of fileadmin references - otherwise it doesn't differ with Web->List
     $Ifilename = str_replace('mod/file/list/list.gif', 'mod/file/file.gif', $Ifilename);
     if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath($Ifilename)) {
         $Ifilename = '../' . substr($Ifilename, strlen(PATH_site));
     }
     return $backPath . $Ifilename;
 }
 /**
  * @test
  */
 public function canSetTemplatePathAndFilename()
 {
     $provider = $this->getConfigurationProviderInstance();
     $record = $this->getBasicRecord();
     $template = 'test.html';
     $provider->setTemplatePathAndFilename($template);
     $this->assertContains($template, $provider->getTemplatePathAndFilename($record));
     $template = NULL;
     $provider->setTemplatePathAndFilename($template);
     $this->assertSame($template, $provider->getTemplatePathAndFilename($record));
     $template = 'EXT:flux/Tests/Fixtures/Templates/Content/Dummy.html';
     $provider->setTemplatePathAndFilename($template);
     $this->assertTrue(GeneralUtility::isAbsPath($provider->getTemplatePathAndFilename($record)), 'EXT relative paths are transformed');
     $this->assertStringEndsWith('flux/Tests/Fixtures/Templates/Content/Dummy.html', $provider->getTemplatePathAndFilename($record), 'EXT relative paths are transformed');
     $template = '/foo/Resources/Private/Foo/Bar.html';
     $provider->setTemplatePathAndFilename($template);
     $this->assertSame($template, $provider->getTemplatePathAndFilename($record), 'Absolute paths are not transformed');
 }
 /**
  * Checks if the $fontFile is already at an absolute path and if not, prepends the correct path.
  * Use PATH_site unless we are in the backend.
  * Call it by \TYPO3\CMS\Core\Imaging\GraphicalFunctions::prependAbsolutePath()
  *
  * @param string $fontFile The font file
  * @return string The font file with absolute path.
  */
 public function prependAbsolutePath($fontFile)
 {
     $absPath = defined('PATH_typo3') ? dirname(PATH_thisScript) . '/' : PATH_site;
     $fontFile = GeneralUtility::isAbsPath($fontFile) ? $fontFile : GeneralUtility::resolveBackPath($absPath . $fontFile);
     return $fontFile;
 }
 /**
  * Returns relative filename to the $Ifilename (for use in img-tags)
  *
  * @param 	string		Icon filename
  * @param 	string		Back path
  * @return 	string		Result
  * @see mIconFile()
  * @todo Define visibility
  */
 public function mIconFilename($Ifilename, $backPath)
 {
     if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath($Ifilename)) {
         $Ifilename = '../' . substr($Ifilename, strlen(PATH_site));
     }
     return $backPath . $Ifilename;
 }
Exemple #21
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);
                 }
             }
         }
     }
 }
 /**
  * Checks if the $fontFile is already at an absolute path and if not, prepends the PATH_site.
  * Call it by \TYPO3\CMS\Core\Imaging\GraphicalFunctions::prependAbsolutePath()
  *
  * @param string $fontFile The font file
  * @return string The font file with absolute path.
  * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 - use GeneralUtility::getFileAbsFileName()
  */
 public function prependAbsolutePath($fontFile)
 {
     GeneralUtility::logDeprecatedFunction();
     return GeneralUtility::isAbsPath($fontFile) ? $fontFile : PATH_site . $fontFile;
 }
 /**
  * Cleans $theDir for slashes in the end of the string and returns the new path, if it exists on the server.
  *
  * @param string $theDir Absolute path to directory
  * @return string The directory path if it existed as was valid to access.
  * @access private
  * @see filelist()
  */
 public function clean_directory($theDir)
 {
     // proceeds if no '//', '..' or '\' is in the $theFile
     if (GeneralUtility::validPathStr($theDir)) {
         // Removes all dots, slashes and spaces after a path...
         $theDir = preg_replace('/[\\/\\. ]*$/', '', $theDir);
         if (!GeneralUtility::isAbsPath($theDir) && @is_dir($theDir)) {
             return $theDir;
         }
     }
     return '';
 }
 /**
  * Copied from core GeneralUtility::getFileAbsFileName with minor mods (no restricting to paths inside
  * TYPO3_ROOT and resolve '../' using `realpath()`)
  *
  * @param $filename
  * @param bool $onlyRelative If $onlyRelative is set (which it is by default), then only return values relative to the current PATH_site is accepted.
  * @return string
  */
 protected function absolutizeFileName($filename, $onlyRelative = TRUE)
 {
     if ((string) $filename === '') {
         return '';
     }
     $relPathPrefix = PATH_site;
     // Extension
     if (strpos($filename, 'EXT:') === 0) {
         list($extKey, $local) = explode('/', substr($filename, 4), 2);
         $filename = '';
         if ((string) $extKey !== '' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey) && (string) $local !== '') {
             $filename = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extKey) . $local;
         }
     } elseif (!GeneralUtility::isAbsPath($filename)) {
         // relative. Prepended with $relPathPrefix
         $filename = $relPathPrefix . $filename;
     } elseif ($onlyRelative && !GeneralUtility::isFirstPartOfStr($filename, $relPathPrefix)) {
         // absolute, but set to blank if not allowed
         $filename = '';
     }
     if ((string) $filename !== '') {
         // checks backpath.
         return GeneralUtility::resolveBackPath($filename);
     }
     return '';
 }
 /**
  * Renders the actual image
  *
  * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject
  * @param $file
  * @param array $fileConfiguration
  * @return array
  */
 public function getImgResource(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject, $file, array $fileConfiguration)
 {
     if ($fileConfiguration['import.']) {
         $ifile = $contentObject->stdWrap('', $fileConfiguration['import.']);
         if ($ifile) {
             $file = $fileConfiguration['import'] . $ifile;
         }
     }
     if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($file)) {
         $file = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory')->getFileObject($file);
     }
     if ($file instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
         $theImage = $file->getForLocalProcessing(FALSE);
     } else {
         // clean ../ sections of the path and resolve to proper string.
         // This is necessary for the \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService to work.
         $file = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($file);
         $theImage = $GLOBALS['TSFE']->tmpl->getFileName($file);
         if (!$theImage) {
             return array();
         }
     }
     $fileConfiguration = $this->processFileConfiguration($fileConfiguration, $contentObject);
     $maskArray = $fileConfiguration['m.'];
     $maskImages = array();
     // Must render mask images and include in hash-calculating - else we
     // cannot be sure the filename is unique for the setup!
     if (is_array($maskArray)) {
         $maskImages['m_mask'] = $this->getImgResource($contentObject, $maskArray['mask'], $maskArray['mask.']);
         $maskImages['m_bgImg'] = $this->getImgResource($contentObject, $maskArray['bgImg'], $maskArray['bgImg.']);
         $maskImages['m_bottomImg'] = $this->getImgResource($contentObject, $maskArray['bottomImg'], $maskArray['bottomImg.']);
         $maskImages['m_bottomImg_mask'] = $this->getImgResource($contentObject, $maskArray['bottomImg_mask'], $maskArray['bottomImg_mask.']);
     }
     // TODO use \TYPO3\CMS\Core\Resource\FileInterface here
     if ($file instanceof \TYPO3\CMS\Core\Resource\FileReference) {
         $hash = $file->getOriginalFile()->calculateChecksum();
     } else {
         $hash = \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5($theImage . serialize($fileConfiguration) . serialize($maskImages));
     }
     if (isset($GLOBALS['TSFE']->tmpl->fileCache[$hash])) {
         return $GLOBALS['TSFE']->tmpl->fileCache[$hash];
     }
     /** @var $gifCreator tslib_gifbuilder */
     $gifCreator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_gifbuilder');
     $gifCreator->init();
     if ($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix']) {
         $filename = basename($theImage);
         // Remove extension
         $filename = substr($filename, 0, strrpos($filename, '.'));
         $tempFilePrefixLength = intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix']);
         if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
             /** @var $t3libCsInstance \TYPO3\CMS\Core\Charset\CharsetConverter */
             $t3libCsInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
             $filenamePrefix = $t3libCsInstance->substr('utf-8', $filename, 0, $tempFilePrefixLength);
         } else {
             // Strip everything non-ascii
             $filename = preg_replace('/[^A-Za-z0-9_-]/', '', trim($filename));
             $filenamePrefix = substr($filename, 0, $tempFilePrefixLength);
         }
         $gifCreator->filenamePrefix = $filenamePrefix . '_';
         unset($filename);
     }
     if ($fileConfiguration['sample']) {
         $gifCreator->scalecmd = '-sample';
         $GLOBALS['TT']->setTSlogMessage('Sample option: Images are scaled with -sample.');
     }
     if ($fileConfiguration['alternativeTempPath'] && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'], $fileConfiguration['alternativeTempPath'])) {
         $gifCreator->tempPath = $fileConfiguration['alternativeTempPath'];
         $GLOBALS['TT']->setTSlogMessage('Set alternativeTempPath: ' . $fileConfiguration['alternativeTempPath']);
     }
     if (!trim($fileConfiguration['ext'])) {
         $fileConfiguration['ext'] = 'web';
     }
     $options = array();
     if ($fileConfiguration['maxW']) {
         $options['maxW'] = $fileConfiguration['maxW'];
     }
     if ($fileConfiguration['maxH']) {
         $options['maxH'] = $fileConfiguration['maxH'];
     }
     if ($fileConfiguration['minW']) {
         $options['minW'] = $fileConfiguration['minW'];
     }
     if ($fileConfiguration['minH']) {
         $options['minH'] = $fileConfiguration['minH'];
     }
     if ($fileConfiguration['noScale']) {
         $options['noScale'] = $fileConfiguration['noScale'];
     }
     $fileInformation = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($theImage);
     $imgExt = strtolower($fileInformation['fileext']) == $gifCreator->gifExtension ? $gifCreator->gifExtension : 'jpg';
     // If no mask  is used or ImageMagick is disabled, processing is quite simple
     if (!is_array($maskArray) || !$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
         $fileConfiguration['params'] = $this->modifyImageMagickStripProfileParameters($fileConfiguration['params'], $fileConfiguration);
         $GLOBALS['TSFE']->tmpl->fileCache[$hash] = $gifCreator->imageMagickConvert($theImage, $fileConfiguration['ext'], $fileConfiguration['width'], $fileConfiguration['height'], $fileConfiguration['params'], $fileConfiguration['frame'], $options);
         if (($fileConfiguration['reduceColors'] || $imgExt === 'png' && !$gifCreator->png_truecolor) && is_file($GLOBALS['TSFE']->tmpl->fileCache[$hash][3])) {
             $reduced = $gifCreator->IMreduceColors($GLOBALS['TSFE']->tmpl->fileCache[$hash][3], \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fileConfiguration['reduceColors'], 256, $gifCreator->truecolorColors, 256));
             if (is_file($reduced)) {
                 unlink($GLOBALS['TSFE']->tmpl->fileCache[$hash][3]);
                 rename($reduced, $GLOBALS['TSFE']->tmpl->fileCache[$hash][3]);
             }
         }
     } else {
         // Filename:
         $fileDestination = $gifCreator->tempPath . $hash . '.' . $imgExt;
         // Generate!
         if (!file_exists($fileDestination)) {
             $this->processMask($maskImages, $gifCreator, $theImage, $fileConfiguration, $options, $fileDestination);
         }
         // Finish off
         if (($fileConfiguration['reduceColors'] || $imgExt === 'png' && !$gifCreator->png_truecolor) && is_file($fileDestination)) {
             $reduced = $gifCreator->IMreduceColors($fileDestination, \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($fileConfiguration['reduceColors'], 256, $gifCreator->truecolorColors, 256));
             if (is_file($reduced)) {
                 unlink($fileDestination);
                 rename($reduced, $fileDestination);
             }
         }
         $GLOBALS['TSFE']->tmpl->fileCache[$hash] = $gifCreator->getImageDimensions($fileDestination);
     }
     $GLOBALS['TSFE']->tmpl->fileCache[$hash]['origFile'] = $theImage;
     // This is needed by tslib_gifbuilder, in order for the setup-array to create a unique filename hash.
     $GLOBALS['TSFE']->tmpl->fileCache[$hash]['origFile_mtime'] = @filemtime($theImage);
     $GLOBALS['TSFE']->tmpl->fileCache[$hash]['fileCacheHash'] = $hash;
     if ($file instanceof \TYPO3\CMS\Core\Resource\FileInterface && \TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath($GLOBALS['TSFE']->tmpl->fileCache[$hash][3])) {
         $GLOBALS['TSFE']->tmpl->fileCache[$hash][3] = $file->getPublicUrl();
     }
     $imageResource = $GLOBALS['TSFE']->tmpl->fileCache[$hash];
     return $imageResource;
 }
 /**
  * Checks if the given path is absolute.
  *
  * @param string $path Path to check
  * @return boolean
  */
 public function isAbsolutePath($path)
 {
     return GeneralUtility::isAbsPath($path);
 }